Merge pull request #329 from infoverload/add_new_metric_go_info

Add new default metric go_info
This commit is contained in:
Björn Rabenstein 2017-07-24 10:13:13 +02:00 committed by GitHub
commit 94ff84a9a6
2 changed files with 11 additions and 2 deletions

View File

@ -11,6 +11,7 @@ type goCollector struct {
goroutinesDesc *Desc goroutinesDesc *Desc
threadsDesc *Desc threadsDesc *Desc
gcDesc *Desc gcDesc *Desc
goInfoDesc *Desc
// metrics to describe and collect // metrics to describe and collect
metrics memStatsMetrics metrics memStatsMetrics
@ -26,12 +27,16 @@ func NewGoCollector() Collector {
nil, nil), nil, nil),
threadsDesc: NewDesc( threadsDesc: NewDesc(
"go_threads", "go_threads",
"Number of OS threads created", "Number of OS threads created.",
nil, nil), nil, nil),
gcDesc: NewDesc( gcDesc: NewDesc(
"go_gc_duration_seconds", "go_gc_duration_seconds",
"A summary of the GC invocation durations.", "A summary of the GC invocation durations.",
nil, nil), nil, nil),
goInfoDesc: NewDesc(
"go_info",
"Information about the Go environment.",
nil, Labels{"version": runtime.Version()}),
metrics: memStatsMetrics{ metrics: memStatsMetrics{
{ {
desc: NewDesc( desc: NewDesc(
@ -239,6 +244,7 @@ func (c *goCollector) Describe(ch chan<- *Desc) {
ch <- c.goroutinesDesc ch <- c.goroutinesDesc
ch <- c.threadsDesc ch <- c.threadsDesc
ch <- c.gcDesc ch <- c.gcDesc
ch <- c.goInfoDesc
for _, i := range c.metrics { for _, i := range c.metrics {
ch <- i.desc ch <- i.desc
} }
@ -261,6 +267,8 @@ func (c *goCollector) Collect(ch chan<- Metric) {
quantiles[0.0] = stats.PauseQuantiles[0].Seconds() quantiles[0.0] = stats.PauseQuantiles[0].Seconds()
ch <- MustNewConstSummary(c.gcDesc, uint64(stats.NumGC), float64(stats.PauseTotal.Seconds()), quantiles) ch <- MustNewConstSummary(c.gcDesc, uint64(stats.NumGC), float64(stats.PauseTotal.Seconds()), quantiles)
ch <- MustNewConstMetric(c.goInfoDesc, GaugeValue, 1)
ms := &runtime.MemStats{} ms := &runtime.MemStats{}
runtime.ReadMemStats(ms) runtime.ReadMemStats(ms)
for _, i := range c.metrics { for _, i := range c.metrics {

View File

@ -54,10 +54,11 @@ func TestGoCollector(t *testing.T) {
} }
// GoCollector performs three sends per call. // 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. // to shut down cleanly.
<-ch <-ch
<-ch <-ch
<-ch
return return
case <-time.After(1 * time.Second): case <-time.After(1 * time.Second):
t.Fatalf("expected collect timed out") t.Fatalf("expected collect timed out")