|
|
|
@ -69,8 +69,6 @@ struct CollectorRegistry |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
const DEFAULT_REGISTRY = CollectorRegistry() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function register(reg::CollectorRegistry, collector::Collector) |
|
|
|
function register(reg::CollectorRegistry, collector::Collector) |
|
|
|
existing_names = Set{String}() # TODO: Cache existing_names in the registry? |
|
|
|
existing_names = Set{String}() # TODO: Cache existing_names in the registry? |
|
|
|
@lock reg.lock begin |
|
|
|
@lock reg.lock begin |
|
|
|
@ -401,6 +399,71 @@ function collect!(metrics::Vector, family::Family{C}) where C |
|
|
|
return metrics |
|
|
|
return metrics |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
############################ |
|
|
|
|
|
|
|
# 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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
############## |
|
|
|
############## |
|
|
|
# Exposition # |
|
|
|
# Exposition # |
|
|
|
@ -563,4 +626,8 @@ function expose(http::HTTP.Stream, reg::CollectorRegistry = DEFAULT_REGISTRY; co |
|
|
|
return |
|
|
|
return |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Default registry and collectors |
|
|
|
|
|
|
|
const DEFAULT_REGISTRY = CollectorRegistry() |
|
|
|
|
|
|
|
const GC_COLLECTOR = GCCollector(DEFAULT_REGISTRY) |
|
|
|
|
|
|
|
|
|
|
|
end # module Prometheus |
|
|
|
end # module Prometheus |
|
|
|
|