diff --git a/src/bin/kiryuu-exporter.rs b/src/bin/kiryuu-exporter.rs index bc21c1e..472aaf7 100644 --- a/src/bin/kiryuu-exporter.rs +++ b/src/bin/kiryuu-exporter.rs @@ -20,13 +20,18 @@ async fn metrics(data: web::Data) -> 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) }