Browse Source

Get the graph list and register metrics on demand

Instead of registering them when getting the graph list.
pull/2/merge
Johannes 'fish' Ziemke 12 years ago
parent
commit
d38d0a7730
  1. 27
      exporter/munin_collector.go

27
exporter/munin_collector.go

@ -155,14 +155,8 @@ func (c *muninCollector) muninConfig(name string) (config map[string]map[string]
return config, graphConfig, err
}
func (c *muninCollector) registerMetrics() (err error) {
items, err := c.muninList()
if err != nil {
return fmt.Errorf("Couldn't get graph list: %s", err)
}
for _, name := range items {
c.graphs = append(c.graphs, name)
func (c *muninCollector) registerMetric(name string) (err error) {
configs, graphConfig, err := c.muninConfig(name)
if err != nil {
return fmt.Errorf("Couldn't get config for graph %s: %s", name, err)
@ -179,14 +173,18 @@ func (c *muninCollector) registerMetrics() (err error) {
c.gaugePerMetric[metricName] = gauge
c.registry.Register(metricName, desc, prometheus.NilLabels, gauge)
}
}
return err
return nil
}
func (c *muninCollector) Update() (updates int, err error) {
err = c.registerMetrics()
items, err := c.muninList()
if err != nil {
return updates, fmt.Errorf("Couldn't register metrics: %s", err)
return updates, fmt.Errorf("Couldn't get graph list: %s", err)
}
for _, name := range items {
c.graphs = append(c.graphs, name)
}
for _, graph := range c.graphs {
@ -215,6 +213,12 @@ func (c *muninCollector) Update() (updates int, err error) {
continue
}
key, value_s := strings.Split(parts[0], ".")[0], parts[1]
name := graph + "-" + key
if _, ok := c.gaugePerMetric[name]; !ok {
if err := c.registerMetric(name); err != nil {
return updates, err
}
}
value, err := strconv.ParseFloat(value_s, 64)
if err != nil {
debug(c.Name(), "Couldn't parse value in line %s, malformed?", line)
@ -223,7 +227,6 @@ func (c *muninCollector) Update() (updates int, err error) {
labels := map[string]string{
"hostname": c.hostname,
}
name := graph + "-" + key
debug(c.Name(), "Set %s{%s}: %f\n", name, labels, value)
c.gaugePerMetric[name].Set(labels, value)
updates++

Loading…
Cancel
Save