Debian Codegraph @

prometheus/collectors/expvar_collector.go

raw
1 // Copyright 2021 The Prometheus Authors
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package collectors
15
16 import "github.com/prometheus/client_golang/prometheus"
17
18 // NewExpvarCollector returns a newly allocated expvar Collector.
19 //
20 // An expvar Collector collects metrics from the expvar interface. It provides a
21 // quick way to expose numeric values that are already exported via expvar as
22 // Prometheus metrics. Note that the data models of expvar and Prometheus are
23 // fundamentally different, and that the expvar Collector is inherently slower
24 // than native Prometheus metrics. Thus, the expvar Collector is probably great
25 // for experiments and prototyping, but you should seriously consider a more
26 // direct implementation of Prometheus metrics for monitoring production
27 // systems.
28 //
29 // The exports map has the following meaning:
30 //
31 // The keys in the map correspond to expvar keys, i.e. for every expvar key you
32 // want to export as Prometheus metric, you need an entry in the exports
33 // map. The descriptor mapped to each key describes how to export the expvar
34 // value. It defines the name and the help string of the Prometheus metric
35 // proxying the expvar value. The type will always be Untyped.
36 //
37 // For descriptors without variable labels, the expvar value must be a number or
38 // a bool. The number is then directly exported as the Prometheus sample
39 // value. (For a bool, 'false' translates to 0 and 'true' to 1). Expvar values
40 // that are not numbers or bools are silently ignored.
41 //
42 // If the descriptor has one variable label, the expvar value must be an expvar
43 // map. The keys in the expvar map become the various values of the one
44 // Prometheus label. The values in the expvar map must be numbers or bools again
45 // as above.
46 //
47 // For descriptors with more than one variable label, the expvar must be a
48 // nested expvar map, i.e. where the values of the topmost map are maps again
49 // etc. until a depth is reached that corresponds to the number of labels. The
50 // leaves of that structure must be numbers or bools as above to serve as the
51 // sample values.
52 //
53 // Anything that does not fit into the scheme above is silently ignored.
54 func NewExpvarCollector(exports map[string]*prometheus.Desc) prometheus.Collector {
55 //nolint:staticcheck // Ignore SA1019 until v2.
56 return prometheus.NewExpvarCollector(exports)
57 }