-
Notifications
You must be signed in to change notification settings - Fork 10
/
insert.py
52 lines (44 loc) · 1.39 KB
/
insert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
''' Insert data in KairosDB using REST API through requests module.
Please, check out the documentation on the KairosDB website:
http://kairosdb.github.io/docs/build/html/restapi/AddDataPoints.html
@author Fernando Paladini <[email protected]>
'''
import requests
import json
import gzip
kairosdb_server = "http://localhost:8080"
# Simple test [without compression]
data = [
{
"name": "test",
"datapoints": [
[1359788400000, 123],
[1359788300000, 13.2],
[1359788410000, 23.1]
],
"tags": {
"project": "rola"
}
}
]
response = requests.post(kairosdb_server + "/api/v1/datapoints", json.dumps(data))
print("Simple test [without compression]: \t%d (status code)" % response.status_code )
# Complex test [gzipping before send to KairosDB]
data = [
{
"name": "test_gzip",
"datapoints": [
[1359788400000, 10],
[1359788300000, 11.223],
[1359788410000, 24.09]
],
"tags": {
"project": "test_gzip",
}
}
]
gzipped = gzip.compress(bytes(json.dumps(data), 'UTF-8'))
headers = {'content-type': 'application/gzip'}
response = requests.post(kairosdb_server + "/api/v1/datapoints", gzipped, headers=headers)
print("Complex test [with compression]: \t%d (status code)" % response.status_code)