Skip to content

Commit 240796d

Browse files
committed
fix(guard): add metrics
1 parent 39220d3 commit 240796d

File tree

9 files changed

+243
-102
lines changed

9 files changed

+243
-102
lines changed

packages/common/logs/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ impl Logs {
2525
}
2626

2727
impl Logs {
28-
pub async fn start(self) -> Result<tokio::task::JoinHandle<()>> {
28+
pub async fn start(mut self) -> Result<tokio::task::JoinHandle<()>> {
2929
// Create logs dir if it does not exist
3030
fs::create_dir_all(&self.path).await?;
3131

32+
self.rotate().await?;
33+
3234
Ok(tokio::spawn(self.run()))
3335
}
3436

@@ -112,10 +114,12 @@ impl Logs {
112114
}
113115

114116
impl Logs {
115-
pub fn start_sync(self) -> Result<std::thread::JoinHandle<()>> {
117+
pub fn start_sync(mut self) -> Result<std::thread::JoinHandle<()>> {
116118
// Create logs dir if it does not exist
117119
std::fs::create_dir_all(&self.path)?;
118120

121+
self.rotate_sync()?;
122+
119123
Ok(std::thread::spawn(|| self.run_sync()))
120124
}
121125

packages/common/server-cli/src/commands/start.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ impl Opts {
5454
.and_then(|x| x.rivet.edge.as_ref())
5555
.and_then(|x| x.redirect_logs_dir.as_ref())
5656
{
57-
std::fs::create_dir_all(logs_dir)?;
5857
rivet_logs::Logs::new(logs_dir.clone(), LOGS_RETENTION)
5958
.start()
6059
.await?;

packages/core/services/cluster/src/workflows/server/install/install_scripts/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,14 @@ pub async fn gen_initialize(
227227
)?);
228228
script.push(components::rivet::guard::fetch_tls(server_token)?);
229229
script.push(components::rivet::guard::configure(config)?);
230+
231+
prometheus_targets.insert(
232+
"guard".into(),
233+
components::vector::PrometheusTarget {
234+
endpoint: "http://127.0.0.1:8091".into(),
235+
scrape_interval: 15,
236+
},
237+
);
230238
}
231239
}
232240

Lines changed: 79 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,95 @@
11
use lazy_static::lazy_static;
2-
use rivet_metrics::prometheus::*;
2+
use rivet_metrics::{prometheus::*, REGISTRY};
33

44
lazy_static! {
5-
pub static ref ACTOR_REQUEST_TOTAL: IntCounterVec = register_int_counter_vec!(
6-
"actor_request_total",
5+
// MARK: Internal
6+
pub static ref ROUTE_CACHE_SIZE: IntGauge = register_int_gauge_with_registry!(
7+
"guard_route_cache_size",
8+
"Number of entries in the route cache",
9+
*REGISTRY,
10+
).unwrap();
11+
pub static ref RATE_LIMITERS_COUNT: IntGauge = register_int_gauge_with_registry!(
12+
"guard_rate_limiters_count",
13+
"Number of active rate limiters",
14+
*REGISTRY,
15+
).unwrap();
16+
pub static ref IN_FLIGHT_COUNTERS_COUNT: IntGauge = register_int_gauge_with_registry!(
17+
"guard_in_flight_counters_count",
18+
"Number of active in-flight counters",
19+
*REGISTRY,
20+
)
21+
.unwrap();
22+
23+
// MARK: TCP
24+
pub static ref TCP_CONNECTION_TOTAL: IntCounter = register_int_counter_with_registry!(
25+
"guard_request_total",
26+
"Total number of TCP connections ever",
27+
*REGISTRY,
28+
)
29+
.unwrap();
30+
pub static ref TCP_CONNECTION_PENDING: IntGauge = register_int_gauge_with_registry!(
31+
"guard_tcp_connection_pending",
32+
"Total number of open TCP connections",
33+
*REGISTRY,
34+
)
35+
.unwrap();
36+
pub static ref TCP_CONNECTION_DURATION: Histogram = register_histogram_with_registry!(
37+
"guard_tcp_connection_duration",
38+
"TCP connection duration in seconds",
39+
*REGISTRY,
40+
)
41+
.unwrap();
42+
43+
// MARK: Requests
44+
pub static ref REQUEST_TOTAL: IntCounterVec = register_int_counter_vec_with_registry!(
45+
"guard_request_total",
46+
"Total number of requests processed",
47+
&["method"],
48+
*REGISTRY,
49+
)
50+
.unwrap();
51+
pub static ref REQUEST_PENDING: IntGaugeVec = register_int_gauge_vec_with_registry!(
52+
"guard_request_pending",
53+
"Total number of active requests being processed",
54+
&["method"],
55+
*REGISTRY,
56+
)
57+
.unwrap();
58+
pub static ref REQUEST_DURATION: HistogramVec = register_histogram_vec_with_registry!(
59+
"guard_request_duration",
60+
"Request duration in seconds",
61+
&["method", "status_code"],
62+
*REGISTRY,
63+
)
64+
.unwrap();
65+
66+
// MARK: Actors
67+
pub static ref ACTOR_REQUEST_TOTAL: IntCounterVec = register_int_counter_vec_with_registry!(
68+
"guard_actor_request_total",
769
"Total number of requests to actor",
8-
&["actor_id", "server_id", "method", "path"]
70+
&["actor_id", "server_id", "method", "path"],
71+
*REGISTRY,
972
)
1073
.unwrap();
11-
pub static ref ACTOR_REQUEST_PENDING: IntGaugeVec = register_int_gauge_vec!(
12-
"actor_request_pending",
74+
pub static ref ACTOR_REQUEST_PENDING: IntGaugeVec = register_int_gauge_vec_with_registry!(
75+
"guard_actor_request_pending",
1376
"Number of pending requests to actor",
14-
&["actor_id", "server_id", "method", "path"]
77+
&["actor_id", "server_id", "method", "path"],
78+
*REGISTRY,
1579
)
1680
.unwrap();
17-
pub static ref ACTOR_REQUEST_DURATION: HistogramVec = register_histogram_vec!(
18-
"actor_request_duration_seconds",
81+
pub static ref ACTOR_REQUEST_DURATION: HistogramVec = register_histogram_vec_with_registry!(
82+
"guard_actor_request_duration",
1983
"Request duration in seconds",
20-
&["actor_id", "server_id", "status"]
84+
&["actor_id", "server_id", "status"],
85+
*REGISTRY,
2186
)
2287
.unwrap();
23-
pub static ref ACTOR_REQUEST_ERRORS: IntCounterVec = register_int_counter_vec!(
24-
"actor_request_errors_total",
88+
pub static ref ACTOR_REQUEST_ERRORS: IntCounterVec = register_int_counter_vec_with_registry!(
89+
"guard_actor_request_errors_total",
2590
"Total number of errors when proxying requests to actor",
26-
&["actor_id", "server_id", "error_type"]
91+
&["actor_id", "server_id", "error_type"],
92+
*REGISTRY,
2793
)
2894
.unwrap();
2995
}

0 commit comments

Comments
 (0)