-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go_metrics: adds new runtime metrics (#58)
* go_metrics: adds new runtime metrics go_sched_latency_seconds - Distribution of the time goroutines have spent in the scheduler in a runnable state before actually running go_mutex_wait_total_seconds - Approximate cumulative time goroutines have spent blocked on a sync.Mutex or sync.RWMutex #54 * fixes data race * add tests * wip * wip --------- Co-authored-by: Aliaksandr Valialkin <valyala@victoriametrics.com>
- Loading branch information
Showing
2 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package metrics | ||
|
||
import ( | ||
"math" | ||
runtimemetrics "runtime/metrics" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestWriteRuntimeHistogramMetricOk(t *testing.T) { | ||
f := func(h *runtimemetrics.Float64Histogram, resultExpected string) { | ||
t.Helper() | ||
var wOut strings.Builder | ||
writeRuntimeHistogramMetric(&wOut, "foo", h) | ||
result := wOut.String() | ||
if result != resultExpected { | ||
t.Fatalf("unexpected result; got\n%s\nwant\n%s", result, resultExpected) | ||
} | ||
|
||
} | ||
|
||
f(&runtimemetrics.Float64Histogram{ | ||
Counts: []uint64{1, 2, 3}, | ||
Buckets: []float64{1, 2, 3, 4}, | ||
}, `foo_bucket{le="1"} 0 | ||
foo_bucket{le="2"} 1 | ||
foo_bucket{le="3"} 3 | ||
foo_bucket{le="4"} 6 | ||
foo_bucket{le="+Inf"} 6 | ||
`) | ||
|
||
f(&runtimemetrics.Float64Histogram{ | ||
Counts: []uint64{0, 25, 1, 3}, | ||
Buckets: []float64{1, 2, 3, 4, math.Inf(1)}, | ||
}, `foo_bucket{le="1"} 0 | ||
foo_bucket{le="2"} 0 | ||
foo_bucket{le="3"} 25 | ||
foo_bucket{le="4"} 26 | ||
foo_bucket{le="+Inf"} 29 | ||
`) | ||
|
||
f(&runtimemetrics.Float64Histogram{ | ||
Counts: []uint64{0, 25, 1, 3, 0, 44, 15, 132, 10, 11}, | ||
Buckets: []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, math.Inf(1)}, | ||
}, `foo_bucket{le="1"} 0 | ||
foo_bucket{le="2"} 0 | ||
foo_bucket{le="3"} 25 | ||
foo_bucket{le="4"} 26 | ||
foo_bucket{le="5"} 29 | ||
foo_bucket{le="6"} 29 | ||
foo_bucket{le="7"} 73 | ||
foo_bucket{le="8"} 88 | ||
foo_bucket{le="9"} 220 | ||
foo_bucket{le="10"} 230 | ||
foo_bucket{le="+Inf"} 241 | ||
`) | ||
|
||
f(&runtimemetrics.Float64Histogram{ | ||
Counts: []uint64{1, 5}, | ||
Buckets: []float64{math.Inf(-1), 4, math.Inf(1)}, | ||
}, `foo_bucket{le="-Inf"} 0 | ||
foo_bucket{le="4"} 1 | ||
foo_bucket{le="+Inf"} 6 | ||
`) | ||
} |