4 Commits
v0.1 ... v0.2

Author SHA1 Message Date
Sven Holz
4ff13ef398 v0.2 2022-06-15 00:01:47 +02:00
Sven Holz
2e6d73a70c setuo script added 2022-06-14 13:55:02 +02:00
Sven Holz
6bfbd869a9 disable ssl verify for influx client 2022-06-14 08:47:02 +02:00
Sven Holz
d144d9ec9f v0.1 2022-06-14 00:55:56 +02:00
7 changed files with 231 additions and 80 deletions

View File

@@ -67,7 +67,8 @@ class MyInfluxDB():
# create influxdb client # create influxdb client
self.client = InfluxDBClient(url=INFX_URL, self.client = InfluxDBClient(url=INFX_URL,
token=INFX_TOKEN, token=INFX_TOKEN,
org=INFX_ORG) org=INFX_ORG,
verify_ssl=False)
# create influxdb write api # create influxdb write api
self.write_api = self.client.write_api(write_options=WriteOptions(batch_size=INFX_BATCH, self.write_api = self.client.write_api(write_options=WriteOptions(batch_size=INFX_BATCH,

212
README.md
View File

@@ -17,17 +17,17 @@ It´s based on python3 an makes usage of following python libraries:
- configparser - configparser
- time - time
Configuration can be passed via ENV **OR** configuration file. You can use it in *standalone* or *full stack* mode.
In case of using the ENV option you are just able to monitor **ONE** target for more targets please use the configuration file. **Standalone:**
- Just the latency-monitor container which sends data to an external InfluxDB2 Server
Also some influx connection options are just configurable via config file but normally they are not needed. **Full Stack:**
- Traefik container as Proxy (full TLS support)
- InfluxDB2 container, fully setup and ready to take data
- Grafana container, fully setup and connected (but without dashboards)
- latency-monitor container sending data to the InfluxDB2 container
Per default the python influx connector will cache all replies and sends them bundled every 30 seconds to the Influx DB.
The container will be build at 1st start.
You can find everything under *./Docker_Build/* and in the python program itself [latency_monitor.py](./Docker_Build/latency_monitor.py)
## Requirements ## Requirements
@@ -36,7 +36,26 @@ You can find everything under *./Docker_Build/* and in the python program itself
- InfluxDB Version >= 2 - InfluxDB Version >= 2
- pythonping needs root privileges so same for the container - pythonping needs root privileges so same for the container
## ENV Variables ## Configuration (GENERAL)
Configuration can be passed via ENV **OR** configuration file.
In case of using the ENV option you are just able to monitor **ONE** target for more targets please use the configuration file.
Also some influx connection options are just configurable via config file but normally they are not needed.
### Behaviour
Per default the python influx connector will cache all replies and sends them bundled every 30 seconds to the Influx DB.
The container will be build at 1st start.
You can find everything under *./Docker_Build/* and in the python program itself [latency_monitor.py](./Docker_Build/latency_monitor.py)
-----
### ENV Variables
Name | Example | Usage | Option/Must Name | Example | Usage | Option/Must
:------: | :-----: | :-----: | :-----: :------: | :-----: | :-----: | :-----:
@@ -48,60 +67,107 @@ TARGET_HOST | 8.8.8.8 | Monitored Host (IP/FQDN) | must
TARGET_TIMER | 3 | ping frequency in sec. | option TARGET_TIMER | 3 | ping frequency in sec. | option
TARGET_LOCATION | Google | decript. location | option TARGET_LOCATION | Google | decript. location | option
## Config File -----
### Config File
**Instead** of using the ENV variables you can use a config file. **Instead** of using the ENV variables you can use a config file.
**Keep in mind it´s a OR decision not a AND** **Keep in mind it´s a OR decision not a AND**
See [template_config.ini](./Docker_Build/template_config.ini) See [./latency-monitor/config.ini](./latency-monitor/config.ini)
Rename the file to *config.ini* make your changes and add it as a volume mount to the container:
### Docker-Compose Style #### Docker-Compose Style
uncomment:
``` ```
volumes: # - ./latency-monitor/config.ini:/app/config.ini:ro # UNCOMMENT IF NEEDED
- /YOUR_PATH/config.ini:/app/config.ini
``` ```
### Docker-CLI Style #### Docker-CLI Style
``` ```
docker latency-monitor -v /YOUR_PATH/config.ini:/app/config.ini docker latency-monitor -v ./latency-monitor/config.ini:/app/config.ini:ro
``` ```
-----
-----
## Configuration (Standalone)
1st thing to do is creating the *docker-compose.yml from [docker-compose-standalone.yml](./docker-compose-standalone.yml):
```
cp docker-compose-standalone.yml docker-compose.yml
```
### Variables
Below paragraph:
```
####################################################
# LATENCY-MONITOR
####################################################
```
in the **.env** file *(env needs to be renamed to .env)* configure following variables:
- YOUR_ORGANIZATION
- YOUR_BUCKET_NAME
- YOUR_ADMIN_TOKEN
- YOUR_MONITORED_TARGET
- YOUR_MONITORED_TARGET_TIMER
- YOUR_MONITORED_TARGET_LOCATION
### Lets go
```
docker-compose up -d latency-monitor
```
should do the job
----- -----
----- -----
## Compose Files ## Configuration (Full-Stack)
### FULL-STACK ### Easy peasy automatic mode
1st thing to do is creating the *docker-compose.yml from [docker-compose-full_stack.yml](./docker-compose-full_stack.yml): Have a look at [./setup-full_stack.sh](./setup-full_stack.sh)
Just create a valid *.env* File by:
``` ```
cp docker-compose-full_stack.yml docker-compose.yml cp env .env
``` ```
#### Certificate and editing it to your needs.
*Traefik* will act as a proxy and ensures the usage of TLS so it needs your certificate and key file. After everyting within *.env* is in order just do:
within the *docker-compose.yml* you will find:
``` ```
- ./traefik/mycert.crt:/certs/cert.crt:ro ./setup-full_stack.sh
- ./traefik/mycert.key:/certs/privkey.key:ro
``` ```
so please place your certificate file as *./traefik/mycert.crt* and the key file as *./traefik/mycert.key*. Everything should be right in place now.
Thats it Just the certificates are missing look [here](#certificate)
-----
-----
### WTF maual mode
You need to set all on your own:
#### Variables #### Variables
You need to configure Variables in following files to make the compose work: You need to configure Variables in following files to make the compose work:
- **file** - **file**
@@ -112,30 +178,32 @@ You need to configure Variables in following files to make the compose work:
----- -----
- **docker-compose.yml** *(was docker-compose-full_stack.yml before)* - **docker-compose.yml** *(was docker-compose-full_stack.yml before)*
- PLACE_YOUR_FQDN_HERE (3 times) - PLACE_YOUR_FQDN_HERE (3 times)
----- -----
- **.env** *(env needs to be renamed to .env)* - **.env** *(env needs to be renamed to .env)*
- YOUR_PATH_TO_CONTAINER_STATIC_DATA - YOUR_PATH_TO_CONTAINER_STATIC_DATA
- YOUR_ADMIN_USER - YOUR_ADMIN_USER
- YOUR_ADMIN_PASSWORD - YOUR_ADMIN_PASSWORD
- YOUR_ORGANIZATION - YOUR_ORGANIZATION
- YOUR_BUCKET_NAME - YOUR_BUCKET_NAME
- YOUR_ADMIN_TOKEN - YOUR_ADMIN_TOKEN
- YOUR_MONITORED_TARGET - YOUR_MONITORED_TARGET
- YOUR_MONITORED_TARGET_TIMER - YOUR_MONITORED_TARGET_TIMER
- YOUR_MONITORED_TARGET_LOCATION - YOUR_MONITORED_TARGET_LOCATION
----- -----
- **grafana/provisioning/datasources/grafana-datasource.yml** - **grafana/provisioning/datasources/grafana-datasource.yml**
- YOUR_ADMIN_TOKEN - YOUR_ADMIN_TOKEN
- YOUR_ORGANIZATION - YOUR_ORGANIZATION
- YOUR_BUCKET_NAME - YOUR_BUCKET_NAME
-----
#### File Permissions #### File Permissions
Because we are configuring *grafana* for permanent data storing and *grafana* actually runs with *UID* + *GID*: *472:472* it´s necessary to change permisson of die permanent storage directory we have configured. Because we are configuring *grafana* for permanent data storing and *grafana* actually runs with *UID* + *GID*: *472:472* it´s necessary to change permisson of die permanent storage directory we have configured.
The directory build from the following config part of grafana within the docker-compose.yml: The directory build from the following config part of grafana within the docker-compose.yml:
@@ -156,16 +224,34 @@ then you have to do the following
chown -R 472:472 /opt/docker/containers/grafana/var_lib chown -R 472:472 /opt/docker/containers/grafana/var_lib
``` ```
#### Lets go Everything should be right in place now.
Just the certificates are missing look [here](#certificate)
-----
-----
## Certificate
*Traefik* will act as a proxy and ensures the usage of TLS so it needs your certificate and key file.
within the *docker-compose.yml* you will find:
``` ```
docker-compose up -d - ./traefik/mycert.crt:/certs/cert.crt:ro
- ./traefik/mycert.key:/certs/privkey.key:ro
``` ```
should do the job so please place your certificate file as *./traefik/mycert.crt* and the key file as *./traefik/mycert.key*.
Thats it
#### Grafana Dashboard Examples
## Grafana Dashboard Examples
Within the local path *./examples/grafana/* you can find example *.json* files which can be imported to grafana as dashboards to give you a first point to start with. Within the local path *./examples/grafana/* you can find example *.json* files which can be imported to grafana as dashboards to give you a first point to start with.
@@ -174,42 +260,10 @@ Within the local path *./examples/grafana/* you can find example *.json* files
----- -----
### STANDALONE
1st thing to do is creating the *docker-compose.yml from [docker-compose-standalone.yml](./docker-compose-standalone.yml):
```
cp docker-compose-standalone.yml docker-compose.yml
```
#### Variables
Below paragraph:
```
####################################################
# LATENCY-MONITOR
####################################################
```
in the **.env** file *(env needs to be renamed to .env)* configure following variables:
- YOUR_ORGANIZATION
- YOUR_BUCKET_NAME
- YOUR_ADMIN_TOKEN
- YOUR_MONITORED_TARGET
- YOUR_MONITORED_TARGET_TIMER
- YOUR_MONITORED_TARGET_LOCATION
#### Lets go
```
docker-compose up -d latency-monitor
```
should do the job
## Authors ## Authors
@@ -220,7 +274,7 @@ Contributors names and contact info
## Version History ## Version History
* 0.1 * v0.1
* Initial Release * Initial Release
## License ## License

View File

@@ -124,6 +124,10 @@ services:
depends_on: depends_on:
- influxdb - influxdb
restart: always restart: always
volumes:
# - ./latency-monitor/config.ini:/app/config.ini:ro # UNCOMMENT IF NEEDED
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
environment: environment:
- INFLUX_URL - INFLUX_URL
- INFLUX_TOKEN - INFLUX_TOKEN

View File

@@ -8,6 +8,10 @@ services:
hostname: latency-monitor hostname: latency-monitor
build: ./Docker_Build build: ./Docker_Build
restart: always restart: always
volumes:
# - ./latency-monitor/config.ini:/app/config.ini:ro # UNCOMMENT IF NEEDED
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
environment: environment:
- INFLUX_URL - INFLUX_URL
- INFLUX_TOKEN - INFLUX_TOKEN

1
env
View File

@@ -8,6 +8,7 @@
MyPath=/YOUR_PATH_TO_CONTAINER_STATIC_DATA/ MyPath=/YOUR_PATH_TO_CONTAINER_STATIC_DATA/
MyFQDN=FQDN_OF_THIS_HOST
#################################################### ####################################################
# INFLUXDB # INFLUXDB

View File

@@ -0,0 +1,35 @@
# Config File Usage
#
# all MUST options are marked with #!!! and have to be configured
#
# Config file ist IGNORED if equivalent environment variables are passed
#
#
[influx] # SOME are MUST; influxdb2 connection relevant options
#!!! infx_url = http://YOUR_INFLUX_DB_V2:8086
#!!! infx_token = YOUR_INFLUX_DB_V2_API_TOKEN
#!!! infx_bucket = YOUR_INFLUX_DB_V2_BUCKET
#!!! infx_org = YOUR_INFLUX_DB_V2_ORGANIZATION
# infx_batch_size = 60 # OPTIONAL; default is '60'
# infx_flush_interval = 30_000 # OPTIONAL; default is '30_000'
# infx_jitter_interval = 5_000 # OPTIONAL; default is '5_000'
# infx_retry_interval = 5_000 # OPTIONAL; default is '5_000'
[hosts] # ONE HOST is MUST, rest ist optional; IP or FQDN
#!!! host1 = 8.8.8.8
# host2 = 8.8.4.4
# host3 = 1.1.1.1
[hosts_timer] # OPTIONAL; ping interval in seconds; default is '5'
# host1 = 1
# host2 = 3
# host3 = 5
[hosts_location] # OPTIONAL; location of host; default is 'unknown'
# host1 = Google-DNS1
# host2 = Google-DNS2
# host3 = Cloudflare-DNS

52
setup-full_stack.sh Executable file
View File

@@ -0,0 +1,52 @@
#!/bin/bash
# Check if .env allready exists
if ! test -e .env; then
echo "FAIL: You need to copy file env to .env and edit it!!!"
exit 1
fi
# copy compose template to final compose file (OVERWRITTEN!!!)
cp -f ./docker-compose-full_stack.yml ./docker-compose.yml
# locate my path
MyScriptPath=`dirname $0`
MyScriptPathContainer="$MyScriptPath/CONTAINER/"
# Replace .env MyPath Path with local path if NOT changed
echo "CHANGE: while not set, changing MyPath in .env to $MyScriptPathContainer"
sed -i -e "s#/YOUR_PATH_TO_CONTAINER_STATIC_DATA#$MyScriptPathContainer#g" .env
# Read variables from .env file
source .env
# Make relevant direcotries
echo "MKDIR: creating $MyPath"
mkdir -p $MyPath
echo "MKDIR: creating $MyPath/influxdb/"
mkdir -p $MyPath/influxdb/
echo "MKDIR: creating $MyPath/grafana/var_lib"
mkdir -p $MyPath/grafana/var_lib
# Changes in docker-compose.yml
echo "CHANGE: replace PLACE_YOUR_FQDN_HERE with $MyFQDN in $MyScriptPath/docker-compose.yml"
sed -i -e "s/PLACE_YOUR_FQDN_HERE/$MyFQDN/g" $MyScriptPath/docker-compose.yml
# Changes in grafana/provisioning/datasources/grafana-datasource.yml
echo "CHANGE: replace YOUR_ADMIN_TOKEN with $INFLUX_TOKEN in $MyScriptPath/grafana/provisioning/datasources/grafana-datasource.yml"
sed -i -e "s/YOUR_ADMIN_TOKEN/$INFLUX_TOKEN/g" $MyScriptPath/grafana/provisioning/datasources/grafana-datasource.yml
echo "CHANGE: replace YYOUR_ORGANIZATION with $INFLUX_ORG in $MyScriptPath/grafana/provisioning/datasources/grafana-datasource.yml"
sed -i -e "s/YOUR_ORGANIZATION/$INFLUX_ORG/g" $MyScriptPath/grafana/provisioning/datasources/grafana-datasource.yml
echo "CHANGE: replace YOUR_BUCKET_NAME with $INFLUX_BUCKET in $MyScriptPath/grafana/provisioning/datasources/grafana-datasource.yml"
sed -i -e "s/YOUR_BUCKET_NAME/$INFLUX_BUCKET/g" $MyScriptPath/grafana/provisioning/datasources/grafana-datasource.yml
# Correct owner and permissions to satisfy the containers
echo "CHMOD: chmod -R 755 $MyPath"
chmod -R 755 $MyPath
echo "CHMOD: chmod 644 $MyScriptPath/grafana/datasources/grafana-datasource.yml"
chmod 644 $MyScriptPath/grafana/datasources/grafana-datasource.yml
echo "CHOWN: chown -R 472.472 $MyPath/grafana/var_lib"
chown -R 472.472 $MyPath/grafana/var_lib
echo "OK: All done"