Skip to content

Commit

Permalink
feat: update all stack and new dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
APO-Axione committed Jan 16, 2023
1 parent b6ea275 commit 6032a1b
Show file tree
Hide file tree
Showing 9 changed files with 1,367 additions and 1,273 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ignore IntelliJ IDEA project files
.idea/
107 changes: 59 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,84 @@

## Introduction

A monitoring solution for Docker hosts and containers with [Prometheus](https://prometheus.io/), [Grafana](http://grafana.org/), [cAdvisor](https://github.com/google/cadvisor), [NodeExporter](https://github.com/prometheus/node_exporter).
This repository contains a `docker-compose` file to run a Raspberry PI monitoring stack. It is based on the following projects:
- [Prometheus](https://prometheus.io/)
- [Grafana](http://grafana.org/)
- [cAdvisor](https://github.com/google/cadvisor)
- [NodeExporter](https://github.com/prometheus/node_exporter)

You can **download** this dashboard at [Grafana Dashboard Community](https://grafana.com/grafana/dashboards/15120)
## Prerequisites

## Screenshot
Before we get started installing the stack, we need to make sure that the following prerequisites are met:
- Docker is installed on the host machine
- Docker Compose is installed on the host machine
- The host machine is running a Raspberry PI OS or any other compatible Linux distribution

![image](https://user-images.githubusercontent.com/18188407/137627367-d872c46c-7052-4dfd-ba86-6b46571ebd15.png)
## Installation and Configuration

## Installation
If you would like to change which targets should be monitored, you can edit the ![prometheus.yml](prometheus/prometheus.yml) file.
<br/>The targets section contains a list of all the targets that should be monitored by Prometheus.
<br/>The names defined in the `job_name` section are used to identify the targets in Grafana.
<br/>The `static_configs` section contains the IP addresses of the targets that should be monitored. Actually, they are sourced from the service names defined in the ![docker-compose.yml](docker-compose.yml) file.
<br/>If you think that the `scrape_interval` value is too aggressive, you can change it to a more suitable value.

First SSH into your Pi and there is one thing we need to do before we get cracking. We need to enable `c-groups` so the stack will work out of the box. To do this you need to modify the configuration file `/boot/cmdline.txt`:

```
sudo nano /boot/cmdline.txt
Once you have made the necessary changes, simply clone this repository and start the stack by running the following command:
```bash
docker-compose up -d
```

And add the following options:

```
cgroup_enable=memory cgroup_memory=1
```
This will start all the containers and make them available on the host machine.
<br/>The following ports are used (only Grafana is exposed on the host machine):
- 3000: Grafana
- 9090: Prometheus
- 8080: cAdvisor
- 9100: NodeExporter

Now save the file in your editor and reboot:
The Grafana dashboard can be accessed by navigating to `http://<host-ip>:3000` in your browser for example `http://192.168.1.100:3000`.
<br/>The default username and password are both `admin`. You will be prompted to change the password on the first login.
<br/>Credentials can be changed by editing the ![.env](grafana/.env) file.

In order to check if the stack is running correctly, you can run the following command:
```bash
docker-compose ps
```
sudo reboot

View the logs of a specific container by running the following command:
```bash
docker logs -f <container-name>
```

Then clone this repository on your Pi host, cd into Docker-Raspberry-PI-Monitoring directory and run docker-compose up:
## Add Data Sources and Dashboards

```sh
git clone https://github.com/oijkn/Docker-Raspberry-PI-Monitoring.git
cd Docker-Raspberry-PI-Monitoring
docker-compose up -d
```
Since Grafana v5 has introduced the concept of provisioning, it is possible to automatically add data sources and dashboards to Grafana.
<br/>This is done by placing the `datasources` and `dashboards` directories in the ![provisioning](grafana/provisioning) folder. The files in these directories are automatically loaded by Grafana on startup.

Containers:
If you like to add a new dashboard, simply place the JSON file in the ![dashboards](grafana/provisioning/dashboards) directory, and it will be automatically loaded next time Grafana is started.

* Prometheus (metrics database) http://<host-ip>:9090
* Grafana (visualize metrics) http://<host-ip>:3000
* NodeExporter (host metrics collector)
* cAdvisor (containers metrics collector)
# Install Dashboard from Grafana.com

## Setup Grafana
If you would like to install this dashboard from Grafana.com, simply follow the steps below:
- Navigate to the dashboard on Grafana.com: https://grafana.com/dashboards/15120
- Click on the `Copy ID to Clipboard` button
- Navigate to the `Import` page in Grafana
- Paste the ID into the `Import via grafana.com` field
- Click on the `Load` button
- Click on the `Import` button

Navigate to `http://<host-ip>:3000` and login with user ***admin*** password ***admin***. You can change the credentials in the compose file or by supplying the `ADMIN_USER` and `ADMIN_PASSWORD` environment variables on compose up.
This dashboard is intended to help you get started with monitoring your Raspberry PI devices. If you have any changes or suggestions, you would like to see, please feel free to open an issue or create a pull request.

```yaml
GF_SECURITY_ADMIN_USER=admin
GF_SECURITY_ADMIN_PASSWORD=changeme
GF_USERS_ALLOW_SIGN_UP=false
```
Here is a screenshot of the dashboard:
![Grafana Dashboard](grafana/screenshots/dashboard.png)

Grafana is not preconfigured with dashboard, so you have to import it from the [json](https://github.com/oijkn/Docker-Raspberry-PI-Monitoring/blob/main/grafana/dashboard_by_oijkn.json) file. And set Prometheus as the default data source.

```
Grafana > Configuration > Data Sources > Prometheus
```
![image](https://user-images.githubusercontent.com/18188407/137201046-691a09e8-3efd-478c-a943-7c61ce409931.png)
## License

This project is licensed under the MIT License - see the ![LICENSE](LICENSE) file for details

## Setup Prometheus
## Troubleshooting

```yaml
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 30s
static_configs:
- targets: ['localhost:9090', 'cadvisor:8080', 'node-exporter:9100']
```
Enable `c-group` memory and swap accounting on the host machine by running the following command:
```bash
sudo sed -i 's/^GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="cgroup_enable=memory cgroup_memory=1 swapaccount=1"/' /etc/default/grub
sudo update-grub
sudo reboot
```
111 changes: 60 additions & 51 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,80 +1,89 @@
version: "3"
services:
grafana:
container_name: monitoring-grafana
image: grafana/grafana:latest
hostname: rpi-grafana
restart: unless-stopped
user: "472"
networks:
- internal
ports:
- "3000:3000"
env_file:
- ./grafana/.env
volumes:
# /!\ To be modified depending on your needs /!\
- ./grafana/data:/var/lib/grafana
- ./grafana/provisioning:/etc/grafana/provisioning
depends_on:
- prometheus

cadvisor:
container_name: monitoring-cadvisor
devices:
- /dev/kmsg
expose:
- 8080
hostname: rpi-cadvisor
image: zcube/cadvisor:latest
ipc: shareable
networks:
- rpimonitor_default
privileged: true
hostname: rpi-cadvisor
restart: unless-stopped
security_opt:
- label=disable
privileged: true
networks:
- internal
expose:
- 8080
devices:
- /dev/kmsg
volumes:
- /:/rootfs:ro
- /var/run:/var/run:ro
- /var/run:/var/run:rw
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
- /dev/disk/:/dev/disk:ro

grafana:
container_name: monitoring-grafana
environment:
- GF_USERS_ALLOW_SIGN_UP=false
- GF_PATHS_CONFIG=/etc/grafana/grafana.ini
- GF_PATHS_DATA=/var/lib/grafana
- GF_PATHS_HOME=/usr/share/grafana
- GF_PATHS_LOGS=/var/log/grafana
- GF_PATHS_PLUGINS=/var/lib/grafana/plugins
- GF_PATHS_PROVISIONING=/etc/grafana/provisioning
hostname: rpi-grafana
image: grafana/grafana:latest
networks:
- rpimonitor_default
ports:
- 3000:3000
restart: unless-stopped
volumes:
# to be modified depending on your needs
- /path/to/your/grafana/data:/var/lib/grafana
- /path/to/your/grafana/grafana.ini:/etc/grafana/grafana.ini
- /path/to/your/grafana/provisioning:/etc/grafana/provisioning
- /etc/machine-id:/etc/machine-id:ro

node-exporter:
container_name: monitoring-node-exporter
expose:
- 9100
hostname: rpi-exporter
image: prom/node-exporter:latest
networks:
- rpimonitor_default
hostname: rpi-exporter
restart: unless-stopped
networks:
- internal
expose:
- 9100
command:
- --path.procfs=/host/proc
- --path.sysfs=/host/sys
- --path.rootfs=/host
- --collector.filesystem.ignored-mount-points
- ^/(sys|proc|dev|host|etc|rootfs/var/lib/docker/containers|rootfs/var/lib/docker/overlay2|rootfs/run/docker/netns|rootfs/var/lib/docker/aufs)($$|/)
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
- /:/host:ro,rslave

prometheus:
container_name: monitoring-prometheus
image: prom/prometheus:latest
hostname: rpi-prometheus
restart: unless-stopped
user: "nobody"
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
container_name: monitoring-prometheus
networks:
- internal
expose:
- 9090
hostname: rpi-prom
image: prom/prometheus:latest
networks:
- rpimonitor_default
restart: unless-stopped
volumes:
# to be modified depending on your needs
- /path/to/your/prometheus/data:/prometheus
- /path/to/your/prometheus/config:/etc/prometheus/
# /!\ To be modified depending on your needs /!\
- ./prometheus/data:/prometheus
- ./prometheus:/etc/prometheus/
depends_on:
- cadvisor
- node-exporter
links:
- cadvisor:cadvisor
- node-exporter:node-exporter

networks:
rpimonitor_default:
external: true
internal:
driver: bridge
11 changes: 11 additions & 0 deletions grafana/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
GF_SECURITY_ADMIN_USER=admin
GF_SECURITY_ADMIN_PASSWORD=admin
GF_USERS_ALLOW_SIGN_UP=false

GF_PATHS_CONFIG=/etc/grafana/grafana.ini
GF_PATHS_DATA=/var/lib/grafana
GF_PATHS_HOME=/usr/share/grafana
GF_PATHS_LOGS=/var/log/grafana
GF_PATHS_PLUGINS=/var/lib/grafana/plugins
GF_PATHS_PROVISIONING=/etc/grafana/provisioning
GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH=/etc/grafana/provisioning/dashboards/Docker-Raspberry-PI-Monitoring.json
Loading

0 comments on commit 6032a1b

Please sign in to comment.