Skip to content

Commit

Permalink
refactor(metrics): use counter rather than gauge for inc-only metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Liang Zhao committed Mar 16, 2022
1 parent b7933e7 commit 3a89972
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
12 changes: 7 additions & 5 deletions rust/meta/src/hummock/hummock_manager.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use itertools::{enumerate, Itertools};
use prometheus::core::{AtomicF64, AtomicI64, GenericGauge};
use prometheus::core::{AtomicF64, AtomicU64, GenericCounter};
use prost::Message;
use risingwave_common::error::{ErrorCode, Result};
use risingwave_pb::hummock::hummock_version::HummockVersionRefId;
Expand Down Expand Up @@ -239,20 +239,22 @@ where
}
}

fn single_level_stat_bytes<T: FnMut(String) -> prometheus::Result<GenericGauge<AtomicF64>>>(
fn single_level_stat_bytes<
T: FnMut(String) -> prometheus::Result<GenericCounter<AtomicF64>>,
>(
mut metric_vec: T,
level_stat: &TableSetStatistics,
) {
let level_label = String::from("L") + &level_stat.level_idx.to_string();
metric_vec(level_label).unwrap().add(level_stat.size_gb);
metric_vec(level_label).unwrap().inc_by(level_stat.size_gb);
}

fn single_level_stat_sstn<T: FnMut(String) -> prometheus::Result<GenericGauge<AtomicI64>>>(
fn single_level_stat_sstn<T: FnMut(String) -> prometheus::Result<GenericCounter<AtomicU64>>>(
mut metric_vec: T,
level_stat: &TableSetStatistics,
) {
let level_label = String::from("L") + &level_stat.level_idx.to_string();
metric_vec(level_label).unwrap().add(level_stat.cnt as i64);
metric_vec(level_label).unwrap().inc_by(level_stat.cnt);
}

fn trigger_rw_stat(&self, compact_metrics: &CompactMetrics) {
Expand Down
28 changes: 14 additions & 14 deletions rust/meta/src/rpc/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use std::sync::Arc;
use hyper::{Body, Request, Response};
use itertools::Itertools;
use prometheus::{
histogram_opts, register_gauge_vec_with_registry, register_histogram_vec_with_registry,
histogram_opts, register_counter_vec_with_registry, register_histogram_vec_with_registry,
register_histogram_with_registry, register_int_counter_vec_with_registry,
register_int_gauge_vec_with_registry, Encoder, GaugeVec, Histogram, HistogramVec,
register_int_gauge_vec_with_registry, CounterVec, Encoder, Histogram, HistogramVec,
IntCounterVec, IntGaugeVec, Registry, TextEncoder, DEFAULT_BUCKETS,
};
use tower::make::Shared;
Expand All @@ -30,17 +30,17 @@ pub struct MetaMetrics {
/// num of SSTs to be merged to next level in each level
pub level_compact_cnt: IntGaugeVec,
/// GBs read from current level during history compactions to next level
pub level_compact_read_curr: GaugeVec,
pub level_compact_read_curr: CounterVec,
/// GBs read from next level during history compactions to next level
pub level_compact_read_next: GaugeVec,
pub level_compact_read_next: CounterVec,
/// GBs written into next level during history compactions to next level
pub level_compact_write: GaugeVec,
pub level_compact_write: CounterVec,
/// num of SSTs read from current level during history compactions to next level
pub level_compact_read_sstn_curr: IntGaugeVec,
pub level_compact_read_sstn_curr: IntCounterVec,
/// num of SSTs read from next level during history compactions to next level
pub level_compact_read_sstn_next: IntGaugeVec,
pub level_compact_read_sstn_next: IntCounterVec,
/// num of SSTs written into next level during history compactions to next level
pub level_compact_write_sstn: IntGaugeVec,
pub level_compact_write_sstn: IntCounterVec,
/// num of compactions from each level to next level
pub level_compact_frequence: IntCounterVec,
}
Expand Down Expand Up @@ -81,47 +81,47 @@ impl MetaMetrics {
)
.unwrap();

let level_compact_read_curr = register_gauge_vec_with_registry!(
let level_compact_read_curr = register_counter_vec_with_registry!(
"storage_level_compact_read_curr",
"GBs read from current level during history compactions to next level",
&["level_index"],
registry
)
.unwrap();

let level_compact_read_next = register_gauge_vec_with_registry!(
let level_compact_read_next = register_counter_vec_with_registry!(
"storage_level_compact_read_next",
"GBs read from next level during history compactions to next level",
&["level_index"],
registry
)
.unwrap();

let level_compact_write = register_gauge_vec_with_registry!(
let level_compact_write = register_counter_vec_with_registry!(
"storage_level_compact_write",
"GBs written into next level during history compactions to next level",
&["level_index"],
registry
)
.unwrap();

let level_compact_read_sstn_curr = register_int_gauge_vec_with_registry!(
let level_compact_read_sstn_curr = register_int_counter_vec_with_registry!(
"storage_level_compact_read_sstn_curr",
"num of SSTs read from current level during history compactions to next level",
&["level_index"],
registry
)
.unwrap();

let level_compact_read_sstn_next = register_int_gauge_vec_with_registry!(
let level_compact_read_sstn_next = register_int_counter_vec_with_registry!(
"storage_level_compact_read_sstn_next",
"num of SSTs read from next level during history compactions to next level",
&["level_index"],
registry
)
.unwrap();

let level_compact_write_sstn = register_int_gauge_vec_with_registry!(
let level_compact_write_sstn = register_int_counter_vec_with_registry!(
"storage_level_compact_write_sstn",
"num of SSTs written into next level during history compactions to next level",
&["level_index"],
Expand Down

0 comments on commit 3a89972

Please sign in to comment.