-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hubble): add prometheus metrics (#711)
* feat(hubble): add prometheus metrics * feat(hubble): support metrics in nixosmodule * feat(hubble): use a single buffer for metrics collection
- Loading branch information
1 parent
b3502b5
commit 676a2f5
Showing
8 changed files
with
342 additions
and
71 deletions.
There are no files selected for viewing
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
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,47 @@ | ||
use lazy_static::lazy_static; | ||
use prometheus::{IntCounterVec, Opts, Registry}; | ||
use reqwest::StatusCode; | ||
|
||
lazy_static! { | ||
pub static ref REGISTRY: Registry = Registry::new(); | ||
pub static ref EVENT_COLLECTOR: IntCounterVec = | ||
IntCounterVec::new(Opts::new("events", "Events"), &["chain_id", "block_hash"]) | ||
.expect("register EVENT_COLLECTOR"); | ||
pub static ref BLOCK_COLLECTOR: IntCounterVec = | ||
IntCounterVec::new(Opts::new("blocks", "Blocks"), &["chain_id"]) | ||
.expect("register BLOCK_COLLECTOR"); | ||
pub static ref POST_COLLECTOR: IntCounterVec = | ||
IntCounterVec::new(Opts::new("posts", "Posts to Hasura"), &["chain_id"]) | ||
.expect("register POSTS"); | ||
} | ||
|
||
pub fn register_custom_metrics() { | ||
REGISTRY | ||
.register(Box::new(EVENT_COLLECTOR.clone())) | ||
.expect("EVENT_COLLECTOR can be registered"); | ||
REGISTRY | ||
.register(Box::new(BLOCK_COLLECTOR.clone())) | ||
.expect("BLOCK_COLLECTOR can be registered"); | ||
REGISTRY | ||
.register(Box::new(POST_COLLECTOR.clone())) | ||
.expect("BLOCK_COLLECTOR can be registered"); | ||
} | ||
|
||
#[axum::debug_handler] | ||
pub async fn handler() -> Result<String, StatusCode> { | ||
let encoder = prometheus::TextEncoder::new(); | ||
let mut response = encoder | ||
.encode_to_string(®ISTRY.gather()) | ||
.map_err(|err| { | ||
tracing::error!("could not gather metrics: {}", err); | ||
StatusCode::INTERNAL_SERVER_ERROR | ||
})?; | ||
|
||
encoder | ||
.encode_utf8(&prometheus::gather(), &mut response) | ||
.map_err(|err| { | ||
tracing::error!("could not gather metrics: {}", err); | ||
StatusCode::INTERNAL_SERVER_ERROR | ||
})?; | ||
Ok(response) | ||
} |
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