简体   繁体   中英

List Namespace name, Namespace Age, and Status on Grafana using PromQL (prometheus) from Kubernetes Metric server

We are having a Kubernetes cluster and using Prometheus + Grafana for monitoring and alerting. We need to show a panel on Grafana that shows us the view (same as kubectl get namespaces). Currently we are able to get name and status column using the below PROMQL along with Hide options in Visualization section of Grafana.

count(kube_namespace_status_phase) by (phase, namespace)

But we also want to find the AGE from when a namespace was active/created. We are not able to find AGE in any of the 4 kube metrics of namespace available -

  1. kube_namespace_created
  2. kube_namespace_status_phase
  3. kube_namespace_lables
  4. kube_namespace_annotations

Any suggestions would be helpful.

Unfortunately as you already noticed there is no specific metric that could be used to calculate the age of an object. The closest thing that you could use to achieve your goal would be to use kube_namespace_created which shows at what time namespace in Kubernetes was created.

I was also not able to find a proper Prometheus operator / function in order to make some kind of workaround PROMQL.

I am posting this answer as a community wiki. Feel free to expand on it as you wish.

I hope it helps.

I have seen on other metrics regarding age that you need to multiply by 1000

So if you do;

kube_namespace_created * 1000

You would need to check/test but I've seen that used on other queries about finding the age of worker nodes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM