How To Empty the Cache in Prometheus Using Curl
I wanted to empty the time series data cache from the Prometheus server to start clean.
The best practice is to use the administrative HTTP API via curl. For example, to clear all data for job mysqld
as defined in the prometheus.yml
configuration file:
1 |
curl -X POST -g 'http://localhost:9090/api/v1/admin/tsdb/delete_series?match[]={job="mysqld"}' |
If you want to delete ALL data from Prometheus, then execute:
1 |
curl -X POST -g 'http://localhost:9090/api/v1/admin/tsdb/delete_series?match[]={__name__=~".+"}' |
Since Prometheus keeps deleted data for 15 days by default, you may want to speed up that process by executing:
1 |
curl -X POST -g 'http://localhost:9090/api/v1/admin/tsdb/clean_tombstones' |
You can change the default of 15 days by setting the --storage.tsdb.retention
option.
NOTE: The administrative HTTP API is disabled by default!
To enable it, add the --web.enable-admin-api
argument to the prometheus commend at startup.
For example, this is an excerpt from my /etc/init.d/prometheus service script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
... PROGNAME=prometheus PROG=/usr/local/prometheus/$PROGNAME USER=root LOGFILE=/var/log/prometheus.log DATADIR=/volumes/data/prometheus LOCKFILE=/var/run/$PROGNAME.pid CONFIG_FILE=/usr/local/prometheus/prometheus.yml start() { echo -n "Starting $PROGNAME: " daemon --user $USER --pidfile="$LOCKFILE" "$PROG --config.file=$CONFIG_FILE --storage.tsdb.path=$DATADIR --storage.tsdb.retention=3d --web.enable-admin-api &>$LOGFILE &" echo $(pidofproc $PROGNAME) >$LOCKFILE echo } |
Credits:
Thanks to ShellHacks – https://www.shellhacks.com/prometheus-delete-time-series-metrics/
Leave Your Comment
All fields marked with "*" are required.