mirror of
https://github.com/shiroyashik/sculptor.git
synced 2025-12-06 04:51:13 +03:00
metric names renamed and small fixes
This commit is contained in:
parent
45aa79da6d
commit
b02cca8608
4 changed files with 18 additions and 21 deletions
|
|
@ -15,7 +15,6 @@ pub async fn initial(
|
|||
ws.on_upgrade(|socket| handle_socket(socket, state))
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
async fn handle_socket(mut ws: WebSocket, state: AppState) {
|
||||
// Trying authenticate & get user data or dropping connection
|
||||
match authenticate(&mut ws, &state).await {
|
||||
|
|
@ -65,7 +64,7 @@ async fn handle_socket(mut ws: WebSocket, state: AppState) {
|
|||
if let Err(kind) = ws.send(Message::Close(None)).await { tracing::trace!("[WebSocket] Closing fault: {}", kind) }
|
||||
}
|
||||
|
||||
#[instrument(skip_all, parent = None, fields(nickname = %session.user.nickname))]
|
||||
#[instrument(skip_all, fields(nickname = %session.user.nickname))]
|
||||
async fn main_worker(session: &mut WSSession, ws: &mut WebSocket, state: &AppState) -> anyhow::Result<()> {
|
||||
tracing::debug!("WebSocket control for {} is transferred to the main worker", session.user.nickname);
|
||||
loop {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ pub const TIMEOUT: std::time::Duration = std::time::Duration::from_secs(10);
|
|||
|
||||
// Figura update checker
|
||||
pub const FIGURA_RELEASES_URL: &str = "https://api.github.com/repos/figuramc/figura/releases";
|
||||
pub const FIGURA_DEFAULT_VERSION: &str = "0.1.4";
|
||||
pub const FIGURA_DEFAULT_VERSION: &str = "0.1.5";
|
||||
|
||||
// Figura Assets
|
||||
pub const FIGURA_ASSETS_ZIP_URL: &str = "https://github.com/FiguraMC/Assets/archive/refs/heads/main.zip";
|
||||
|
|
|
|||
20
src/main.rs
20
src/main.rs
|
|
@ -105,6 +105,13 @@ async fn main() -> Result<()> {
|
|||
},
|
||||
}
|
||||
|
||||
// Creating avatars folder
|
||||
let path = PathBuf::from(&*AVATARS_VAR);
|
||||
if !path.exists() {
|
||||
fs::create_dir_all(path).await.expect("Can't create avatars folder!");
|
||||
tracing::info!("Created avatars directory");
|
||||
}
|
||||
|
||||
// 4. Starting an app() that starts to serve. If app() returns true, the sculptor will be restarted. TODO: for future
|
||||
loop {
|
||||
if !app().await? {
|
||||
|
|
@ -116,15 +123,6 @@ async fn main() -> Result<()> {
|
|||
}
|
||||
|
||||
async fn app() -> Result<bool> {
|
||||
// Preparing for launch
|
||||
{
|
||||
let path = PathBuf::from(&*AVATARS_VAR);
|
||||
if !path.exists() {
|
||||
fs::create_dir_all(path).await.expect("Can't create avatars folder!");
|
||||
tracing::info!("Created avatars directory");
|
||||
}
|
||||
}
|
||||
|
||||
// Config
|
||||
let config = Config::parse(CONFIG_VAR.clone().into());
|
||||
let listen = config.listen.clone();
|
||||
|
|
@ -198,6 +196,8 @@ async fn app() -> Result<bool> {
|
|||
.nest("/api", api)
|
||||
.route("/api/", get(check_auth))
|
||||
.route("/ws", get(ws))
|
||||
.merge(metrics::metrics_router(config.metrics_enabled))
|
||||
.with_state(state)
|
||||
.layer(TraceLayer::new_for_http()
|
||||
// .on_request(|request: &axum::http::Request<_>, _span: &tracing::Span| {
|
||||
// // only for developing purposes
|
||||
|
|
@ -209,8 +209,6 @@ async fn app() -> Result<bool> {
|
|||
.on_request(())
|
||||
)
|
||||
.layer(axum::middleware::from_fn(track_metrics))
|
||||
.merge(metrics::metrics_router(config.metrics_enabled))
|
||||
.with_state(state)
|
||||
.route("/health", get(|| async { "ok" }));
|
||||
|
||||
let listener = tokio::net::TcpListener::bind(listen).await?;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ async fn metrics(State(state): State<AppState>) -> String {
|
|||
let mut metric = prometheus::proto::Metric::default();
|
||||
metric.set_gauge(prometheus::proto::Gauge::default());
|
||||
metric.mut_gauge().set_value(state.session.len() as f64);
|
||||
create_mf("players_count".to_string(), "Number of players".to_string(), MetricType::GAUGE, metric)
|
||||
create_mf("sculptor_players_count".to_string(), "Number of players".to_string(), MetricType::GAUGE, metric)
|
||||
};
|
||||
|
||||
metric_families.push(players);
|
||||
|
|
@ -58,14 +58,14 @@ pub async fn track_metrics(req: Request<Body>, next: Next) -> Result<Response<Bo
|
|||
Ok(response)
|
||||
}
|
||||
|
||||
pub static PINGS_ERROR: LazyLock<prometheus::IntCounter> = LazyLock::new(|| {
|
||||
register_int_counter!("pings_error", "Number of ping decoding errors").unwrap()
|
||||
});
|
||||
|
||||
pub static REQUESTS: LazyLock<prometheus::HistogramVec> = LazyLock::new(|| {
|
||||
register_histogram_vec!("requests_count", "Number of requests", &["uri", "code"], vec![0.025, 0.250, 0.500]).unwrap()
|
||||
register_histogram_vec!("sculptor_requests_count", "Number of requests", &["uri", "code"], vec![0.025, 0.250, 0.500]).unwrap()
|
||||
});
|
||||
|
||||
pub static PINGS: LazyLock<prometheus::HistogramVec> = LazyLock::new(|| {
|
||||
register_histogram_vec!("pings_count", "Number of pings", &["type"], vec![0.000003, 0.00002, 0.0002]).unwrap()
|
||||
register_histogram_vec!("sculptor_pings_count", "Number of pings", &["type"], vec![0.000003, 0.00002, 0.0002]).unwrap()
|
||||
});
|
||||
|
||||
pub static PINGS_ERROR: LazyLock<prometheus::IntCounter> = LazyLock::new(|| {
|
||||
register_int_counter!("sculptor_pings_error", "Number of ping decoding errors").unwrap()
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue