-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for publishing kernel statistics to oximeter
- Loading branch information
Showing
8 changed files
with
523 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! Report metrics about Ethernet data links on the host system | ||
use crate::kstat::kstat_snapshot_time; | ||
use crate::kstat::ConvertNamedData; | ||
use crate::kstat::Error; | ||
use crate::kstat::KstatList; | ||
use crate::kstat::KstatTarget; | ||
use kstat_rs::Data; | ||
use kstat_rs::Kstat; | ||
use kstat_rs::Named; | ||
use oximeter::types::Cumulative; | ||
use oximeter::Metric; | ||
use oximeter::Sample; | ||
use oximeter::Target; | ||
use uuid::Uuid; | ||
|
||
/// Information about a single physical Ethernet link on a host. | ||
#[derive(Debug, Target)] | ||
pub struct PhysicalDataLink { | ||
/// The ID of the rack (cluster) containing this host. | ||
rack_id: Uuid, | ||
/// The ID of the sled itself. | ||
sled_id: Uuid, | ||
/// The name of the host. | ||
hostname: String, | ||
/// The name of the link. | ||
link_name: String, | ||
} | ||
|
||
/// Information about a virtual Ethernet link on a host. | ||
/// | ||
/// Note that this is specifically for a VNIC in on the host system, not a guest | ||
/// data link. | ||
#[derive(Debug, Target)] | ||
pub struct VirtualDataLink { | ||
/// The ID of the rack (cluster) containing this host. | ||
rack_id: Uuid, | ||
/// The ID of the sled itself. | ||
sled_id: Uuid, | ||
/// The name of the host. | ||
hostname: String, | ||
/// The name of the link. | ||
link_name: String, | ||
} | ||
|
||
/// Information about a guest virtual Ethernet link. | ||
#[derive(Debug, Target)] | ||
pub struct GuestDataLink { | ||
/// The ID of the rack (cluster) containing this host. | ||
rack_id: Uuid, | ||
/// The ID of the sled itself. | ||
sled_id: Uuid, | ||
/// The name of the host. | ||
hostname: String, | ||
/// The ID of the project containing the instance. | ||
project_id: Uuid, | ||
/// The ID of the instance. | ||
instance_id: Uuid, | ||
/// The name of the link. | ||
link_name: String, | ||
} | ||
|
||
/// The number of packets received on the link. | ||
#[derive(Clone, Copy, Metric)] | ||
pub struct PacketsReceived { | ||
datum: Cumulative<u64>, | ||
} | ||
|
||
/// The number of packets sent on the link. | ||
#[derive(Clone, Copy, Metric)] | ||
pub struct PacketsSent { | ||
datum: Cumulative<u64>, | ||
} | ||
|
||
/// The number of bytes sent on the link. | ||
#[derive(Clone, Copy, Metric)] | ||
pub struct BytesSent { | ||
datum: Cumulative<u64>, | ||
} | ||
|
||
/// The number of bytes received on the link. | ||
#[derive(Clone, Copy, Metric)] | ||
pub struct BytesReceived { | ||
datum: Cumulative<u64>, | ||
} | ||
|
||
/// The number of errors received on the link. | ||
#[derive(Clone, Copy, Metric)] | ||
pub struct ErrorsReceived { | ||
datum: Cumulative<u64>, | ||
} | ||
|
||
/// The number of errors sent on the link. | ||
#[derive(Clone, Copy, Metric)] | ||
pub struct ErrorsSent { | ||
datum: Cumulative<u64>, | ||
} | ||
|
||
impl KstatTarget for PhysicalDataLink { | ||
fn interested<'a>(&self, kstat: &Kstat<'a>) -> bool { | ||
kstat.ks_module == "link" | ||
&& kstat.ks_instance == 0 | ||
&& kstat.ks_name == &self.link_name | ||
} | ||
|
||
fn to_samples<'k>( | ||
&self, | ||
kstats: KstatList<'_, 'k>, | ||
) -> Result<Vec<Sample>, Error> { | ||
let (creation_time, kstat, data) = kstats.first().unwrap(); | ||
let snapshot_time = kstat_snapshot_time(&kstat)?; | ||
let Data::Named(named) = data else { | ||
return Err(Error::ExpectedNamedKstat); | ||
}; | ||
named | ||
.iter() | ||
.filter_map(|nd| { | ||
let Named { name, value } = nd; | ||
if *name == "rbytes64" { | ||
Some(value.as_u64().and_then(|x| { | ||
let metric = BytesReceived { | ||
datum: Cumulative::with_start_time( | ||
*creation_time, | ||
x, | ||
), | ||
}; | ||
Sample::new_with_timestamp(snapshot_time, self, &metric) | ||
.map_err(Error::Sample) | ||
})) | ||
} else if *name == "obytes64" { | ||
Some(value.as_u64().and_then(|x| { | ||
let metric = BytesSent { | ||
datum: Cumulative::with_start_time( | ||
*creation_time, | ||
x, | ||
), | ||
}; | ||
Sample::new_with_timestamp(snapshot_time, self, &metric) | ||
.map_err(Error::Sample) | ||
})) | ||
} else { | ||
None | ||
} | ||
}) | ||
.collect() | ||
} | ||
} |
Oops, something went wrong.