-
Notifications
You must be signed in to change notification settings - Fork 131
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
1 parent
5b385c9
commit 22ac097
Showing
17 changed files
with
579 additions
and
393 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
Empty file.
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#![warn(clippy::unwrap_used)] | ||
|
||
pub mod config; | ||
pub mod discovery; | ||
pub mod events; | ||
pub mod find; | ||
|
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod labels; | ||
pub mod overlay; | ||
pub mod storage; |
Large diffs are not rendered by default.
Oops, something went wrong.
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,147 @@ | ||
use ethportal_api::types::distance::Distance; | ||
use prometheus_exporter::{ | ||
self, | ||
prometheus::{ | ||
opts, register_gauge_vec_with_registry, register_int_gauge_vec_with_registry, GaugeVec, | ||
IntGaugeVec, Registry, | ||
}, | ||
}; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct StorageMetrics { | ||
pub content_storage_usage_bytes: GaugeVec, | ||
pub total_storage_usage_bytes: GaugeVec, | ||
pub storage_capacity_bytes: GaugeVec, | ||
pub radius_ratio: GaugeVec, | ||
pub entry_count: IntGaugeVec, | ||
} | ||
|
||
const BYTES_IN_MB_F64: f64 = 1000.0 * 1000.0; | ||
|
||
impl StorageMetrics { | ||
pub fn new(registry: &Registry) -> anyhow::Result<Self> { | ||
let content_storage_usage_bytes = register_gauge_vec_with_registry!( | ||
opts!( | ||
"trin_content_storage_usage_bytes", | ||
"sum of size of individual content stored, in bytes" | ||
), | ||
&["protocol"], | ||
registry | ||
)?; | ||
let total_storage_usage_bytes = register_gauge_vec_with_registry!( | ||
opts!( | ||
"trin_total_storage_usage_bytes", | ||
"full on-disk database size, in bytes" | ||
), | ||
&["protocol"], | ||
registry | ||
)?; | ||
let storage_capacity_bytes = register_gauge_vec_with_registry!( | ||
opts!( | ||
"trin_storage_capacity_bytes", | ||
"user-defined limit on storage usage, in bytes" | ||
), | ||
&["protocol"], | ||
registry | ||
)?; | ||
let radius_ratio = register_gauge_vec_with_registry!( | ||
opts!( | ||
"trin_radius_ratio", | ||
"the fraction of the whole data ring covered by the data radius" | ||
), | ||
&["protocol"], | ||
registry | ||
)?; | ||
let entry_count = register_int_gauge_vec_with_registry!( | ||
opts!("trin_entry_count", "total number of storage entries"), | ||
&["protocol"], | ||
registry | ||
)?; | ||
Ok(Self { | ||
content_storage_usage_bytes, | ||
total_storage_usage_bytes, | ||
storage_capacity_bytes, | ||
radius_ratio, | ||
entry_count, | ||
}) | ||
} | ||
|
||
pub fn report_content_data_storage_bytes(&self, protocol: &str, bytes: f64) { | ||
self.content_storage_usage_bytes | ||
.with_label_values(&[protocol]) | ||
.set(bytes); | ||
} | ||
|
||
pub fn report_total_storage_usage_bytes(&self, protocol: &str, bytes: f64) { | ||
self.total_storage_usage_bytes | ||
.with_label_values(&[protocol]) | ||
.set(bytes); | ||
} | ||
|
||
pub fn report_storage_capacity_bytes(&self, protocol: &str, bytes: f64) { | ||
self.storage_capacity_bytes | ||
.with_label_values(&[protocol]) | ||
.set(bytes); | ||
} | ||
|
||
pub fn report_radius(&self, protocol: &str, radius: Distance) { | ||
let radius_high_bytes = [ | ||
radius.byte(31), | ||
radius.byte(30), | ||
radius.byte(29), | ||
radius.byte(28), | ||
]; | ||
let radius_int = u32::from_be_bytes(radius_high_bytes); | ||
let coverage_ratio = radius_int as f64 / u32::MAX as f64; | ||
self.radius_ratio | ||
.with_label_values(&[protocol]) | ||
.set(coverage_ratio); | ||
} | ||
|
||
pub fn report_entry_count(&self, protocol: &str, count: u64) { | ||
let count: i64 = count | ||
.try_into() | ||
.expect("Number of db entries will be small enough to fit in i64"); | ||
self.entry_count.with_label_values(&[protocol]).set(count); | ||
} | ||
|
||
pub fn increase_entry_count(&self, protocol: &str) { | ||
self.entry_count.with_label_values(&[protocol]).inc(); | ||
} | ||
|
||
pub fn decrease_entry_count(&self, protocol: &str) { | ||
self.entry_count.with_label_values(&[protocol]).dec(); | ||
} | ||
|
||
pub fn get_summary(&self, protocol: &str) -> String { | ||
let radius_percent = self.radius_ratio.with_label_values(&[protocol]).get() * 100.0; | ||
format!( | ||
"radius={:.*}% content={:.1}/{}mb #={} disk={:.1}mb", | ||
Self::precision_for_percentage(radius_percent), | ||
radius_percent, | ||
self.content_storage_usage_bytes | ||
.with_label_values(&[protocol]) | ||
.get() | ||
/ BYTES_IN_MB_F64, | ||
self.storage_capacity_bytes | ||
.with_label_values(&[protocol]) | ||
.get() | ||
/ BYTES_IN_MB_F64, | ||
self.entry_count.with_label_values(&[protocol]).get(), | ||
self.total_storage_usage_bytes | ||
.with_label_values(&[protocol]) | ||
.get() | ||
/ BYTES_IN_MB_F64, | ||
) | ||
} | ||
|
||
pub fn precision_for_percentage(percent: f64) -> usize { | ||
match percent { | ||
x if x >= 10.0 => 0, | ||
x if x >= 1.0 => 1, | ||
x if x >= 0.1 => 2, | ||
x if x >= 0.01 => 3, | ||
_ => 4, | ||
} | ||
} | ||
} |
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
Oops, something went wrong.