Final Push?!
This commit is contained in:
parent
4505222fae
commit
44f0e29929
10
dockerfile
Normal file
10
dockerfile
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# set base image (host OS)
|
||||||
|
FROM python:3.8
|
||||||
|
# copy the dependencies file to the working directory
|
||||||
|
COPY requirements.txt .
|
||||||
|
# install dependencies
|
||||||
|
RUN pip install -r requirements.txt
|
||||||
|
# copy the content of the local src directory to the working directory
|
||||||
|
COPY main.py .
|
||||||
|
# command to run on container start
|
||||||
|
CMD [ "python", "./main.py" ]
|
||||||
43
main.py
Normal file
43
main.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
from os import environ
|
||||||
|
import pythonping
|
||||||
|
from influxdb import InfluxDBClient
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
IPs = import os.environ['hosts']
|
||||||
|
IPs = IPs.replace(' ', '').split(",")
|
||||||
|
|
||||||
|
|
||||||
|
def senddataInflux(data, host='192.168.0.13', port=8086):
|
||||||
|
for ip in data:
|
||||||
|
json_body = [
|
||||||
|
{
|
||||||
|
"measurement": "data",
|
||||||
|
"tags": {
|
||||||
|
'pingresult': ip,
|
||||||
|
},
|
||||||
|
|
||||||
|
"fields": {
|
||||||
|
"average_rtt": data[ip],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
client = InfluxDBClient(host, port, database = "telegraf") # Init connection to Influx Server
|
||||||
|
client.write_points(json_body) # Write Speedtest results
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def ping(IPs):
|
||||||
|
results = {}
|
||||||
|
for IP in IPs:
|
||||||
|
pingRES = pythonping.ping(IP, count=5)
|
||||||
|
results[IP] = pingRES.rtt_avg_ms
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
## Pull a list from the env variable - Max ~ 2000 IP addresses
|
||||||
|
senddataInflux(ping(IPs))
|
||||||
|
|
||||||
|
main()
|
||||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
pythonping
|
||||||
|
influxdb
|
||||||
Loading…
Reference in New Issue
Block a user