-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an async collector plugin for tc stats
Tc stats is made best effort as netlink operations could be blocking.
- Loading branch information
Showing
4 changed files
with
118 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use slog::error; | ||
use tc::TcStats; | ||
|
||
use crate::collector_plugin::AsyncCollectorPlugin; | ||
|
||
pub type SampleType = TcStats; | ||
|
||
pub struct TcStatsCollectorPlugin { | ||
logger: slog::Logger, | ||
} | ||
|
||
impl TcStatsCollectorPlugin { | ||
pub fn new(logger: slog::Logger) -> Result<Self> { | ||
Ok(Self { logger }) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl AsyncCollectorPlugin for TcStatsCollectorPlugin { | ||
type T = TcStats; | ||
|
||
async fn try_collect(&mut self) -> Result<Option<SampleType>> { | ||
let stats = match tc::tc_stats() { | ||
Ok(tc_stats) => Some(tc_stats), | ||
Err(e) => { | ||
error!(self.logger, "{:#}", e); | ||
Default::default() | ||
} | ||
}; | ||
|
||
Ok(stats) | ||
} | ||
} |
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