2014-06-04 13:12:34 +02:00
|
|
|
// +build !noattributes
|
|
|
|
|
|
|
|
package collector
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/golang/glog"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type attributesCollector struct {
|
2014-06-26 19:20:36 +02:00
|
|
|
config Config
|
2014-11-25 03:00:17 +01:00
|
|
|
metric *prometheus.GaugeVec
|
2014-06-04 13:12:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
Factories["attributes"] = NewAttributesCollector
|
|
|
|
}
|
|
|
|
|
|
|
|
// Takes a config struct and prometheus registry and returns a new Collector exposing
|
|
|
|
// labels from the config.
|
2014-06-26 19:20:36 +02:00
|
|
|
func NewAttributesCollector(config Config) (Collector, error) {
|
|
|
|
labelNames := []string{}
|
2014-11-25 03:00:17 +01:00
|
|
|
for l := range config.Attributes {
|
2014-06-26 19:20:36 +02:00
|
|
|
labelNames = append(labelNames, l)
|
|
|
|
}
|
2014-11-25 03:00:17 +01:00
|
|
|
|
|
|
|
return &attributesCollector{
|
|
|
|
config: config,
|
|
|
|
metric: prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Namespace: Namespace,
|
|
|
|
Name: "attributes",
|
|
|
|
Help: "The node_exporter attributes.",
|
|
|
|
},
|
|
|
|
labelNames,
|
|
|
|
),
|
|
|
|
}, nil
|
2014-06-04 13:12:34 +02:00
|
|
|
}
|
|
|
|
|
2014-10-29 15:16:43 +01:00
|
|
|
func (c *attributesCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
2014-06-04 13:12:34 +02:00
|
|
|
glog.V(1).Info("Set node_attributes{%v}: 1", c.config.Attributes)
|
2014-11-25 03:00:17 +01:00
|
|
|
c.metric.Reset()
|
|
|
|
c.metric.With(c.config.Attributes).Set(1)
|
|
|
|
c.metric.Collect(ch)
|
2014-10-29 15:16:43 +01:00
|
|
|
return err
|
2014-06-04 13:12:34 +02:00
|
|
|
}
|