InfluxDB: Total percentage of entries where a given field is > 0

Hi everyone,

My usecase is this: I have a series in InfluxDB where each entry has a “failures” field, an int which can be >= 0. I want to find the total percentage of entries in the series (under the given time period) which have failures > 0 (let’s call them “Failed Entries”). I then want to visualise it as a percentage, for example using a Gauge (or other fitting visualization)

This seems simple, but I have been bashing my head against this for hours now and I simply can’t find how to do it. I find the following problem: I would need a way to separate Failed Entries from regular entries somehow, so that I can calculate their total ratio, but how would I go about doing this in one or more queries. Further, how would I then calculate the total proportions so I can get the percentage?

Thanks in advance for all help!

Welcome to the forum. I think the reason it has taken 3 days for a response is because your problem is not super simple. But I think what you want can be done.

Have you played around with Grafana Transformations? Give that a try and see what you can come up with. Start simple. Make a new field that does simple math. The first Transformation listed (Add field from calculation) is probably what you will want to try.

Add field from calculation

Use this transformation to add a new field calculated from two other fields. Each transformation allows you to add one new field.

  • Mode - Select a mode:
    • Reduce row - Apply selected calculation on each row of selected fields independently.
    • Binary option - Apply basic math operation(sum, multiply, etc) on values in a single row from two selected fields.
  • Field name - Select the names of fields you want to use in the calculation for the new field.
  • Calculation - If you select Reduce row mode, then the Calculation field appears. Click in the field to see a list of calculation choices you can use to create the new field. For information about available calculations, refer to the Calculation list.
  • Operation - If you select Binary option mode, then the Operation fields appear. These fields allow you to do basic math operations on values in a single row from two selected fields. You can also use numerical values for binary operations.
  • Alias - (Optional) Enter the name of your new field. If you leave this blank, then the field will be named to match the calculation.
  • Replace all fields - (Optional) Select this option if you want to hide all other fields and display only your calculated field in the visualization.

Transformations process the result set of a query before it’s passed on for visualization. They allow you to rename fields, join separate time series together, do math across queries, and more. For users, with numerous dashboards or with a large volume of queries, the ability to reuse the query result from one panel in another panel can be a huge performance gain.

The transformations feature is accessible from the Transform tab of the Grafana panel editor.

Transformations sometimes result in data that cannot be graphed. When that happens, click the Table view toggle above the visualization to switch to a table view of the data. This can help you understand the final result of your transformations.