prometheus
This commit is contained in:
parent
c7e317985f
commit
173a903e78
3 changed files with 42 additions and 33 deletions
|
|
@ -5,6 +5,7 @@ use axum::{
|
|||
};
|
||||
use log::error;
|
||||
use thiserror::Error;
|
||||
use tokio::task::JoinError;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum Error {
|
||||
|
|
@ -49,6 +50,9 @@ pub enum Error {
|
|||
|
||||
#[error("Prometheus: {0:?}")]
|
||||
Prometheus(std::fmt::Error),
|
||||
|
||||
#[error("join error")]
|
||||
Join(#[from] JoinError),
|
||||
}
|
||||
|
||||
impl IntoResponse for Error {
|
||||
|
|
|
|||
15
src/main.rs
15
src/main.rs
|
|
@ -28,13 +28,13 @@ use garbage_collector::{start_gc, GarbageCollectorItem};
|
|||
use prometheus_client::{
|
||||
encoding::EncodeLabelSet,
|
||||
metrics::{counter::Counter, family::Family, gauge::Gauge},
|
||||
registry::Registry,
|
||||
registry::{self, Registry},
|
||||
};
|
||||
use question::{single_choice::SingleChoiceQuestion, Question};
|
||||
use sailfish::TemplateOnce;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use stream::{PlayerBroadcastStream, ViewerBroadcastStream};
|
||||
use tokio::sync::RwLock;
|
||||
use tokio::{sync::RwLock, task::spawn_blocking};
|
||||
use tower::ServiceBuilder;
|
||||
use tower_http::services::ServeDir;
|
||||
use tower_sessions::{cookie::SameSite, MemoryStore, SessionManagerLayer};
|
||||
|
|
@ -313,9 +313,14 @@ pub async fn sse_player(
|
|||
}
|
||||
|
||||
async fn metrics(State(app_state): State<AppState>) -> HandlerResult<impl IntoResponse> {
|
||||
let mut buffer = String::new();
|
||||
prometheus_client::encoding::text::encode(&mut buffer, &app_state.prometheus_registry)
|
||||
.map_err(Error::Prometheus)?;
|
||||
let registry = app_state.prometheus_registry.clone();
|
||||
let buffer = spawn_blocking::<_, Result<String, Error>>(move || {
|
||||
let mut buffer = String::new();
|
||||
prometheus_client::encoding::text::encode(&mut buffer, ®istry)
|
||||
.map_err(Error::Prometheus)?;
|
||||
Ok(buffer)
|
||||
})
|
||||
.await??;
|
||||
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue