def system_memery_data_handle(host, result): final_result = {host: []} for item in result[host]: process_data = {} item = item.split() process_data["total"] = item[0] process_data["used"] = item[1] process_data["free"] = item[2] process_data["shared"] = item[3] final_result[host].append(process_data) try: for data in final_result[host]: json_body[0]["measurement"] = "system_ec2_memery" json_body[0]["fields"]["used"] = float( "%.3f" % (int(data["used"]) / int(data["total"]))) json_body[0]["fields"]["free"] = float( "%.3f" % (int(data["free"]) / int(data["total"]))) json_body[0]["fields"]["shared"] = float( "%.3f" % (int(data["shared"]) / int(data["total"]))) json_body[0]["tags"]["host"] = host influxdb_client.write_points(json_body) except Exception as e: print(e) else: print("system_memery'data handle OK")
def redis_cloudwatch(monitor_item,measurement, start_time=now_time, end_time=end_time, allec_id=all_ec_id, period=60, converge="Average"): for id in allec_id: try: ec_item = redis_cloudwatch_data(monitor_item, id[0], start_time, end_time, period, converge) except Exception: pass else: for data in ec_item: json_body[0]["measurement"] = measurement json_body[0]["tags"]["id"] = id[0] json_body[0]["time"] = data["Timestamp"] if re.search("free", monitor_item, flags=re.I): json_body[0]["fields"][monitor_item] = int((data["data"]/1024)/1024) else: json_body[0]["fields"][monitor_item] = data["data"] influxdb_client.write_points(json_body)
def system_cpu_data_handle(host, result): final_result = {host: []} for item in result[host]: process_data = {} item = item.split() process_data["user_cpu"] = item[0] process_data["sys_cpu"] = item[1] process_data["idle_cpu"] = item[2] final_result[host].append(process_data) try: for data in final_result[host]: json_body[0]["measurement"] = "system_ec2_cpu" json_body[0]["fields"]["user_cpu"] = float(data["user_cpu"]) json_body[0]["fields"]["sys_cpu"] = float(data["sys_cpu"]) json_body[0]["fields"]["idle_cpu"] = float(data["idle_cpu"]) json_body[0]["tags"]["host"] = host influxdb_client.write_points(json_body) except Exception as e: print(e) else: print("system_cpu'data handle OK")
def app_cpu_top(host, result): final_result = {host: []} for item in result[host]: process_data = {} item = item.split() process_data["pid"] = item[0] process_data["cpu_percent"] = item[1] process_data["name"] = str(item[2]).split('/')[-1] final_result[host].append(process_data) try: for data in final_result[host]: json_body[0]["measurement"] = "app_cpu_top" json_body[0]["tags"]["pid"] = data["pid"] json_body[0]["tags"]["process_name"] = data["name"] json_body[0]["tags"]["host"] = host json_body[0]["fields"]["cpu_percent"] = data["cpu_percent"] influxdb_client.write_points(json_body) except Exception as e: print(e) else: print("app_mem_top'data handle OK")