from influxdb import InfluxDBClient
from multiprocessing import Pool

import sys

DATABASE_NAME = 'monasca'
client = InfluxDBClient('localhost', 8086, 'root', 'root', DATABASE_NAME)

print "Creating database: {}...".format(DATABASE_NAME)
client.create_database(DATABASE_NAME)

DB_USER = 'admin'
DB_USER_PASSWORD = 'my_secret_password'

print "Switch user: {}".format(DB_USER)
client.switch_user(DB_USER, DB_USER_PASSWORD)

TOTAL_MEASUREMENT_PROCESSES = 5
MEASUREMENTS_FILENAME = '/tmp/measurements.txt'


def add_measurement_batch(meas_list, filename):
    client1 = InfluxDBClient('localhost', 8086, 'root', 'root', DATABASE_NAME)
    if DATABASE_NAME not in client.get_list_database():
        client1.create_database(DATABASE_NAME)
    client1.switch_user(DB_USER, DB_USER_PASSWORD)

    client1.write_points(meas_list, batch_size=len(meas_list),
                         time_precision='ms', protocol='line')


def main():
    measurement_process_pool = Pool(TOTAL_MEASUREMENT_PROCESSES)
    measurement_process_id = 0
    for i in xrange(5):
        meas_list = ['cpu.perc,cloud_name=test_cloud value=1,id={}'.format(measurement_process_id),
                     'cpu.avg,cloud_name=test_cloud value=2,id={}'.format(measurement_process_id)]
        measurement_process_pool.apply_async(add_measurement_batch,
                                             args=(meas_list,
                                                   MEASUREMENTS_FILENAME +
                                                   str(measurement_process_id,)))
        print "measurement_process_id = {}".format(measurement_process_id)
        measurement_process_id += 1
    print("Waiting for measurement process pool to close")
    measurement_process_pool.close()
    measurement_process_pool.join()

if __name__ == "__main__":
    sys.exit(main())
@@ -73,16 +73,28 @@
 port sys
+%0Aimport time
 %0A%0ADATABA
@@ -641,111 +641,8 @@
 ME)%0A
-    if DATABASE_NAME not in client.get_list_database():%0A        client1.create_database(DATABASE_NAME)%0A
     
@@ -688,17 +688,16 @@
 SSWORD)%0A
-%0A
     clie
@@ -751,17 +751,16 @@
 _list),%0A
- 
         
@@ -813,16 +813,16 @@
 'line')%0A
+
 %0A%0Adef ma
@@ -995,24 +995,25 @@
 e=test_cloud
+1
  value=1,id=
@@ -1099,16 +1099,17 @@
 st_cloud
+2
  value=2
@@ -1146,16 +1146,297 @@
 cess_id)
+,%0A                     'vswitch.out_errors_sec,tenant_id=%22f99DbEd937bABDaD46a8%22,region=%22Region_1%22,cloud_name=cloud,cluster=cluster,service=compute,resource_id=4f905288-215c-4d18-9449-3c154b978c2c,zone=nova,component=vm,hostname=test_1,lifespan=10,device=vs3 value=160550 140000000'
 %5D%0A      
@@ -1791,16 +1791,38 @@
 ess_id)%0A
+        time.sleep(1)%0A
         
@@ -2009,16 +2009,16 @@
 ain__%22:%0A
-
     sys.
@@ -2029,8 +2029,9 @@
 (main())
+%0A

Fix add measurement batch function