Created
February 19, 2014 13:47
-
-
Save Lispython/9092313 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from datetime import datetime | |
from time import mktime | |
import json | |
from human_curl.async import AsyncClient | |
success_count = 0 | |
fail_count = 0 | |
bad_response_count = 0 | |
host = "127.0.0.1" | |
port = 8086 | |
username = "lispython" | |
db = "test_db1" | |
password = "none" | |
def success_callback(response, **kwargs): | |
"""This function call when response successed | |
""" | |
global bad_response_count, success_count | |
if response.status_code != 200: | |
bad_response_count += 1 | |
return | |
success_count += 1 | |
def fail_callback(request, opener, **kwargs): | |
"""Collect errors | |
""" | |
global fail_count | |
fail_count += 1 | |
with AsyncClient(success_callback=success_callback, | |
fail_callback=fail_callback, | |
size=1000) as async_client: | |
for x in xrange(1000000): | |
data = [{ | |
"points": [ | |
[int(mktime(datetime.utcnow().timetuple())), 1, "Completed"]], | |
"name": "test", | |
"columns": ["timestamp", "value", "status"] | |
}] | |
async_client.post("http://{host}:{port}/db/{db}/series?u={username}&p={password}".format( | |
host=host, port=port, db=db, username=username, password=password), | |
data=json.dumps(data), headers=(("Content-Type", "application/json"), | |
("Accept", "text/plain"))) | |
print("Success: {0}".format(success_count)) | |
print("Fail: {0}".format(fail_count)) | |
print("Bad response: {0}".format(bad_response_count)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment