1
0
Fork 0
mirror of https://github.com/sdr-enthusiasts/docker-adsb-ultrafeeder.git synced 2024-11-22 05:40:10 +00:00
docker-adsb-ultrafeeder/README-grafana.md

161 lines
6.1 KiB
Markdown
Raw Normal View History

2023-03-30 19:18:53 +00:00
# Using Ultrafeeder with Grafana and Prometheus
[`Grafana`](https://grafana.com/) is an analytics platform that can provide alternative graphs for `readsb`.
In this guide we will be using [`Prometheus`](https://prometheus.io/) as the data repository.
Using Grafana and Prometheus in this configuration does not require a plan, account, or credentials for their respective cloud offerings.
## Hardware requirements
Prometheus will store a lot of data, and Grafana will do a lot of data queries. As a result, it would be better if you run these containers on a different system than your feeder Raspberry Pi. This will leave your Pi focused on data collection and processing, and unbothered by the CPU and Disk IO load that Prometheus/Grafana will cause.
You *can* do it on a single system. We're assuming below that you are not. If you do it on a single system, then you can combine the `docker-compose.yml` components in a single file
## Step 1: Make Prometheus data available for the Ultrafeeder
- Edit your Ultrafeeder's `docker-compose.yml` file and ensure that the following is set for the `ultrafeeder` service:
```yaml
environment:
- PROMETHEUS_ENABLE=true
- TAR1090_ENABLE_AC_DB=true
2023-03-30 19:18:53 +00:00
ports:
- 9273-9274:9273-9274
```
Now recreate the ultrafeeder container (`docker-compose up -d ultrafeeder`) and it will generate Prometheus data.
## Step 2: create a container stack for `prometheus` and `grafana`
On the machine where you will run Prometheus and Grafana, create a docker-compose file in the `/opt/grafana` directory:
```bash
2023-03-30 21:45:32 +00:00
sudo mkdir -p -m777 /opt/grafana/grafana/appdata /opt/grafana/prometheus/config /opt/grafana/prometheus/data
2023-03-30 20:19:16 +00:00
cd /opt/grafana
2023-03-30 19:18:53 +00:00
cat > docker-compose.yml
```
2023-03-30 20:14:38 +00:00
Now paste in the following text *):
2023-03-30 19:18:53 +00:00
<details>
2023-03-30 19:27:08 +00:00
<summary>&lt;&dash;&dash; Click the arrow to see the <code>docker-compose.yml</code> text</summary>
2023-03-30 19:18:53 +00:00
```yaml
version: '3.9'
2023-03-30 20:14:38 +00:00
volumes:
grafana:
driver: local
driver_opts:
type: none
device: "/opt/grafana/grafana/appdata"
o: bind
prom-config:
driver: local
driver_opts:
type: none
device: "/opt/grafana/prometheus/config"
o: bind
prom-data:
driver: local
driver_opts:
type: none
device: "/opt/grafana/prometheus/data"
o: bind
2023-03-30 19:18:53 +00:00
services:
grafana:
image: grafana/grafana-oss:latest
restart: unless-stopped
container_name: grafana
hostname: grafana
tty: true
# uncomment the following section and set the variables if you are exposing Grafana to the internet behind a rev web proxy:
environment:
# windrose panel plugin is needed for polar plots:
- GF_INSTALL_PLUGINS=fatcloud-windrose-panel
# uncomment and set the following variables if you are exposing Grafana to the internet behind a rev web proxy:
# - GF_SERVER_ROOT_URL=https://mywebsite.com/grafana/
2023-03-30 19:18:53 +00:00
# - GF_SERVER_SERVE_FROM_SUB_PATH=true
ports:
- 3000:3000
volumes:
2023-03-30 20:14:38 +00:00
- grafana:/var/lib/grafana
2023-03-30 19:18:53 +00:00
prometheus:
image: prom/prometheus
container_name: prometheus
hostname: prometheus
restart: unless-stopped
tmpfs:
- /tmp
volumes:
2023-03-30 20:14:38 +00:00
- prom-config:/etc/prometheus
- prom-data:/prometheus
2023-03-30 19:18:53 +00:00
ports:
- 9090:9090
```
</details>
2023-03-30 20:19:16 +00:00
*) The volume definition structure is written this way purposely to ensure that the containers can place files in the persistent directories. Do not try to "directly" map volumes (`/opt/grafana/grafana/appdata:/var/lib/grafana`).
2023-03-30 19:18:53 +00:00
2023-03-30 20:19:16 +00:00
You should be able to see the following directories:
2023-03-30 19:18:53 +00:00
- `/opt/grafana/grafana/appdata`
- `/opt/grafana/prometheus/config`
- `/opt/grafana/prometheus/data`
2023-03-30 20:14:38 +00:00
Download and create Grafana and Prometheus for the first time with this command:
2023-03-30 19:27:08 +00:00
2023-03-30 19:18:53 +00:00
```bash
2023-03-30 20:14:38 +00:00
docker compose up -d
2023-03-30 19:18:53 +00:00
```
2023-03-30 20:14:38 +00:00
## Step 3: Configuring Prometheus
2023-03-30 19:27:08 +00:00
2023-03-30 20:14:38 +00:00
Prometheus needs to be told where to look for the data from the ultrafeeder. We will create a target prometheus configuration file that does this, please copy and paste the following. Make sure to replace `ip_of_ultrafeeder_machine` with the IP address or hostname of the machine where `ultrafeeder` is running:
2023-03-30 19:18:53 +00:00
2023-03-30 20:14:38 +00:00
```bash
docker exec -it prometheus sh -c "echo -e \" - job_name: 'readsb'\n static_configs:\n - targets: ['ip_of_ultrafeeder_machine:9273', 'ip_of_ultrafeeder_machine:9274']\" >> /etc/prometheus/prometheus.yml"
docker stop prometheus
docker compose up -d
```
2023-03-30 19:18:53 +00:00
2023-03-30 20:14:38 +00:00
(If you screw this up, **do NOT** re-run the command. Instead, try `sudo nano /opt/grafana//prometheus/config/prometheus.yml` and fix it that way.)
2023-03-30 19:18:53 +00:00
2023-03-30 20:14:38 +00:00
## Accessing Prometheus and Grafana via your browser
2023-03-30 19:18:53 +00:00
2023-03-30 20:14:38 +00:00
You should be able to point your web browser at:
2023-03-30 19:18:53 +00:00
2023-04-18 18:16:23 +00:00
- `http://docker.host.ip.addr:9090/` to access the `prometheus` console.
- `http://docker.host.ip.addr:3000/` to access the `grafana` console, use admin/admin as initial credentials, you should be prompted to change the password on first login.
2023-03-30 19:18:53 +00:00
Remember to change `docker.host.ip.addr` to the IP address of your docker host.
## Configuring data source and dashboard in Grafana
After you have logged into the `grafana` console the following manual steps are required to connect to `prometheus` as the data source
1. Click `Add your first data source` in the main panel
2. Click `Prometheus` from the list of options provided
3. Input or select the following options, if the option is not listed, do not input anything for that option:
Option | Input
------------- | -------------
Name | readsb
2023-04-18 18:16:23 +00:00
URL | `http://prometheus:9090/`
2023-03-30 19:18:53 +00:00
Clicking `Save & Test` should return a green message indicating success. The dashboard can now be imported with the following steps
1. Hover over the `four squares` icon in the sidebar, click `+ Import`
2. Enter `18398` into the `Import via grafana.com` section and click `Load`
3. Select `readsb` from the bottom drop down list
4. Click `Import` on the subsequent dialogue box
At this point you should see a very nice dashboard, you can find it under `General` in the `Dashboards` section.
2023-03-30 19:27:08 +00:00
<img src="https://user-images.githubusercontent.com/15090643/228942953-ed8b64aa-3a38-4c6f-bd42-e929b72399b2.png">
<img src="https://user-images.githubusercontent.com/15090643/228943041-7e135856-543a-416a-9331-50853d2e0929.png">
<img src="https://user-images.githubusercontent.com/15090643/228943083-c017c5a0-f5aa-4d03-b241-8e58f2c8a5f6.png">