christoph ender's


monday the 20th of may, 2024

influx: get minium time value from all series

In order to free some diskspace from my influx databases, which are storing all the performance metrics from my icinga installations, I've been trying to remove the older, no longer relevant records, from the database. In order to get an overview over the current data, I've been trying to find out for how long I've been storing data at all. However, it appears there's no easy way to query the mininum time value for all series/measurements.

One way to work around this would be to iterate over all the measurements and to request the record having the minimum time value. After that, the time values are sorted accordingly.

echo "show measurements" \
 | influx -database dbname \
 | while read M; do \
     echo "select time,value from \"$M\" order by time limit 1" \
       | influx -format csv -database dbname \
       | (read dummy ; cat) \
       | cut -d, -f2 \
   done \
 | sort --numeric-sort --reverse

Here, the (read dummy ; cat) line will remove the first line, which contains the column header names, from the output. The cut statement will get the second field from the actual output, which contains the requested time value.