From f79443b7bd8387ecd6a6b0db9c6f77fc47d26dc5 Mon Sep 17 00:00:00 2001 From: Kalebris Date: Tue, 31 Jul 2018 14:21:58 +0200 Subject: [PATCH 1/8] adding the --quite flag to make logging less verbose --- munin_exporter.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/munin_exporter.go b/munin_exporter.go index e7768e6..62f02ce 100644 --- a/munin_exporter.go +++ b/munin_exporter.go @@ -26,6 +26,7 @@ var ( listeningPath = flag.String("listeningPath", "/metrics", "Path on which to expose Prometheus metrics.") muninAddress = flag.String("muninAddress", "localhost:4949", "munin-node address.") muninScrapeInterval = flag.Int("muninScrapeInterval", 60, "Interval in seconds between scrapes.") + quite = flag.Bool("quite", false, "Makes logging a bit more quite") globalConn net.Conn hostname string graphs []string @@ -239,7 +240,9 @@ func fetchMetrics() (err error) { return err } if len(line) == 1 && line[0] == '.' { - log.Printf("End of list") + if !*quite { + log.Printf("End of list") + } break } @@ -255,12 +258,18 @@ func fetchMetrics() (err error) { continue } name := strings.Replace(graph+"_"+key, "-", "_", -1) - log.Printf("%s: %f\n", name, value) + if !*quite { + log.Printf("%s: %f\n", name, value) + } _, isGauge := gaugePerMetric[name] if isGauge { gaugePerMetric[name].WithLabelValues(hostname, graph, key).Set(value) - } else { + continue + } + _, isCounter := counterPerMetric[name] + if isCounter { counterPerMetric[name].WithLabelValues(hostname, graph, key).Add(value) + continue } } } @@ -278,7 +287,9 @@ func main() { func() { for { - log.Printf("Scraping") + if !*quite { + log.Printf("Scraping") + } err := fetchMetrics() if err != nil { log.Printf("Error occured when trying to fetch metrics: %s", err) From 747ce9e19634fd3704b1d4308b65fee06d03dbdc Mon Sep 17 00:00:00 2001 From: Kalebris Date: Fri, 3 Aug 2018 15:00:41 +0200 Subject: [PATCH 2/8] fixed spelling --- munin_exporter.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/munin_exporter.go b/munin_exporter.go index 62f02ce..121b7a7 100644 --- a/munin_exporter.go +++ b/munin_exporter.go @@ -26,7 +26,7 @@ var ( listeningPath = flag.String("listeningPath", "/metrics", "Path on which to expose Prometheus metrics.") muninAddress = flag.String("muninAddress", "localhost:4949", "munin-node address.") muninScrapeInterval = flag.Int("muninScrapeInterval", 60, "Interval in seconds between scrapes.") - quite = flag.Bool("quite", false, "Makes logging a bit more quite") + quiet = flag.Bool("quiet", false, "Makes logging a bit more quiet") globalConn net.Conn hostname string graphs []string @@ -240,7 +240,7 @@ func fetchMetrics() (err error) { return err } if len(line) == 1 && line[0] == '.' { - if !*quite { + if !*quiet { log.Printf("End of list") } break @@ -258,7 +258,7 @@ func fetchMetrics() (err error) { continue } name := strings.Replace(graph+"_"+key, "-", "_", -1) - if !*quite { + if !*quiet { log.Printf("%s: %f\n", name, value) } _, isGauge := gaugePerMetric[name] @@ -287,7 +287,7 @@ func main() { func() { for { - if !*quite { + if !*quiet { log.Printf("Scraping") } err := fetchMetrics() From d544c514faa497624f5fe971d76f8b9af15c3514 Mon Sep 17 00:00:00 2001 From: Kalebris Date: Wed, 5 Sep 2018 18:55:18 +0200 Subject: [PATCH 3/8] changing the counter metrics from NewCounterVec to MustNewConstMetric as the .Add() function incremeants the counter with the value while we need to be able to set the metric to the actual value --- munin_exporter.go | 71 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 17 deletions(-) diff --git a/munin_exporter.go b/munin_exporter.go index 62f02ce..3fcab15 100644 --- a/munin_exporter.go +++ b/munin_exporter.go @@ -26,20 +26,61 @@ var ( listeningPath = flag.String("listeningPath", "/metrics", "Path on which to expose Prometheus metrics.") muninAddress = flag.String("muninAddress", "localhost:4949", "munin-node address.") muninScrapeInterval = flag.Int("muninScrapeInterval", 60, "Interval in seconds between scrapes.") - quite = flag.Bool("quite", false, "Makes logging a bit more quite") + quiet = flag.Bool("quiet", false, "Makes logging a bit more quiet") globalConn net.Conn hostname string graphs []string gaugePerMetric map[string]*prometheus.GaugeVec - counterPerMetric map[string]*prometheus.CounterVec + counterPerMetric map[string]*MuninCounter muninBanner *regexp.Regexp ) +type MuninCounter struct { + counterDesc *prometheus.Desc + value float64 + current_labels []string +} + +func (c *MuninCounter) Describe(ch chan<- *prometheus.Desc) { + ch <- c.counterDesc +} + +func (c *MuninCounter) Collect(ch chan<- prometheus.Metric) { + if (len(c.current_labels) ==0 ) { + c.current_labels=[]string{"ThisMunin", "Plugin", "IsBroken"} + } + ch <- prometheus.MustNewConstMetric( + c.counterDesc, + prometheus.CounterValue, + c.value, + c.current_labels..., + ) +} + +func (c *MuninCounter) Update(NewValue float64) { + c.value=NewValue +} +func (c *MuninCounter) UpdateLabels(current_labels []string, NewValue float64) { + c.value=NewValue + c.current_labels=current_labels +} + +func NewMuninCounter(metricName string, desc string, VariableLabels []string, constlabels prometheus.Labels) *MuninCounter { + return &MuninCounter{ + counterDesc: prometheus.NewDesc( + metricName, + desc, + []string{VariableLabels[0], VariableLabels[1],VariableLabels[2]}, + constlabels, + ), + } +} + func init() { flag.Parse() var err error gaugePerMetric = map[string]*prometheus.GaugeVec{} - counterPerMetric = map[string]*prometheus.CounterVec{} + counterPerMetric = map[string]*MuninCounter{} muninBanner = regexp.MustCompile(`# munin node at (.*)`) err = connect() @@ -192,14 +233,7 @@ func registerMetrics() (err error) { muninType := strings.ToLower(config["type"]) // muninType can be empty and defaults to gauge if muninType == "counter" || muninType == "derive" { - gv := prometheus.NewCounterVec( - prometheus.CounterOpts{ - Name: metricName, - Help: desc, - ConstLabels: prometheus.Labels{"type": muninType}, - }, - []string{"hostname", "graphname", "muninlabel"}, - ) + gv := NewMuninCounter(metricName, desc, []string{"hostname", "graphname", "muninlabel"}, prometheus.Labels{"type": muninType}) log.Printf("Registered counter %s: %s", metricName, desc) counterPerMetric[metricName] = gv prometheus.Register(gv) @@ -240,7 +274,7 @@ func fetchMetrics() (err error) { return err } if len(line) == 1 && line[0] == '.' { - if !*quite { + if !*quiet { log.Printf("End of list") } break @@ -258,17 +292,20 @@ func fetchMetrics() (err error) { continue } name := strings.Replace(graph+"_"+key, "-", "_", -1) - if !*quite { - log.Printf("%s: %f\n", name, value) - } _, isGauge := gaugePerMetric[name] if isGauge { gaugePerMetric[name].WithLabelValues(hostname, graph, key).Set(value) + if !*quiet { + log.Printf("Gauge %s: %f\n", name, value) + } continue } _, isCounter := counterPerMetric[name] if isCounter { - counterPerMetric[name].WithLabelValues(hostname, graph, key).Add(value) + if !*quiet { + log.Printf("Counter %s: %f\n", name, value) + } + counterPerMetric[name].UpdateLabels([]string{hostname, graph, key}, value) continue } } @@ -287,7 +324,7 @@ func main() { func() { for { - if !*quite { + if !*quiet { log.Printf("Scraping") } err := fetchMetrics() From c813409c8ee2013f352c7b3bd90c4a92a8055895 Mon Sep 17 00:00:00 2001 From: Eri Bastos Date: Wed, 5 Sep 2018 15:11:22 -0300 Subject: [PATCH 4/8] Modified logs and update some names to meet golang style --- munin_exporter.go | 106 +++++++++++++++++++++++----------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/munin_exporter.go b/munin_exporter.go index 3fcab15..b1a6076 100644 --- a/munin_exporter.go +++ b/munin_exporter.go @@ -5,17 +5,21 @@ import ( "flag" "fmt" "io" - "log" "net" "net/http" + "os" "regexp" "strconv" "strings" "time" + "github.com/juju/loggo" "github.com/prometheus/client_golang/prometheus" ) +var logger = loggo.GetLogger("main") +var rootLogger = loggo.GetLogger("") + const ( proto = "tcp" retryInterval = 1 @@ -26,51 +30,51 @@ var ( listeningPath = flag.String("listeningPath", "/metrics", "Path on which to expose Prometheus metrics.") muninAddress = flag.String("muninAddress", "localhost:4949", "munin-node address.") muninScrapeInterval = flag.Int("muninScrapeInterval", 60, "Interval in seconds between scrapes.") - quiet = flag.Bool("quiet", false, "Makes logging a bit more quiet") + logLevel = flag.String("logLevel", "INFO", "TRACE, DEBUG, INFO, WARNING, ERROR, CRITICAL") globalConn net.Conn hostname string graphs []string gaugePerMetric map[string]*prometheus.GaugeVec - counterPerMetric map[string]*MuninCounter + counterPerMetric map[string]*muninCounter muninBanner *regexp.Regexp ) -type MuninCounter struct { - counterDesc *prometheus.Desc - value float64 - current_labels []string +type muninCounter struct { + counterDesc *prometheus.Desc + value float64 + currentLabels []string } -func (c *MuninCounter) Describe(ch chan<- *prometheus.Desc) { +func (c *muninCounter) Describe(ch chan<- *prometheus.Desc) { ch <- c.counterDesc } -func (c *MuninCounter) Collect(ch chan<- prometheus.Metric) { - if (len(c.current_labels) ==0 ) { - c.current_labels=[]string{"ThisMunin", "Plugin", "IsBroken"} +func (c *muninCounter) Collect(ch chan<- prometheus.Metric) { + if len(c.currentLabels) == 0 { + c.currentLabels = []string{"ThisMunin", "Plugin", "IsBroken"} } ch <- prometheus.MustNewConstMetric( c.counterDesc, prometheus.CounterValue, c.value, - c.current_labels..., + c.currentLabels..., ) } -func (c *MuninCounter) Update(NewValue float64) { - c.value=NewValue +func (c *muninCounter) Update(NewValue float64) { + c.value = NewValue } -func (c *MuninCounter) UpdateLabels(current_labels []string, NewValue float64) { - c.value=NewValue - c.current_labels=current_labels +func (c *muninCounter) UpdateLabels(currentLabels []string, NewValue float64) { + c.value = NewValue + c.currentLabels = currentLabels } -func NewMuninCounter(metricName string, desc string, VariableLabels []string, constlabels prometheus.Labels) *MuninCounter { - return &MuninCounter{ +func newMuninCounter(metricName string, desc string, VariableLabels []string, constlabels prometheus.Labels) *muninCounter { + return &muninCounter{ counterDesc: prometheus.NewDesc( metricName, desc, - []string{VariableLabels[0], VariableLabels[1],VariableLabels[2]}, + []string{VariableLabels[0], VariableLabels[1], VariableLabels[2]}, constlabels, ), } @@ -80,12 +84,13 @@ func init() { flag.Parse() var err error gaugePerMetric = map[string]*prometheus.GaugeVec{} - counterPerMetric = map[string]*MuninCounter{} + counterPerMetric = map[string]*muninCounter{} muninBanner = regexp.MustCompile(`# munin node at (.*)`) - + loggo.ConfigureLoggers(*logLevel) err = connect() if err != nil { - log.Fatalf("Could not connect to %s: %s", *muninAddress, err) + rootLogger.Criticalf("Could not connect to %s: %s", *muninAddress, err) + os.Exit(1) } } @@ -95,12 +100,12 @@ func serveStatus() { } func connect() (err error) { - log.Printf("Connecting...") + rootLogger.Infof("Connecting to %s", *muninAddress) globalConn, err = net.Dial(proto, *muninAddress) if err != nil { return } - log.Printf("connected!") + rootLogger.Debugf("connected!") reader := bufio.NewReader(globalConn) head, err := reader.ReadString('\n') @@ -113,7 +118,7 @@ func connect() (err error) { return fmt.Errorf("Unexpected line: %s", head) } hostname = matches[1] - log.Printf("Found hostname: %s", hostname) + rootLogger.Infof("Found hostname: %s", hostname) return } @@ -125,14 +130,14 @@ func muninCommand(cmd string) (reader *bufio.Reader, err error) { _, err = reader.Peek(1) switch err { case io.EOF: - log.Printf("not connected anymore, closing connection") + rootLogger.Infof("not connected anymore, closing connection") globalConn.Close() for { err = connect() if err == nil { break } - log.Printf("Couldn't reconnect: %s", err) + rootLogger.Warningf("Couldn't reconnect: %s", err) time.Sleep(retryInterval * time.Second) } @@ -140,7 +145,8 @@ func muninCommand(cmd string) (reader *bufio.Reader, err error) { case nil: //no error break default: - log.Fatalf("Unexpected error: %s", err) + rootLogger.Criticalf("Unexpected error: %s", err) + os.Exit(1) } return @@ -149,13 +155,13 @@ func muninCommand(cmd string) (reader *bufio.Reader, err error) { func muninList() (items []string, err error) { munin, err := muninCommand("list") if err != nil { - log.Printf("couldn't get list") + rootLogger.Warningf("couldn't get list") return } response, err := munin.ReadString('\n') // we are only interested in the first line if err != nil { - log.Printf("couldn't read response") + rootLogger.Warningf("couldn't read response") return } @@ -173,14 +179,14 @@ func muninConfig(name string) (config map[string]map[string]string, graphConfig resp, err := muninCommand("config " + name) if err != nil { - log.Printf("couldn't get config for %s", name) + rootLogger.Warningf("couldn't get config for %s", name) return } for { line, err := resp.ReadString('\n') if err == io.EOF { - log.Fatalf("unexpected EOF, retrying") + rootLogger.Criticalf("unexpected EOF, retrying") return muninConfig(name) } if err != nil { @@ -233,8 +239,8 @@ func registerMetrics() (err error) { muninType := strings.ToLower(config["type"]) // muninType can be empty and defaults to gauge if muninType == "counter" || muninType == "derive" { - gv := NewMuninCounter(metricName, desc, []string{"hostname", "graphname", "muninlabel"}, prometheus.Labels{"type": muninType}) - log.Printf("Registered counter %s: %s", metricName, desc) + gv := newMuninCounter(metricName, desc, []string{"hostname", "graphname", "muninlabel"}, prometheus.Labels{"type": muninType}) + rootLogger.Infof("Registered counter %s: %s", metricName, desc) counterPerMetric[metricName] = gv prometheus.Register(gv) @@ -247,7 +253,7 @@ func registerMetrics() (err error) { }, []string{"hostname", "graphname", "muninlabel"}, ) - log.Printf("Registered gauge %s: %s", metricName, desc) + rootLogger.Infof("Registered gauge %s: %s", metricName, desc) gaugePerMetric[metricName] = gv prometheus.Register(gv) } @@ -267,44 +273,39 @@ func fetchMetrics() (err error) { line, err := munin.ReadString('\n') line = strings.TrimRight(line, "\n") if err == io.EOF { - log.Fatalf("unexpected EOF, retrying") + rootLogger.Criticalf("unexpected EOF, retrying") return fetchMetrics() } if err != nil { return err } if len(line) == 1 && line[0] == '.' { - if !*quiet { - log.Printf("End of list") - } + rootLogger.Debugf("End of list") + break } parts := strings.Fields(line) if len(parts) != 2 { - log.Printf("unexpected line: %s", line) + rootLogger.Debugf("unexpected line: %s", line) continue } key, valueString := strings.Split(parts[0], ".")[0], parts[1] value, err := strconv.ParseFloat(valueString, 64) if err != nil { - log.Printf("Couldn't parse value in line %s, malformed?", line) + rootLogger.Warningf("Couldn't parse value in line %s, malformed?", line) continue } name := strings.Replace(graph+"_"+key, "-", "_", -1) _, isGauge := gaugePerMetric[name] if isGauge { gaugePerMetric[name].WithLabelValues(hostname, graph, key).Set(value) - if !*quiet { - log.Printf("Gauge %s: %f\n", name, value) - } + rootLogger.Debugf("Gauge %s: %f\n", name, value) continue } _, isCounter := counterPerMetric[name] if isCounter { - if !*quiet { - log.Printf("Counter %s: %f\n", name, value) - } + rootLogger.Debugf("Counter %s: %f\n", name, value) counterPerMetric[name].UpdateLabels([]string{hostname, graph, key}, value) continue } @@ -317,19 +318,18 @@ func main() { flag.Parse() err := registerMetrics() if err != nil { - log.Fatalf("Could not register metrics: %s", err) + rootLogger.Criticalf("Could not register metrics: %s", err) + os.Exit(1) } go serveStatus() func() { for { - if !*quiet { - log.Printf("Scraping") - } + rootLogger.Debugf("Scrapping") err := fetchMetrics() if err != nil { - log.Printf("Error occured when trying to fetch metrics: %s", err) + rootLogger.Warningf("Error occured when trying to fetch metrics: %s", err) } time.Sleep(time.Duration(*muninScrapeInterval) * time.Second) } From 797d104770aedb77ad0960daaaa24ab5448904d6 Mon Sep 17 00:00:00 2001 From: Kalebris Date: Wed, 9 Jan 2019 14:31:35 +0100 Subject: [PATCH 5/8] adding munin_exporter_build_info metric, version flag, instead of sleep using ticker, also dealt with concurency when scraping and fetching happens at the same time to avoid returning the same value twice messing up counters --- munin_exporter.go | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/munin_exporter.go b/munin_exporter.go index b1a6076..c47fbf8 100644 --- a/munin_exporter.go +++ b/munin_exporter.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "sync" "flag" "fmt" "io" @@ -12,7 +13,7 @@ import ( "strconv" "strings" "time" - + "runtime" "github.com/juju/loggo" "github.com/prometheus/client_golang/prometheus" ) @@ -21,8 +22,11 @@ var logger = loggo.GetLogger("main") var rootLogger = loggo.GetLogger("") const ( - proto = "tcp" - retryInterval = 1 + proto = "tcp" + retryInterval = 1 + version_string = "Munin Exporter version 0.2.1" + version_num = "0.2.1" + revision = "0.2.1" ) var ( @@ -31,20 +35,24 @@ var ( muninAddress = flag.String("muninAddress", "localhost:4949", "munin-node address.") muninScrapeInterval = flag.Int("muninScrapeInterval", 60, "Interval in seconds between scrapes.") logLevel = flag.String("logLevel", "INFO", "TRACE, DEBUG, INFO, WARNING, ERROR, CRITICAL") + version = flag.Bool("version", false, "Show application version") globalConn net.Conn hostname string graphs []string gaugePerMetric map[string]*prometheus.GaugeVec counterPerMetric map[string]*muninCounter muninBanner *regexp.Regexp + wg = &sync.WaitGroup{} ) type muninCounter struct { counterDesc *prometheus.Desc value float64 currentLabels []string + } + func (c *muninCounter) Describe(ch chan<- *prometheus.Desc) { ch <- c.counterDesc } @@ -82,6 +90,10 @@ func newMuninCounter(metricName string, desc string, VariableLabels []string, co func init() { flag.Parse() + if (*version) { + fmt.Println(version_string) + os.Exit(1) + } var err error gaugePerMetric = map[string]*prometheus.GaugeVec{} counterPerMetric = map[string]*muninCounter{} @@ -95,7 +107,11 @@ func init() { } func serveStatus() { - http.Handle(*listeningPath, prometheus.Handler()) + prom := prometheus.Handler() + http.HandleFunc(*listeningPath, func(res http.ResponseWriter, req *http.Request){ + wg.Wait(); + prom.ServeHTTP(res, req) + }) http.ListenAndServe(*listeningAddress, nil) } @@ -259,10 +275,23 @@ func registerMetrics() (err error) { } } } + version_metric := prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "munin_exporter_build_info", + Help: fmt.Sprintf( + "A metric with a constant '1' value labeled by version, revision, branch, and goversion from which %s was built.", + version_string, + ), + }, + []string{"version", "goversion"}, + ) + version_metric.WithLabelValues(version_num, runtime.Version()).Set(1) + prometheus.Register(version_metric) return nil } func fetchMetrics() (err error) { + wg.Add(1) for _, graph := range graphs { munin, err := muninCommand("fetch " + graph) if err != nil { @@ -311,6 +340,7 @@ func fetchMetrics() (err error) { } } } + wg.Done() return } @@ -325,13 +355,13 @@ func main() { go serveStatus() func() { - for { + ticker := time.NewTicker(time.Duration(*muninScrapeInterval)*time.Second) + for range ticker.C { rootLogger.Debugf("Scrapping") err := fetchMetrics() if err != nil { rootLogger.Warningf("Error occured when trying to fetch metrics: %s", err) } - time.Sleep(time.Duration(*muninScrapeInterval) * time.Second) } }() } From 180499be61fc07b8d6a53d3d83a2b2b2120e3d5e Mon Sep 17 00:00:00 2001 From: Kalebris Date: Wed, 9 Jan 2019 15:44:09 +0100 Subject: [PATCH 6/8] adding metric to store how long it takes to get the data from munin --- munin_exporter.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/munin_exporter.go b/munin_exporter.go index c47fbf8..4e75f6f 100644 --- a/munin_exporter.go +++ b/munin_exporter.go @@ -287,11 +287,22 @@ func registerMetrics() (err error) { ) version_metric.WithLabelValues(version_num, runtime.Version()).Set(1) prometheus.Register(version_metric) + gv := prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "munin_exporter_munin_data_fetch_time", + Help: "A metric showing the amount of time it takes to get all the data from munin and it's plugins", + ConstLabels: prometheus.Labels{"type": "gauge"}, + }, + []string{"hostname"}, + ) + gaugePerMetric["munin_fetching_metric"] = gv + prometheus.Register(gv) return nil } func fetchMetrics() (err error) { wg.Add(1) + start := time.Now() for _, graph := range graphs { munin, err := muninCommand("fetch " + graph) if err != nil { @@ -340,6 +351,7 @@ func fetchMetrics() (err error) { } } } + gaugePerMetric["munin_fetching_metric"].WithLabelValues(hostname).Set(time.Since(start).Seconds()) wg.Done() return } From a42967310f5a7c3e2c1e11af82112db062438c6e Mon Sep 17 00:00:00 2001 From: kalebris Date: Tue, 2 Apr 2019 19:21:27 +0200 Subject: [PATCH 7/8] adding feature to die if it can't bind to given -listeningAddress --- munin_exporter.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/munin_exporter.go b/munin_exporter.go index 4e75f6f..b56b7d4 100644 --- a/munin_exporter.go +++ b/munin_exporter.go @@ -112,7 +112,9 @@ func serveStatus() { wg.Wait(); prom.ServeHTTP(res, req) }) - http.ListenAndServe(*listeningAddress, nil) + if err := http.ListenAndServe(*listeningAddress, nil); err != nil { + panic(err) + } } func connect() (err error) { From 5137f34b3e8b7e5469fd68f43db90ece932698d3 Mon Sep 17 00:00:00 2001 From: kalebris Date: Tue, 9 Apr 2019 10:35:08 +0200 Subject: [PATCH 8/8] defering the wg.Done() so it doesn't pile up if munin misbehaves adding graphs name to error message of unexpected EOF so it's easier to identify misbehaving plugins --- munin_exporter.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/munin_exporter.go b/munin_exporter.go index b56b7d4..309cccb 100644 --- a/munin_exporter.go +++ b/munin_exporter.go @@ -24,8 +24,8 @@ var rootLogger = loggo.GetLogger("") const ( proto = "tcp" retryInterval = 1 - version_string = "Munin Exporter version 0.2.1" - version_num = "0.2.1" + version_string = "Munin Exporter version 0.2.2" + version_num = "0.2.2" revision = "0.2.1" ) @@ -305,6 +305,7 @@ func registerMetrics() (err error) { func fetchMetrics() (err error) { wg.Add(1) start := time.Now() + defer wg.Done() for _, graph := range graphs { munin, err := muninCommand("fetch " + graph) if err != nil { @@ -315,7 +316,7 @@ func fetchMetrics() (err error) { line, err := munin.ReadString('\n') line = strings.TrimRight(line, "\n") if err == io.EOF { - rootLogger.Criticalf("unexpected EOF, retrying") + rootLogger.Criticalf("unexpected EOF while fetching "+graph+", retrying") return fetchMetrics() } if err != nil { @@ -354,7 +355,6 @@ func fetchMetrics() (err error) { } } gaugePerMetric["munin_fetching_metric"].WithLabelValues(hostname).Set(time.Since(start).Seconds()) - wg.Done() return }