|
|
<!DOCTYPE html> |
|
|
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Prometheus.jl · Prometheus.jl</title><meta name="title" content="Prometheus.jl · Prometheus.jl"/><meta property="og:title" content="Prometheus.jl · Prometheus.jl"/><meta property="twitter:title" content="Prometheus.jl · Prometheus.jl"/><meta name="description" content="Documentation for Prometheus.jl."/><meta property="og:description" content="Documentation for Prometheus.jl."/><meta property="twitter:description" content="Documentation for Prometheus.jl."/><meta property="og:url" content="https://fredrikekre.github.io/Prometheus.jl/v1/"/><meta property="twitter:url" content="https://fredrikekre.github.io/Prometheus.jl/v1/"/><link rel="canonical" href="https://fredrikekre.github.io/Prometheus.jl/v1/"/><script data-outdated-warner src="assets/warner.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/lato-font/3.0.0/css/lato-font.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/juliamono/0.050/juliamono.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.8/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL="."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="assets/documenter.js"></script><script src="search_index.js"></script><script src="siteinfo.js"></script><script src="../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="assets/themes/documenter-dark.css" data-theme-name="documenter-dark" data-theme-primary-dark/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="assets/themeswap.js"></script></head><body><div id="documenter"><div class="docs-main" style="margin: auto; padding-right: 0;"><header class="docs-navbar"><div class="docs-right" style="margin-left: auto;"><a class="docs-navbar-link" href="https://github.com/fredrikekre/Prometheus.jl" title="View the repository on GitHub"><span class="docs-icon fa-brands"></span><span class="docs-label is-hidden-touch">GitHub</span></a><a class="docs-navbar-link" href="https://github.com/fredrikekre/Prometheus.jl/blob/master/docs/src/index.md" title="Edit source on GitHub"><span class="docs-icon fa-solid"></span></a><a class="docs-settings-button docs-navbar-link fa-solid fa-gear" id="documenter-settings-button" href="#" title="Settings"></a></div></header><article class="content" id="documenter-page"><h1 id="Prometheus.jl"><a class="docs-heading-anchor" href="#Prometheus.jl">Prometheus.jl</a><a id="Prometheus.jl-1"></a><a class="docs-heading-anchor-permalink" href="#Prometheus.jl" title="Permalink"></a></h1><h2 id="Introduction"><a class="docs-heading-anchor" href="#Introduction">Introduction</a><a id="Introduction-1"></a><a class="docs-heading-anchor-permalink" href="#Introduction" title="Permalink"></a></h2><p>This package is a Julia client for <a href="https://prometheus.io/">Prometheus</a>. If you are not familiar with Prometheus it is recommended to browse the <a href="https://prometheus.io/docs/introduction/overview/">upstream documentation</a>. The documentation here focuses on the Julia client.</p><p>Two of the basic concepts of a Prometheus client are <a href="#Registries">Registries</a> and <a href="#Collectors">Collectors</a>. 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 <a href="#Default-collector-registry">Default collector registry</a>).</p><p>The third important concept is <a href="#Exposition">Exposition</a> of the collected metrics. Typically metrics are exposed over a HTTP server, as in the <a href="#Quickstart">Quickstart</a>-example just below. See the section about <a href="#Exposition">Exposition</a> for more details and examples on how metrics can be exposed.</p><h2 id="Quickstart"><a class="docs-heading-anchor" href="#Quickstart">Quickstart</a><a id="Quickstart-1"></a><a class="docs-heading-anchor-permalink" href="#Quickstart" title="Permalink"></a></h2><ol><li><p>Install Prometheus.jl and <a href="https://github.com/JuliaWeb/HTTP.jl">HTTP.jl</a> using the package manager:</p><pre><code class="nohighlight hljs">pkg> add Prometheus HTTP</code></pre></li><li><p>Paste the following code into a Julia REPL.</p><pre><code class="language-julia hljs"># Load the packages |
|
|
using Prometheus, HTTP |
|
|
|
|
|
# Create a Counter metric |
|
|
const request_counter = Prometheus.Counter("request_count", "Number of handled requests") |
|
|
|
|
|
# Start a HTTP server on localhost port 8000 to server the metrics |
|
|
server = HTTP.listen!(8000) do http |
|
|
Prometheus.inc(request_counter) # Increment the request counter |
|
|
return Prometheus.expose(http) # Expose the metrics |
|
|
end</code></pre></li><li><p>Visit <a href="http://localhost:8000">http://localhost:8000</a> in your browser. You will see something like the following</p><pre><code class="nohighlight hljs"># HELP gc_alloc_bytes_total Total number of allocated bytes |
|
|
# TYPE gc_alloc_bytes_total counter |
|
|
gc_alloc_bytes_total 365578814 |
|
|
|
|
|
[...] |
|
|
|
|
|
# HELP request_count Number of handled requests |
|
|
# TYPE request_count counter |
|
|
request_count 1</code></pre><p>The output contains some default metrics related to the running process, as well as the request counter that we added ourselves. Every time you refresh, the counter will increment its value. <code>close(server)</code> will shutdown the server.</p></li></ol><h2 id="Collectors"><a class="docs-heading-anchor" href="#Collectors">Collectors</a><a id="Collectors-1"></a><a class="docs-heading-anchor-permalink" href="#Collectors" title="Permalink"></a></h2><p>This section documents the collectors that are currently supported. This include the "basic" collectors (<a href="#Counter">Counter</a>, <a href="#Gauge">Gauge</a>, <a href="#Summary">Summary</a>) as well as some custom collectors (<a href="#GCCollector">GCCollector</a>, <a href="#ProcessCollector">ProcessCollector</a>). There is also a section on how to implement your own collector, see <a href="#Custom-collectors">Custom collectors</a>.</p><p>Upstream documentation:</p><ul><li><a href="https://prometheus.io/docs/concepts/metric_types/">https://prometheus.io/docs/concepts/metric_types/</a></li><li><a href="https://prometheus.io/docs/instrumenting/writing_clientlibs/#metrics">https://prometheus.io/docs/instrumenting/writing_clientlibs/#metrics</a></li></ul><h3 id="Counter"><a class="docs-heading-anchor" href="#Counter">Counter</a><a id="Counter-1"></a><a class="docs-heading-anchor-permalink" href="#Counter" title="Permalink"></a></h3><p>Quoting the <a href="https://prometheus.io/docs/concepts/metric_types/#counter">upstream documentation</a>:</p><blockquote><p>A counter is a cumulative metric that represents a single monotonically increasing counter whose value can only increase or be reset to zero on restart. For example, you can use a counter to represent the number of requests served, tasks completed, or errors.</p><p>Do not use a counter to expose a value that can decrease. For example, do not use a counter for the number of currently running processes; instead use a gauge.</p></blockquote><h4 id="Counter-API-reference"><a class="docs-heading-anchor" href="#Counter-API-reference">Counter API reference</a><a id="Counter-API-reference-1"></a><a class="docs-heading-anchor-permalink" href="#Counter-API-reference" title="Permalink"></a></h4><article class="docstring"><header><a class="docstring-article-toggle-button fa-solid fa-chevron-down" href="javascript:;" title="Collapse docstring"></a><a class="docstring-binding" id="Prometheus.Counter" href="#Prometheus.Counter"><code>Prometheus.Counter</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia hljs">Prometheus.Counter(; name, help, registry=DEFAULT_REGISTRY)</code></pre><p>Construct a Counter collector.</p><p><strong>Required keyword arguments</strong></p><ul><li><code>name :: String</code>: the name of the counter metric.</li><li><code>help :: String</code>: the documentation for the counter metric.</li></ul><p><strong>Optional keyword arguments</strong></p><ul><li><code>registry :: Prometheus.CollectorRegistry</code>: the registry in which to register the collector. If not specified the default registry is used. Pass <code>registry = nothing</code> to skip registration.</li></ul></div><a class="docs-sourcelink" target="_blank" href="https://github.com/fredrikekre/Prometheus.jl/blob/419b4e4f7d9835c8b56c4b1c42d4922be8d49a18/src/Prometheus.jl#L132-L145">source</a></section></article><article class="docstring"><header><a class="docstring-article-toggle-button fa-solid fa-chevron-down" href="javascript:;" title="Collapse docstring"></a><a class="docstring-binding" id="Prometheus.inc-Tuple{Prometheus.Counter, Any}" href="#Prometheus.inc-Tuple{Prometheus.Counter, Any}"><code>Prometheus.inc</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia hljs">Prometheus.inc(c::Counter, v = 1)</code></pre><p>Increment the value of the counter <code>c</code> with <code>v</code>. <code>v</code> must be non-negative, and defaults to <code>v = 1</code>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/fredrikekre/Prometheus.jl/blob/419b4e4f7d9835c8b56c4b1c42d4922be8d49a18/src/Prometheus.jl#L152-L157">source</a></section></article><h3 id="Gauge"><a class="docs-heading-anchor" href="#Gauge">Gauge</a><a id="Gauge-1"></a><a class="docs-heading-anchor-permalink" href="#Gauge" title="Permalink"></a></h3><p>Quoting the <a href="https://prometheus.io/docs/concepts/metric_types/#gauge">upstream documentation</a>:</p><blockquote><p>A gauge is a metric that represents a single numerical value that can arbitrarily go up and down.</p><p>Gauges are typically used for measured values like temperatures or current memory usage, but also "counts" that can go up and down, like the number of concurrent requests.</p></blockquote><h4 id="Gauge-API-reference"><a class="docs-heading-anchor" href="#Gauge-API-reference">Gauge API reference</a><a id="Gauge-API-reference-1"></a><a class="docs-heading-anchor-permalink" href="#Gauge-API-reference" title="Permalink"></a></h4><article class="docstring"><header><a class="docstring-article-toggle-button fa-solid fa-chevron-down" href="javascript:;" title="Collapse docstring"></a><a class="docstring-binding" id="Prometheus.Gauge" href="#Prometheus.Gauge"><code>Prometheus.Gauge</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia hljs">Prometheus.Gauge(; name, help, registry=DEFAULT_REGISTRY)</code></pre><p>Construct a Gauge collector.</p><p><strong>Required keyword arguments</strong></p><ul><li><code>name :: String</code>: the name of the gauge metric.</li><li><code>help :: String</code>: the documentation for the gauge metric.</li></ul><p><strong>Optional keyword arguments</strong></p><ul><li><code>registry :: Prometheus.CollectorRegistry</code>: the registry in which to register the collector. If not specified the default registry is used. Pass <code>registry = nothing</code> to skip registration.</li></ul></div><a class="docs-sourcelink" target="_blank" href="https://github.com/fredrikekre/Prometheus.jl/blob/419b4e4f7d9835c8b56c4b1c42d4922be8d49a18/src/Prometheus.jl#L212-L225">source</a></section></article><article class="docstring"><header><a class="docstring-article-toggle-button fa-solid fa-chevron-down" href="javascript:;" title="Collapse docstring"></a><a class="docstring-binding" id="Prometheus.inc-Tuple{Prometheus.Gauge, Any}" href="#Prometheus.inc-Tuple{Prometheus.Gauge, Any}"><code>Prometheus.inc</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia hljs">Prometheus.inc(g::Gauge, v = 1)</code></pre><p>Increment the value of the gauge <code>g</code> with <code>v</code>. <code>v</code> defaults to <code>v = 1</code>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/fredrikekre/Prometheus.jl/blob/419b4e4f7d9835c8b56c4b1c42d4922be8d49a18/src/Prometheus.jl#L232-L237">source</a></section></article><article class="docstring"><header><a class="docstring-article-toggle-button fa-solid fa-chevron-down" href="javascript:;" title="Collapse docstring"></a><a class="docstring-binding" id="Prometheus.dec-Tuple{Prometheus.Gauge, Any}" href="#Prometheus.dec-Tuple{Prometheus.Gauge, Any}"><code>Prometheus.dec</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia hljs">Prometheus.dec(g::Gauge, v = 1)</code></pre><p>Decrement the value of the gauge <code>g</code> with <code>v</code>. <code>v</code> defaults to <code>v = 1</code>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/fredrikekre/Prometheus.jl/blob/419b4e4f7d9835c8b56c4b1c42d4922be8d49a18/src/Prometheus.jl#L243-L248">source</a></section></article><article class="docstring"><header><a class="docstring-article-toggle-button fa-solid fa-chevron-down" href="javascript:;" title="Collapse docstring"></a><a class="docstring-binding" id="Prometheus.set-Tuple{Prometheus.Gauge, Any}" href="#Prometheus.set-Tuple{Prometheus.Gauge, Any}"><code>Prometheus.set</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia hljs">Prometheus.set(g::Gauge, v)</code></pre><p>Set the value of the gauge to <code>v</code>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/fredrikekre/Prometheus.jl/blob/419b4e4f7d9835c8b56c4b1c42d4922be8d49a18/src/Prometheus.jl#L254-L258">source</a></section></article><article class="docstring"><header><a class="docstring-article-toggle-button fa-solid fa-chevron-down" href="javascript:;" title="Collapse docstring"></a><a class="docstring-binding" id="Prometheus.set_to_current_time-Tuple{Prometheus.Gauge}" href="#Prometheus.set_to_current_time-Tuple{Prometheus.Gauge}"><code>Prometheus.set_to_current_time</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia hljs">Prometheus.set_to_current_time(g::Gauge)</code></pre><p>Set the value of the gauge to the current unixtime in seconds.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/fredrikekre/Prometheus.jl/blob/419b4e4f7d9835c8b56c4b1c42d4922be8d49a18/src/Prometheus.jl#L264-L268">source</a></section></article><h3 id="Summary"><a class="docs-heading-anchor" href="#Summary">Summary</a><a id="Summary-1"></a><a class="docs-heading-anchor-permalink" href="#Summary" title="Permalink"></a></h3><p>Quoting the <a href="https://prometheus.io/docs/concepts/metric_types/#summary">upstream documentation</a>:</p><blockquote><p>Similar to a histogram, a summary samples observations (usually things like request durations and response sizes). While it also provides a total count of observations and a sum of all observed values, it calculates configurable quantiles over a sliding time window.</p></blockquote><h4 id="Summary-API-reference"><a class="docs-heading-anchor" href="#Summary-API-reference">Summary API reference</a><a id="Summary-API-reference-1"></a><a class="docs-heading-anchor-permalink" href="#Summary-API-reference" title="Permalink"></a></h4><article class="docstring"><header><a class="docstring-article-toggle-button fa-solid fa-chevron-down" href="javascript:;" title="Collapse docstring"></a><a class="docstring-binding" id="Prometheus.Summary" href="#Prometheus.Summary"><code>Prometheus.Summary</code></a> — <span class="docstring-category">Type</span></header><section><div><pre><code class="language-julia hljs">Prometheus.Summary(; name, help, registry=DEFAULT_REGISTRY)</code></pre><p>Construct a Summary collector.</p><p><strong>Required keyword arguments</strong></p><ul><li><code>name :: String</code>: the name of the summary metric.</li><li><code>help :: String</code>: the documentation for the summary metric.</li></ul><p><strong>Optional keyword arguments</strong></p><ul><li><code>registry :: Prometheus.CollectorRegistry</code>: the registry in which to register the collector. If not specified the default registry is used. Pass <code>registry = nothing</code> to skip registration.</li></ul></div><a class="docs-sourcelink" target="_blank" href="https://github.com/fredrikekre/Prometheus.jl/blob/419b4e4f7d9835c8b56c4b1c42d4922be8d49a18/src/Prometheus.jl#L320-L333">source</a></section></article><article class="docstring"><header><a class="docstring-article-toggle-button fa-solid fa-chevron-down" href="javascript:;" title="Collapse docstring"></a><a class="docstring-binding" id="Prometheus.observe-Tuple{Prometheus.Summary, Any}" href="#Prometheus.observe-Tuple{Prometheus.Summary, Any}"><code>Prometheus.observe</code></a> — <span class="docstring-category">Method</span></header><section><div><pre><code class="language-julia hljs">Prometheus.observe(summary::Summary, v)</code></pre><p>Add the observed value <code>v</code> to the summary. This increases the sum and count of the summary with <code>v</code> and <code>1</code>, respectively.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/fredrikekre/Prometheus.jl/blob/419b4e4f7d9835c8b56c4b1c42d4922be8d49a18/src/Prometheus.jl#L340-L345">source</a></section></article><h3 id="GCCollector"><a class="docs-heading-anchor" href="#GCCollector">GCCollector</a><a id="GCCollector-1"></a><a class="docs-heading-anchor-permalink" href="#GCCollector" title="Permalink"></a></h3><p>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 <code>gc_</code> prefix in their name.</p><h3 id="ProcessCollector"><a class="docs-heading-anchor" href="#ProcessCollector">ProcessCollector</a><a id="ProcessCollector-1"></a><a class="docs-heading-anchor-permalink" href="#ProcessCollector" title="Permalink"></a></h3><p>A collector that exports metrics about a running process, for example CPU seconds and metrics about I/O operations. Metrics from this collector have the <code>process_</code> prefix in their name. This collector is only available on Linux since it requires the <code>/proc</code> file system.</p><h3 id="Custom-collectors"><a class="docs-heading-anchor" href="#Custom-collectors">Custom collectors</a><a id="Custom-collectors-1"></a><a class="docs-heading-anchor-permalink" href="#Custom-collectors" title="Permalink"></a></h3><p>RandomCollector</p><h2 id="Labels"><a class="docs-heading-anchor" href="#Labels">Labels</a><a id="Labels-1"></a><a class="docs-heading-anchor-permalink" href="#Labels" title="Permalink"></a></h2><p>See <a href="https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels">https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels</a> for details.</p><p>All metrics can be labeled using the special <code>Prometheus.Family</code> collector. For example, a labeled Counter collector</p><pre><code class="language-julia hljs">labelnames = ["endpoint", "status_code"] |
|
|
counter_family = Prometheus.Family{Prometheus.Collector}( |
|
|
"http_requests", |
|
|
"Number of processed requests", |
|
|
labelnames, |
|
|
)</code></pre><p>Supported methods:</p><ul><li><code>Prometheus.labels(family, ["label 1", "label 2"])</code>: extract the child collector corresponding to the labels <code>["label 1", "label 2"]</code>.</li><li><code>Prometheus.remove(family, ["label 1", "label 2"])</code>: remove the child collector corresponding to the labels <code>["label 1", "label 2"]</code>.</li><li><code>Prometheus.clear(family)</code>: clear all child collectors.</li></ul><h2 id="Registries"><a class="docs-heading-anchor" href="#Registries">Registries</a><a id="Registries-1"></a><a class="docs-heading-anchor-permalink" href="#Registries" title="Permalink"></a></h2><h3 id="Default-collector-registry"><a class="docs-heading-anchor" href="#Default-collector-registry">Default collector registry</a><a id="Default-collector-registry-1"></a><a class="docs-heading-anchor-permalink" href="#Default-collector-registry" title="Permalink"></a></h3><h2 id="Exposition"><a class="docs-heading-anchor" href="#Exposition">Exposition</a><a id="Exposition-1"></a><a class="docs-heading-anchor-permalink" href="#Exposition" title="Permalink"></a></h2><p>Prometheus support</p><article class="docstring"><header><a class="docstring-article-toggle-button fa-solid fa-chevron-down" href="javascript:;" title="Collapse docstring"></a><a class="docstring-binding" id="Prometheus.expose" href="#Prometheus.expose"><code>Prometheus.expose</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia hljs">Prometheus.expose(file::String, reg::CollectorRegistry = DEFAULT_REGISTRY)</code></pre><p>Export all metrics in <code>reg</code> by writing them to the file <code>file</code>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/fredrikekre/Prometheus.jl/blob/419b4e4f7d9835c8b56c4b1c42d4922be8d49a18/src/Prometheus.jl#L603-L607">source</a></section><section><div><pre><code class="language-julia hljs">expose(io::IO, reg::CollectorRegistry = DEFAULT_REGISTRY)</code></pre><p>Export all metrics in <code>reg</code> by writing them to the I/O stream <code>io</code>.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/fredrikekre/Prometheus.jl/blob/419b4e4f7d9835c8b56c4b1c42d4922be8d49a18/src/Prometheus.jl#L619-L623">source</a></section><section><div><pre><code class="language-julia hljs">expose(http::HTTP.Stream, reg::CollectorRegistry = DEFAULT_REGISTRY; kwargs...)</code></pre><p>Export all metrics in <code>reg</code> by writing them to the HTTP stream <code>http</code>.</p><p>The caller is responsible for checking e.g. the HTTP method and URI target. For HEAD requests this method do not write a body, however.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/fredrikekre/Prometheus.jl/blob/419b4e4f7d9835c8b56c4b1c42d4922be8d49a18/src/Prometheus.jl#L662-L669">source</a></section></article></article><nav class="docs-footer"><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option><option value="auto">Automatic (OS)</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 1.1.2 on <span class="colophon-date" title="Saturday 4 November 2023 12:59">Saturday 4 November 2023</span>. Using Julia version 1.9.3.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
|
|
|
|