Skip to content

Commit

Permalink
Active torrent count as well
Browse files Browse the repository at this point in the history
  • Loading branch information
ckcr4lyf committed Oct 29, 2024
1 parent b7107d5 commit 544d84b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/bin/kiryuu-exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ async fn metrics(data: web::Data<AppState>) -> HttpResponse {

let (announce_count, req_duration, cache_hit_count, nochange_count): (i64, i64, i64, i64) = redis::cmd("MGET").arg(constants::ANNOUNCE_COUNT_KEY).arg(constants::REQ_DURATION_KEY).arg(constants::CACHE_HIT_ANNOUNCE_COUNT_KEY).arg(constants::NOCHANGE_ANNOUNCE_COUNT_KEY).query_async(&mut redis_connection).await.expect("fucc");

let rows = data.postgres_client.query("SELECT COUNT(*) FROM torrents WHERE last_announce > (extract(epoch from now()) * 1000) - 1000 * 60 * 31;", &[]).await.expect("fucc psql");

let active_count: i64 = rows[0].get(0);

let response = format!(r#"
kouko_http_nochange_request_count{{status_code="200", method="GET", path="announce"}} {}
kouko_http_cache_hit_request_count{{status_code="200", method="GET", path="announce"}} {}
kouko_http_request_count{{status_code="200", method="GET", path="announce"}} {}
kouko_http_request_duration_sum{{status_code="200", method="GET", path="announce"}} {}
kiryuu_http_nochange_request_count{{status_code="200", method="GET", path="announce"}} {}
kiryuu_http_cache_hit_request_count{{status_code="200", method="GET", path="announce"}} {}
kiryuu_http_request_count{{status_code="200", method="GET", path="announce"}} {}
kiryuu_http_request_duration_sum{{status_code="200", method="GET", path="announce"}} {}
kiryuu_active_torrent_count {}
"#, nochange_count, cache_hit_count, announce_count, req_duration);
"#, nochange_count, cache_hit_count, announce_count, req_duration, active_count);

HttpResponse::build(StatusCode::OK).append_header(header::ContentType::plaintext()).body(response)
}
Expand Down

0 comments on commit 544d84b

Please sign in to comment.