-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dedicated prometheus metrics endpoint
- Loading branch information
1 parent
528ffa1
commit 404d681
Showing
14 changed files
with
501 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,29 @@ | ||
[package] | ||
name = "http_metrics" | ||
version = "0.1.0" | ||
authors = ["Paul Hauner <paul@paulhauner.com>"] | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
prometheus = "0.9.0" | ||
warp = "0.2.5" | ||
serde = { version = "1.0.110", features = ["derive"] } | ||
slog = "2.5.2" | ||
beacon_chain = { path = "../beacon_chain" } | ||
store = { path = "../store" } | ||
eth2_libp2p = { path = "../eth2_libp2p" } | ||
slot_clock = { path = "../../common/slot_clock" } | ||
lighthouse_metrics = { path = "../../common/lighthouse_metrics" } | ||
lazy_static = "1.4.0" | ||
|
||
[dev-dependencies] | ||
tokio = { version = "0.2.21", features = ["sync"] } | ||
reqwest = { version = "0.10.8", features = ["json"] } | ||
environment = { path = "../../lighthouse/environment" } | ||
types = { path = "../../consensus/types" } | ||
|
||
[target.'cfg(target_os = "linux")'.dependencies] | ||
psutil = "3.1.0" | ||
procinfo = "0.4.2" |
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,72 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[cfg(target_os = "linux")] | ||
use {procinfo::pid, psutil::process::Process}; | ||
|
||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] | ||
/// Reports on the health of the Lighthouse instance. | ||
pub struct Health { | ||
/// The pid of this process. | ||
pub pid: u32, | ||
/// The number of threads used by this pid. | ||
pub pid_num_threads: i32, | ||
/// The total resident memory used by this pid. | ||
pub pid_mem_resident_set_size: u64, | ||
/// The total virtual memory used by this pid. | ||
pub pid_mem_virtual_memory_size: u64, | ||
/// Total virtual memory on the system | ||
pub sys_virt_mem_total: u64, | ||
/// Total virtual memory available for new processes. | ||
pub sys_virt_mem_available: u64, | ||
/// Total virtual memory used on the system | ||
pub sys_virt_mem_used: u64, | ||
/// Total virtual memory not used on the system | ||
pub sys_virt_mem_free: u64, | ||
/// Percentage of virtual memory used on the system | ||
pub sys_virt_mem_percent: f32, | ||
/// System load average over 1 minute. | ||
pub sys_loadavg_1: f64, | ||
/// System load average over 5 minutes. | ||
pub sys_loadavg_5: f64, | ||
/// System load average over 15 minutes. | ||
pub sys_loadavg_15: f64, | ||
} | ||
|
||
impl Health { | ||
#[cfg(not(target_os = "linux"))] | ||
pub fn observe() -> Result<Self, String> { | ||
Err("Health is only available on Linux".into()) | ||
} | ||
|
||
#[cfg(target_os = "linux")] | ||
pub fn observe() -> Result<Self, String> { | ||
let process = | ||
Process::current().map_err(|e| format!("Unable to get current process: {:?}", e))?; | ||
|
||
let process_mem = process | ||
.memory_info() | ||
.map_err(|e| format!("Unable to get process memory info: {:?}", e))?; | ||
|
||
let stat = pid::stat_self().map_err(|e| format!("Unable to get stat: {:?}", e))?; | ||
|
||
let vm = psutil::memory::virtual_memory() | ||
.map_err(|e| format!("Unable to get virtual memory: {:?}", e))?; | ||
let loadavg = | ||
psutil::host::loadavg().map_err(|e| format!("Unable to get loadavg: {:?}", e))?; | ||
|
||
Ok(Self { | ||
pid: process.pid(), | ||
pid_num_threads: stat.num_threads, | ||
pid_mem_resident_set_size: process_mem.rss(), | ||
pid_mem_virtual_memory_size: process_mem.vms(), | ||
sys_virt_mem_total: vm.total(), | ||
sys_virt_mem_available: vm.available(), | ||
sys_virt_mem_used: vm.used(), | ||
sys_virt_mem_free: vm.free(), | ||
sys_virt_mem_percent: vm.percent(), | ||
sys_loadavg_1: loadavg.one, | ||
sys_loadavg_5: loadavg.five, | ||
sys_loadavg_15: loadavg.fifteen, | ||
}) | ||
} | ||
} |
Oops, something went wrong.