Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Mysql
- real: 6m 39sec
- user: 2.956sec
- sys: 0.504sec
- Influxdb
- real: 6m 17.193sec
- user: 11.860sec
- sys: 0.328sec
- #!/usr/bin/env python
- # coding: utf-8
- import time
- import csv
- import sys
- import datetime
- import calendar
- import pytz
- from influxdb import client as influxdb
- from datetime import datetime
- host = 'localhost'
- port = 8086
- user = "admin"
- password = "admin"
- db_name = "testdatabase"
- db = influxdb.InfluxDBClient(database=db_name)
- def read_data():
- with open(file) as f:
- reader = f.readlines()[4:]
- for line in reader:
- yield (line.strip().split(','))
- fmt = '%Y-%m-%d %H:%M:%S'
- file = '/home/rob/mycsvfile.csv'
- csvToInflux = read_data()
- for metric in csvToInflux:
- timestamp = datetime.strptime(metric[0][1: len(metric[0]) - 1], fmt)
- new_value = float(metric[1])
- influx_metric = [{
- 'measurement': 'mytable1',
- 'time': timestamp,
- 'fields': {
- 'col1': metric[1],
- 'col2': metric[2],
- 'col3': metric[3],
- 'col4': metric[4],
- 'col5': metric[5],
- 'col6': metric[6],
- 'col7': metric[7],
- 'col8': metric[8],
- 'col9': metric[9]
- }
- }]
- db.write_points(influx_metric)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement