Since I started other projects, I moved away from Grafana some time ago.
In re-building my NAS from FreeNAS to Openmediavault, I decided to install Grafana as a docker container in the new system (OVM Extras allows you to add some extra goodies like NFS and Docker)
In any case, this is not really relevant since the following document should work on any x86 system installed with Docker and Docker Compose (there are other guides you can find to get the ARM version for docker builds if you want to try it on a Raspberry Pi)
Lets start creating the project and volumes directories
"root@vault:/etc/docker# cd /vol01/
root@vault:/vol01# mkdir -p Docker/monitoring
root@vault:/vol01# cd Docker/monitoring"
Create a Docker Compose playbook, which will contain all the necessary info for the different builds.
You can see what we are doing by reading the playbook.
Grafana is built and we reroute the port 3000, where normally it listens, to the port 3000 of the host. InfluxDB and its port 8086 are also rerouted.
Additionally, we set up a monitoring network to make sure the Containers have access to the host and the internet
The default configuration file for Telegraf needs to be "redirected" to the file created in the host so we don't have to modify anything in the container, since it will be done in the host
By using 2 Persistent Volumes, we can get the data into the host, which makes the installation more permanent.
Of course, remember to chose better USER/PASSWORDS if you are doing this. I just wanted to give it a try :)
"root@vault:/vol01/Docker/monitoring# cat docker-compose.yml
version: "2"
services:
grafana:
image: grafana/grafana
container_name: grafana
restart: always
ports:
- 3000:3000
networks:
- monitoring
volumes:
- grafana-volume:/vol01/Docker/monitoring
influxdb:
image: influxdb
container_name: influxdb
restart: always
ports:
- 8086:8086
networks:
- monitoring
volumes:
- influxdb-volume:/vol01/Docker/monitoring
environment:
- INFLUXDB_DB=telegraf
- INFLUXDB_USER=telegraf
- INFLUXDB_ADMIN_ENABLED=true
- INFLUXDB_ADMIN_USER=admin
- INFLUXDB_ADMIN_PASSWORD=Welcome1
telegraf:
image: telegraf
container_name: telegraf
restart: always
extra_hosts:
- "influxdb:192.168.0.110"
environment:
HOST_PROC: /rootfs/proc
HOST_SYS: /rootfs/sys
HOST_ETC: /rootfs/etc
volumes:
- ./telegraf.conf:/etc/telegraf/telegraf.conf:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- /sys:/rootfs/sys:ro
- /proc:/rootfs/proc:ro
- /etc:/rootfs/etc:ro
networks:
monitoring:
volumes:
grafana-volume:
external: true
influxdb-volume:
external: true
root@vault:/vol01/Docker/monitoring#'"
Create telegraf.conf file and add the following default configuration.
For mi case, the host IP is 192.168.0.110 and I also added some ping input just to try to see some of my local devices
"root@vault:/vol01/Docker/monitoring# cat telegraf.conf
[global_tags]
[agent]
interval = "60s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = "0s"
flush_interval = "10s"
flush_jitter = "0s"
precision = ""
hostname = "192.168.0.110"
omit_hostname = false
[[outputs.influxdb]]
urls = ["http://192.168.0.110:8086"]
database = "telegraf"
timeout = "5s"
username = "telegraf"
password = "Welcome1"
[[inputs.ping]]
interval = "5s"
urls = ["192.168.0.44", "192.168.0.131", "192.168.0.130", "google.com", "amazon.com", "github.com"]
count = 4
ping_interval = 1.0
timeout = 2.0
[[inputs.cpu]]
percpu = true
totalcpu = true
collect_cpu_time = false
report_active = false
[[inputs.disk]]
ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]
[[inputs.diskio]]
[[inputs.kernel]]
[[inputs.mem]]
[[inputs.processes]]
[[inputs.swap]]
[[inputs.system]]
root@vault:/vol01/Docker/monitoring#"
In the docker-compose playbook, start everything. Since you need to download all the images if you don't have them, it may take some time, but it should take less than 5 minutes if your computer is fast enough
"root@vault:/vol01/Docker/monitoring# docker-compose up -d
Creating network "monitoring_monitoring" with the default driver
Pulling grafana (grafana/grafana:)...
latest: Pulling from grafana/grafana
4167d3e14976: Pull complete
dd2bf2ad25d9: Pull complete
bc3026833a3a: Pull complete
8789bc1f4250: Pull complete
fc931efc1e71: Pull complete
09de0f0f5c91: Pull complete
b9833e14e8a2: Pull complete
763366917f49: Pull complete
Digest: sha256:b409a69218ca5990b61e33fe00121c94b2f9b5a7ec2f3118c703454c26067020
Status: Downloaded newer image for grafana/grafana:latest
Creating grafana ... done
Creating influxdb ... done
root@vault:/vol01/Docker/monitoring#"
and Voila! we just got Grafana running. Enter the host IP and port 3000 and you are ready to start
As a default, the username and password for Grafana is "admin", however, you will be asked to create a new password during your first login.
You will need to use the details we set in our Docker Compose to set InfluxDB as the default Datasource:
I suggest you look at different Dashboards you can import just by putting the ID into the import dialog, very useful
I would like to add a few additional notes.
I hope this encourages you to begin your Grafana project. This is a very versatile tool, and it can be installed and tested anywhere with Docker