Skip to content

Commit

Permalink
[instrument] Config option to emit detailed Go runtime metrics only (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vdarulis authored Mar 8, 2021
1 parent a6607a6 commit 73a98e6
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/x/instrument/extended.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ const (
// - GC pause times
DetailedExtendedMetrics

// DetailedGoRuntimeMetrics reports all detailed metrics, sans FD metrics to save CPU
// if in-use file descriptors are measured by an external system, like cAdvisor.
DetailedGoRuntimeMetrics

// DefaultExtendedMetricsType is the default extended metrics level.
DefaultExtendedMetricsType = SimpleExtendedMetrics
)
Expand All @@ -73,6 +77,7 @@ var (
SimpleExtendedMetrics,
ModerateExtendedMetrics,
DetailedExtendedMetrics,
DetailedGoRuntimeMetrics,
}
)

Expand All @@ -86,6 +91,8 @@ func (t ExtendedMetricsType) String() string {
return "moderate"
case DetailedExtendedMetrics:
return "detailed"
case DetailedGoRuntimeMetrics:
return "runtime"
}
return "unknown"
}
Expand Down Expand Up @@ -191,20 +198,35 @@ func NewExtendedMetricsReporter(
reportInterval time.Duration,
metricsType ExtendedMetricsType,
) Reporter {
r := new(extendedMetricsReporter)
var (
r = new(extendedMetricsReporter)
enableProcessReporter bool
)

r.metricsType = metricsType
r.init(reportInterval, func() {
r.runtime.report(r.metricsType)
})
if r.metricsType >= ModerateExtendedMetrics {

if r.metricsType == NoExtendedMetrics {
return r
}

switch r.metricsType {
case ModerateExtendedMetrics:
enableProcessReporter = true
case DetailedExtendedMetrics:
enableProcessReporter = true
default:
enableProcessReporter = false
}

if enableProcessReporter {
// ProcessReporter can be quite slow in some situations (specifically
// counting FDs for processes that have many of them) so it runs on
// its own report loop.
r.processReporter = NewProcessReporter(scope, reportInterval)
}
if r.metricsType == NoExtendedMetrics {
return r
}

runtimeScope := scope.SubScope("runtime")
r.runtime.NumGoRoutines = runtimeScope.Gauge("num-goroutines")
Expand Down

0 comments on commit 73a98e6

Please sign in to comment.