From bb65157ca466f85886fb3c3bb53711c1f29cc3ec Mon Sep 17 00:00:00 2001 From: Matthew Stidham Date: Thu, 8 Apr 2021 13:54:58 -0700 Subject: [PATCH] Add tags variable back to posttoinflux Signed-off-by: Matthew Stidham --- py-json/influx.py | 39 +++++++++++++++++---------------- py-scripts/test_l3_longevity.py | 23 +++++-------------- 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/py-json/influx.py b/py-json/influx.py index c4a44447..6aa9bb75 100644 --- a/py-json/influx.py +++ b/py-json/influx.py @@ -41,32 +41,31 @@ class RecordInflux(LFCliBase): self.influx_passwd, self.influx_db) - def post_to_influx(self, key, value): + def post_to_influx(self, key, value, tags): data = dict() data["measurement"] = key - data["tags"] = dict() - data["tags"]["host"] = self.influx_host - data["tags"]["region"] = 'us-west' + tags["host"] = self.influx_host + data["tags"] = tags data["time"] = str(datetime.datetime.utcnow().isoformat()) data["fields"] = dict() data["fields"]["value"] = value data1 = [data] print(data1) - json_body = [ - { - "measurement": key, - "tags": { - "host": self.influx_host, - "region": "us-west" - }, - "time": str(datetime.datetime.utcnow().isoformat()), - "fields": { - "value": value - } - } - ] - print(json_body) + #json_body = [ + # { + # "measurement": key, + # "tags": { + # "host": self.influx_host, + # "region": "us-west" + # }, + # "time": str(datetime.datetime.utcnow().isoformat()), + # "fields": { + # "value": value + # } + # } + #] + #print(json_body) self.client.write_points(data1) # Don't use this unless you are sure you want to. @@ -88,6 +87,8 @@ class RecordInflux(LFCliBase): # Poke everything into influx db for key in response['interface'].keys(): - self.posttoinflux("%s-%s" % (station, key), response['interface'][key]) + tags = dict() + tags["region"] = 'us-west' + self.posttoinflux("%s-%s" % (station, key), response['interface'][key], tags) time.sleep(monitor_interval) diff --git a/py-scripts/test_l3_longevity.py b/py-scripts/test_l3_longevity.py index 2f943f59..e5c020c5 100755 --- a/py-scripts/test_l3_longevity.py +++ b/py-scripts/test_l3_longevity.py @@ -620,21 +620,6 @@ class L3VariableTime(Realm): if self.influxdb == None: return - class MyKvPair: - key = "" - val = "" - - #tags = [MyKvPair] * 5 - #tags[0].key = "requested-ul-bps" - #tags[0].val = ul - #tags[1].key = "requested-dl-bps" - #tags[1].val = dl - #tags[2].key = "ul-pdu-size" - #tags[2].val = ul_pdu - #tags[3].key = "dl-pdu-size" - #tags[3].val = dl_pdu - #tags[4].key = "station-count" - #tags[4].val = sta_count valuemap=dict() valuemap['requested-ul-bps'] = ul valuemap['requested-ul-bps'] = dl @@ -642,7 +627,9 @@ class L3VariableTime(Realm): valuemap['dl-pdu-size'] = dl_pdu valuemap['station-count'] = sta_count for key, value in valuemap.items(): - self.influxdb.post_to_influx(key, value) + tags = dict() + tags["region"] = 'us-west' + self.influxdb.post_to_influx(key, value, tags) #self.influxdb.post_to_influx("total-download-bps", total_dl_bps, tags) #self.influxdb.post_to_influx("total-upload-bps", total_ul_bps, tags) @@ -877,7 +864,7 @@ python3 test_l3_longevity.py --cisco_ctlr 192.168.100.112 --cisco_dfs True --mgr parser.add_argument('-bmp','--side_b_min_pdu', help='--side_b_min_pdu , upstream pdu size default 1518', default="MTU") parser.add_argument('--influx_host', help='Hostname for the Influx database') - parser.add_argument('--influx_port', help='IP Port for the Influx database') + parser.add_argument('--influx_port', help='IP Port for the Influx database', default=8086) parser.add_argument('--influx_user', help='Username for the Influx database') parser.add_argument('--influx_passwd', help='Password for the Influx database') parser.add_argument('--influx_db', help='Name of the Influx database') @@ -922,7 +909,7 @@ python3 test_l3_longevity.py --cisco_ctlr 192.168.100.112 --cisco_dfs True --mgr _influx_port=args.influx_port, _influx_db=args.influx_db, _influx_user=args.influx_user, - _influx_passwd=args.influx_passwd) + _influx_passwd=args.influx_passwd) MAX_NUMBER_OF_STATIONS = 1000