From c0223f5a232ebfa0148f710acef72d0050271f4d Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Sun, 5 Nov 2023 22:04:11 +0100 Subject: [PATCH] ProcessCollector: add docstring and documentation. --- docs/src/index.md | 13 +++++++++++-- src/process_collector.jl | 28 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/docs/src/index.md b/docs/src/index.md index 85449f8..d03880b 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -11,7 +11,7 @@ Two of the basic concepts of a Prometheus client are [Registries](@ref) and [Collectors](@ref). Registries are collections of collectors, and the collectors are the units responsible to record and capture metrics. Client libraries implement a default registry which all collectors implicity register with, so for basic usage there is no need -to interact with a registry (see [Default collector registry](@ref)). +to interact with a registry (see [Default registry](@ref)). The third important concept is [Exposition](@ref) of the collected metrics. Typically metrics are exposed over a HTTP server, as in the [Quickstart](@ref)-example just below. See @@ -138,6 +138,15 @@ metrics about I/O operations. Metrics from this collector have the `process_` pr their name. This collector is only available on Linux since it requires the `/proc` file system. +A `ProcessCollector` for the current process is registered automatically with the +default registry, see [Default registry](@ref) for more details. + +#### ProcessCollector API reference + +```@docs +Prometheus.ProcessCollector(::Function; kwargs...) +``` + ### Custom collectors RandomCollector @@ -168,7 +177,7 @@ Supported methods: ## Registries -### Default collector registry +### Default registry ## Exposition diff --git a/src/process_collector.jl b/src/process_collector.jl index 74cdc93..03267a5 100644 --- a/src/process_collector.jl +++ b/src/process_collector.jl @@ -53,6 +53,34 @@ mutable struct ProcessCollector <: Collector end end +""" + Prometheus.ProcessCollector(pid; registry=DEFAULT_REGISTRY) + +Create a process collector for the process id given by the `pid` function. The collector +exposes metrics about the process' CPU time, start time, memory usage, file usage, and I/O +operations. + +**Arguments** + - `pid :: Function`: a function returning a process id as a string or integer for which to + collect metrics. By default the `"self"` pid is used, i.e. the current process. +**Keyword arguments** + - `registry :: Prometheus.CollectorRegistry`: the registry in which to register the + collector. The default registry is used by default. Pass `registry = nothing` to skip + registration. + +!!! note + A `ProcessCollector` for the current process is registered automatically with the + default registry. If necessary it can be removed by calling + ```julia + Prometheus.unregister(Prometheus.DEFAULT_REGISTRY, Prometheus.PROCESS_COLLECTOR) + ``` + +!!! note + The process collector is currently only available on Linux since it requires the `/proc` + file system. On Windows and macOS this collector will not expose any metrics. +""" +ProcessCollector(::Function; kwargs...) + function metric_names(::ProcessCollector) return ( "process_cpu_seconds_total", "process_start_time_seconds",