Line data Source code
1 : use metrics::core::{AtomicF64, Collector, GenericGauge};
2 : use metrics::proto::MetricFamily;
3 : use metrics::{
4 : IntCounterVec, UIntGaugeVec, register_gauge, register_int_counter_vec, register_uint_gauge_vec,
5 : };
6 : use once_cell::sync::Lazy;
7 :
8 0 : pub(crate) static INSTALLED_EXTENSIONS: Lazy<UIntGaugeVec> = Lazy::new(|| {
9 0 : register_uint_gauge_vec!(
10 0 : "compute_installed_extensions",
11 0 : "Number of databases where the version of extension is installed",
12 0 : &["extension_name", "version", "owned_by_superuser"]
13 0 : )
14 0 : .expect("failed to define a metric")
15 0 : });
16 :
17 : // Normally, any HTTP API request is described by METHOD (e.g. GET, POST, etc.) + PATH,
18 : // but for all our APIs we defined a 'slug'/method/operationId in the OpenAPI spec.
19 : // And it's fair to call it a 'RPC' (Remote Procedure Call).
20 : pub enum CPlaneRequestRPC {
21 : GetSpec,
22 : }
23 :
24 : impl CPlaneRequestRPC {
25 0 : pub fn as_str(&self) -> &str {
26 0 : match self {
27 0 : CPlaneRequestRPC::GetSpec => "GetSpec",
28 0 : }
29 0 : }
30 : }
31 :
32 : pub const UNKNOWN_HTTP_STATUS: &str = "unknown";
33 :
34 0 : pub(crate) static CPLANE_REQUESTS_TOTAL: Lazy<IntCounterVec> = Lazy::new(|| {
35 0 : register_int_counter_vec!(
36 0 : "compute_ctl_cplane_requests_total",
37 0 : "Total number of control plane requests made by compute_ctl by status",
38 0 : &["rpc", "http_status"]
39 0 : )
40 0 : .expect("failed to define a metric")
41 0 : });
42 :
43 : /// Total number of failed database migrations. Per-compute, this is actually a boolean metric,
44 : /// either empty or with a single value (1, migration_id) because we stop at the first failure.
45 : /// Yet, the sum over the fleet will provide the total number of failures.
46 0 : pub(crate) static DB_MIGRATION_FAILED: Lazy<IntCounterVec> = Lazy::new(|| {
47 0 : register_int_counter_vec!(
48 0 : "compute_ctl_db_migration_failed_total",
49 0 : "Total number of failed database migrations",
50 0 : &["migration_id"]
51 0 : )
52 0 : .expect("failed to define a metric")
53 0 : });
54 :
55 0 : pub(crate) static REMOTE_EXT_REQUESTS_TOTAL: Lazy<IntCounterVec> = Lazy::new(|| {
56 0 : register_int_counter_vec!(
57 0 : "compute_ctl_remote_ext_requests_total",
58 0 : "Total number of requests made by compute_ctl to download extensions from S3 proxy by status",
59 0 : &["http_status", "filename"]
60 0 : )
61 0 : .expect("failed to define a metric")
62 0 : });
63 :
64 : // Size of audit log directory in bytes
65 0 : pub(crate) static AUDIT_LOG_DIR_SIZE: Lazy<GenericGauge<AtomicF64>> = Lazy::new(|| {
66 0 : register_gauge!(
67 0 : "compute_audit_log_dir_size",
68 0 : "Size of audit log directory in bytes",
69 0 : )
70 0 : .expect("failed to define a metric")
71 0 : });
72 :
73 0 : pub fn collect() -> Vec<MetricFamily> {
74 0 : let mut metrics = INSTALLED_EXTENSIONS.collect();
75 0 : metrics.extend(CPLANE_REQUESTS_TOTAL.collect());
76 0 : metrics.extend(REMOTE_EXT_REQUESTS_TOTAL.collect());
77 0 : metrics.extend(DB_MIGRATION_FAILED.collect());
78 0 : metrics.extend(AUDIT_LOG_DIR_SIZE.collect());
79 0 : metrics
80 0 : }
|