paregupt / ucs_traffic_monitor

Cisco UCS traffic monitoring using Grafana, InfluxDB and Telegraf
MIT License
80 stars 25 forks source link

Flushing old data #63

Closed neddyuk closed 3 years ago

neddyuk commented 3 years ago

how do you flush all the old data out of the system?

paregupt commented 3 years ago

The first and simplest option is to just leave the data untouched. All the visualizations on the UI are time based (defaults to 6 hours). As time passes by, the UI will start looking at the recent data and the older data will cease to display.

However, if you wish to keep the database clean, here are the options to clear the data within the database. Login to the UTM VM and open the Influx CLI (the time series database powering UTM).

# influx -precision rfc3339 By default, UTM uses telegraf database. Change the database via:

> use telegraf
Using database telegraf

You can delete the complete telegraf database. This is fine in a lab environment but not recommended in general. If you still wish to take this route, following is the command.

> drop database telegraf
>

This will delete the data within the telegraf database permanently. Be cautious!

The recommended approach is to delete data from individual measurements (table in InfluxDB). As of UTM v0.4, it created the following 6 measurements:

  1. BackplanePortStats
  2. FIEnvStats
  3. FIServerPortStats
  4. FIUplinkPortStats
  5. Servers
  6. VnicStats

You can use show measurements command to see the available measurements.

> show measurements
name: measurements
name
----
BackplanePortStats
FIEnvStats
FIServerPortStats
FIUplinkPortStats
Servers
VnicStats
cpu
disk
diskio
kernel
mem
net
processes
swap
system
> 

Use the delete command as shown below.

> delete from FIEnvStats where time < now() - 90d This will delete data older than 90 days. You can use 5d, 6h, 10m, etc.

The other option is to use absolute dates, as shown below:

> delete from FIEnvStats where time < '2020-01-01'

You would have to execute the above command for all the 6 measurements. For example:

> delete from FIEnvStats where time < now() - 1d
> delete from BackplanePortStats where time < now() - 1d
> delete from FIServerPortStats where time < now() - 1d
> delete from FIUplinkPortStats where time < now() - 1d
> delete from Servers where time < now() - 1d
> delete from VnicStats where time < now() - 1d

Please be careful in using the < and >. Changing the symbol will delete all the recent data while keeping the older data. It may not matter in a lab environment but you can imagine the impact in production. Also, InfluxDB does not return anything when a command is successful. If you clean the data while UTM is running, it is possible that the measurements are created within a few seconds again as new data is written. Do not get confused if you notice this.

Finally, exist from Influx CLI via

> exit
#

There are many more options for data management in general, all described in detail in the InfluxDB documentation: https://docs.influxdata.com/influxdb/v1.8/. Hope this helps.

Note: By following these steps, you own the full responsibility of your data. I do not guarantee the accuracy of these steps. InfluxDB supports data backup and restore, if you wish to use the functionality.

mnagy7 commented 3 years ago

Is there is an easy way to delete a couple of locations and UCS domains I added by mistake from the DB?

neddyuk commented 3 years ago

This worked perfectly as you described above, I used:

delete from FIEnvStats where time < now() - 7d delete from BackplanePortStats where time < now() - 7d delete from FIServerPortStats where time < now() - 7d delete from FIUplinkPortStats where time < now() - 7d delete from Servers where time < now() - 7d delete from VnicStats where time < now() - 7d