Compare commits
No commits in common. "bd86ab8b521e5da68d901485faff6af06a121951" and "72fc8fb5889c7e37dad307a454330f43599af935" have entirely different histories.
bd86ab8b52
...
72fc8fb588
19
src/main.rs
19
src/main.rs
@ -53,7 +53,7 @@ async fn get_baeder_names() -> Result<HashMap<String, String>, String> {
|
||||
|
||||
for c in r.captures_iter(baedernames_body.as_str()) {
|
||||
baedernames.insert(
|
||||
c.get(1).unwrap().as_str().trim_start_matches('0').to_string(), // id
|
||||
c.get(1).unwrap().as_str().to_string(), // id
|
||||
c.get(2).unwrap().as_str().to_string(), // name
|
||||
);
|
||||
}
|
||||
@ -62,13 +62,6 @@ async fn get_baeder_names() -> Result<HashMap<String, String>, String> {
|
||||
|
||||
}
|
||||
|
||||
fn escape_metric_label_value(value: &String) -> String {
|
||||
let value = value.replace(r#"\"#, r#"\\"#);
|
||||
let value = value.replace("\n", r"\n");
|
||||
let value = value.replace(r#"""#, r#"\""#);
|
||||
return value;
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct AppState {
|
||||
baedernames: HashMap<String, String>,
|
||||
@ -121,7 +114,6 @@ async fn main() {
|
||||
|
||||
let listener = tokio::net::TcpListener::bind(listen).await.unwrap();
|
||||
println!("Server listening on: http://{}", listener.local_addr().unwrap());
|
||||
println!("Matrics exposed as: http://{}/metrics", listener.local_addr().unwrap());
|
||||
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
}
|
||||
@ -151,14 +143,7 @@ async fn route_metrics(
|
||||
let mut out = String::new();
|
||||
|
||||
for bad in trafficdata {
|
||||
let badid = escape_metric_label_value(&bad.id);
|
||||
match state.baedernames.get(&bad.id) {
|
||||
Some(name) => {
|
||||
let badname = escape_metric_label_value(name);
|
||||
out.push_str(&format!("berlinerbaeder_occupation{{bad=\"{}\", badname=\"{}\"}} {}\n", badid, badname, bad.counter.unwrap_or(-1)))}
|
||||
,
|
||||
None => out.push_str(&format!("berlinerbaeder_occupation{{bad=\"{}\"}} {}\n", badid, bad.counter.unwrap_or(-1))),
|
||||
};
|
||||
out.push_str(&format!("berlinerbaeder_occupation{{bad=\"{}\" badname=\"{}\"}} {}\n", bad.id, state.baedernames.get(&bad.id).unwrap_or(&String::new()), bad.counter.unwrap_or(-1)));
|
||||
}
|
||||
|
||||
return Ok(out);
|
||||
|
Loading…
Reference in New Issue
Block a user