-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add garbage collection stats #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,13 @@ package prometheus | |
|
||
import ( | ||
"runtime" | ||
"runtime/debug" | ||
"time" | ||
) | ||
|
||
type goCollector struct { | ||
goroutines Gauge | ||
gcDesc *Desc | ||
} | ||
|
||
// NewGoCollector returns a collector which exports metrics about the current | ||
|
@@ -16,16 +19,32 @@ func NewGoCollector() *goCollector { | |
Name: "process_goroutines", | ||
Help: "Number of goroutines that currently exist.", | ||
}), | ||
gcDesc: NewDesc( | ||
"go_gc_duration_seconds", | ||
"A summary of the GC invocation durations.", | ||
nil, nil), | ||
} | ||
} | ||
|
||
// Describe returns all descriptions of the collector. | ||
func (c *goCollector) Describe(ch chan<- *Desc) { | ||
ch <- c.goroutines.Desc() | ||
ch <- c.gcDesc | ||
} | ||
|
||
// Collect returns the current state of all metrics of the collector. | ||
func (c *goCollector) Collect(ch chan<- Metric) { | ||
c.goroutines.Set(float64(runtime.NumGoroutine())) | ||
ch <- c.goroutines | ||
|
||
var stats debug.GCStats | ||
stats.PauseQuantiles = make([]time.Duration, 5) | ||
debug.ReadGCStats(&stats) | ||
|
||
quantiles := make(map[float64]float64) | ||
for idx, pq := range stats.PauseQuantiles[1:] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But why skip the min? The Go runtime provides it, why not mirror it, too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As what? The zero-th pecentile? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that would make most sense, IMHO. Objections welcome. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, done. |
||
quantiles[float64(idx+1)/float64(len(stats.PauseQuantiles)-1)] = pq.Seconds() | ||
} | ||
quantiles[0.0] = stats.PauseQuantiles[0].Seconds() | ||
ch <- MustNewConstSummary(c.gcDesc, uint64(stats.NumGC), float64(stats.PauseTotal.Seconds()), quantiles) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the empty line after the function signature.