Delete points with unwanted field values from InfluxDB measurement

后端 未结 3 1559
野趣味
野趣味 2020-12-16 13:11

InfluxDB lets you delete points based on WHERE tag=\'value\' conditions, but not by field value.

For example, if you have accidentally stored a measurem

3条回答
  •  眼角桃花
    2020-12-16 13:41

    Ugly and slow but fairly robust solution: store timestamps, then delete entries by timestamp, optionally filtering DELETE statement with additional tags.

    N.B. this only works if fields have unique timestamps! E.g. if there are multiple fields for one timestamp, all these fields are deleted with below command. Using epoch=ns practically mitigates this, unless you have ~billion data points/second

    curl -G 'http://localhost:8086/query?db=DATABASE&epoch=ns' \
      --data-urlencode "q=SELECT * FROM metrics WHERE cpu=-1" |\
      jq -r "(.results[0].series[0].values[][0])" > delete_timestamps.txt
    
    for i in $(cat delete_timestamps.txt); do
      echo $i;
      curl -G 'http://localhost:8086/query?db=DATABASE&epoch=ns' \
        --data-urlencode "q=DELETE FROM metrics WHERE time=$i AND cpu=-1"; 
    done
    

提交回复
热议问题