diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b5072f7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +#IDE +.idea/ diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml deleted file mode 100644 index e96534f..0000000 --- a/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/modules/lepd/LepDClient.py b/app/modules/lepd/LepDClient.py index ff46500..0330133 100644 --- a/app/modules/lepd/LepDClient.py +++ b/app/modules/lepd/LepDClient.py @@ -8,7 +8,7 @@ import pprint import re import datetime -import click +import clock class LepDClient: diff --git a/dataStore/__init__.py b/dataStore/__init__.py new file mode 100644 index 0000000..43660d6 --- /dev/null +++ b/dataStore/__init__.py @@ -0,0 +1,44 @@ +import argparse + +from influxdb import InfluxDBClient + +def main(host='localhost',port=8086): + user = 'root' + password = 'root' + dbname = 'example' + dbuser = 'smly' + dbuser_password = 'my_secret_password' + query = 'select value from cpu_load_short;' + json_body = [{ + "measurement": "cpu_load_short", + "tags":{ + "host":"server01", + "region":"us-west" + }, + "time":"2009-11-10T23:00:00Z", + "fields":{ + "value":0.64 + } + }] + + + client = InfluxDBClient(host,port,user,password,dbname) + client.create_database(dbname) + client.create_retention_policy('awesome_policy','3d',3,default=True) + client.switch_user(dbuser, dbuser_password) + client.write_points(json_body) + result = client.query(query) + print(result) + client.switch_user(user,password) + #client.drop_database(dbname) +def parse_args(): + parser = argparse.ArgumentParser(description='exmple code to play with InfluxDB') + parser.add_argument('--host',type=str,required = False,default='localhost', + help='hostnameof InfluxDB http Api') + parser.add_argument('--port',type=int ,required=False,default=8086, + help='port of InfluxDb http Api') + return parser.parse_args() + +# if __name__ == '__main__': +# args = parse_args() +# main(host=args.host,port=args.port) \ No newline at end of file diff --git a/dataStore/influxDbUtil/__init__.py b/dataStore/influxDbUtil/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dataStore/influxDbUtil/dbUtil.py b/dataStore/influxDbUtil/dbUtil.py new file mode 100644 index 0000000..0b69c26 --- /dev/null +++ b/dataStore/influxDbUtil/dbUtil.py @@ -0,0 +1,26 @@ +"""Core module for interacting with influxDB""" + +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from influxdb import InfluxDBClient + +''' +MyInfluxDbClient is the warpper of InfluxDBClient, +To insert data and to query data can use it +''' + + +class MyInfluxDbClient: + def __init__(self, influxDBAddress,port=8086,username='root',password='',database="lep"): + self._client = InfluxDBClient(influxDBAddress, port,username,password,database) + + def write_points(self, json_body): + + if self._client.write_points(json_body): + return True + else: + return False + + def query(self, statement): + return self._client.query(statement) diff --git a/dataStore/lepdClient/LepdClient.py b/dataStore/lepdClient/LepdClient.py new file mode 100644 index 0000000..97747ab --- /dev/null +++ b/dataStore/lepdClient/LepdClient.py @@ -0,0 +1,66 @@ +"""Core module for interacting with LEPD""" + +__author__ = "Copyright (c) 2016, 李旭升 " +__copyright__ = "Licensed under GPLv2 or later." + +import json +import pprint +import socket + +''' +LepdClient pulls data from lepd +''' + + +class LepdClient(object): + def __init__(self, server, port=12307, config='release'): + self.server = server + self.port = port + self.bufferSize = 2048 + self.config = config + + self.LEPDENDINGSTRING = 'lepdendstring' + + def sendRequest(self, methodName): + sock = None + try: + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.connect((self.server, self.port)) + + input_data = {} + input_data['method'] = methodName + + dumped_data = json.dumps(input_data) + + sock.send(dumped_data.encode()) + serverResponse = str.encode("") + end = str.encode("lepdendstring") + while True: + data = sock.recv(self.bufferSize) + if end in data: + data = data.replace(end, str.encode("")) + serverResponse = serverResponse + data + break + serverResponse = serverResponse + data + responseJsonDecoded = json.loads(serverResponse.decode()) + return responseJsonDecoded + except Exception as error: + print("dataStore/lepdClient/LepdClient.py.sendRequest() throws an exception\n") + pass + finally: + if (sock): + sock.close() + + def listAllMethods(self): + response = self.sendRequest('ListAllMethod') + if (response == None or 'result' not in response): + return [] + lines = response['result'].strip().split() + return lines + + +if (__name__ == '__main__'): + pp = pprint.PrettyPrinter(indent=2) + client = LepdClient('www.rmlink.cn', config='debug') + + print(client.listAllMethods()) diff --git a/dataStore/lepdClient/__init__.py b/dataStore/lepdClient/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dataStore/modules/__init__.py b/dataStore/modules/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dataStore/modules/cpu/__init__.py b/dataStore/modules/cpu/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dataStore/modules/cpu/pullAndStoreGetCmdMpstat.py b/dataStore/modules/cpu/pullAndStoreGetCmdMpstat.py new file mode 100755 index 0000000..f760fd6 --- /dev/null +++ b/dataStore/modules/cpu/pullAndStoreGetCmdMpstat.py @@ -0,0 +1,57 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time +import re + +''' +fetch data related to GetCmdMpstat from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetCmdMpstat(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetCmdMpstat') + # print(res) + myStr = res['result'].split('\n') + + data = re.findall(r"\d+\.?\d*", myStr[10]) + + + json_body = [ + { + "measurement": "GetCmdMpstat", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "%usr": float(data[0]), + "%nice": float(data[1]), + "%sys": float(data[2]), + "%iowait": float(data[3]), + "%irq": float(data[4]), + "%soft": float(data[5]), + "%steal": float(data[6]), + "%guest": float(data[7]), + "%gnice": float(data[8]), + "%idle": float(data[9]) + } + + } + ] + + influxDbClient.write_points(json_body) + + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(30): + pullAndStoreGetCmdMpstat(lepdClient, influxDbClient) + time.sleep(1) + + diff --git a/dataStore/modules/influx b/dataStore/modules/influx new file mode 100644 index 0000000..97f2dc6 --- /dev/null +++ b/dataStore/modules/influx @@ -0,0 +1,44 @@ +CREATE CONTINUOUS QUERY cp_1_week_GetCmdIotop ON lep BEGIN SELECT mean("Total_DISK_READ") AS "meanTDR" ,mean("Total_DISK_WRITE") +AS "meanTDW" INTO lep."1_week".GetCmdIotop FROM lep."12_hours".GetCmdIotop GROUP BY time(60s) END + + + + +CREATE CONTINUOUS QUERY cp_1_week_GetCmdMpstat ON lep BEGIN +SELECT +mean("%usr") AS meanusr,mean("%nice") AS meannice, +mean("%sys") AS meansys,mean("%iowait") AS meaniowait, +mean("%irq") AS meanirq,mean("%soft") AS meansoft, +mean("%steal")AS meansteal,mean("%guest") AS meanguest, +mean("%gnice") AS meangnice,mean("%idle") AS meanidle +INTO lep."1_week".GetCmdMpstat FROM lep."12_hours".GetCmdMpstat +GROUP BY time(60s) END + + +CREATE CONTINUOUS QUERY cp_1_month_GetCmdMpstat ON lep BEGIN +SELECT +mean("%usr") AS meanusr,mean("%nice") AS meannice, +mean("%sys") AS meansys,mean("%iowait") AS meaniowait, +mean("%irq") AS meanirq,mean("%soft") AS meansoft, +mean("%steal")AS meansteal,mean("%guest") AS meanguest, +mean("%gnice") AS meangnice,mean("%idle") AS meanidle +INTO lep."1_month".GetCmdMpstat FROM lep."12_hours".GetCmdMpstat +GROUP BY time(600s) END + + +CREATE CONTINUOUS QUERY cp_1_year_GetCmdMpstat ON lep BEGIN +SELECT +mean("%usr") AS meanusr,mean("%nice") AS meannice, +mean("%sys") AS meansys,mean("%iowait") AS meaniowait, +mean("%irq") AS meanirq,mean("%soft") AS meansoft, +mean("%steal")AS meansteal,mean("%guest") AS meanguest, +mean("%gnice") AS meangnice,mean("%idle") AS meanidle +INTO lep."1_year".GetCmdMpstat FROM lep."12_hours".GetCmdMpstat +GROUP BY time(1800s) END + + + +CREATE CONTINUOUS QUERY cp_1_week_GetCmdIostat ON lep BEGIN SELECT mean("rrqm/s") AS meanrrqm,mean("wrqm/s") AS meanwrqm, mean("r/s") AS meanr, mean("w/s") AS meanw, mean("rkB/s") AS meanrkB,mean("wkB/s") AS meanwkb,mean("avgrq-sz") AS meanavgrq, +mean("avgqu-sz") AS meanavgqu,mean("await") AS meanawait,mean("r_await") AS meanr_await,mean("w_await") AS meanw_await,mean("svctm") AS meansvctm,mean("%util") As meanutil INTO lep."1_week".GetCmdIostat FROM lep."12_hours".GetCmdIostat GROUP BY time(60s) END + + diff --git a/dataStore/modules/io/__init__.py b/dataStore/modules/io/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dataStore/modules/io/pullAndStoreGetCmdIostat.py b/dataStore/modules/io/pullAndStoreGetCmdIostat.py new file mode 100755 index 0000000..f12b5e0 --- /dev/null +++ b/dataStore/modules/io/pullAndStoreGetCmdIostat.py @@ -0,0 +1,62 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +fetch data related to GetCmdIostat from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetCmdIostat(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetCmdIostat') + # print(res) + mystr = res['result'].split('\n') + # for x in mystr: + # print(x) + # print(mystr[3]) + data = [] + mystr1 = mystr[3].split(' ') + for y in mystr1: + if(y!=''): + data.append(y) + # print(data) + + json_body = [ + { + "measurement": "GetCmdIostat", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "Device": data[0], + "rrqm/s": float(data[1]), + "wrqm/s": float(data[2]), + "r/s": float(data[3]), + "w/s": float(data[4]), + "rkB/s": float(data[5]), + "wkB/s": float(data[6]), + "avgrq-sz": float(data[7]), + "avgqu-sz": float(data[8]), + "await": float(data[9]), + "r_await": float(data[10]), + "w_await": float(data[11]), + "svctm": float(data[12]), + "%util": float(data[13]) + } + } + ] + + influxDbClient.write_points(json_body) + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(120): + pullAndStoreGetCmdIostat(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/memory/__init__.py b/dataStore/modules/memory/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dataStore/modules/memory/pullAndStoreGetProcMeminfo.py b/dataStore/modules/memory/pullAndStoreGetProcMeminfo.py new file mode 100644 index 0000000..0913872 --- /dev/null +++ b/dataStore/modules/memory/pullAndStoreGetProcMeminfo.py @@ -0,0 +1,101 @@ +__author__ = "李旭升 programmerli@foxmail.com > " + +__copyright__ = "Licensed under GPLv2 or later." + + +''' +用lepdClient请求数据并把返回的数据用influxDbClient存储到InfluxDB中 +''' + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +def pullAndStoreGetProcMeminfo(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetProcMeminfo') + # print(res) + mystr = res['result'].split('\n') + data = {} + for x in mystr: + + x1 = x.replace('kB', '') + x2 = x1.replace(' ', '') + list = x2.split(':') + if (len(list) == 2): + data[list[0]] = list[1] + + + #print(data['Active']) + + + json_body = [ + { + "measurement": "GetProcMeminfo", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "MemTotal": int(data['MemTotal']), + "MemFree": int(data['MemFree']), + # "MemAvailable": data['MemAvailable'], + "Buffers": int(data['Buffers']), + "Cached": int(data['Cached']), + "SwapCached": int(data['MemTotal']), + "Active": int(data['Active']), + "Inactive": int(data['Inactive']), + "Active(anon)": int(data['Active(anon)']), + "Inactive(anon)": int(data['Inactive(anon)']), + "Active(file)": int(data['Active(file)']), + "Inactive(file)": int(data['Inactive(file)']), + "Unevictable": int(data['Unevictable']), + "Mlocked": int(data['Mlocked']), + "SwapTotal": int(data['SwapTotal']), + "SwapFree": int(data['SwapFree']), + "Dirty": int(data['Dirty']), + "Writeback": int(data['Writeback']), + "AnonPages": int(data['AnonPages']), + "Mapped": int(data['Mapped']), + "Shmem": int(data['Shmem']), + "Slab": int(data['Slab']), + "SReclaimable": int(data['SReclaimable']), + "SUnreclaim": int(data['SUnreclaim']), + "KernelStack": int(data['KernelStack']), + "PageTables": int(data['PageTables']), + "NFS_Unstable": int(data['NFS_Unstable']), + "Bounce": int(data['Bounce']), + "WritebackTmp": int(data['WritebackTmp']), + "CommitLimit": int(data['CommitLimit']), + "Committed_AS": int(data['Committed_AS']), + "VmallocTotal": int(data['VmallocTotal']), + "VmallocUsed": int(data['VmallocUsed']), + "VmallocChunk": int(data['VmallocChunk']), + "HardwareCorrupted": int(data['HardwareCorrupted']), + "AnonHugePages": int(data['AnonHugePages']), + # "ShmemHugePages": data['ShmemHugePages'], + # "ShmemPmdMapped": data['ShmemPmdMapped'], + # "CmaTotal": data['CmaTotal'], + # "CmaFree": data['CmaFree'], + "HugePages_Total": int(data['HugePages_Total']), + "HugePages_Free": int(data['HugePages_Free']), + "HugePages_Rsvd": int(data['HugePages_Rsvd']), + "HugePages_Surp": int(data['HugePages_Surp']), + "Hugepagesize": int(data['Hugepagesize']), + "DirectMap4k": int(data['DirectMap4k']), + "DirectMap2M": int(data['DirectMap2M']), + "DirectMap1G": int(data['DirectMap1G']) + } + } + ] + + influxDbClient.write_points( json_body) + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(60): + pullAndStoreGetProcMeminfo(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/others/__init__.py b/dataStore/modules/others/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dataStore/modules/others/pullAndStoreGetCmdDf.py b/dataStore/modules/others/pullAndStoreGetCmdDf.py new file mode 100755 index 0000000..412f30d --- /dev/null +++ b/dataStore/modules/others/pullAndStoreGetCmdDf.py @@ -0,0 +1,53 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +fetch data related to GetCmdDf from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetCmdDf(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetCmdDf') + # print(res) + + str1 = res["result"].split("\n") + str2 = str1[3].split(' ') + data = [] + for x in str2: + if(x!=''): + data.append(x) + # for y in data: + # print(y) + + json_body = [ + { + "measurement": "GetCmdDf", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "Filesystem": data[0], + "Size": data[1], + "Used": data[2], + "Available": data[3], + "Use%": data[4], + "Mounted on": data[5] + } + } + ] + + influxDbClient.write_points(json_body) + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetCmdDf(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/others/pullAndStoreGetCmdDmesg.py b/dataStore/modules/others/pullAndStoreGetCmdDmesg.py new file mode 100755 index 0000000..82a55d0 --- /dev/null +++ b/dataStore/modules/others/pullAndStoreGetCmdDmesg.py @@ -0,0 +1,47 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +fetch data related to GetCmdDmesg from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetCmdDmesg(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetCmdDmesg') + # print(res) + data = res["result"].split("\n") + # for x in data: + # print(x) + + json_body = [ + { + "measurement": "GetCmdDmesg", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "audit": data[7], + "Adding":data[8], + "NET": data[9], + "e1000":data[12], + "IPv6":data[13] + + } + } + ] + + influxDbClient.write_points(json_body) + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetCmdDmesg(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/others/pullAndStoreGetCmdFree.py b/dataStore/modules/others/pullAndStoreGetCmdFree.py new file mode 100755 index 0000000..de30815 --- /dev/null +++ b/dataStore/modules/others/pullAndStoreGetCmdFree.py @@ -0,0 +1,51 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +fetch data related to GetCmdFree from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetCmdFree(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetCmdFree') + # print(res) + str1 = res["result"].split("\n") + str2 = str1[1].split(" ") + data = [] + for x in str2: + if(x!=""): + data.append(x) + + json_body = [ + { + "measurement": "GetCmdFree", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "total": int(data[1]), + "used": int(data[2]), + "free": int(data[3]), + "shared": int(data[4]), + "buffers": int(data[5]), + "cached": int(data[6]), + } + } + ] + + influxDbClient.write_points(json_body) + + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetCmdFree(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/others/pullAndStoreGetCmdIotop.py b/dataStore/modules/others/pullAndStoreGetCmdIotop.py new file mode 100755 index 0000000..a5ad99e --- /dev/null +++ b/dataStore/modules/others/pullAndStoreGetCmdIotop.py @@ -0,0 +1,47 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient +import re + +import time + +''' +fetch data related to GetCmdIrqInfo from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetCmdIotop(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetCmdIotop') + # print(res) + + str1 = res["result"].split("\n") + + data=re.findall(r"\d+\.?\d*", str1[0]) + + # print(data) + json_body = [ + { + + "measurement": "GetCmdIotop", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "Total_DISK_READ": float(data[0]), + "Total_DISK_WRITE": float(data[1]) + } + } + ] + + influxDbClient.write_points(json_body) + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(120): + pullAndStoreGetCmdIotop(lepdClient, influxDbClient) + # time.sleep(0.3) diff --git a/dataStore/modules/others/pullAndStoreGetCmdIrqInfo.py b/dataStore/modules/others/pullAndStoreGetCmdIrqInfo.py new file mode 100755 index 0000000..8f18ae0 --- /dev/null +++ b/dataStore/modules/others/pullAndStoreGetCmdIrqInfo.py @@ -0,0 +1,50 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +fetch data related to GetCmdDmesg from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetCmdIrqInfo(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetCmdIrqInfo') + print(res) + str1 = res["result"].split(" ") + x1=str1[0].split(":") + x2=x1[1].split("/") + x3=x2[0] + print(x3) + y1=str1[1].split(":") + y2=y1[1].split("/") + y3=y2[0] + print(y3) + + json_body = [ + { + "measurement": "GetCmdIrqInfo", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "irq": int(x3), + "softirq": int(y3) + } + } + ] + + influxDbClient.write_points(json_body) + + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetCmdIrqInfo(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/others/pullAndStoreGetCmdMpstat-I.py b/dataStore/modules/others/pullAndStoreGetCmdMpstat-I.py new file mode 100755 index 0000000..acac944 --- /dev/null +++ b/dataStore/modules/others/pullAndStoreGetCmdMpstat-I.py @@ -0,0 +1,58 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +fetch data related to GetCmdMpstat-I from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetCmdMpstat_I(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetCmdMpstat-I') + print(res) + str1 = res["result"].split("\n") + # for x in str1: + # print(x) + data = [] + str2=str1[27].split(" ") + for y in str2: + if(y!=""): + data.append(y) + json_body = [ + { + "measurement": "GetProcSwaps", + + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "CPU": float(data[1]), + "HI/s": float(data[2]), + "TIMER/s": float(data[3]), + "NET_TX/s": float(data[4]), + "NET_RX/s": float(data[5]), + "BLOCK/s": float(data[6]), + "IRQ_POLL/s": float(data[7]), + "TASKLET/s": float(data[8]), + "SCHED/s": float(data[9]), + "HRTIMER/s": float(data[10]), + "RCU/s": float(data[11]) + } + } + ] + + influxDbClient.write_points(json_body) + + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetCmdMpstat_I(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/others/pullAndStoreGetCmdProcrank.py b/dataStore/modules/others/pullAndStoreGetCmdProcrank.py new file mode 100755 index 0000000..c4b53dd --- /dev/null +++ b/dataStore/modules/others/pullAndStoreGetCmdProcrank.py @@ -0,0 +1,53 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time +import re + +''' +fetch data related to GetCmdProcrank from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetCmdProcrank(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetCmdProcrank') + print(res) + str1 = res["result"].split("\n") + # for x in str1: + # print(x) + # print(str1[-2]) + + data = re.findall(r"\d+\.?\d*", str1[-2]) + print(data) + + json_body = [ + { + "measurement": "GetCmdProcrank", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "total": int(data[0]), + "free": int(data[1]), + "buffers": int(data[2]), + "cached": int(data[3]), + "shmem": int(data[4]), + "slab": int(data[5]) + + } + } + ] + + influxDbClient.write_points(json_body) + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetCmdProcrank(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/others/pullAndStoreGetCpuInfo.py b/dataStore/modules/others/pullAndStoreGetCpuInfo.py new file mode 100755 index 0000000..851bdaf --- /dev/null +++ b/dataStore/modules/others/pullAndStoreGetCpuInfo.py @@ -0,0 +1,48 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +fetch data related to GetCpuInfo from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetCpuInfo(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetCpuInfo') + # print(res) + str1 = res["result"].split("\n") + data1 = str1[0].split(": ") + data2 = str1[1].split(": ") + # for x in data1: + # print(x) + # for x in data2: + # print(x) + json_body = [ + { + "measurement": "GetCpuInfo", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "cpunr": int(data1[1]), + "cpu_name": data2[1] + + } + } + ] + + influxDbClient.write_points(json_body) + + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetCpuInfo(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/others/pullAndStoreGetProcBuddyinfo.py b/dataStore/modules/others/pullAndStoreGetProcBuddyinfo.py new file mode 100755 index 0000000..dd7231f --- /dev/null +++ b/dataStore/modules/others/pullAndStoreGetProcBuddyinfo.py @@ -0,0 +1,44 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +fetch data related to GetProcBuddyinfo from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetProcBuddyinfo(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetProcBuddyinfo') + # print(res) + str1 = res["result"].split("\n") + # for x in str1: + # print(x) + + + json_body = [ + { + "measurement": "GetProcBuddyinfo", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "DMA": str1[0], + "DMA32": str1[1] + } + } + ] + + influxDbClient.write_points( json_body) + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetProcBuddyinfo(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/others/pullAndStoreGetProcCpuinfo.py b/dataStore/modules/others/pullAndStoreGetProcCpuinfo.py new file mode 100644 index 0000000..1e39744 --- /dev/null +++ b/dataStore/modules/others/pullAndStoreGetProcCpuinfo.py @@ -0,0 +1,44 @@ +__author__ = "李旭升 " +__copyright__ = "Licensed under GPLv2 or later." + + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + + +''' +用lepdClient请求CPU相关数据并把返回的数据用influxDbClient存储到InfluxDB中 +''' +def pullAndStoreGetProcCpuinfo(lepdClient,influxDbClient): + res = lepdClient.sendRequest('GetProcCpuinfo') + print(res) + str1 = res["result"].split("\n") + + str='' + for i in range(27): + str=str+str1[i] + # print(str) + json_body = [ + { + "measurement": "GetProcCpuinfo", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "cpuInfo":str + } + } + ] + + influxDbClient.write_points(json_body) + + +if(__name__=='__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + + pullAndStoreGetProcCpuinfo(lepdClient,influxDbClient) diff --git a/dataStore/modules/others/pullAndStoreGetProcSwaps.py b/dataStore/modules/others/pullAndStoreGetProcSwaps.py new file mode 100755 index 0000000..6a8fa04 --- /dev/null +++ b/dataStore/modules/others/pullAndStoreGetProcSwaps.py @@ -0,0 +1,48 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +fetch data related to GetProcSwaps from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetProcSwaps(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetProcSwaps') + # print(res) + mystr = res['result'].split('\n') + x1 = mystr[1].split('\t') + # for x in x1: + # print(x) + + + + json_body = [ + { + "measurement": "GetProcSwaps", + "tags": { + + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "FilenameType": x1[0], + "Size": int(x1[1]), + "Used": int(x1[2]), + "Priority": int(x1[3]) + } + } + ] + + influxDbClient.write_points(json_body) + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetProcSwaps(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/others/pullAndStoreGetProcVmstat.py b/dataStore/modules/others/pullAndStoreGetProcVmstat.py new file mode 100755 index 0000000..55c9973 --- /dev/null +++ b/dataStore/modules/others/pullAndStoreGetProcVmstat.py @@ -0,0 +1,178 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + + + +import time + +''' +fetch data related to GetProcVmstat from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetProcVmstat(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetProcVmstat') + # print(res) + str = res['result'].split('\n') + data = {} + for x in str: + list = x.split(' ') + if (len(list) == 2): + data[list[0]] = list[1] + print(data) + + json_body = [ + { + "measurement": "GetProcVmstat", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + + + "fields": { + "compact_stall" : int(data['compact_stall']), + "balloon_migrate": int(data['balloon_migrate']), + "nr_unevictable": int(data['nr_unevictable']), + "nr_vmscan_write": int(data['nr_vmscan_write']), + "pgskip_movable": int(data['pgskip_movable']), + "thp_fault_fallback": int(data['thp_fault_fallback']), + "nr_anon_pages": int(data['nr_anon_pages']), + "numa_other": int(data['numa_other']), + "thp_split_page": int(data['thp_split_page']), + "unevictable_pgs_stranded": int(data['unevictable_pgs_stranded']), + "nr_shmem_pmdmapped": int(data['nr_shmem_pmdmapped']), + "nr_shmem": int(data['nr_shmem']), + "nr_zone_write_pending": int(data['nr_zone_write_pending']), + "compact_migrate_scanned": int(data['compact_migrate_scanned']), + "nr_zone_active_anon": int(data['nr_zone_active_anon']), + "pglazyfree": int(data['pglazyfree']), + "numa_foreign": int(data['numa_foreign']), + "pglazyfreed": int(data['pglazyfreed']), + "nr_zone_active_file": int(data['nr_zone_active_file']), + "numa_pte_updates": int(data['numa_pte_updates']), + "pgscan_direct_throttle":int(data['pgscan_direct_throttle']), + "kswapd_low_wmark_hit_quickly": int(data['kswapd_low_wmark_hit_quickly']), + "nr_dirtied": int(data['nr_dirtied']), + "htlb_buddy_alloc_fail": int(data['htlb_buddy_alloc_fail']), + "nr_dirty_background_threshold": int(data['nr_dirty_background_threshold']), + "pgalloc_dma32": int(data['pgalloc_dma32']), + "compact_daemon_migrate_scanned": int(data['compact_daemon_migrate_scanned']), + "unevictable_pgs_culled": int(data['unevictable_pgs_culled']), + "numa_miss": int(data['numa_miss']), + "compact_isolated": int(data['compact_isolated']), + "pswpout": int(data['pswpout']), + "pgsteal_kswapd": int(data['pgsteal_kswapd']), + "thp_split_pud": int(data['thp_split_pud']), + "unevictable_pgs_mlocked": int(data['unevictable_pgs_mlocked']), + "thp_zero_page_alloc": int(data['thp_zero_page_alloc']), + "workingset_activate": int(data['workingset_activate']), + "unevictable_pgs_cleared": int(data['unevictable_pgs_cleared']), + "pgalloc_movable": int(data['pgalloc_movable']), + "pageoutrun": int(data['pageoutrun']), + "pgfault": int(data['pgfault']), + "nr_unstable": int(data['nr_unstable']), + "kswapd_high_wmark_hit_quickly": int(data['kswapd_high_wmark_hit_quickly']), + "thp_deferred_split_page": int(data['thp_deferred_split_page']), + "thp_file_mapped": int(data['thp_file_mapped']), + "pgscan_kswapd": int(data['pgscan_kswapd']), + "nr_writeback_temp": int(data['nr_writeback_temp']), + "nr_dirty_threshold": int(data['nr_dirty_threshold']), + "nr_mlock": int(data['nr_mlock']), + "htlb_buddy_alloc_success": int(data['htlb_buddy_alloc_success']), + "nr_isolated_anon": int(data['nr_isolated_anon']), + "allocstall_normal": int(data['allocstall_normal']), + "nr_mapped": int(data['nr_mapped']), + "numa_local": int(data['numa_local']), + "nr_zone_inactive_anon": int(data['nr_zone_inactive_anon']), + "pgmajfault": int(data['pgmajfault']), + "thp_fault_alloc": int(data['thp_fault_alloc']), + "compact_success": int(data['compact_success']), + "allocstall_dma": int(data['allocstall_dma']), + "thp_split_pmd": int(data['thp_split_pmd']), + "nr_bounce": int(data['nr_bounce']), + "thp_zero_page_alloc_failed": int(data['thp_zero_page_alloc_failed']), + "pgdeactivate": int(data['pgdeactivate']), + "allocstall_dma32": int(data['allocstall_dma32']), + "nr_file_pages": int(data['nr_file_pages']), + "nr_anon_transparent_hugepages": int(data['nr_anon_transparent_hugepages']), + "compact_fail": int(data['compact_fail']), + "nr_page_table_pages": int(data['nr_page_table_pages']), + "numa_hint_faults": int(data['numa_hint_faults']), + "pgskip_dma32": int(data['pgskip_dma32']), + "numa_pages_migrated": int(data['numa_pages_migrated']), + "nr_vmscan_immediate_reclaim": int(data['nr_vmscan_immediate_reclaim']), + "nr_zone_unevictable": int(data['nr_zone_unevictable']), + "pgmigrate_fail": int(data['pgmigrate_fail']), + "compact_daemon_wake": int(data['compact_daemon_wake']), + "pgskip_dma": int(data['pgskip_dma']), + "nr_active_anon": int(data['nr_active_anon']), + "pgpgout": int(data['pgpgout']), + "pgskip_normal": int(data['pgskip_normal']), + "pginodesteal": int(data['pginodesteal']), + "nr_zspages": int(data['nr_zspages']), + "unevictable_pgs_rescued": int(data['unevictable_pgs_rescued']), + "pgalloc_dma": int(data['pgalloc_dma']), + "pswpin": int(data['pswpin']), + "thp_collapse_alloc": int(data['thp_collapse_alloc']), + "nr_writeback": int(data['nr_writeback']), + "nr_free_pages": int(data['nr_free_pages']), + "pgpgin": int(data['pgpgin']), + "pgalloc_normal": int(data['pgalloc_normal']), + "slabs_scanned": int(data['slabs_scanned']), + "thp_file_alloc": int(data['thp_file_alloc']), + "nr_written": int(data['nr_written']), + "compact_free_scanned": int(data['compact_free_scanned']), + "numa_hint_faults_local": int(data['numa_hint_faults_local']), + "drop_pagecache": int(data['drop_pagecache']), + "thp_split_page_failed": int(data['thp_split_page_failed']), + "nr_zone_inactive_file": int(data['nr_zone_inactive_file']), + "unevictable_pgs_munlocked": int(data['unevictable_pgs_munlocked']), + "nr_slab_reclaimable": int(data['nr_slab_reclaimable']), + "allocstall_movable": int(data['allocstall_movable']), + "oom_kill": int(data['oom_kill']), + "nr_free_cma": int(data['nr_free_cma']), + "balloon_inflate": int(data['balloon_inflate']), + "numa_huge_pte_updates": int(data['numa_huge_pte_updates']), + "unevictable_pgs_scanned": int(data['unevictable_pgs_scanned']), + "nr_active_file": int(data['nr_active_file']), + "nr_shmem_hugepages": int(data['nr_shmem_hugepages']), + "kswapd_inodesteal": int(data['kswapd_inodesteal']), + "pgscan_direct": int(data['pgscan_direct']), + "numa_interleave": int(data['numa_interleave']), + "nr_slab_unreclaimable": int(data['nr_slab_unreclaimable']), + "thp_collapse_alloc_failed": int(data['thp_collapse_alloc_failed']), + "workingset_refault": int(data['workingset_refault']), + "compact_daemon_free_scanned": int(data['compact_daemon_free_scanned']), + "zone_reclaim_failed": int(data['zone_reclaim_failed']), + "nr_isolated_file": int(data['nr_isolated_file']), + "nr_inactive_anon": int(data['nr_inactive_anon']), + "pgrotated": int(data['pgrotated']), + "nr_kernel_stack": int(data['nr_kernel_stack']), + "numa_hit": int(data['numa_hit']), + "nr_dirty": int(data['nr_dirty']), + "workingset_nodereclaim": int(data['workingset_nodereclaim']), + "drop_slab": int(data['drop_slab']), + "nr_inactive_file": int(data['nr_inactive_file']), + "pgrefill": int(data['pgrefill']), + "pgmigrate_success": int(data['pgmigrate_success']), + "pgactivate": int(data['pgactivate']), + "balloon_deflate": int(data['balloon_deflate']), + "pgfree": int(data['pgfree']), + "pgsteal_direct": int(data['pgsteal_direct']) + } + } + ] + + influxDbClient.write_points(json_body) + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetProcVmstat(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/others/pullAndStoreGetProcZoneinfo.py b/dataStore/modules/others/pullAndStoreGetProcZoneinfo.py new file mode 100755 index 0000000..2fa7aa4 --- /dev/null +++ b/dataStore/modules/others/pullAndStoreGetProcZoneinfo.py @@ -0,0 +1,82 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + + +import time + +''' +fetch data related to GetProcZoneinfo from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetProcZoneinfo(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetProcZoneinfo') + print(res) + data = {} + + mystr = res['result'].split('\n') + for x in mystr: + x1 = x.strip() + x2 = x1.split(' ') + #把所有参数没有存完 + if (len(x2) == 2): + data[x2[0]]=x2[1] + + + + + json_body = [ + { + "measurement": "GetProcZoneinfo", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "nr_inactive_anon": int(data['nr_inactive_anon']), + "nr_active_anon": int(data['nr_active_anon']), + "nr_inactive_file": int(data['nr_inactive_file']), + "nr_active_file": int(data['nr_active_file']), + "nr_unevictable": int(data['nr_unevictable']), + "nr_slab_reclaimable": int(data['nr_slab_reclaimable']), + "nr_slab_unreclaimable": int(data['nr_slab_unreclaimable']), + "nr_isolated_anon": int(data['nr_isolated_anon']), + "nr_isolated_file": int(data['nr_isolated_file']), + "workingset_refault": int(data['workingset_refault']), + "workingset_activate": int(data['workingset_activate']), + "workingset_nodereclaim": int(data['workingset_nodereclaim']), + "nr_anon_pages": int(data['nr_anon_pages']), + "nr_file_pages": int(data['nr_file_pages']), + "nr_writeback": int(data['nr_writeback']), + "nr_writeback_temp": int(data['nr_writeback_temp']), + "nr_shmem_hugepages": int(data['nr_shmem_hugepages']), + "nr_shmem_pmdmapped": int(data['nr_shmem_pmdmapped']), + "nr_anon_transparent_hugepages": int(data['nr_anon_transparent_hugepages']), + "nr_vmscan_write": int(data['nr_vmscan_write']), + "nr_vmscan_immediate_reclaim": int(data['nr_vmscan_immediate_reclaim']), + "nr_free_pages": int(data['nr_free_pages']), + "nr_zone_inactive_anon": int(data['nr_zone_inactive_anon']), + "nr_zone_active_anon": int(data['nr_zone_active_anon']), + "nr_zone_inactive_file": int(data['nr_zone_inactive_file']), + "nr_zone_active_file": int(data['nr_zone_active_file']), + "nr_zone_unevictable": int(data['nr_zone_unevictable']), + "nr_zone_write_pending": int(data['nr_zone_write_pending']), + "nr_page_table_pages": int(data['nr_page_table_pages']), + "nr_kernel_stack": int(data['nr_kernel_stack']), + "numa_foreign": int(data['numa_foreign']), + "numa_interleave": int(data['numa_interleave']) + } + } + ] + + influxDbClient.write_points(json_body) + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetProcZoneinfo(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/perf/__init__.py b/dataStore/modules/perf/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dataStore/modules/perf/pullAndStoreGetCmdPerfCpuclock.py b/dataStore/modules/perf/pullAndStoreGetCmdPerfCpuclock.py new file mode 100755 index 0000000..7ae2663 --- /dev/null +++ b/dataStore/modules/perf/pullAndStoreGetCmdPerfCpuclock.py @@ -0,0 +1,41 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +fetch data related to GetCmdPerfCpuclock from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetCmdPerfCpuclock(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetCmdPerfCpuclock') + print(res) + # json_body = [ + # { + # "measurement": "GetProcSwaps", + # "tags": { + # # the address of lepd + # "server": lepdClient.server + # }, + # # "time": "2017-03-12T22:00:00Z", + # "fields": { + # "LinuxVersion": mystr, + # "compact_stall": int(data['compact_stall']), + # "balloon_migrate": int(data['balloon_migrate']), + # } + # } + # ] + # + # influxDbClient.write_points(json_body) + + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetCmdPerfCpuclock(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/perf/pullAndStoreGetCmdPerfFaults.py b/dataStore/modules/perf/pullAndStoreGetCmdPerfFaults.py new file mode 100755 index 0000000..b3307f3 --- /dev/null +++ b/dataStore/modules/perf/pullAndStoreGetCmdPerfFaults.py @@ -0,0 +1,41 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +fetch data related to GetCmdPerfFaults from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetCmdPerfFaults(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetCmdPerfFaults') + print(res) + + # json_body = [ + # { + # "measurement": "GetProcSwaps", + # "tags": { + # # the address of lepd + # "server": lepdClient.server + # }, + # # "time": "2017-03-12T22:00:00Z", + # "fields": { + # "LinuxVersion": mystr, + # "compact_stall": int(data['compact_stall']), + # "balloon_migrate": int(data['balloon_migrate']), + # } + # } + # ] + # + # influxDbClient.write_points(json_body) + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetCmdPerfFaults(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/perf/pullAndStoreGetCmdPerfFlame.py b/dataStore/modules/perf/pullAndStoreGetCmdPerfFlame.py new file mode 100755 index 0000000..e2ea371 --- /dev/null +++ b/dataStore/modules/perf/pullAndStoreGetCmdPerfFlame.py @@ -0,0 +1,41 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +fetch data related to GetCmdPerfFlame from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetCmdPerfFlame(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetCmdPerfFlame') + print(res) + # json_body = [ + # { + # "measurement": "GetProcSwaps", + # "tags": { + # # the address of lepd + # "server": lepdClient.server + # }, + # # "time": "2017-03-12T22:00:00Z", + # "fields": { + # "LinuxVersion": mystr, + # "compact_stall": int(data['compact_stall']), + # "balloon_migrate": int(data['balloon_migrate']), + # } + # } + # ] + # + # influxDbClient.write_points(json_body) + + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetCmdPerfFlame(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/raw/__init__.py b/dataStore/modules/raw/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dataStore/modules/raw/pullAndStoreGetCmdTop.py b/dataStore/modules/raw/pullAndStoreGetCmdTop.py new file mode 100755 index 0000000..96d66d4 --- /dev/null +++ b/dataStore/modules/raw/pullAndStoreGetCmdTop.py @@ -0,0 +1,41 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +fetch data related to GetCmdTop from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetCmdTop(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetCmdTop') + # print(res) + # str1 = res["result"].split("\n") + # for x in str1: + # print(x) + json_body = [ + { + "measurement": "GetCmdTop", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "top": res["result"] + } + } + ] + + influxDbClient.write_points(json_body) + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetCmdTop(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/raw/pullAndStoreGetProcDiskstats.py b/dataStore/modules/raw/pullAndStoreGetProcDiskstats.py new file mode 100755 index 0000000..ff354bf --- /dev/null +++ b/dataStore/modules/raw/pullAndStoreGetProcDiskstats.py @@ -0,0 +1,40 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +fetch data related to GetProcDiskstats from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetProcDiskstats(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetProcDiskstats') + # print(res) + + + + json_body = [ + { + "measurement": "GetProcDiskstats", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "Diskstats": res["result"] + } + } + ] + + influxDbClient.write_points(json_body) + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetProcDiskstats(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/raw/pullAndStoreGetProcInterrupts.py b/dataStore/modules/raw/pullAndStoreGetProcInterrupts.py new file mode 100755 index 0000000..b26328a --- /dev/null +++ b/dataStore/modules/raw/pullAndStoreGetProcInterrupts.py @@ -0,0 +1,41 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +fetch data related to GetProcInterrupts from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetProcInterrupts(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetProcInterrupts') + # print(res) + # + # str1 = res["result"].split("\n") + # for x in str1: + # print(x) + json_body = [ + { + "measurement": "GetProcInterrupts", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "interrupts": res["result"] + } + } + ] + + influxDbClient.write_points(json_body) + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetProcInterrupts(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/raw/pullAndStoreGetProcLoadavg.py b/dataStore/modules/raw/pullAndStoreGetProcLoadavg.py new file mode 100755 index 0000000..68a03ae --- /dev/null +++ b/dataStore/modules/raw/pullAndStoreGetProcLoadavg.py @@ -0,0 +1,42 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +fetch data related to GetProcLoadavg from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetProcLoadavg(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetProcLoadavg') + # print(res) + + + + json_body = [ + { + "measurement": "GetProcLoadavg", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "loadavg": res["result"] + + } + } + ] + + influxDbClient.write_points(json_body) + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetProcLoadavg(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/raw/pullAndStoreGetProcModules.py b/dataStore/modules/raw/pullAndStoreGetProcModules.py new file mode 100755 index 0000000..204d54a --- /dev/null +++ b/dataStore/modules/raw/pullAndStoreGetProcModules.py @@ -0,0 +1,43 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +fetch data related to GetProcModules from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetProcModules(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetProcModules') + # print(res) + # str1 = res["result"].split("\n") + # for x in str1: + # print(x) + json_body = [ + { + "measurement": "GetProcModules", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "modules": res["result"] + + } + } + ] + + influxDbClient.write_points(json_body) + + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetProcModules(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/raw/pullAndStoreGetProcSlabinfo.py b/dataStore/modules/raw/pullAndStoreGetProcSlabinfo.py new file mode 100755 index 0000000..0ac8adb --- /dev/null +++ b/dataStore/modules/raw/pullAndStoreGetProcSlabinfo.py @@ -0,0 +1,43 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +fetch data related to GetProcSlabinfo from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetProcSlabinfo(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetProcSlabinfo') + # print(res) + # str1 = res["result"].split("\n") + # for x in str1: + # print(x) + json_body = [ + { + "measurement": "GetProcSlabinfo", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "slabinfo": res["result"] + + } + } + ] + + influxDbClient.write_points(json_body) + + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetProcSlabinfo(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/raw/pullAndStoreGetProcSoftirqs.py b/dataStore/modules/raw/pullAndStoreGetProcSoftirqs.py new file mode 100755 index 0000000..54475fc --- /dev/null +++ b/dataStore/modules/raw/pullAndStoreGetProcSoftirqs.py @@ -0,0 +1,41 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +fetch data related to GetProcSoftirqs from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetProcSoftirqs(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetProcSoftirqs') + # print(res) + # str1 = res["result"].split("\n") + # for x in str1: + # print(x) + json_body = [ + { + "measurement": "GetProcSoftirqs", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "softirqs": res["result"] + } + } + ] + + influxDbClient.write_points(json_body) + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetProcSoftirqs(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/raw/pullAndStoreGetProcStat.py b/dataStore/modules/raw/pullAndStoreGetProcStat.py new file mode 100755 index 0000000..f0e5b54 --- /dev/null +++ b/dataStore/modules/raw/pullAndStoreGetProcStat.py @@ -0,0 +1,41 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +fetch data related to GetProcStat from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetProcStat(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetProcStat') + # print(res) + # str1 = res["result"].split("\n") + # for x in str1: + # print(x) + json_body = [ + { + "measurement": "GetProcStat", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "procstat": res["result"] + + } + } + ] + + influxDbClient.write_points(json_body) + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetProcStat(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/raw/pullAndStoreGetProcVersion.py b/dataStore/modules/raw/pullAndStoreGetProcVersion.py new file mode 100755 index 0000000..1c200f4 --- /dev/null +++ b/dataStore/modules/raw/pullAndStoreGetProcVersion.py @@ -0,0 +1,38 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +fetch data related to GetProcVersion from lepd by lepdClient and +store the returned data into the influxDB by influxDBClient. +''' +def pullAndStoreGetProcVersion(lepdClient, influxDbClient): + res = lepdClient.sendRequest('GetProcVersion') + + + json_body = [ + { + "measurement": "GetProcVersion", + "tags": { + # the address of lepd + "server": lepdClient.server + }, + # "time": "2017-03-12T22:00:00Z", + "fields": { + "LinuxVersion": res['result'] + } + } + ] + + influxDbClient.write_points(json_body) + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + pullAndStoreGetProcVersion(lepdClient, influxDbClient) + time.sleep(1) diff --git a/dataStore/modules/run.py b/dataStore/modules/run.py new file mode 100644 index 0000000..69f8259 --- /dev/null +++ b/dataStore/modules/run.py @@ -0,0 +1,20 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient +from dataStore.modules.cpu.pullAndStoreGetCmdMpstat import pullAndStoreGetCmdMpstat +from dataStore.modules.memory.pullAndStoreGetProcMeminfo import pullAndStoreGetProcMeminfo +from dataStore.modules.io.pullAndStoreGetCmdIostat import pullAndStoreGetCmdIostat + +import time + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(120): + pullAndStoreGetCmdIostat(lepdClient,influxDbClient) + pullAndStoreGetProcMeminfo(lepdClient,influxDbClient) + pullAndStoreGetCmdMpstat(lepdClient,influxDbClient) + time.sleep(1) diff --git a/dataStore/myGUI/__init__.py b/dataStore/myGUI/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dataStore/myGUI/mywindows b/dataStore/myGUI/mywindows new file mode 100644 index 0000000..0e3a10c --- /dev/null +++ b/dataStore/myGUI/mywindows @@ -0,0 +1,59 @@ +from tkinter import * +import tkinter.messagebox as messagebox + +class config(Frame): + def __init__(self,master=None): + Frame.__init__(self, master) + self.pack() + self.createWidgets() + def createWidgets(self): + self.ipLabel = Label(self, text="ipAddress:") + self.ipLabel.pack() + self.ipInput = Entry(self) + self.ipInput.pack() + self.portLabel = Label(self,text="port:") + self.portLabel.pack() + self.portInput= Entry(self) + self.portInput.pack() + + + +class Application(Frame): + def __init__(self, master=None): + self.username="admin" + self.password="admin" + Frame.__init__(self, master) + self.pack() + self.createWidgets() + + + + def createWidgets(self): + self.name = Label(self,text='username') + self.name.pack() + self.nameInput = Entry(self) + self.nameInput.pack() + self.passwd = Label(self, text='password') + self.passwd.pack() + self.passwdInput = Entry(self) + self.passwdInput.pack() + + self.alertButton = Button(self, text='login', command=self.hello) + self.alertButton.pack() + + def hello(self): + + name = self.nameInput.get() + passwd = self.passwdInput.get() + if(name==self.username and passwd==self.password): + app1 = config() + app1.master.title('config') + app1.mainloop() + else: + messagebox.showerror("error","login error") + +app = Application() +# 设置窗口标题: +app.master.title('store') +# 主消息循环: +app.mainloop() \ No newline at end of file diff --git a/dataStore/query/__init__.py b/dataStore/query/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dataStore/query/memory/__init__.py b/dataStore/query/memory/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dataStore/query/memory/queryGetProcMeminfo.py b/dataStore/query/memory/queryGetProcMeminfo.py new file mode 100644 index 0000000..be7dcfd --- /dev/null +++ b/dataStore/query/memory/queryGetProcMeminfo.py @@ -0,0 +1,23 @@ +__author__ = "李旭升 " +__copyright__ = "Licensed under GPLv2 or later." + + +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +import time + +''' +从InfluxDB中查询memory信息 +拼接字段还未完成 +''' +def queryGetProcMeminfo(influxDbClient): + res = influxDbClient.query('select * from GetProcMeminfo limit 1') + print(res) + # help(res) + + return None + +if(__name__=='__main__'): + influxDbClient = MyInfluxDbClient('127.0.0.1') + queryGetProcMeminfo(influxDbClient) + diff --git a/dataStore/runall.py b/dataStore/runall.py new file mode 100644 index 0000000..db372d5 --- /dev/null +++ b/dataStore/runall.py @@ -0,0 +1,35 @@ +__author__ = "" +__copyright__ = "Licensed under GPLv2 or later." + +from dataStore.lepdClient.LepdClient import LepdClient +from dataStore.influxDbUtil.dbUtil import MyInfluxDbClient + +from dataStore.modules.cpu.pullAndStoreGetCmdMpstat import pullAndStoreGetCmdMpstat +from dataStore.modules.io.pullAndStoreGetCmdIostat import pullAndStoreGetCmdIostat +from dataStore.modules.memory.pullAndStoreGetProcMeminfo import pullAndStoreGetProcMeminfo + + + +from dataStore.modules.others.pullAndStoreGetCmdDf import pullAndStoreGetCmdDf +from dataStore.modules.others.pullAndStoreGetCmdDmesg import pullAndStoreGetCmdDmesg +from dataStore.modules.others.pullAndStoreGetCmdFree import pullAndStoreGetCmdFree +from dataStore.modules.others.pullAndStoreGetCmdIotop import pullAndStoreGetCmdIotop +from dataStore.modules.others.pullAndStoreGetCmdIrqInfo import pullAndStoreGetCmdIrqInfo + + + + +import time + + +if (__name__ == '__main__'): + lepdClient = LepdClient('localhost') + influxDbClient = MyInfluxDbClient('localhost') + for i in range(1): + + pullAndStoreGetCmdIostat(lepdClient,influxDbClient) + pullAndStoreGetProcMeminfo(lepdClient,influxDbClient) + pullAndStoreGetCmdMpstat(lepdClient,influxDbClient) + + + time.sleep(1)