File: examples_test.go

package info (click to toggle)
golang-gitlab-gitlab-org-labkit 1.17.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,092 kB
  • sloc: sh: 210; javascript: 49; makefile: 4
file content (34 lines) | stat: -rw-r--r-- 1,039 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package monitoring_test

import (
	"log"
	"runtime/debug"

	"gitlab.com/gitlab-org/labkit/monitoring"
)

func ExampleStart() {
	go func() {
		// Add the standard version and build time labels
		buildInfoOption := monitoring.WithBuildInformation("0.1.1", "2019-09-01T00:22:00Z")
		if buildInfo, ok := debug.ReadBuildInfo(); ok {
			// If we're able to read the Go build information from
			// the currently running binary then we use that as
			// build info option instead. Binaries that are built
			// from a Go project with module support should always
			// have build info available.
			buildInfoOption = monitoring.WithGoBuildInformation(buildInfo)
		}

		log.Fatal(monitoring.Start(
			// Listen on port 7822 on all interfaces
			monitoring.WithListenerAddress(":7822"),
			// Add the standard version and build time labels
			buildInfoOption,
			// Add any additional application-specific labels to the `gitlab_build_info` metric
			monitoring.WithBuildExtraLabels(map[string]string{
				"git_version": "2.0.0",
			}),
		))
	}()
}