Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker integration and example #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM debian:stretch-slim

# install collectd
RUN \
apt-get update -qq; \
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -qq \
collectd \
libpython2.7 \
python-setuptools \
python-wheel \
python-pip; \
apt-get clean; \
rm -f /var/lib/apt/lists/deb* /var/lib/apt/lists/sec*


RUN pip install fritzcollectd

COPY entrypoint.sh /
RUN chmod 755 /entrypoint.sh

ENTRYPOINT [ "/entrypoint.sh" ]
30 changes: 30 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Docker Image

## Building

Just run inside of the `docker` directory

```
docker build -t fritzcollectd .
```

Afterwards, you can run it in debug to see if everything works as expected:

```
docker run -it --rm -e VERBOSE=true \
-e FRITZBOX_USER=<username> -e FRITZBOX_PASSWORD=<password> \
fritzcollectd
```

The output should show the values read from the FritzBox. The Docker image is templated via
environment variables. For more information, please see `docker/entrypoint.sh`.

## Test with `docker-compose`

You can also spin up a whole Docker stack including InfluxDB and Grafana to play with:

```
FRITZBOX_USER=<username> FRITZBOX_PASSWORD=<password> docker-compose up --build -d
```

You can access the Grafana UI on `<your-docker-machine>:3000`, Chronograph runs on `:8888`.
40 changes: 40 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: '3'

services:

fritzcollectd:
build: .
hostname: fritzbox
depends_on:
- influxdb
environment:
- FRITZBOX_USER
- FRITZBOX_PASSWORD

influxdb:
build: influx-provisioning
environment:
- INFLUXDB_REPORTING_DISABLED=true

grafana:
build: grafana-provisioning
ports:
- "3000:3000"
environment:
- GF_ANALYTICS_REPORTING_ENABLED=false
- GF_ALERTING_ENABLED=false
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
- GF_AUTH_BASIC_ENABLED=false
- GF_AUTH_DISABLE_LOGIN_FORM=true
- GF_AUTH_DISABLE_SIGNOUT_MENU=true
depends_on:
- influxdb

chronograf:
image: chronograf:alpine
command: --influxdb-url=http://influxdb:8086
ports:
- 8888:8888
depends_on:
- influxdb
48 changes: 48 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# access to InfluxDB
INFLUXDB_HOST=${INFLUXDB_HOST:-influxdb}
INFLUXDB_PORT=${INFLUXDB_PORT:-25826}

# access to FritzBox
FRITZBOX_HOST=${FRITZBOX_HOST:-fritz.box}
FRITZBOX_PORT=${FRITZBOX_PORT:-49000}

# reported hostname
FRITZBOX_HOSTNAME=${FRITZBOX_HOSTNAME:fritzbox}

# Plugin verbosity
VERBOSE=${VERBOSE:-false}

cat > /etc/collectd/collectd.conf <<EOF
FQDNLookup true
LoadPlugin logfile

<Plugin logfile>
LogLevel "info"
File STDOUT
Timestamp true
PrintSeverity false
</Plugin>

LoadPlugin network
LoadPlugin python

<Plugin network>
Server "$INFLUXDB_HOST" "$INFLUXDB_PORT"
</Plugin>
<Plugin python>
Import "fritzcollectd"

<Module fritzcollectd>
Address "$FRITZBOX_HOST"
Port $FRITZBOX_PORT
User "$FRITZBOX_USER"
Password "$FRITZBOX_PASSWORD"
Hostname "$FRITZBOX_HOSTNAME"
Verbose "$VERBOSE"
</Module>
</Plugin>
EOF

exec /usr/sbin/collectd -f
13 changes: 13 additions & 0 deletions docker/grafana-provisioning/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM grafana/grafana

USER root

COPY datasources /etc/grafana/provisioning/datasources/
COPY dashboards /etc/grafana/provisioning/dashboards/

RUN \
mkdir -p /var/lib/grafana/dashboards; \
curl https://grafana.com/api/dashboards/713/revisions/4/download > /var/lib/grafana/dashboards/713.json; \
sed -i -e 's/${DS_INFLUXDB_COLLECTD}/influxdb/g' /var/lib/grafana/dashboards/713.json

USER grafana
11 changes: 11 additions & 0 deletions docker/grafana-provisioning/dashboards/dashs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: 1

providers:
- name: 'default'
orgId: 1
folder: ''
type: file
disableDeletion: false
updateIntervalSeconds: 10 #how often Grafana will scan for changed dashboards
options:
path: /var/lib/grafana/dashboards
11 changes: 11 additions & 0 deletions docker/grafana-provisioning/datasources/influx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# config file version
apiVersion: 1

datasources:
- name: influxdb
type: influxdb
access: proxy
database: collectd
url: http://influxdb:8086
isDefault: true
editable: false
7 changes: 7 additions & 0 deletions docker/influx-provisioning/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM docker_fritzcollectd

FROM influxdb:alpine

COPY --from=0 /usr/share/collectd/types.db /usr/share/collectd/types.db

COPY influxdb.conf /etc/influxdb
21 changes: 21 additions & 0 deletions docker/influx-provisioning/influxdb.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[meta]
dir = "/var/lib/influxdb/meta"

[data]
dir = "/var/lib/influxdb/data"
engine = "tsm1"
wal-dir = "/var/lib/influxdb/wal"

[[collectd]]
enabled = true
bind-address = ":25826"
database = "collectd"
retention-policy = ""
batch-size = 5000
batch-pending = 10
batch-timeout = "10s"
read-buffer = 0
typesdb = "/usr/share/collectd/types.db"
security-level = "none"
auth-file = "/etc/collectd/auth_file"
parse-multivalue-plugin = "split"