7 Commits
v0.1 ... v0.2a

Author SHA1 Message Date
Sven Holz
bb9263781e v0.2 2022-06-15 00:40:19 +02:00
Sven Holz
abd98c49b8 v0.2 2022-06-15 00:11:27 +02:00
Sven Holz
5e6bd76557 v0.2 2022-06-15 00:08:53 +02:00
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 234 additions and 81 deletions

View File

@@ -67,7 +67,8 @@ class MyInfluxDB():
# create influxdb client
self.client = InfluxDBClient(url=INFX_URL,
token=INFX_TOKEN,
org=INFX_ORG)
org=INFX_ORG,
verify_ssl=False)
# create influxdb write api
self.write_api = self.client.write_api(write_options=WriteOptions(batch_size=INFX_BATCH,
@@ -81,7 +82,7 @@ class MyInfluxDB():
def write(self, host, host_location, ping_response):
self.host = host
self.host_location = host_location
self.ping_response = ping_response
self.ping_response = int(ping_response)
self.influx_timestamp = int(time_ns())
self.data_point = Point("latency_monitor").tag("location", self.host_location).tag("host", self.host).field("latency", self.ping_response).time(self.influx_timestamp)
self.write_api.write(bucket=self.INFX_BUCKET,

186
README.md
View File

@@ -17,17 +17,17 @@ It´s based on python3 an makes usage of following python libraries:
- configparser
- 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
@@ -36,7 +36,26 @@ You can find everything under *./Docker_Build/* and in the python program itself
- InfluxDB Version >= 2
- 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
:------: | :-----: | :-----: | :-----:
@@ -48,60 +67,107 @@ TARGET_HOST | 8.8.8.8 | Monitored Host (IP/FQDN) | must
TARGET_TIMER | 3 | ping frequency in sec. | option
TARGET_LOCATION | Google | decript. location | option
## Config File
-----
### 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**
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:
- /YOUR_PATH/config.ini:/app/config.ini
# - ./latency-monitor/config.ini:/app/config.ini:ro # UNCOMMENT IF NEEDED
```
### 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.
within the *docker-compose.yml* you will find:
After everyting within *.env* is in order just do:
```
- ./traefik/mycert.crt:/certs/cert.crt:ro
- ./traefik/mycert.key:/certs/privkey.key:ro
./setup-full_stack.sh
```
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
You need to configure Variables in following files to make the compose work:
- **file**
@@ -134,8 +200,10 @@ You need to configure Variables in following files to make the compose work:
- YOUR_ORGANIZATION
- YOUR_BUCKET_NAME
-----
#### 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.
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
```
#### 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.
@@ -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
@@ -220,7 +274,7 @@ Contributors names and contact info
## Version History
* 0.1
* v0.1
* Initial Release
## License

View File

@@ -124,6 +124,10 @@ services:
depends_on:
- influxdb
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:
- INFLUX_URL
- INFLUX_TOKEN

View File

@@ -8,6 +8,10 @@ services:
hostname: latency-monitor
build: ./Docker_Build
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:
- INFLUX_URL
- INFLUX_TOKEN

1
env
View File

@@ -8,6 +8,7 @@
MyPath=/YOUR_PATH_TO_CONTAINER_STATIC_DATA/
MyFQDN=FQDN_OF_THIS_HOST
####################################################
# 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

54
setup-full_stack.sh Executable file
View File

@@ -0,0 +1,54 @@
#!/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
sed -i -e "s#/YOUR_PATH_TO_CONTAINER_STATIC_DATA#$MyScriptPathContainer#g" .env
# Read variables from .env file
source .env
echo "INFO: MyPath is $MyPath"
# 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 YOUR_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/provisioning/datasources/grafana-datasource.yml"
chmod 644 $MyScriptPath/grafana/provisioning/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"