mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-12-28 23:19:46 -08:00
1c17481a42
Switch to Update using the Collecter Collect interface, due to not knowing all metricnames in all modules beforehand we can't use Describe and thus the full Collecter interface. Remove 'updates', it's meaning varies by module and doesn't add much.
50 lines
1 KiB
Go
50 lines
1 KiB
Go
// +build !noattributes
|
|
|
|
package collector
|
|
|
|
import (
|
|
"github.com/golang/glog"
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
)
|
|
|
|
var (
|
|
attributes *prometheus.GaugeVec
|
|
)
|
|
|
|
type attributesCollector struct {
|
|
config Config
|
|
}
|
|
|
|
func init() {
|
|
Factories["attributes"] = NewAttributesCollector
|
|
}
|
|
|
|
// Takes a config struct and prometheus registry and returns a new Collector exposing
|
|
// labels from the config.
|
|
func NewAttributesCollector(config Config) (Collector, error) {
|
|
c := attributesCollector{
|
|
config: config,
|
|
}
|
|
labelNames := []string{}
|
|
for l := range c.config.Attributes {
|
|
labelNames = append(labelNames, l)
|
|
}
|
|
attributes = prometheus.NewGaugeVec(
|
|
prometheus.GaugeOpts{
|
|
Namespace: Namespace,
|
|
Name: "attributes",
|
|
Help: "The node_exporter attributes.",
|
|
},
|
|
labelNames,
|
|
)
|
|
return &c, nil
|
|
}
|
|
|
|
func (c *attributesCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
|
glog.V(1).Info("Set node_attributes{%v}: 1", c.config.Attributes)
|
|
attributes.Reset()
|
|
attributes.With(c.config.Attributes).Set(1)
|
|
attributes.Collect(ch)
|
|
return err
|
|
}
|