From f36d4a3e733360de95cd29dd630390002752d506 Mon Sep 17 00:00:00 2001 From: "hazey.dazey" Date: Sun, 23 Jul 2017 23:36:09 +0200 Subject: [PATCH] Add new default metric go_info --- prometheus/go_collector.go | 10 +++++++++- prometheus/go_collector_test.go | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/prometheus/go_collector.go b/prometheus/go_collector.go index f967645..096454a 100644 --- a/prometheus/go_collector.go +++ b/prometheus/go_collector.go @@ -11,6 +11,7 @@ type goCollector struct { goroutinesDesc *Desc threadsDesc *Desc gcDesc *Desc + goInfoDesc *Desc // metrics to describe and collect metrics memStatsMetrics @@ -26,12 +27,16 @@ func NewGoCollector() Collector { nil, nil), threadsDesc: NewDesc( "go_threads", - "Number of OS threads created", + "Number of OS threads created.", nil, nil), gcDesc: NewDesc( "go_gc_duration_seconds", "A summary of the GC invocation durations.", nil, nil), + goInfoDesc: NewDesc( + "go_info", + "Information about the Go environment.", + nil, Labels{"version": runtime.Version()}), metrics: memStatsMetrics{ { desc: NewDesc( @@ -239,6 +244,7 @@ func (c *goCollector) Describe(ch chan<- *Desc) { ch <- c.goroutinesDesc ch <- c.threadsDesc ch <- c.gcDesc + ch <- c.goInfoDesc for _, i := range c.metrics { ch <- i.desc } @@ -261,6 +267,8 @@ func (c *goCollector) Collect(ch chan<- Metric) { quantiles[0.0] = stats.PauseQuantiles[0].Seconds() ch <- MustNewConstSummary(c.gcDesc, uint64(stats.NumGC), float64(stats.PauseTotal.Seconds()), quantiles) + ch <- MustNewConstMetric(c.goInfoDesc, GaugeValue, 1) + ms := &runtime.MemStats{} runtime.ReadMemStats(ms) for _, i := range c.metrics { diff --git a/prometheus/go_collector_test.go b/prometheus/go_collector_test.go index 59dabc0..2d05118 100644 --- a/prometheus/go_collector_test.go +++ b/prometheus/go_collector_test.go @@ -54,10 +54,11 @@ func TestGoCollector(t *testing.T) { } // GoCollector performs three sends per call. - // On line 27 we need to receive the second send + // On line 27 we need to receive three more sends // to shut down cleanly. <-ch <-ch + <-ch return case <-time.After(1 * time.Second): t.Fatalf("expected collect timed out")