Skip to content

Commit 1787010

Browse files
authored
Add events ingested counter in stats (#253)
1 parent 4c537e4 commit 1787010

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

server/src/handlers/logstream.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ pub async fn get_stats(req: HttpRequest) -> Result<impl Responder, StreamError>
213213
"stream": stream_name,
214214
"time": time,
215215
"ingestion": {
216+
"count": stats.events,
216217
"size": format!("{} {}", stats.ingestion, "Bytes"),
217218
"format": "json"
218219
},

server/src/metadata.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ impl STREAM_INFO {
154154
.ok_or(MetadataError::StreamMetaNotFound(stream_name.to_owned()))?;
155155

156156
stream.stats.add_ingestion_size(size);
157+
stream.stats.increase_event_by_one();
157158

158159
Ok(())
159160
}

server/src/stats.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ use serde::{Deserialize, Serialize};
2222

2323
#[derive(Debug)]
2424
pub struct StatsCounter {
25+
events_ingested: AtomicU64,
2526
ingestion_size: AtomicU64,
2627
storage_size: AtomicU64,
2728
}
2829

2930
impl Default for StatsCounter {
3031
fn default() -> Self {
3132
Self {
33+
events_ingested: AtomicU64::new(0),
3234
ingestion_size: AtomicU64::new(0),
3335
storage_size: AtomicU64::new(0),
3436
}
@@ -43,13 +45,18 @@ impl PartialEq for StatsCounter {
4345
}
4446

4547
impl StatsCounter {
46-
pub fn new(ingestion_size: u64, storage_size: u64) -> Self {
48+
pub fn new(ingestion_size: u64, storage_size: u64, event_ingested: u64) -> Self {
4749
Self {
48-
ingestion_size: AtomicU64::new(ingestion_size),
49-
storage_size: AtomicU64::new(storage_size),
50+
ingestion_size: ingestion_size.into(),
51+
storage_size: storage_size.into(),
52+
events_ingested: event_ingested.into(),
5053
}
5154
}
5255

56+
pub fn events_ingested(&self) -> u64 {
57+
self.events_ingested.load(Ordering::Relaxed)
58+
}
59+
5360
pub fn ingestion_size(&self) -> u64 {
5461
self.ingestion_size.load(Ordering::Relaxed)
5562
}
@@ -65,18 +72,24 @@ impl StatsCounter {
6572
pub fn add_storage_size(&self, size: u64) {
6673
self.storage_size.fetch_add(size, Ordering::AcqRel);
6774
}
75+
76+
pub fn increase_event_by_one(&self) {
77+
self.events_ingested.fetch_add(1, Ordering::Relaxed);
78+
}
6879
}
6980

7081
/// Helper struct type created by copying stats values from metadata
7182
#[derive(Debug, Default, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
7283
pub struct Stats {
84+
pub events: u64,
7385
pub ingestion: u64,
7486
pub storage: u64,
7587
}
7688

7789
impl From<&StatsCounter> for Stats {
7890
fn from(stats: &StatsCounter) -> Self {
7991
Self {
92+
events: stats.events_ingested(),
8093
ingestion: stats.ingestion_size(),
8194
storage: stats.storage_size(),
8295
}
@@ -85,6 +98,6 @@ impl From<&StatsCounter> for Stats {
8598

8699
impl From<Stats> for StatsCounter {
87100
fn from(stats: Stats) -> Self {
88-
StatsCounter::new(stats.ingestion, stats.storage)
101+
StatsCounter::new(stats.ingestion, stats.storage, stats.events)
89102
}
90103
}

0 commit comments

Comments
 (0)