()
| 107 | } |
| 108 | |
| 109 | func 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 | } |
nothing calls this directly
no test coverage detected