test_ipv4_variable_time can push data to influx v2

Signed-off-by: Matthew Stidham <stidmatt@protonmail.com>
This commit is contained in:
Matthew Stidham
2021-04-15 10:19:48 -07:00
parent 6a0dd64c33
commit 0008f856e0
2 changed files with 22 additions and 16 deletions

View File

@@ -38,8 +38,8 @@ class RecordInflux(LFCliBase):
self.influx_org = _influx_org
self.influx_token = _influx_token
self.influx_bucket = _influx_bucket
url = "http://%s:%s"%(self.influx_host, self.influx_port)
self.client = influxdb_client.InfluxDBClient(url=url, token=self.influx_token, org=self.influx_org)
self.url = "http://%s:%s"%(self.influx_host, self.influx_port)
self.client = influxdb_client.InfluxDBClient(url=self.url, token=self.influx_token, org=self.influx_org, debug=_debug_on)
self.write_api = self.client.write_api(write_options=SYNCHRONOUS)
#print("org: ", self.influx_org)
#print("token: ", self.influx_token)
@@ -50,8 +50,10 @@ class RecordInflux(LFCliBase):
p = influxdb_client.Point(key)
for tag_key, tag_value in tags.items():
p.tag(tag_key, tag_value)
print(tag_key, tag_value)
p.time(time)
p.field("value", value)
print(self.influx_bucket, self.influx_org, self.url, self.influx_port)
self.write_api.write(bucket=self.influx_bucket, org=self.influx_org, record=p)
def set_bucket(self, b):
@@ -77,10 +79,10 @@ class RecordInflux(LFCliBase):
url1 = url + station
response = json.loads(requests.get(url1).text)
time = str(datetime.datetime.utcnow().isoformat())
current_time = str(datetime.datetime.utcnow().isoformat())
# Poke everything into influx db
for key in response['interface'].keys():
self.posttoinflux(bucket, "%s-%s" % (station, key), response['interface'][key], tags, time)
self.post_to_influx("%s-%s" % (station, key), response['interface'][key], tags, current_time)
time.sleep(monitor_interval)

View File

@@ -265,9 +265,10 @@ python3 ./test_ipv4_variable_time.py
parser.add_argument('--monitor_interval',
help='how frequently do you want your monitor function to take measurements; 250ms, 35s, 2h',
default='10s')
parser.add_argument('--influx_user', help='Username for your Influx database')
parser.add_argument('--influx_passwd', help='Password for your Influx database')
parser.add_argument('--influx_db', help='Name of your Influx database')
parser.add_argument('--influx_token', help='Username for your Influx database')
parser.add_argument('--influx_bucket', help='Password for your Influx database')
parser.add_argument('--influx_org', help='Name of your Influx database')
parser.add_argument('--influx_port', help='Port where your influx database is located', default=8086)
args = parser.parse_args()
@@ -403,19 +404,22 @@ python3 ./test_ipv4_variable_time.py
if not ip_var_test.passes():
print(ip_var_test.get_fail_message())
ip_var_test.exit_fail()
time.sleep(30)
if args.influx_db is not None:
from influx import RecordInflux
LFUtils.wait_until_ports_admin_up(port_list=station_list)
if args.influx_org is not None:
from influx2 import RecordInflux
grapher = RecordInflux(_influx_host=args.mgr,
_port=args.mgr_port,
_influx_db=args.influx_db,
_influx_user=args.influx_user,
_influx_passwd=args.influx_passwd)
_influx_port=args.influx_port,
_influx_org=args.influx_org,
_influx_token=args.influx_token,
_influx_bucket=args.influx_bucket)
devices=[station.split('.')[-1] for station in station_list]
grapher.getdata(longevity=5,
tags=dict()
tags['script']='test_ipv4_variable_time'
grapher.monitor_port_data(longevity=5,
devices=devices,
monitor_interval=2,
target_kpi=['bps rx'])
tags=tags)
ip_var_test.cleanup()
if ip_var_test.passes():
ip_var_test.success()