Browse Source

GCCollector: change prefix from `gc_` to `julia_gc_`.

pull/4/head
Fredrik Ekre 2 years ago
parent
commit
d147be5b63
  1. 2
      docs/src/index.md
  2. 16
      src/gc_collector.jl
  3. 20
      test/runtests.jl

2
docs/src/index.md

@ -129,7 +129,7 @@ Prometheus.observe(::Prometheus.Summary, ::Any) @@ -129,7 +129,7 @@ Prometheus.observe(::Prometheus.Summary, ::Any)
A collector that exports metrics about allocations and garbage collection (for example
number of allocations, number of bytes allocated, time spent in garbage collection, etc).
These metrics have the `gc_` prefix in their name.
These metrics have the `julia_gc_` prefix in their name.
A `GCCollector` is registered automatically with the default registry, see
[Default registry](@ref) for more details.

16
src/gc_collector.jl

@ -33,8 +33,8 @@ GCCollector(; kwargs...) @@ -33,8 +33,8 @@ GCCollector(; kwargs...)
function metric_names(::GCCollector)
return (
"gc_alloc_total", "gc_free_total", "gc_alloc_bytes_total",
"gc_live_bytes", "gc_seconds_total", "gc_collections_total",
"julia_gc_alloc_total", "julia_gc_free_total", "julia_gc_alloc_bytes_total",
"julia_gc_live_bytes", "julia_gc_seconds_total", "julia_gc_collections_total",
)
end
@ -45,7 +45,7 @@ function collect!(metrics::Vector, ::GCCollector) @@ -45,7 +45,7 @@ function collect!(metrics::Vector, ::GCCollector)
# Push all the metrics
push!(metrics,
Metric(
"counter", "gc_alloc_total", "Total number of allocations (calls to malloc, realloc, etc)",
"counter", "julia_gc_alloc_total", "Total number of allocations (calls to malloc, realloc, etc)",
LabelNames(["type"]),
[
Sample(nothing, LabelValues(["bigalloc"]), gc_num.bigalloc),
@ -55,23 +55,23 @@ function collect!(metrics::Vector, ::GCCollector) @@ -55,23 +55,23 @@ function collect!(metrics::Vector, ::GCCollector)
],
),
Metric(
"counter", "gc_free_total", "Total number of calls to free()",
"counter", "julia_gc_free_total", "Total number of calls to free()",
nothing, Sample(nothing, nothing, gc_num.freecall),
),
Metric(
"counter", "gc_alloc_bytes_total", "Total number of allocated bytes", nothing,
"counter", "julia_gc_alloc_bytes_total", "Total number of allocated bytes", nothing,
Sample(nothing, nothing, Base.gc_total_bytes(gc_num)),
),
Metric(
"gauge", "gc_live_bytes", "Current number of live bytes", nothing,
"gauge", "julia_gc_live_bytes", "Current number of live bytes", nothing,
Sample(nothing, nothing, gc_live_bytes),
),
Metric(
"counter", "gc_seconds_total", "Total time spent in garbage collection", nothing,
"counter", "julia_gc_seconds_total", "Total time spent in garbage collection", nothing,
Sample(nothing, nothing, gc_num.total_time / 10^9), # [ns] to [s]
),
Metric(
"counter", "gc_collections_total", "Total number of calls to garbage collection",
"counter", "julia_gc_collections_total", "Total number of calls to garbage collection",
LabelNames(["type"]),
[
Sample(nothing, LabelValues(["full"]), gc_num.full_sweep),

20
test/runtests.jl

@ -290,27 +290,27 @@ end @@ -290,27 +290,27 @@ end
x = zeros(1024^2); x = nothing; GC.gc(); GC.gc()
new_stats = Base.gc_num()
@test length(metrics) == 6
gc_alloc_total = metrics[findfirst(x -> x.metric_name == "gc_alloc_total", metrics)]
gc_alloc_total = metrics[findfirst(x -> x.metric_name == "julia_gc_alloc_total", metrics)]
@test old_stats.bigalloc <= gc_alloc_total.samples[1].value <= new_stats.bigalloc
@test old_stats.malloc <= gc_alloc_total.samples[2].value <= new_stats.malloc
@test old_stats.poolalloc <= gc_alloc_total.samples[3].value <= new_stats.poolalloc
@test old_stats.realloc <= gc_alloc_total.samples[4].value <= new_stats.realloc
gc_free_total = metrics[findfirst(x -> x.metric_name == "gc_free_total", metrics)]
gc_free_total = metrics[findfirst(x -> x.metric_name == "julia_gc_free_total", metrics)]
@test old_stats.freecall <= gc_free_total.samples.value <= new_stats.freecall
gc_alloc_bytes_total = metrics[findfirst(x -> x.metric_name == "gc_alloc_bytes_total", metrics)]
gc_alloc_bytes_total = metrics[findfirst(x -> x.metric_name == "julia_gc_alloc_bytes_total", metrics)]
@test Base.gc_total_bytes(old_stats) <= gc_alloc_bytes_total.samples.value <= Base.gc_total_bytes(new_stats)
gc_seconds_total = metrics[findfirst(x -> x.metric_name == "gc_seconds_total", metrics)]
gc_seconds_total = metrics[findfirst(x -> x.metric_name == "julia_gc_seconds_total", metrics)]
@test old_stats.total_time / 10^9 <= gc_seconds_total.samples.value <= new_stats.total_time / 10^9
# Prometheus.expose_metric(...)
str = sprint(Prometheus.expose_metric, gc_alloc_total)
@test occursin(
r"""
# HELP gc_alloc_total Total number of allocations \(calls to malloc, realloc, etc\)
# TYPE gc_alloc_total counter
gc_alloc_total{type="bigalloc"} \d+
gc_alloc_total{type="malloc"} \d+
gc_alloc_total{type="poolalloc"} \d+
gc_alloc_total{type="realloc"} \d+
# HELP julia_gc_alloc_total Total number of allocations \(calls to malloc, realloc, etc\)
# TYPE julia_gc_alloc_total counter
julia_gc_alloc_total{type="bigalloc"} \d+
julia_gc_alloc_total{type="malloc"} \d+
julia_gc_alloc_total{type="poolalloc"} \d+
julia_gc_alloc_total{type="realloc"} \d+
""",
sprint(Prometheus.expose_metric, gc_alloc_total),
)

Loading…
Cancel
Save