-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AverageIntCounter for backpressure states (#6963)
- Loading branch information
1 parent
4831cf6
commit b65b876
Showing
7 changed files
with
97 additions
and
23 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
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
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,61 @@ | ||
// Copyright © Aptos Foundation | ||
|
||
use prometheus::{register_counter, register_int_counter, Counter, IntCounter}; | ||
|
||
pub struct AverageCounter { | ||
sum: Counter, | ||
count: IntCounter, | ||
} | ||
|
||
impl AverageCounter { | ||
pub fn register(name: &str, desc: &str) -> AverageCounter { | ||
AverageCounter { | ||
sum: register_counter!( | ||
format!("{}_sum", name), | ||
format!("{}. Sum part of the counter", desc), | ||
) | ||
.unwrap(), | ||
count: register_int_counter!( | ||
format!("{}_count", name), | ||
format!("{}. Count part of the counter", desc), | ||
) | ||
.unwrap(), | ||
} | ||
} | ||
|
||
pub fn observe(&self, value: f64) { | ||
if value != 0.0 { | ||
self.sum.inc_by(value); | ||
} | ||
self.count.inc(); | ||
} | ||
} | ||
|
||
pub struct AverageIntCounter { | ||
sum: IntCounter, | ||
count: IntCounter, | ||
} | ||
|
||
impl AverageIntCounter { | ||
pub fn register(name: &str, desc: &str) -> AverageIntCounter { | ||
AverageIntCounter { | ||
sum: register_int_counter!( | ||
format!("{}_sum", name), | ||
format!("{}. Sum part of the counter", desc), | ||
) | ||
.unwrap(), | ||
count: register_int_counter!( | ||
format!("{}_count", name), | ||
format!("{}. Count part of the counter", desc), | ||
) | ||
.unwrap(), | ||
} | ||
} | ||
|
||
pub fn observe(&self, value: u64) { | ||
if value != 0 { | ||
self.sum.inc_by(value); | ||
} | ||
self.count.inc(); | ||
} | ||
} |
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