mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-01 19:28:00 +00:00
Create influx.py in py-json and import it into recordinflux.py
Signed-off-by: lanforge <stidmatt@gmail.com>
This commit is contained in:
@@ -20,68 +20,9 @@ if sys.version_info[0] != 3:
|
||||
if 'py-json' not in sys.path:
|
||||
sys.path.append(os.path.join(os.path.abspath('..'), 'py-json'))
|
||||
|
||||
import requests
|
||||
import json
|
||||
from influxdb import InfluxDBClient
|
||||
import datetime
|
||||
from LANforge.lfcli_base import LFCliBase
|
||||
from influx import Influx
|
||||
import argparse
|
||||
import time
|
||||
|
||||
class graphdata(LFCliBase):
|
||||
def __init__(self,
|
||||
_host="localhost",
|
||||
_port=8080,
|
||||
_influx_user=None,
|
||||
_influx_passwd=None,
|
||||
_influx_db=None,
|
||||
_longevity=None,
|
||||
_monitor_interval=None,
|
||||
_devices=None,
|
||||
_debug_on=False,
|
||||
_exit_on_fail=False
|
||||
):
|
||||
super().__init__(_host,
|
||||
_port,
|
||||
_debug=_debug_on,
|
||||
_exit_on_fail=_exit_on_fail)
|
||||
self.host=_host
|
||||
self.port=_port
|
||||
self.influx_user=_influx_user
|
||||
self.influx_passwd=_influx_passwd
|
||||
self.influx_db=_influx_db
|
||||
self.longevity=_longevity
|
||||
self.stations=_devices
|
||||
self.monitor_interval=_monitor_interval
|
||||
def getdata(self):
|
||||
url='http://192.168.1.32:8080/port/1/1/'
|
||||
client = InfluxDBClient(self.host,
|
||||
8086,
|
||||
self.influx_user,
|
||||
self.influx_passwd,
|
||||
self.influx_db)
|
||||
end=datetime.datetime.now()+datetime.timedelta(0, self.longevity)
|
||||
while datetime.datetime.now() < end:
|
||||
stations=self.stations
|
||||
for station in stations:
|
||||
url1=url+station
|
||||
response = json.loads(requests.get(url1).text)
|
||||
for key in response['interface'].keys():
|
||||
json_body = [
|
||||
{
|
||||
"measurement": station+' '+key,
|
||||
"tags": {
|
||||
"host": self.host,
|
||||
"region": "us-west"
|
||||
},
|
||||
"time":str(datetime.datetime.utcnow().isoformat()),
|
||||
"fields": {
|
||||
"value":response['interface'][key]
|
||||
}
|
||||
}
|
||||
]
|
||||
client.write_points(json_body)
|
||||
time.sleep(self.monitor_interval)
|
||||
|
||||
def main():
|
||||
parser = LFCliBase.create_bare_argparse(
|
||||
@@ -108,7 +49,7 @@ def main():
|
||||
args = parser.parse_args()
|
||||
monitor_interval=LFCliBase.parse_time(args.monitor_interval).total_seconds()
|
||||
longevity=LFCliBase.parse_time(args.longevity).total_seconds()
|
||||
grapher=graphdata(_host=args.mgr,
|
||||
grapher=Influx(_host=args.mgr,
|
||||
_port=args.mgr_port,
|
||||
_influx_db=args.influx_db,
|
||||
_influx_user=args.influx_user,
|
||||
|
||||
Reference in New Issue
Block a user