How to set Default value to Prometheus Metric


I have Two metrics,

  1. no_of_published_messages
  2. no_of_failed_messages

So, i am calculating the % as below for the success and failure scenarios.

success % = no_of_published_messages / ( no_of_published_messages + no_of_failed_messages) * 100

failure % = no_of_failed_messages/ ( no_of_published_messages + no_of_failed_messages) * 100

the problem is, the metric “no_of_failed_messages” is not always be there (i.e it’s value may be there or may not be there at all).

since in my case, it don’t have any value/data points in the selected range. so grafana % widgets are not showing any value.
Is there any way to set default value to "no_of_failed_messages " metric.
so that grafana dashboard starts displaying the success and failure % even though “no_of_failed_messages” having no data points.

or is there any alternative way to handle it.

can you share the raw unformatted data for each of these queries, one at a time?