mz_postgres_client/
metrics.rs1use mz_ore::metric;
13use mz_ore::metrics::{Counter, IntCounter, MetricsRegistry, UIntGauge};
14
15#[derive(Debug, Clone)]
18pub struct PostgresClientMetrics {
19 pub(crate) connpool_size: UIntGauge,
20 pub(crate) connpool_acquires: IntCounter,
21 pub(crate) connpool_acquire_seconds: Counter,
22 pub(crate) connpool_available: prometheus::Gauge,
23 pub(crate) connpool_connections_created: Counter,
24 pub(crate) connpool_connection_errors: Counter,
25 pub(crate) connpool_ttl_reconnections: Counter,
26}
27
28impl PostgresClientMetrics {
29 pub fn new(registry: &MetricsRegistry, prefix: &str) -> Self {
31 Self {
32 connpool_size: registry.register(metric!(
33 name: format!("{}_postgres_connpool_size", prefix),
34 help: "number of connections currently in pool",
35 )),
36 connpool_acquires: registry.register(metric!(
37 name: format!("{}_postgres_connpool_acquires", prefix),
38 help: "times a connection has been acquired from pool",
39 )),
40 connpool_acquire_seconds: registry.register(metric!(
41 name: format!("{}_postgres_connpool_acquire_seconds", prefix),
42 help: "time spent acquiring connections from pool",
43 )),
44 connpool_available: registry.register(metric!(
45 name: format!("{}_postgres_connpool_available", prefix),
46 help: "available connections in the pool",
47 )),
48 connpool_connections_created: registry.register(metric!(
49 name: format!("{}_postgres_connpool_connections_created", prefix),
50 help: "times a connection was created",
51 )),
52 connpool_connection_errors: registry.register(metric!(
53 name: format!("{}_postgres_connpool_connection_errors", prefix),
54 help: "number of errors when establishing a new connection",
55 )),
56 connpool_ttl_reconnections: registry.register(metric!(
57 name: format!("{}_postgres_connpool_ttl_reconnections", prefix),
58 help: "times a connection was recycled due to ttl",
59 )),
60 }
61 }
62}