1
0
mirror of https://github.com/chylex/Apache-Prometheus-Exporter.git synced 2025-04-19 19:15:46 +02:00

Add apache_requests_total metric

This commit is contained in:
chylex 2022-09-11 23:22:08 +02:00
parent 507bfc1137
commit e4ef6726c1
Signed by: chylex
GPG Key ID: 4DE42C8F19A80548
2 changed files with 15 additions and 3 deletions

View File

@ -1,12 +1,23 @@
use prometheus_client::metrics::counter::Counter;
use prometheus_client::metrics::family::Family;
use prometheus_client::registry::Registry;
#[derive(Clone)]
pub struct ApacheMetrics {}
pub struct ApacheMetrics {
pub requests_total: Family<(&'static str, String), Counter>
}
impl ApacheMetrics {
pub fn new() -> (Registry, ApacheMetrics) {
let mut registry = <Registry>::default();
let metrics = ApacheMetrics {};
let requests_total = Family::<(&'static str, String), Counter>::default();
registry.register("apache_requests", "Number of received requests", Box::new(requests_total.clone()));
let metrics = ApacheMetrics {
requests_total
};
return (registry, metrics);
}
}

View File

@ -36,8 +36,9 @@ async fn read_logs(log_files: Vec<LogFilePath>, metrics: ApacheMetrics) -> io::R
let event_result = file_reader.next_line().await?;
if let Some(event) = event_result {
match label_lookup.get(event.source()) {
Some(label) => {
Some(&label) => {
println!("[LogWatcher] Received line from \"{}\": {}", label, event.line());
metrics.requests_total.get_or_create(&("file", label.clone())).inc();
}
None => {
println!("[LogWatcher] Received line from unknown file: {}", event.source().display());