mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-07-31 01:36:15 -04:00
ops: Add prometheus metrics
Adds a /metrics endpoint in serve mode. Can be disabled via --disable-metrics. In fetch, dumps the metrics if --metrics is specified (defaults to false). None of the metrics being collected are on a hot path, so they're just always collected using atomic operations (i.e. no `if (!enabled) return;`). Because the operations are cheap and infrequent enough not to matter. The one place I want to add more metrics is in HttpClient (bytes, status, counts, ...) but after the pending HttpClient-related PR is merged. ./lightpanda fetch --log-level fatal --metrics "https://lightpanda.io/" ``` build_info{version="1.0.0-dev.7837+70493ce35"} 1 cdp_connections_total 0 cdp_connection_limit_total 0 cdp_active_connections 0 cdp_commands_total 0 cdp_unknown_commands_total 0 js_heap_limits_total 0 script_errors_total 0 arena_hit_total{size="tiny"} 908 arena_hit_total{size="small"} 35 arena_hit_total{size="medium"} 0 arena_hit_total{size="large"} 27 arena_miss_total{size="tiny"} 193 arena_miss_total{size="small"} 31 arena_miss_total{size="medium"} 5 arena_miss_total{size="large"} 23 navigate_total{type="page"} 1 navigate_total{type="iframe"} 0 navigate_total{type="popup"} 0 js_heap_size_bytes_bucket{le="4194304"} 0 js_heap_size_bytes_bucket{le="8388608"} 0 js_heap_size_bytes_bucket{le="16777216"} 1 js_heap_size_bytes_bucket{le="33554432"} 1 js_heap_size_bytes_bucket{le="67108864"} 1 js_heap_size_bytes_bucket{le="134217728"} 1 js_heap_size_bytes_bucket{le="268435456"} 1 js_heap_size_bytes_bucket{le="536870912"} 1 js_heap_size_bytes_bucket{le="+Inf"} 1 js_heap_size_bytes_sum 11223040 js_heap_size_bytes_count 1 ```
This commit is contained in:
@@ -203,6 +203,7 @@ const Commands = cli.Builder(.{
|
||||
.{ .name = "cdp_max_message_size", .type = u32, .default = 1024 * 1024 },
|
||||
// Don't widen this without growing the reader buffer in the HTTP path.
|
||||
.{ .name = "cdp_max_http_message_size", .type = u14, .default = 4096 },
|
||||
.{ .name = "disable_metrics", .type = bool },
|
||||
},
|
||||
.shared_options = CommonOptions,
|
||||
},
|
||||
@@ -235,6 +236,7 @@ const Commands = cli.Builder(.{
|
||||
},
|
||||
.{ .name = "terminate_ms", .type = ?u32 },
|
||||
.{ .name = "json", .type = bool },
|
||||
.{ .name = "metrics", .type = bool },
|
||||
},
|
||||
.shared_options = CommonOptions,
|
||||
},
|
||||
@@ -586,6 +588,20 @@ pub fn cdpMaxMessageSize(self: *const Config) u32 {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn metricsEndpointEnabled(self: *const Config) bool {
|
||||
return switch (self.mode) {
|
||||
.serve => |opts| !opts.disable_metrics,
|
||||
else => unreachable,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn dumpMetricsOnExit(self: *const Config) bool {
|
||||
return switch (self.mode) {
|
||||
.fetch => |opts| opts.metrics,
|
||||
else => false,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn cdpMaxHTTPMessageSize(self: *const Config) u14 {
|
||||
return switch (self.mode) {
|
||||
.serve => |opts| opts.cdp_max_http_message_size,
|
||||
|
||||
Reference in New Issue
Block a user