Skip to main content

zebra_rpc/
metrics.rs

1//! Descriptions of the metrics this crate records.
2//!
3//! Applications that install a [`metrics`] recorder call [`describe`] right after installing it, so
4//! that exporters can document each metric, for example in Prometheus `# HELP` lines.
5
6use metrics::{describe_counter, describe_gauge, describe_histogram, Unit};
7
8/// The label keys of each labelled metric this crate records.
9///
10/// - `method`: a JSON-RPC method name the server registers, or `unknown`.
11/// - `status`: `success` or `error`.
12/// - `error_code`: the JSON-RPC error code, such as `-8`, or `unknown`.
13/// - `outcome`: a `submitblock` result, `accepted`, `duplicate`, `duplicate-inconclusive`,
14///   `inconclusive`, or `rejected`.
15pub const LABELS: &[(&str, &[&str])] = &[
16    ("rpc.requests.total", &["method", "status"]),
17    ("rpc.request.duration_seconds", &["method"]),
18    ("rpc.errors.total", &["method", "error_code"]),
19    ("rpc.submitblock.outcomes.total", &["outcome"]),
20];
21
22/// Describes every metric this crate records to the installed [`metrics`] recorder.
23pub fn describe() {
24    describe_counter!(
25        "rpc.requests.total",
26        Unit::Count,
27        "JSON-RPC requests handled, by method and status."
28    );
29    describe_histogram!(
30        "rpc.request.duration_seconds",
31        Unit::Seconds,
32        "Time taken to handle a JSON-RPC request."
33    );
34    describe_gauge!(
35        "rpc.active_requests",
36        Unit::Count,
37        "JSON-RPC requests currently being handled."
38    );
39    describe_histogram!(
40        "rpc.getblocktemplate.build.duration_seconds",
41        Unit::Seconds,
42        "Time taken to select transactions and build a block template, including the coinbase."
43    );
44    describe_histogram!(
45        "rpc.getblocktemplate.first_template.duration_seconds",
46        Unit::Seconds,
47        "Time from a new best chain tip until the first block template on it was served."
48    );
49    describe_counter!(
50        "rpc.submitblock.outcomes.total",
51        Unit::Count,
52        "Blocks submitted with submitblock, by their zcashd-compatible result."
53    );
54    describe_counter!(
55        "rpc.errors.total",
56        Unit::Count,
57        "JSON-RPC requests that returned an error, by method and error code."
58    );
59}