-
Notifications
You must be signed in to change notification settings - Fork 132
rust version implementation of procdockerstatsd #227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
/azp run |
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command. |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
scripts/rs/Cargo.toml
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the rusttoml edition, and yea, it is 2024 for now.
scripts/rs/main.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scripts/rs/main.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scripts/rs/main.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scripts/rs/main.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
@@ -0,0 +1,18 @@ | |||
[package] | |||
name = "procdockerstatsd_rs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
procdockerstatsd-rs is more rusty : D
authors = ["Feng Pan"] | ||
|
||
[dependencies] | ||
redis = "0.23" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have wrapped the swss-common rust APIs here: https://github.com/sonic-net/sonic-dash-ha/tree/master/crates/swss-common, so I wonder if we can use it instead of using redis package directly.
@@ -0,0 +1,18 @@ | |||
[package] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we update the folder to procdockerstatsd to be more explicit?
if we like a single crate to have multiple bin, then updating the main.rs into procdockerstatsd.rs will be better for future.
} | ||
|
||
fn convert_to_bytes(value: &str) -> u64 { | ||
let re = Regex::new(r"(\d+\.?\d*)([a-zA-Z]+)").unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This recompiles the regex on every call. This is bad practice, though admittedly if it's just once every 2 minutes it won't matter. This code will cache it for you.
fn convert_to_bytes(value: &str) -> u64 {
static RE: Regex = LazyLock::new(|| Regex::new(r"(\d+\.?\d*)([a-zA-Z]+)").unwrap());
if let Some(caps) = RE.captures(value) {
...
let mut stats = HashMap::new(); | ||
stats.insert("CONTAINER ID".to_string(), values[0].to_string()); | ||
stats.insert("NAME".to_string(), values[1].to_string()); | ||
stats.insert("CPU%".to_string(), values[2].trim_end_matches('%').to_string()); | ||
stats.insert("MEM_BYTES".to_string(), convert_to_bytes(values[3]).to_string()); | ||
stats.insert("MEM_LIMIT_BYTES".to_string(), convert_to_bytes(values[5]).to_string()); | ||
stats.insert("MEM%".to_string(), values[6].trim_end_matches('%').to_string()); | ||
stats.insert("NET_IN_BYTES".to_string(), convert_to_bytes(values[7]).to_string()); | ||
stats.insert("NET_OUT_BYTES".to_string(), convert_to_bytes(values[9]).to_string()); | ||
stats.insert("BLOCK_IN_BYTES".to_string(), convert_to_bytes(values[10]).to_string()); | ||
stats.insert("BLOCK_OUT_BYTES".to_string(), convert_to_bytes(values[12]).to_string()); | ||
stats.insert("PIDS".to_string(), values[13].to_string()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might be cleaner if the key was &'static str
, no calls to .to_string() for keys. I also like to construct maps like HashMap::from_iter([("CONTAINER_ID", values[0].to_string()), ("NAME", values[1].to_string()), ...]);
but both suggestions are just a matter of taste.
rust version implementation of procdockerstatsd
Why I did it
rust version implementation of procdockerstatsd to save memory utilitization.
How I did it
How to verify it
memory comparison between python and rs implementation
