-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use std::collections::HashMap; | ||
use crate::metrics::metrics_type::MetricsType; | ||
|
||
pub struct CounterManager{ | ||
date_map : HashMap<MetricsType,u64>, | ||
} | ||
|
||
pub struct GaugeManager{ | ||
date_map : HashMap<MetricsType,u64>, | ||
} | ||
|
||
pub struct HistogramManager { | ||
|
||
} | ||
|
||
pub struct MetricsManager{ | ||
//counter: CounterManager, | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use std::collections::HashMap; | ||
use crate::metrics::metrics_type::MetricsType; | ||
|
||
|
||
#[derive(Default,Debug)] | ||
pub struct CounterItem(u64); | ||
|
||
impl CounterItem { | ||
pub fn increment(&mut self, value: u64) { | ||
self.0 += value; | ||
} | ||
|
||
pub fn absolute(&mut self, value: u64) { | ||
self.0 = value; | ||
} | ||
|
||
pub fn value(&self) -> u64 { | ||
self.0 | ||
} | ||
} | ||
|
||
impl From<CounterItem> for u64 { | ||
fn from(value: CounterItem) -> Self { | ||
value.0 | ||
} | ||
} | ||
|
||
impl From<u64> for CounterItem { | ||
fn from(value: u64) -> Self { | ||
Self(value) | ||
} | ||
} | ||
|
||
type Key = MetricsType; | ||
|
||
#[derive(Default,Debug)] | ||
pub struct CounterManager{ | ||
date_map : HashMap<Key,CounterItem>, | ||
} | ||
|
||
impl CounterManager { | ||
pub fn increment(&mut self,key:Key,value:u64) { | ||
if let Some(item) = self.date_map.get_mut(&key) { | ||
item.increment(value); | ||
} | ||
else { | ||
self.date_map.insert(key,value.into()); | ||
} | ||
} | ||
|
||
pub fn absolute(&mut self,key:Key,value:u64) { | ||
if let Some(item) = self.date_map.get_mut(&key) { | ||
item.absolute(value); | ||
} | ||
else { | ||
self.date_map.insert(key,value.into()); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use std::collections::HashMap; | ||
use crate::metrics::metrics_type::MetricsType; | ||
|
||
pub struct GaugeManager{ | ||
date_map : HashMap<MetricsType,u64>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
|
||
pub struct HistogramManager { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
#[derive(Debug, Eq, PartialEq, Clone, Hash)] | ||
pub enum MetricsType { | ||
None, | ||
ConfigDataSize, | ||
ConfigListenerSize, | ||
} | ||
|
||
impl Default for MetricsType { | ||
fn default() -> Self { | ||
Self::None | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub mod core; | ||
pub mod metrics_type; | ||
pub mod counter; | ||
mod gauge; | ||
mod histogram; |