Browse Source

GCCollector: move to a separate file.

pull/6/head
Fredrik Ekre 2 years ago
parent
commit
3213140383
  1. 66
      src/Prometheus.jl
  2. 64
      src/gc_collector.jl

66
src/Prometheus.jl

@ -463,71 +463,6 @@ function collect!(metrics::Vector, family::Family{C}) where C @@ -463,71 +463,6 @@ function collect!(metrics::Vector, family::Family{C}) where C
return metrics
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 #
@ -690,6 +625,7 @@ function expose(http::HTTP.Stream, reg::CollectorRegistry = DEFAULT_REGISTRY; co @@ -690,6 +625,7 @@ function expose(http::HTTP.Stream, reg::CollectorRegistry = DEFAULT_REGISTRY; co
return
end
include("gc_collector.jl")
include("process_collector.jl")
# Default registry and collectors

64
src/gc_collector.jl

@ -0,0 +1,64 @@ @@ -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…
Cancel
Save