From bfa7f30fd3e41db0b47be19569a0b4d2e0d544ef Mon Sep 17 00:00:00 2001 From: Jack Rubacha Date: Sat, 28 Sep 2024 18:27:35 -0400 Subject: [PATCH] latency ringbuffer to datetime --- scylla-server/src/processors/mqtt_processor.rs | 7 ++++--- scylla-server/src/proto/serverdata.proto | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/scylla-server/src/processors/mqtt_processor.rs b/scylla-server/src/processors/mqtt_processor.rs index 5f366c2f..6cac6a5c 100644 --- a/scylla-server/src/processors/mqtt_processor.rs +++ b/scylla-server/src/processors/mqtt_processor.rs @@ -4,6 +4,7 @@ use std::{ time::{Duration, SystemTime}, }; +use chrono::TimeDelta; use prisma_client_rust::bigdecimal::ToPrimitive; use protobuf::Message; use ringbuffer::RingBuffer; @@ -128,7 +129,7 @@ impl MqttProcessor { let mut view_interval = tokio::time::interval(Duration::from_secs(3)); let mut latency_interval = tokio::time::interval(Duration::from_millis(250)); - let mut latency_ringbuffer = ringbuffer::AllocRingBuffer::::new(20); + let mut latency_ringbuffer = ringbuffer::AllocRingBuffer::::new(20); let mut upload_counter: u8 = 0; @@ -153,7 +154,7 @@ impl MqttProcessor { Some(msg) => msg, None => continue }; - latency_ringbuffer.push((chrono::offset::Utc::now() - msg.timestamp).num_milliseconds()); + latency_ringbuffer.push(chrono::offset::Utc::now() - msg.timestamp); self.send_db_msg(msg.clone()).await; self.send_socket_msg(msg, &mut upload_counter); }, @@ -181,7 +182,7 @@ impl MqttProcessor { let avg_latency = if latency_ringbuffer.is_empty() { 0 } else { - latency_ringbuffer.iter().sum::() / latency_ringbuffer.len().to_i64().unwrap_or_default() + latency_ringbuffer.iter().sum::().num_milliseconds() / latency_ringbuffer.len().to_i64().unwrap_or_default() }; let client_data = ClientData { diff --git a/scylla-server/src/proto/serverdata.proto b/scylla-server/src/proto/serverdata.proto index a9b7e44c..1cf8efa3 100644 --- a/scylla-server/src/proto/serverdata.proto +++ b/scylla-server/src/proto/serverdata.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package serverdata.v1; +package serverdata.v2; message ServerData { // ensure old type is reserved