MCPcopy
hub / github.com/prometheus/client_golang / ExampleMetricVec

Function ExampleMetricVec

prometheus/example_metricvec_test.go:109–133  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

107}
108
109func ExampleMetricVec() {
110 infoVec := NewInfoVec(
111 "library_version_info",
112 "Versions of the libraries used in this binary.",
113 []string{"library", "version"},
114 )
115
116 infoVec.WithLabelValues("prometheus/client_golang", "1.7.1")
117 infoVec.WithLabelValues("k8s.io/client-go", "0.18.8")
118
119 // Just for demonstration, let's check the state of the InfoVec by
120 // registering it with a custom registry and then let it collect the
121 // metrics.
122 reg := prometheus.NewRegistry()
123 reg.MustRegister(infoVec)
124
125 metricFamilies, err := reg.Gather()
126 if err != nil || len(metricFamilies) != 1 {
127 panic("unexpected behavior of custom test registry")
128 }
129 fmt.Println(toNormalizedJSON(metricFamilies[0]))
130
131 // Output:
132 // {"name":"library_version_info","help":"Versions of the libraries used in this binary.","type":"GAUGE","metric":[{"label":[{"name":"library","value":"k8s.io/client-go"},{"name":"version","value":"0.18.8"}],"gauge":{"value":1}},{"label":[{"name":"library","value":"prometheus/client_golang"},{"name":"version","value":"1.7.1"}],"gauge":{"value":1}}]}
133}

Callers

nothing calls this directly

Calls 7

WithLabelValuesMethod · 0.95
MustRegisterMethod · 0.95
GatherMethod · 0.95
NewRegistryFunction · 0.92
NewInfoVecFunction · 0.85
toNormalizedJSONFunction · 0.85
PrintlnMethod · 0.65

Tested by

no test coverage detected