Setting up InfluxDB

Time Series1 databases are all the rage right now.

They were explicitly designed to store data sequentially, the same way time passes. For this playground, I’ve chosen InfluxDB. Prometheus2 is also very popular, and you could use the PostgreSQL extensions3 for time series as well.

Influx has its own dialect of SQL. Make sure you look at the docs4.

## Setup

There isn’t much to configure when you set it up. I only modified the section for graphite (uncommenting if its already there, or pasting it in). Everything else is default.

[[graphite]]
enabled = true
database = "graphite"
retention-policy = ""
bind-address = ":2003"
protocol = "tcp"
consistency-level = "one"


The whole config (with comments stripped out) looks like this:

root@monitoring:~ # grep -v '^#' /usr/local/etc/influxd.conf | grep -v '  #' | grep -v '^$' [meta] dir = "/var/db/influxdb/meta" [data] dir = "/var/db/influxdb/data" wal-dir = "/var/db/influxdb/wal" series-id-set-cache-size = 100 [coordinator] [retention] [shard-precreation] [monitor] [http] [logging] [subscriber] [[graphite]] enabled = true database = "graphite" retention-policy = "" bind-address = ":2003" protocol = "tcp" consistency-level = "one" [[collectd]] [[opentsdb]] [[udp]] [continuous_queries] [tls] root@monitoring:~ #  When we start it up root@monitoring:~ # sysrc influxd_enable=YES root@monitoring:~ # service influxd start root@monitoring:~ #  and then check what is listening, we can see root@monitoring:~ # sockstat -46l USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS influxd influxd 66684 6 tcp4 127.0.0.1:8088 *:* influxd influxd 66684 7 tcp46 *:8086 *:* influxd influxd 66684 8 tcp46 *:2003 *:* root@monitoring:~ #  We can see that in addition to listening on the default 8088, and 8086, its also listening on 2003, as we configured above. ## Creating a DB $ influx
Connected to http://localhost:8086 version 1.8.0
InfluxDB shell version: 1.8.0
>

CREATE DATABASE graphite


Hopefully this does the obvious. We now have a database created called graphite.

## Creating a retention policy

What if you want to keep the data longer than the default of something like 168 hours? This is where retention policies come in to play. You can also assign whether the policy is the default for the database or not.

> show retention policies on graphite
name    duration shardGroupDuration replicaN default
----    -------- ------------------ -------- -------
autogen 0s       168h0m0s           1        true
> create retention policy "1year" on graphite duration 52w replication 1 default
> show retention policies on graphite
name    duration  shardGroupDuration replicaN default
----    --------  ------------------ -------- -------
autogen 0s        168h0m0s           1        false
1year   8736h0m0s 168h0m0s           1        true
>


Now your data will automatically expire after 52wks.

## Conclusion

OK, we have a database setup that we can use. What next? We have 2 more things to do (not an ordered list).

1. Setup an agent that will collect information and put it in the database
2. Setup grafana so we can visualize the information we’re collecting