Create histograms with Flux

If you’re just getting started with Flux queries, check out the following:

  • Get started with Flux for a conceptual overview of Flux and parts of a Flux query.
  • to discover a variety of ways to run your queries.

The histogram() function approximates the cumulative distribution of a dataset by counting data frequencies for a list of “bins.” A bin is simply a range in which a data point falls. All data points that are less than or equal to the bound are counted in the bin. In the histogram output, a column is added (le) that represents the upper bounds of of each bin. Bin counts are cumulative.

Values output by the histogram function represent points of data aggregated over time. Since values do not represent single points in time, there is no _time column in the output table.

Flux provides two helper functions for generating histogram bins. Each generates an array of floats designed to be used in the histogram() function’s bins parameter.

  1. linearBins(start: 0.0, width: 10.0, count: 10)

logarithmicBins()

The logarithmicBins() function generates a list of exponentially separated floats.

The automatically converts query results into a binned and segmented histogram.

Use the Histogram visualization controls to specify the number of bins and define groups in bins.

Output of the is not compatible with the Histogram visualization type. View the example below.

Generate a histogram with linear bins

  1. from(bucket: "example-bucket")
  2. |> range(start: -5m)
  3. |> histogram(bins: linearBins(start: 65.5, width: 0.5, count: 20, infinity: false))
Output table
  1. from(bucket: "example-bucket")
  2. |> range(start: -5m)
  3. |> filter(fn: (r) => r._measurement == "mem" and r._field == "used_percent")
Output table

Visualize errors by severity

Use the to collect error information from your system. Query the severity_code field in the syslog measurement:

  1. from(bucket: "example-bucket")
  2. |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  3. |> filter(fn: (r) => r._measurement == "syslog" and r._field == "severity_code")

In the Histogram visualization options, select _time as the X Column and severity as the Group By option:

Logs by severity histogram