Replies: 1 comment
-
Hey @Pier4413, I toyed with the following snippet to answer a different question on the same topic: use kube::{core::DynamicObject, Api, Resource, ResourceExt};
use serde::Deserialize;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let client = kube::Client::try_default().await?;
let apigroup = kube::discovery::group(&client, "metrics.k8s.io").await?;
let res = apigroup.recommended_resources();
for (ar, _caps) in res {
println!("Ar: {ar:?}");
}
let (ar, _caps) = apigroup.recommended_kind("NodeMetrics").unwrap();
let api: Api<DynamicObject> = Api::all_with(client.clone(), &ar);
for obj in api.list(&Default::default()).await? {
let (name, metric) = extract_metric(obj)?;
println!("{name}: {metric:?}");
}
Ok(())
}
#[derive(Default, Deserialize, Clone, Debug)]
struct Metric {
cpu: String,
memory: String,
}
fn extract_metric(obj: DynamicObject) -> anyhow::Result<(String, Metric)> {
let metric = obj
.data
.get("usage")
.cloned()
.ok_or_else(|| anyhow::anyhow!("missing 'usage'"))?;
let metric = serde_json::from_value(metric)?;
Ok((obj.name_any(), metric))
} This is a functional equivalent of I didn't find a way to dynamically fetch the timeseries data without manually creating an http client and hitting the I'd either build an abstraction over the kubelet's admin endpoint or just use a timeseries ingester and use a provided client to query this data. |
Beta Was this translation helpful? Give feedback.
-
As the title says. Is there a way to access the data in Node metrics data
The exemple provided by Node metrics data is for minikube but I could access it on other workers. I don't use minikube but another framework that create the same route except the minikube part of the uri is replaced by another worker name.
Currently I have added a reqwest call to my code but that bother me as this is a specific use case and my other functions use Kube.rs
I there a way to access data via something generic like that :
/api/v1/nodes/${WORKER_NAME}/proxy/stats/summary using Kube.rs ?
Beta Was this translation helpful? Give feedback.
All reactions