Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21e5627d58 | ||
|
|
7ed91947ab | ||
|
|
5c07ade336 | ||
|
|
6980539a02 | ||
|
|
99d934d041 | ||
|
|
4c5e9ceb90 | ||
|
|
5f5aea0332 | ||
|
|
b400e34c9a |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,4 +4,4 @@
|
|||||||
*.backup
|
*.backup
|
||||||
grafana-datasource.yml
|
grafana-datasource.yml
|
||||||
docker-compose.yml
|
docker-compose.yml
|
||||||
config-template.ini
|
config.ini
|
||||||
@@ -23,6 +23,11 @@
|
|||||||
# host2 = 8.8.4.4
|
# host2 = 8.8.4.4
|
||||||
# host3 = 1.1.1.1
|
# host3 = 1.1.1.1
|
||||||
|
|
||||||
|
[hosts_timeout] # OPTIONAL; ping timeout in seconds (float); default is '1'
|
||||||
|
# host1 = 1
|
||||||
|
# host2 = 0.5
|
||||||
|
# host3 = 0.2
|
||||||
|
|
||||||
[hosts_timer] # OPTIONAL; ping interval in seconds; default is '5'
|
[hosts_timer] # OPTIONAL; ping interval in seconds; default is '5'
|
||||||
# host1 = 1
|
# host1 = 1
|
||||||
# host2 = 3
|
# host2 = 3
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class MyInfluxDB():
|
|||||||
writes received data to Influxdb:
|
writes received data to Influxdb:
|
||||||
host: string which includes IP or FQDN
|
host: string which includes IP or FQDN
|
||||||
host_location: string which includes location of the host
|
host_location: string which includes location of the host
|
||||||
ping_response: string which includes the ping reply in ms
|
ping_response: float which includes the ping reply in ms
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -100,20 +100,23 @@ class ThreadPing(Thread):
|
|||||||
----------
|
----------
|
||||||
db: InfluxDB Object
|
db: InfluxDB Object
|
||||||
host: string which includes IP or FQDN
|
host: string which includes IP or FQDN
|
||||||
|
host_timeout: float which defines how long we wait for a reply
|
||||||
host_timer: integer which defines how often pings are send in seconds (min. 1)
|
host_timer: integer which defines how often pings are send in seconds (min. 1)
|
||||||
host_location: string which includes location of the host
|
host_location: string which includes location of the host
|
||||||
"""
|
"""
|
||||||
def __init__(self, db, host, host_timer, host_location):
|
|
||||||
|
def __init__(self, db, host, host_timeout, host_timer, host_location):
|
||||||
Thread.__init__(self)
|
Thread.__init__(self)
|
||||||
self.MyDB = db
|
self.MyDB = db
|
||||||
self.host = host
|
self.host = host
|
||||||
|
self.host_timeout = host_timeout
|
||||||
self.host_timer = host_timer
|
self.host_timer = host_timer
|
||||||
self.host_location = host_location
|
self.host_location = host_location
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.starttime = time()
|
self.starttime = time()
|
||||||
while True:
|
while True:
|
||||||
self.ping_response_list = ping(self.host, count=1)
|
self.ping_response_list = ping(self.host, timeout=self.host_timeout, count=1)
|
||||||
self.ping_response = "{:.2f}".format(self.ping_response_list.rtt_avg_ms)
|
self.ping_response = "{:.2f}".format(self.ping_response_list.rtt_avg_ms)
|
||||||
self.MyDB.write(self.host, self.host_location, self.ping_response)
|
self.MyDB.write(self.host, self.host_location, self.ping_response)
|
||||||
sleep(self.host_timer - ((time() - self.starttime) % 1))
|
sleep(self.host_timer - ((time() - self.starttime) % 1))
|
||||||
@@ -129,12 +132,14 @@ def main():
|
|||||||
## IF ENVIRONMENT VARIABLES ARE PASSED IGNORE CONFIG FILE
|
## IF ENVIRONMENT VARIABLES ARE PASSED IGNORE CONFIG FILE
|
||||||
if 'TARGET_HOST' in os.environ:
|
if 'TARGET_HOST' in os.environ:
|
||||||
host = os.environ['TARGET_HOST']
|
host = os.environ['TARGET_HOST']
|
||||||
|
host_timeout = float(os.getenv('TARGET_TIMEOUT', 1))
|
||||||
host_timer = int(os.getenv('TARGET_TIMER', 5))
|
host_timer = int(os.getenv('TARGET_TIMER', 5))
|
||||||
host_location = os.getenv('TARGET_LOCATION', 'unknown')
|
host_location = os.getenv('TARGET_LOCATION', 'unknown')
|
||||||
|
|
||||||
# Create Thread
|
# Create Thread
|
||||||
print("Creating thread for: %s, with interval: %s and location: %s" %(host, host_timer, host_location))
|
print("Creating thread for: %s, with timeout: %s, with interval: %s and location: %s" % (
|
||||||
thread = ThreadPing(MyDB, host, host_timer, host_location)
|
host, host_timeout, host_timer, host_location))
|
||||||
|
thread = ThreadPing(MyDB, host, host_timeout, host_timer, host_location)
|
||||||
my_threads.append(thread)
|
my_threads.append(thread)
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
@@ -149,6 +154,9 @@ def main():
|
|||||||
# Create thread for each configured host
|
# Create thread for each configured host
|
||||||
for key, host in host_items:
|
for key, host in host_items:
|
||||||
|
|
||||||
|
# Check if hosts timeout is set otherwise use "1" (means 1 seconds)
|
||||||
|
host_timeout = float(config.get('hosts_timeout', key, fallback=1))
|
||||||
|
|
||||||
# Check if hosts timer is set otherwise use "5" (means 5 seconds)
|
# Check if hosts timer is set otherwise use "5" (means 5 seconds)
|
||||||
host_timer = int(config.get('hosts_timer', key, fallback=5))
|
host_timer = int(config.get('hosts_timer', key, fallback=5))
|
||||||
|
|
||||||
@@ -156,8 +164,8 @@ def main():
|
|||||||
host_location = config.get('hosts_location', key, fallback="unknown")
|
host_location = config.get('hosts_location', key, fallback="unknown")
|
||||||
|
|
||||||
# Create Thread
|
# Create Thread
|
||||||
print("Creating thread for: %s, with interval: %s and location: %s" %(host, host_timer, host_location))
|
print("Creating thread for: %s, with timeout: %s, with interval: %s and location: %s" % (host, host_timeout, host_timer, host_location))
|
||||||
thread = ThreadPing(MyDB, host, host_timer, host_location)
|
thread = ThreadPing(MyDB, host, host_timeout, host_timer, host_location)
|
||||||
my_threads.append(thread)
|
my_threads.append(thread)
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
|
|||||||
26
README.md
26
README.md
@@ -64,6 +64,7 @@ INFLUX_TOKEN | eWOcp-MCv2Y3IJPlER7wc...ICKirhw0lwEczRNnrIoTqZAg== | InfluxDB API
|
|||||||
INFLUX_BUCKET | latency | InfluxDB Bucket | must
|
INFLUX_BUCKET | latency | InfluxDB Bucket | must
|
||||||
INFLUX_ORG | MyOrg | InfluxDB Organization | must
|
INFLUX_ORG | MyOrg | InfluxDB Organization | must
|
||||||
TARGET_HOST | 8.8.8.8 | Monitored Host (IP/FQDN) | must
|
TARGET_HOST | 8.8.8.8 | Monitored Host (IP/FQDN) | must
|
||||||
|
TARGET_TIMEOUT | 0.5 | ping timeout in sec. | option
|
||||||
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
|
||||||
|
|
||||||
@@ -77,6 +78,8 @@ TARGET_LOCATION | Google | decript. location | option
|
|||||||
|
|
||||||
See [./latency-monitor/config.ini](./latency-monitor/config.ini)
|
See [./latency-monitor/config.ini](./latency-monitor/config.ini)
|
||||||
|
|
||||||
|
**ENV wins over file**
|
||||||
|
|
||||||
|
|
||||||
#### Docker-Compose Style
|
#### Docker-Compose Style
|
||||||
|
|
||||||
@@ -119,6 +122,7 @@ in the **.env** file *(env needs to be renamed to .env)* configure following var
|
|||||||
- YOUR_BUCKET_NAME
|
- YOUR_BUCKET_NAME
|
||||||
- YOUR_ADMIN_TOKEN
|
- YOUR_ADMIN_TOKEN
|
||||||
- YOUR_MONITORED_TARGET
|
- YOUR_MONITORED_TARGET
|
||||||
|
- YOUR_MONITORED_TARGET_TIMEOUT
|
||||||
- YOUR_MONITORED_TARGET_TIMER
|
- YOUR_MONITORED_TARGET_TIMER
|
||||||
- YOUR_MONITORED_TARGET_LOCATION
|
- YOUR_MONITORED_TARGET_LOCATION
|
||||||
|
|
||||||
@@ -161,6 +165,14 @@ Just the certificates are missing look [here](#certificate)
|
|||||||
|
|
||||||
Now run it and mybe pick a example dashboard for grafana from [here](#grafana-dashboard-examples)
|
Now run it and mybe pick a example dashboard for grafana from [here](#grafana-dashboard-examples)
|
||||||
|
|
||||||
|
#### BACKUPS FILES ???
|
||||||
|
|
||||||
|
The script will backup following files if found:
|
||||||
|
|
||||||
|
- *./docker-compose.yml*
|
||||||
|
- *./grafana/provisioning/datasources/grafana-datasource.yml*
|
||||||
|
|
||||||
|
|
||||||
-----
|
-----
|
||||||
-----
|
-----
|
||||||
|
|
||||||
@@ -181,7 +193,7 @@ 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** *(generated from docker-compose-full_stack.yml)*
|
||||||
- PLACE_YOUR_FQDN_HERE (3 times)
|
- PLACE_YOUR_FQDN_HERE (3 times)
|
||||||
|
|
||||||
-----
|
-----
|
||||||
@@ -194,12 +206,13 @@ You need to configure Variables in following files to make the compose work:
|
|||||||
- YOUR_BUCKET_NAME
|
- YOUR_BUCKET_NAME
|
||||||
- YOUR_ADMIN_TOKEN
|
- YOUR_ADMIN_TOKEN
|
||||||
- YOUR_MONITORED_TARGET
|
- YOUR_MONITORED_TARGET
|
||||||
|
- YOUR_MONITORED_TARGET_TIMEOUT
|
||||||
- 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** *(generated from grafana/grafana-datasource-template.yml)*
|
||||||
- YOUR_ADMIN_TOKEN
|
- YOUR_ADMIN_TOKEN
|
||||||
- YOUR_ORGANIZATION
|
- YOUR_ORGANIZATION
|
||||||
- YOUR_BUCKET_NAME
|
- YOUR_BUCKET_NAME
|
||||||
@@ -280,6 +293,15 @@ Contributors names and contact info
|
|||||||
|
|
||||||
## Version History
|
## Version History
|
||||||
|
|
||||||
|
- v0.3a
|
||||||
|
- ping timeout added
|
||||||
|
- cleanup
|
||||||
|
|
||||||
|
* v0.3
|
||||||
|
* setup-script fixed and backup added
|
||||||
|
* fixed latency value problem (was sometimes string instead of float)
|
||||||
|
* cleanup
|
||||||
|
|
||||||
* v0.2b
|
* v0.2b
|
||||||
* cleanup
|
* cleanup
|
||||||
|
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ services:
|
|||||||
- INFLUX_BUCKET
|
- INFLUX_BUCKET
|
||||||
- INFLUX_ORG
|
- INFLUX_ORG
|
||||||
- TARGET_HOST
|
- TARGET_HOST
|
||||||
|
- TARGET_TIMEOUT
|
||||||
- TARGET_TIMER
|
- TARGET_TIMER
|
||||||
- TARGET_LOCATION
|
- TARGET_LOCATION
|
||||||
networks:
|
networks:
|
||||||
|
|||||||
1
env
1
env
@@ -36,5 +36,6 @@ INFLUX_TOKEN=YOUR_ADMIN_TOKEN
|
|||||||
INFLUX_BUCKET=YOUR_BUCKET_NAME
|
INFLUX_BUCKET=YOUR_BUCKET_NAME
|
||||||
INFLUX_ORG=YOUR_ORGANIZATION
|
INFLUX_ORG=YOUR_ORGANIZATION
|
||||||
TARGET_HOST=YOUR_MONITORED_TARGET
|
TARGET_HOST=YOUR_MONITORED_TARGET
|
||||||
|
TARGET_TIMEOUT=YOUR_MONITORED_TARGET_TIMEOUT
|
||||||
TARGET_TIMER=YOUR_MONITORED_TARGET_TIMER
|
TARGET_TIMER=YOUR_MONITORED_TARGET_TIMER
|
||||||
TARGET_LOCATION=YOUR_MONITORED_TARGET_LOCATION
|
TARGET_LOCATION=YOUR_MONITORED_TARGET_LOCATION
|
||||||
@@ -23,6 +23,11 @@
|
|||||||
# host2 = 8.8.4.4
|
# host2 = 8.8.4.4
|
||||||
# host3 = 1.1.1.1
|
# host3 = 1.1.1.1
|
||||||
|
|
||||||
|
[hosts_timeout] # OPTIONAL; ping timeout in seconds (float); default is '1'
|
||||||
|
# host1 = 1
|
||||||
|
# host2 = 0.5
|
||||||
|
# host3 = 0.2
|
||||||
|
|
||||||
[hosts_timer] # OPTIONAL; ping interval in seconds; default is '5'
|
[hosts_timer] # OPTIONAL; ping interval in seconds; default is '5'
|
||||||
# host1 = 1
|
# host1 = 1
|
||||||
# host2 = 3
|
# host2 = 3
|
||||||
Reference in New Issue
Block a user