Skip to content

Commit

Permalink
Extract node data only
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkreeftmeijer committed Jul 2, 2024
1 parent eb70d08 commit 1124b39
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ struct KubernetesMetric {
}

impl KubernetesMetric {
pub fn from_json(json: serde_json::Value) -> KubernetesMetric {
pub fn from_node_json(json: serde_json::Value) -> KubernetesMetric {
KubernetesMetric {
metric_type: "node".to_string(),
name: json["node"]["nodeName"].to_string(),
cpu_usage_nano_cores: json["node"]["cpu"]["usageNanoCores"].as_u64().unwrap(),
cpu_usage_core_nano_seconds: json["node"]["cpu"]["usageCoreNanoSeconds"].as_u64().unwrap(),
memory_available_bytes: json["node"]["memory"]["availableBytes"].as_u64().unwrap(),
memory_usage_bytes: json["node"]["memory"]["usageBytes"].as_u64().unwrap(),
memory_working_set_bytes: json["node"]["memory"]["workingSetBytes"].as_u64().unwrap(),
memory_rss_bytes: json["node"]["memory"]["rssBytes"].as_u64().unwrap(),
memory_page_faults: json["node"]["memory"]["pageFaults"].as_u64().unwrap(),
memory_major_page_faults: json["node"]["memory"]["majorPageFaults"].as_u64().unwrap(),
swap_usage_bytes: json["node"]["swap"]["swapUsageBytes"].as_u64().unwrap(),
name: json["nodeName"].to_string(),
cpu_usage_nano_cores: json["cpu"]["usageNanoCores"].as_u64().unwrap(),
cpu_usage_core_nano_seconds: json["cpu"]["usageCoreNanoSeconds"].as_u64().unwrap(),
memory_available_bytes: json["memory"]["availableBytes"].as_u64().unwrap(),
memory_usage_bytes: json["memory"]["usageBytes"].as_u64().unwrap(),
memory_working_set_bytes: json["memory"]["workingSetBytes"].as_u64().unwrap(),
memory_rss_bytes: json["memory"]["rssBytes"].as_u64().unwrap(),
memory_page_faults: json["memory"]["pageFaults"].as_u64().unwrap(),
memory_major_page_faults: json["memory"]["majorPageFaults"].as_u64().unwrap(),
swap_usage_bytes: json["swap"]["swapUsageBytes"].as_u64().unwrap(),
}
}
}
Expand Down Expand Up @@ -113,8 +113,8 @@ async fn run() -> Result<(), Error> {
.request::<serde_json::Value>(kube_request.clone())
.await?;

println!("KubernetesMetric: {:?}",
KubernetesMetric::from_json(kube_response.clone())
println!("Node: {:?}",
KubernetesMetric::from_node_json(kube_response["node"].clone())
);

if let Some(pods) = kube_response["pods"].as_array() {
Expand Down

0 comments on commit 1124b39

Please sign in to comment.