67b3054e7163b178f64d214e2f7eb3b5411c9fac
[kvmfornfv.git] / ci / envs / data_publish.py
1 from __future__ import print_function
2 import glob, os
3 import csv
4 import json
5 import sys
6 import ast
7 import subprocess
8 from influxdb import InfluxDBClient
9
10 time_stamp=sys.argv[1]
11 test_type=sys.argv[2]
12 results_dir=sys.argv[3]
13
14 def publish_results(testtype):
15     for file in glob.glob("*.csv"):
16         print(file)
17         f = open( file, 'r' )
18         reader = csv.DictReader( f )
19         result = json.dumps( [ row for row in reader ] )
20         result = ast.literal_eval(result)
21         print(result)
22
23         for i in result:
24             test = i['id'] + '_' +testtype
25             json_body = [
26                  {
27                      "measurement": test,
28                      "tags": {
29                      "id": i['id'],
30                      "type": i['type'],
31                      "packet_size": i['packet_size']
32                      },
33                      "time": time_stamp,
34                      "fields": {
35                      "min_value": i['min_latency_ns'],
36                      "avg_value": i['avg_latency_ns'],
37                      "max_value": i['max_latency_ns']
38                      }
39                  }
40             ]
41             print(time_stamp)
42             client = InfluxDBClient('104.197.68.199', 8086, 'opnfv', '0pnfv2015', 'yardstick')
43             client.switch_database('yardstick')
44             client.write_points(json_body)
45
46 os.chdir(results_dir)
47 publish_results(test_type)