2014-06-04 04:12:34 -07:00
|
|
|
// +build !noattributes
|
|
|
|
|
|
|
|
package collector
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/golang/glog"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
|
|
|
|
|
|
|
type attributesCollector struct {
|
2014-06-26 10:20:36 -07:00
|
|
|
config Config
|
2014-11-24 18:00:17 -08:00
|
|
|
metric *prometheus.GaugeVec
|
2014-06-04 04:12:34 -07: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 10:20:36 -07:00
|
|
|
func NewAttributesCollector(config Config) (Collector, error) {
|
|
|
|
labelNames := []string{}
|
2014-11-24 18:00:17 -08:00
|
|
|
for l := range config.Attributes {
|
2014-06-26 10:20:36 -07:00
|
|
|
labelNames = append(labelNames, l)
|
|
|
|
}
|
2014-11-24 18:00:17 -08:00
|
|
|
|
|
|
|
return &attributesCollector{
|
|
|
|
config: config,
|
|
|
|
metric: prometheus.NewGaugeVec(
|
|
|
|
prometheus.GaugeOpts{
|
|
|
|
Namespace: Namespace,
|
|
|
|
Name: "attributes",
|
|
|
|
Help: "The node_exporter attributes.",
|
|
|
|
},
|
|
|
|
labelNames,
|
|
|
|
),
|
|
|
|
}, nil
|
2014-06-04 04:12:34 -07:00
|
|
|
}
|
|
|
|
|
2014-10-29 07:16:43 -07:00
|
|
|
func (c *attributesCollector) Update(ch chan<- prometheus.Metric) (err error) {
|
2014-06-04 04:12:34 -07:00
|
|
|
glog.V(1).Info("Set node_attributes{%v}: 1", c.config.Attributes)
|
2014-11-24 18:00:17 -08:00
|
|
|
c.metric.Reset()
|
|
|
|
c.metric.With(c.config.Attributes).Set(1)
|
|
|
|
c.metric.Collect(ch)
|
2014-10-29 07:16:43 -07:00
|
|
|
return err
|
2014-06-04 04:12:34 -07:00
|
|
|
}
|