mirror of
https://git.madhouse-project.org/algernon/iocaine.git
synced 2025-03-10 09:18:49 +01:00
metrics: Implement iocaine_maze_depth
Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
This commit is contained in:
parent
fd1530707e
commit
2bfc4c81a8
3 changed files with 18 additions and 1 deletions
|
@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- The `iocaine_garbage_served` metric will have the same labels applied to it as `iocaine_requests_total`.
|
- The `iocaine_garbage_served` metric will have the same labels applied to it as `iocaine_requests_total`.
|
||||||
|
- Implemented a new metric, `iocaine_maze_depth`, a counter to track how deep the maze has been explored so far.
|
||||||
- When metrics are enabled, process metrics such as CPU seconds used, memory usage, etc, are also emitted.
|
- When metrics are enabled, process metrics such as CPU seconds used, memory usage, etc, are also emitted.
|
||||||
|
|
||||||
## [1.0.0] - 2025-03-01
|
## [1.0.0] - 2025-03-01
|
||||||
|
|
|
@ -123,7 +123,7 @@ async fn poison(
|
||||||
) -> std::result::Result<Html<String>, AppError> {
|
) -> std::result::Result<Html<String>, AppError> {
|
||||||
let default_host = axum::http::HeaderValue::from_static("<unknown>");
|
let default_host = axum::http::HeaderValue::from_static("<unknown>");
|
||||||
let host = headers.get("host").unwrap_or(&default_host).to_str()?;
|
let host = headers.get("host").unwrap_or(&default_host).to_str()?;
|
||||||
let path = path.unwrap_or(Path("/".to_string()));
|
let path = path.unwrap_or(Path("".to_string()));
|
||||||
|
|
||||||
let garbage = AssembledStatisticalSequences::generate(&state.iocaine, host, &path)?;
|
let garbage = AssembledStatisticalSequences::generate(&state.iocaine, host, &path)?;
|
||||||
|
|
||||||
|
@ -135,6 +135,13 @@ async fn poison(
|
||||||
.garbage_served_counter
|
.garbage_served_counter
|
||||||
.with_label_values(&labels)
|
.with_label_values(&labels)
|
||||||
.inc_by(garbage.len() as u64);
|
.inc_by(garbage.len() as u64);
|
||||||
|
|
||||||
|
let depth = path.chars().filter(|c| *c == '/').count() as u64;
|
||||||
|
let maze_depth_counter = counters.maze_depth.with_label_values(&labels);
|
||||||
|
let maze_depth = maze_depth_counter.get();
|
||||||
|
if depth > maze_depth {
|
||||||
|
maze_depth_counter.inc_by(depth - maze_depth);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Html(garbage))
|
Ok(Html(garbage))
|
||||||
|
|
|
@ -22,6 +22,7 @@ pub struct TenXProgrammer {
|
||||||
pub struct TenXProgrammerCounters {
|
pub struct TenXProgrammerCounters {
|
||||||
pub request_counter: IntCounterVec,
|
pub request_counter: IntCounterVec,
|
||||||
pub garbage_served_counter: IntCounterVec,
|
pub garbage_served_counter: IntCounterVec,
|
||||||
|
pub maze_depth: IntCounterVec,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TenXProgrammer {
|
impl TenXProgrammer {
|
||||||
|
@ -109,11 +110,19 @@ impl TenXProgrammer {
|
||||||
.register(Box::new(garbage_served_counter.clone()))
|
.register(Box::new(garbage_served_counter.clone()))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
let maze_depth_opts = Opts::new(
|
||||||
|
"iocaine_maze_depth",
|
||||||
|
"Maximum explored depth of the maze (in path parts)",
|
||||||
|
);
|
||||||
|
let maze_depth = IntCounterVec::new(maze_depth_opts, &labels).unwrap();
|
||||||
|
registry.register(Box::new(maze_depth.clone())).unwrap();
|
||||||
|
|
||||||
Some(Self {
|
Some(Self {
|
||||||
registry,
|
registry,
|
||||||
counters: TenXProgrammerCounters {
|
counters: TenXProgrammerCounters {
|
||||||
request_counter,
|
request_counter,
|
||||||
garbage_served_counter,
|
garbage_served_counter,
|
||||||
|
maze_depth,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue