prometheushealth-monitoringpromqlkube-apiserver

Availability calculation using PromQL


I'm going to monitor my Kubernetes cluster availability. Prometheus server scraping kube-apiserver metrics and calculate availability percent according to kube-apiserver pods availability. Sometime kube-apiserver pods down and Prometheus server is not able to scrape at all and sometime pods are up and running and also serving requests but due to network connectivity or any other reason Prometheus server can not scrape metrics. Is there any way to use PromQL to ignore no values? Or the better way to calculate Kubernetes cluster availability?


Solution

  • To manage 'no data', I found this article and helped me to write my query:

    clamp_max(sum by (cluster) (up{component="kube-apiserver"}),1) or on() vector(0)
    

    Using or on() vector(0) to the end of your expression. It will return 0 if the metric expression does not return anything.