2 changed files with 65 additions and 65 deletions
@ -0,0 +1,64 @@ |
|||||||
|
############################ |
||||||
|
# GCCollector <: Collector # |
||||||
|
############################ |
||||||
|
|
||||||
|
mutable struct GCCollector <: Collector |
||||||
|
function GCCollector(registry::Union{CollectorRegistry, Nothing}=DEFAULT_REGISTRY) |
||||||
|
gcc = new() |
||||||
|
if registry !== nothing |
||||||
|
register(registry, gcc) |
||||||
|
end |
||||||
|
return gcc |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
function metric_names(::GCCollector) |
||||||
|
return ( |
||||||
|
"gc_alloc_total", "gc_free_total", "gc_alloc_bytes_total", |
||||||
|
"gc_live_bytes", "gc_seconds_total", "gc_collections_total", |
||||||
|
) |
||||||
|
end |
||||||
|
|
||||||
|
function collect!(metrics::Vector, ::GCCollector) |
||||||
|
# See base/timing.jl |
||||||
|
gc_num = Base.gc_num() |
||||||
|
gc_live_bytes = Base.gc_live_bytes() |
||||||
|
# Push all the metrics |
||||||
|
push!(metrics, |
||||||
|
Metric( |
||||||
|
"counter", "gc_alloc_total", "Total number of allocations (calls to malloc, realloc, etc)", |
||||||
|
LabelNames(["type"]), |
||||||
|
[ |
||||||
|
Sample(nothing, LabelValues(["bigalloc"]), gc_num.bigalloc), |
||||||
|
Sample(nothing, LabelValues(["malloc"]), gc_num.malloc), |
||||||
|
Sample(nothing, LabelValues(["poolalloc"]), gc_num.poolalloc), |
||||||
|
Sample(nothing, LabelValues(["realloc"]), gc_num.realloc), |
||||||
|
], |
||||||
|
), |
||||||
|
Metric( |
||||||
|
"counter", "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, |
||||||
|
Sample(nothing, nothing, Base.gc_total_bytes(gc_num)), |
||||||
|
), |
||||||
|
Metric( |
||||||
|
"gauge", "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, |
||||||
|
Sample(nothing, nothing, gc_num.total_time / 10^9), # [ns] to [s] |
||||||
|
), |
||||||
|
Metric( |
||||||
|
"counter", "gc_collections_total", "Total number of calls to garbage collection", |
||||||
|
LabelNames(["type"]), |
||||||
|
[ |
||||||
|
Sample(nothing, LabelValues(["full"]), gc_num.full_sweep), |
||||||
|
Sample(nothing, LabelValues(["minor"]), gc_num.pause - gc_num.full_sweep), |
||||||
|
], |
||||||
|
), |
||||||
|
) |
||||||
|
return metrics |
||||||
|
end |
||||||
Loading…
Reference in new issue