Skip to content

Instantly share code, notes, and snippets.

@fdcore
Created October 21, 2016 01:41
Show Gist options
  • Save fdcore/5fec95c6acb2d27bedc33150f11f7a9f to your computer and use it in GitHub Desktop.
Save fdcore/5fec95c6acb2d27bedc33150f11f7a9f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# influxdata metric function
import requests, time
METRIC_URL = "http://0.0.0.0:8086/"
def metric(database, collection='metrics', tags={}, values={}):
url = ''
tags2 = []
values2 = []
for key, value in tags.items():
tags2.append(key+"="+str(value))
for key, value in values.items():
values2.append(key+"="+str(value))
url = ','.join(tags2) + ' ' +','.join(values2)
full_url = METRIC_URL+'write?db='+database
data = collection+"," + url + " " + str(int(round(time.time() * 1000000000)))
result = requests.post(full_url, data=data)
return result.status_code
# metric('server', 'metrics', {'server': '01', 'by': 'nya'}, {'cpu': 123, 'mem': 234})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment