Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions deployment-and-dashboards-influxdb-v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# InfluxDB and Grafana stack

This directory contains a package with the files needed to spin up a stack with InfluxDB and Grafana where Grafana comes pre-populated with multiple dashboards useful for monitoring system metrics from the devices and the propagation of configuration parameters. The stack is using InfluxDB v2 and Flux.

## Running the stack

This stack (defined in `docker-compose.yml`) will run:

- InfluxDB storing time series data (system metrics and configuration parameters)
- Grafana to create dashboards

To run it:

1. Run `docker-compose up`
2. Then go to [http://127.0.0.1:8086](http://127.0.0.1:8086) and log in with username `test` and password `testtest` (from the `docker-compose.yml` file)
3. Open grafana UI on [http://127.0.0.1:3000](http://127.0.0.1:3000) and log in with username `admin` and password `test` (from the `docker-compose.yml` file).

### Example of more secure setup

The supplied `docker-compose.yml` file is for development usage. For production, you should hande keys in a more secure way. One example of a better setup is to use the `docker-compose.prod.yml` override file:

```bash
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d
```

## Grafana

Open the grafana UI on [http://127.0.0.1:3000](http://127.0.0.1:3000), login with user `admin` and password `test` (specified in the [./docker-compose.yml](./docker-compose.yml) file). Click on "Dashboards" and you should see the pre-populated dashboards in the "Cameras" folder.

## Helper scripts

The directory [helper_scripts](./helper_scripts/) contains scripts that can assist with deployment, see the [README](./helper_scripts/README.md) for more details.
52 changes: 52 additions & 0 deletions deployment-and-dashboards-influxdb-v2/docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This override file:
# - Adds Ouroboros for monitoring, updating, and restarting unhealthy containers
# - Adds healthchecks to InfluxDB and Grafana
# - Configures Slack notifications for status updates
# - Overrides production secrets for InfluxDB and Grafana
#
# This stack is only intended as an example.

version: "3.8"

services:
ouroboros:
image: pyouroboros/ouroboros
container_name: ouroboros
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
- INTERVAL=300 # Check every 5 minutes
- CLEANUP=true # Remove old images
- SELF_UPDATE=true # Update Ouroboros itself
- HEALTHCHECK_MONITORING=true # Restart unhealthy containers
- NOTIFIERS=slack://${OUROBOROS_SLACK_HOOK_URL}
labels:
- "com.ouroboros.enable=true" # Allow Ouroboros to watch itself
restart: unless-stopped

influxdb:
environment:
- DOCKER_INFLUXDB_INIT_USERNAME=${INFLUXDB_USERNAME}
- DOCKER_INFLUXDB_INIT_PASSWORD=${INFLUXDB_PASSWORD}
- DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=${INFLUXDB_ADMIN_TOKEN}
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8086/health"]
interval: 30s
timeout: 5s
retries: 3
labels:
- "com.ouroboros.enable=true" # Explicitly allow monitoring
restart: unless-stopped

grafana:
environment:
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_ADMIN_PASSWORD}
- INFLUXDB_TOKEN=${INFLUXDB_ADMIN_TOKEN}
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/api/health"]
interval: 30s
timeout: 5s
retries: 3
labels:
- "com.ouroboros.enable=true" # Explicitly allow monitoring
restart: unless-stopped
47 changes: 47 additions & 0 deletions deployment-and-dashboards-influxdb-v2/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This is a simple example of a stack with InfluxDB and Grafana.
# It is not intended for production use.
# For production use, see an example in docker-compose.prod.yml.

version: "3.8"

x-common-vars: &common-vars
INFLUXDB_ORG: &org Whisperer
INFLUXDB_BUCKET: &bucket Cameras

services:
influxdb:
image: influxdb:2
container_name: influxdb
ports:
- "8086:8086"
environment:
DOCKER_INFLUXDB_INIT_MODE: setup
DOCKER_INFLUXDB_INIT_USERNAME: test
DOCKER_INFLUXDB_INIT_PASSWORD: testtest
DOCKER_INFLUXDB_INIT_ORG: *org
DOCKER_INFLUXDB_INIT_BUCKET: *bucket
DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: KLoG_Z0NsDIbVzS7zVn_VwhgxUgvwaGWE1wwO9SsGfNEeMaopLMsAA2aAGbCshpetVdu86Ig3-WTKugv6Srg6w==
volumes:
- ./influxdb-data:/var/lib/influxdb2

grafana:
image: grafana/grafana
container_name: grafana
ports:
- "3000:3000"
# To avoid permission issues to the mounted dir we run as root...
# Should be changed. See:
# https://grafana.com/docs/grafana/latest/setup-grafana/installation/run-grafana-docker-image/#migrate-to-v51-or-later
user: "0"
environment:
GF_SECURITY_ADMIN_PASSWORD: test
INFLUXDB_TOKEN: KLoG_Z0NsDIbVzS7zVn_VwhgxUgvwaGWE1wwO9SsGfNEeMaopLMsAA2aAGbCshpetVdu86Ig3-WTKugv6Srg6w==
INFLUXDB_ORG: *org
INFLUXDB_BUCKET: *bucket
volumes:
- ./grafana-data:/var/lib/grafana
# The provisioning folder contains the data source info.
# This automatically sets up InfluxDB as a data source.
- ./provisioning:/etc/grafana/provisioning
depends_on:
- influxdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Helper scripts

## [install-docker-aws-ec2.sh](./install-docker-aws-ec2.sh)

This script can be used to install docker with docker compose on an AWS EC2 instance with Amazon Linux 2. This makes it easy to deploy the example dashboard to an AWS EC2 instance.

Just copy the script to the EC2 instance and run it with `./install-docker-aws-ec2.sh`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -euo pipefail

# Install Docker
sudo yum update -y
sudo amazon-linux-extras enable docker
sudo yum install -y docker
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker $USER

# Install Docker Compose as a plugin
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p "$DOCKER_CONFIG/cli-plugins"

curl -SL https://github.com/docker/compose/releases/download/v2.37.3/docker-compose-linux-x86_64 \
-o "$DOCKER_CONFIG/cli-plugins/docker-compose"

chmod +x "$DOCKER_CONFIG/cli-plugins/docker-compose"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: 1

providers:
- name: 'Camera monitoring dashboards'
folder: 'Cameras'
type: file
disableDeletion: false
editable: true
options:
# Look for dashboards in this folder (json files)
path: /etc/grafana/provisioning/dashboards
Loading