def rest_processors(host, headers, method, example, field): try: example = json.loads(example) example[field] = get_random_id() item = json.dumps(example, encoding='utf8') start_time = time.time() if method is 'PUT': r = requests.put(host, data=item, headers=headers, timeout=10) else: if method is 'POST': r = requests.post(host, data=item, headers=headers, timeout=10) else: if method is 'GET': r = requests.get(host, headers=headers, timeout=10) else: print "Method {0} unknow".format(method) if r.status_code not in (200, 201): print "Failed {0}".format(r.status_code) mzbench.notify(('failed_requests', 'counter'), 1) else: mzbench.notify(('success_requests', 'counter'), 1) mzbench.notify(('request_time', 'histogram'), (time.time() - start_time)) except Exception as error: mzbench.notify(('exception_requests', 'counter'), 1) print "Timeout: {0}".format(str(error))
def run_network(): network.send_guardian_status_report() mzbench.notify(('MQTT_Packets', 'counter'), 1) mzbench.notify(('MQTT_Status', 'counter'), 1) for i in range(1, 4): time.sleep(59) network.send_heartbeat() mzbench.notify(('MQTT_Packets', 'counter'), 1) mzbench.notify(('MQTT_Heartbeat', 'counter'), 1)
def my_print(msg): mzbench.notify(('print', 'counter'), 1) mzbench.notify(('print_2', 'counter'), 2) print "{0}".format(msg) mzbench.notify(('dummy', 'histogram'), random.uniform(0, 1000000000) / 7)
def my_print(msg): mzbench.notify(('print', 'counter'), 1) mzbench.notify(('print_2', 'counter'), 2) print msg mzbench.notify(('dummy', 'histogram'), random.uniform(0, 1000000000)/7)
def nap_processors(host, user, password, topic, writer, bytes_writer, example, field): try: example = json.loads(example) example[field] = get_random_id() encoder = avro.io.BinaryEncoder(bytes_writer) writer.write(example, encoder) start_time = time.time() publish.single(topic, bytes_writer.getvalue(), hostname=host, auth={ 'username': user, 'password': password }) mzbench.notify(('success_requests', 'counter'), 1) mzbench.notify(('request_time', 'histogram'), (time.time() - start_time)) except Exception as error: mzbench.notify(('exception_requests', 'counter'), 1) print "Timeout: {0}".format(str(error))
def processors(host): try: start_time = time.time() response = urllib2.urlopen(host) if 200 is int(response.code): mzbench.notify(('success_requests', 'counter'), 1) else: print "{0}".format(response.code) mzbench.notify(('failed_requests', 'counter'), 1) mzbench.notify(('request_time', 'histogram'), (time.time() - start_time)) response.close() except Exception as error: mzbench.notify(('failed_requests', 'counter'), 1) print "{0}".format(str(error))
def get_perf_metrics(host, port): url = 'http://' + host + ':' + str(port) + '/status' try: response = urllib2.urlopen(url) status = response.read() status = json.loads(status) mzbench.notify(('load.avg1', 'gauge'), status['load']['load1']) mzbench.notify(('load.avg5', 'gauge'), status['load']['load5']) mzbench.notify(('load.avg15', 'gauge'), status['load']['load15']) mzbench.notify(('cpu.usr', 'gauge'), status['cpu']['usr']) mzbench.notify(('cpu.nice', 'gauge'), status['cpu']['nice']) mzbench.notify(('cpu.sys', 'gauge'), status['cpu']['sys']) mzbench.notify(('cpu.iowait', 'gauge'), status['cpu']['iowait']) mzbench.notify(('cpu.irq', 'gauge'), status['cpu']['irq']) mzbench.notify(('cpu.soft', 'gauge'), status['cpu']['soft']) mzbench.notify(('cpu.steal', 'gauge'), status['cpu']['steal']) mzbench.notify(('cpu.guest', 'gauge'), status['cpu']['guest']) mzbench.notify(('cpu.gnice', 'gauge'), status['cpu']['gnice']) mzbench.notify(('cpu.all', 'gauge'), status['cpu']['all']) mzbench.notify(('mem.used', 'gauge'), status['mem']['used']) mzbench.notify(('mem.free', 'gauge'), status['mem']['free']) mzbench.notify(('mem.shared', 'gauge'), status['mem']['shared']) mzbench.notify(('mem.buffers', 'gauge'), status['mem']['buffers']) mzbench.notify(('mem.cached', 'gauge'), status['mem']['cached']) mzbench.notify(('mem.swap.used', 'gauge'), status['mem']['swap_used']) mzbench.notify(('mem.swap.free', 'gauge'), status['mem']['swap_free']) except Exception: pass
def run_motion(): network.send_motion() mzbench.notify(('MQTT_Packets', 'counter'), 1) mzbench.notify(('MQTT_Motion', 'counter'), 1)
def run_guardian_status_report(): network.send_guardian_status_report() mzbench.notify(('MQTT_Packets', 'counter'), 1) mzbench.notify(('MQTT_Status', 'counter'), 1)
def run_heartbeat(): network.send_heartbeat() mzbench.notify(('MQTT_Packets', 'counter'), 1) mzbench.notify(('MQTT_Heartbeat', 'counter'), 1)
def _notify_disconnect(): print("no booya") mzbench.notify(('MQTT_Active', 'counter'), -1) mzbench.notify(('MQTT_Connections', 'counter'), -1)
def run_registration(server): global network #print(sys.version) mac = MacAddress(random.randint(0, 999999999) * 256) time_stamp = time.time() - 31536000 try_again = True #print(mac.number()) #print(threading.active_count()) gk_url = "https://mns." + server + "/gatekeeper" network = CoreNetworkSimple(mac=mac.number(), gk_url=gk_url, mqtt_on_connect=_notify_connect, mqtt_on_disconnect=_notify_disconnect) registration = network.populate_network() GK_response_time = registration["runtimes"]["gatekeeper"] MQ_response_time = registration["runtimes"]["mqtt"] mzbench.notify(('Guardian', 'histogram'), GK_response_time) mzbench.notify(('MQTT', 'histogram'), MQ_response_time) for status in registration["results"]: if status == 200: mzbench.notify(('HTTP_Success', 'counter'), 1) elif status == 201: mzbench.notify(('HTTP_Retry', 'counter'), 1) else: mzbench.notify(('HTTP_Fail', 'counter'), 1) mzbench.notify(('MQTT_Packets', 'counter'), 1) mzbench.notify(('MQTT_Status', 'counter'), 1)