Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#IDE
.idea/
124 changes: 0 additions & 124 deletions .idea/uiDesigner.xml

This file was deleted.

2 changes: 1 addition & 1 deletion app/modules/lepd/LepDClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pprint
import re
import datetime
import click
import clock

class LepDClient:

Expand Down
44 changes: 44 additions & 0 deletions dataStore/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
Empty file.
26 changes: 26 additions & 0 deletions dataStore/influxDbUtil/dbUtil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Core module for interacting with influxDB"""

__author__ = "<programmerli@foxmail.com>"
__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)
66 changes: 66 additions & 0 deletions dataStore/lepdClient/LepdClient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""Core module for interacting with LEPD"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why another LepdClient? we already have one, we should use that.


__author__ = "Copyright (c) 2016, 李旭升 <programmerli@foxmail.com>"
__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())
Empty file.
Empty file added dataStore/modules/__init__.py
Empty file.
Empty file.
57 changes: 57 additions & 0 deletions dataStore/modules/cpu/pullAndStoreGetCmdMpstat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
__author__ = "<programmerli@foxmail.com>"
__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)


44 changes: 44 additions & 0 deletions dataStore/modules/influx
Original file line number Diff line number Diff line change
@@ -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


Empty file.
Loading