Dynamic data visualization and Docker [InfluxDB, Chronograf]

TICK [Telegraf, InfluxDB, Chronograf, Kapacitor] Stack helps you display the dynamic real-time data visually with impressive chart and alert you in your popular chat application (e.g., slack)

  • Clone influxdata/sandbox
git clone https://github.com/influxdata/sandbox.git
  • Pull all the required docker images – InfluxDB, Chronograf, Telegraf, and Kapacitor through docker-compose.yml and run containers (linked) with a single command as scheduled
cd sandbox
./sandbox up

Chronograf

  • Select database, status, function and click submit

  • green tick to see the real-time data in dashboard

 

Alerts in Slack

  • Open Chronograf and click Alerting > Manage Tasks > Build Alert Rule

  • Set database name, measurements, and fields
  • Set conditions of the fields as shown in the below image

  • Choose Slack from Add Handler

  • Configure slack webhooks in the details and save changes

  • Trigger an alert with post API; and check for the alerts in Alerts Dashboard

  • Observe the slack alert as seen below

 

InfluxDB

  • Run the following command to enter influxdb container in debug mode and to connect influxdb, where you can create databases
./sandbox influxdb
  • Create databases and manipulate them
CREATE DATABASE database_name
USE database_name
SHOW SERIES
EXIT

  • Let’s see few influxdb example queries here:

post / write

curl -i -XPOST 'http://localhost:8086/write?db=automation' --data-binary 'country status=3'

get / write

curl -i GET 'http://localhost:8086/query?pretty=true' --data-urlencode "db=automation" --data-urlencode "q=SELECT * FROM country"

curl -i GET 'http://localhost:8086/query?db=automation&pretty=true' --data-urlencode "q=SELECT * FROM country"

http://localhost:8086/query?db=automation&q=select%20*%20from%20country&pretty=true

 

Backup InfluxDB

Let’s see how to backup, copy it in the local machine:

approach #1

create a backup inside influxdb container

[case #1]
docker exec -it influxdb_container_id influxd backup -portable container_dir

(i.e., docker exec -it 459a48ac9a0c influxd backup -portable backup)

[case #2]
docker exec -it influxdb_container_id influxd backup -portable -database database_name container_dir

copy the backup in local machine

docker cp influxdb_container_id:container_dir local_dir

(i.e., docker cp 459a48ac9a0c:backup_db/ ~/Downloads/backup_db/)

restore the backup in influxdb container

# transfer data into the container
docker cp local_dir influxdb_container_id:/container_dir
(i.e., docker cp ./ 459a48ac9a0c:/update_data)

# restore data
[case #1]
docker exec -it influxdb_container_id influxd restore -portable ./
container_dir

(i.e., docker exec -it 459a48ac9a0c influxd restore -portable ./new_data)

[case #2]
docker exec -it influxdb_container_id influxd restore -portable -db database_name container_dir

[cmdline run]
docker run --rm \
--entrypoint /bin/bash \
-v ./influxdb/data:/var/lib/influxdb \
-v local_backup:/backups \
influxdb:1.3 \
-c "influxd restore -metadir /var/lib/influxdb/meta -datadir /var/lib/influxdb/data -database [DB_NAME] /backups/[BACKUP_DIR_NAME]"

approach #2 (Legacy)

create a backup inside influxdb container

docker exec -it influxdb_container_id influxd backup -database database_name container_dir

(i.e., docker exec -it 459a48ac9a0c influxd backup -database automation backup_db)

Advertisements