Expose HTTP /stats endpoint

This commit is contained in:
Igor Katson 2024-08-21 12:20:36 +01:00
parent 5d3a93b8bd
commit 561c8b8a1d
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
5 changed files with 46 additions and 1 deletions

View file

@ -63,6 +63,7 @@ impl HttpApi {
"GET /dht/table": "DHT routing table",
"GET /torrents": "List torrents",
"GET /torrents/playlist": "Generate M3U8 playlist for all files in all torrents",
"GET /stats": "Global session stats",
"POST /torrents/resolve_magnet": "Resolve a magnet to torrent file bytes",
"GET /torrents/{id_or_infohash}": "Torrent details",
"GET /torrents/{id_or_infohash}/haves": "The bitfield of have pieces",
@ -92,6 +93,10 @@ impl HttpApi {
state.api_dht_table().map(axum::Json)
}
async fn session_stats(State(state): State<ApiState>) -> impl IntoResponse {
axum::Json(state.api_session_stats())
}
async fn torrents_list(State(state): State<ApiState>) -> impl IntoResponse {
axum::Json(state.api_torrent_list())
}
@ -450,6 +455,7 @@ impl HttpApi {
.route("/rust_log", post(set_rust_log))
.route("/dht/stats", get(dht_stats))
.route("/dht/table", get(dht_table))
.route("/stats", get(session_stats))
.route("/torrents", get(torrents_list))
.route("/torrents/:id", get(torrent_details))
.route("/torrents/:id/haves", get(torrent_haves))