gitlab.com/gitlab-org/labkit@v1.21.0/monitoring/examples_test.go (about)

     1  package monitoring_test
     2  
     3  import (
     4  	"log"
     5  	"runtime/debug"
     6  
     7  	"gitlab.com/gitlab-org/labkit/monitoring"
     8  )
     9  
    10  func ExampleStart() {
    11  	go func() {
    12  		// Add the standard version and build time labels
    13  		buildInfoOption := monitoring.WithBuildInformation("0.1.1", "2019-09-01T00:22:00Z")
    14  		if buildInfo, ok := debug.ReadBuildInfo(); ok {
    15  			// If we're able to read the Go build information from
    16  			// the currently running binary then we use that as
    17  			// build info option instead. Binaries that are built
    18  			// from a Go project with module support should always
    19  			// have build info available.
    20  			buildInfoOption = monitoring.WithGoBuildInformation(buildInfo)
    21  		}
    22  
    23  		log.Fatal(monitoring.Start(
    24  			// Listen on port 7822 on all interfaces
    25  			monitoring.WithListenerAddress(":7822"),
    26  			// Add the standard version and build time labels
    27  			buildInfoOption,
    28  			// Add any additional application-specific labels to the `gitlab_build_info` metric
    29  			monitoring.WithBuildExtraLabels(map[string]string{
    30  				"git_version": "2.0.0",
    31  			}),
    32  		))
    33  	}()
    34  }