Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Fix the cfg guards in service/metrics.rs (#5770)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka committed Apr 24, 2020
1 parent 8c755a2 commit 47b304d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion client/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ tracing = "0.1.10"
parity-util-mem = { version = "0.6.1", default-features = false, features = ["primitive-types"] }


[target.'cfg(any(unix, windows))'.dependencies]
[target.'cfg(all(any(unix, windows), not(target_os = "android")))'.dependencies]
netstat2 = "0.8.1"

[target.'cfg(target_os = "linux")'.dependencies]
Expand Down
24 changes: 12 additions & 12 deletions client/service/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ use sp_utils::metrics::register_globals;

use sysinfo::{self, ProcessExt, SystemExt};

#[cfg(not(target_os = "unknown"))]
#[cfg(all(any(unix, windows), not(target_os = "android")))]
use netstat2::{
TcpState, ProtocolSocketInfo, iterate_sockets_info, AddressFamilyFlags, ProtocolFlags,
};

struct PrometheusMetrics {
// system
#[cfg(any(unix, windows))]
#[cfg(all(any(unix, windows), not(target_os = "android")))]
load_avg: GaugeVec<F64>,

// process
Expand All @@ -42,7 +42,7 @@ struct PrometheusMetrics {
threads: Gauge<U64>,
open_files: GaugeVec<U64>,

#[cfg(any(unix, windows))]
#[cfg(all(any(unix, windows), not(target_os = "android")))]
netstat: GaugeVec<U64>,

// -- inner counters
Expand Down Expand Up @@ -79,7 +79,7 @@ impl PrometheusMetrics {

Ok(Self {
// system
#[cfg(any(unix, windows))]
#[cfg(all(any(unix, windows), not(target_os = "android")))]
load_avg: register(GaugeVec::new(
Opts::new("load_avg", "System load average"),
&["over"]
Expand All @@ -94,7 +94,7 @@ impl PrometheusMetrics {
"cpu_usage_percentage", "Node CPU usage",
)?, registry)?,

#[cfg(any(unix, windows))]
#[cfg(all(any(unix, windows), not(target_os = "android")))]
netstat: register(GaugeVec::new(
Opts::new("netstat_tcp", "Current TCP connections "),
&["status"]
Expand Down Expand Up @@ -144,7 +144,7 @@ impl PrometheusMetrics {
}
}

#[cfg(any(unix, windows))]
#[cfg(all(any(unix, windows), not(target_os = "android")))]
#[derive(Default)]
struct ConnectionsCount {
listen: u64,
Expand Down Expand Up @@ -176,7 +176,7 @@ struct ProcessInfo {

pub struct MetricsService {
metrics: Option<PrometheusMetrics>,
#[cfg(not(target_os = "unknown"))]
#[cfg(all(any(unix, windows), not(target_os = "android")))]
system: sysinfo::System,
pid: Option<sysinfo::Pid>,
}
Expand Down Expand Up @@ -219,7 +219,7 @@ impl MetricsService {
}
}

#[cfg(all(any(unix, windows), not(target_os = "linux")))]
#[cfg(all(any(unix, windows), not(target_os = "android"), not(target_os = "linux")))]
impl MetricsService {
fn inner_new(metrics: Option<PrometheusMetrics>) -> Self {
Self {
Expand All @@ -235,7 +235,7 @@ impl MetricsService {
}


#[cfg(target_os = "unknown")]
#[cfg(not(all(any(unix, windows), not(target_os = "android"))))]
impl MetricsService {
fn inner_new(metrics: Option<PrometheusMetrics>) -> Self {
Self {
Expand Down Expand Up @@ -263,7 +263,7 @@ impl MetricsService {
Self::inner_new(None)
}

#[cfg(not(target_os = "unknown"))]
#[cfg(all(any(unix, windows), not(target_os = "android")))]
fn process_info_for(&mut self, pid: &sysinfo::Pid) -> ProcessInfo {
let mut info = ProcessInfo::default();
if self.system.refresh_process(*pid) {
Expand All @@ -275,7 +275,7 @@ impl MetricsService {
info
}

#[cfg(not(target_os = "unknown"))]
#[cfg(all(any(unix, windows), not(target_os = "android")))]
fn connections_info(&self) -> Option<ConnectionsCount> {
self.pid.as_ref().and_then(|pid| {
let af_flags = AddressFamilyFlags::IPV4 | AddressFamilyFlags::IPV6;
Expand Down Expand Up @@ -406,7 +406,7 @@ impl MetricsService {
);
}

#[cfg(not(target_os = "unknown"))]
#[cfg(all(any(unix, windows), not(target_os = "android")))]
{
let load = self.system.get_load_average();
metrics.load_avg.with_label_values(&["1min"]).set(load.one);
Expand Down

0 comments on commit 47b304d

Please sign in to comment.