-
Notifications
You must be signed in to change notification settings - Fork 61
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 recording ethtool stats (#8204)
Summary: The PR is broken into modular commits, so it might be easier to review the PR commit-by-commit. Commit: [Add crate for reading NIC stats using ethtool](965795c) - Adds the library support to read and parse `ethtool` stats using `ioctl` - Parses some common stats into fields while others are stored as raw stats Commit: [Add model to represent ethtool stats](66dbb26) - Adds the model struct and parsing logic to convert `ethtool` stats into a sub-model in existing `network.interface` model Commit: [Add render configs for ethtool fields](9401fed) - Updates and adds the required commands for dumping new fields and model - Adds the parsing for rendering the new fields and model Commit: [Add ability for printing raw_stats in OpenMetrics format](7d6349e) - Modifies the printing logic of `OpenMetrics` format to handle a map type Pull Request resolved: #8204 Reviewed By: brianc118 Differential Revision: D50714625 Pulled By: dschatzberg fbshipit-source-id: 156f3054944d86fe489bd9ca5bfb3023d1e02c26
- Loading branch information
1 parent
6b64f9f
commit 7fc6f7f
Showing
24 changed files
with
6,525 additions
and
92 deletions.
There are no files selected for viewing
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,110 @@ | ||
use super::*; | ||
|
||
pub struct EthtoolQueue { | ||
opts: GeneralOpt, | ||
fields: Vec<EthtoolQueueField>, | ||
} | ||
|
||
impl EthtoolQueue { | ||
pub fn new(opts: &GeneralOpt, fields: Vec<EthtoolQueueField>) -> Self { | ||
Self { | ||
opts: opts.to_owned(), | ||
fields, | ||
} | ||
} | ||
} | ||
|
||
impl Dumper for EthtoolQueue { | ||
fn dump_model( | ||
&self, | ||
ctx: &CommonFieldContext, | ||
model: &model::Model, | ||
output: &mut dyn Write, | ||
round: &mut usize, | ||
comma_flag: bool, | ||
) -> Result<IterExecResult> { | ||
let mut queues = Vec::new(); | ||
for nic in model.network.interfaces.values() { | ||
for queue in &nic.queues { | ||
queues.push(queue); | ||
} | ||
} | ||
|
||
// Return if we filtered everything. | ||
if queues.is_empty() { | ||
return Ok(IterExecResult::Skip); | ||
} | ||
|
||
let mut json_output = json!([]); | ||
|
||
queues | ||
.into_iter() | ||
.map(|queue| { | ||
match self.opts.output_format { | ||
Some(OutputFormat::Raw) | None => write!( | ||
output, | ||
"{}", | ||
print::dump_raw( | ||
&self.fields, | ||
ctx, | ||
queue, | ||
*round, | ||
self.opts.repeat_title, | ||
self.opts.disable_title, | ||
self.opts.raw | ||
) | ||
)?, | ||
Some(OutputFormat::Csv) => write!( | ||
output, | ||
"{}", | ||
print::dump_csv( | ||
&self.fields, | ||
ctx, | ||
queue, | ||
*round, | ||
self.opts.disable_title, | ||
self.opts.raw | ||
) | ||
)?, | ||
Some(OutputFormat::Tsv) => write!( | ||
output, | ||
"{}", | ||
print::dump_tsv( | ||
&self.fields, | ||
ctx, | ||
queue, | ||
*round, | ||
self.opts.disable_title, | ||
self.opts.raw | ||
) | ||
)?, | ||
Some(OutputFormat::KeyVal) => write!( | ||
output, | ||
"{}", | ||
print::dump_kv(&self.fields, ctx, queue, self.opts.raw) | ||
)?, | ||
Some(OutputFormat::Json) => { | ||
let par = print::dump_json(&self.fields, ctx, queue, self.opts.raw); | ||
json_output.as_array_mut().unwrap().push(par); | ||
} | ||
Some(OutputFormat::OpenMetrics) => write!( | ||
output, | ||
"{}", | ||
print::dump_openmetrics(&self.fields, ctx, queue) | ||
)?, | ||
} | ||
*round += 1; | ||
Ok(()) | ||
}) | ||
.collect::<Result<Vec<_>>>()?; | ||
|
||
match (self.opts.output_format, comma_flag) { | ||
(Some(OutputFormat::Json), true) => write!(output, ",{}", json_output)?, | ||
(Some(OutputFormat::Json), false) => write!(output, "{}", json_output)?, | ||
(Some(OutputFormat::OpenMetrics), _) => (), | ||
_ => write!(output, "\n")?, | ||
}; | ||
|
||
Ok(IterExecResult::Success) | ||
} | ||
} |
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
Oops, something went wrong.