Pybix
is a lightweight monitor framework, using the Python2.7
language,it contains Client
and Server
.
- Use
RESTful
interface betweenClient
andServer
communication. - Easy for extending the
Pybix
service. - The
Server
is base onFlask
. - Use two database backend include
Mysql
andMongodb
, UsingMysql
for thehost
record andtask
conf, UsingMongodb
for themonitor data
. Pybix
only responsible for monitoring data acquisition and put into database, users can developCURD
portal service to display data.
git clone https://github.com/lioncui/pybix
cd pybix
pip install -r requirements.txt
cd server
Edit config.py
, configure the database
DBUSER = 'root'
DBPASS = '123456'
DBHOST = '127.0.0.1'
DBPORT = '3306'
DBNAME = 'pybix'
DEBUG = False
PORT = 8080
SQLALCHEMY_DATABASE_URI = "mysql+pymysql://%s:%s@%s:%s/%s" % (
DBUSER, DBPASS, DBHOST, DBPORT, DBNAME)
SQLALCHEMY_TRACK_MODIFICATIONS = False
MONGODB_SETTINGS = {'HOST': 'localhost', 'PORT': 27017, 'DB': 'pybix'}
SECRET_KEY = "4RTG2WQSUHEDUJ"
PRE_SHARE_KEY = "7Y5TGH76RFGH6RFGHY5RDCVHY2W34"
Run test
python manage.py runserver
Now already run the pybix-server, If you want to collector monitor data,the following order:
- create the host record.
- create the monitor task.
- run the client agent.py.
Your pybix-server provide services ipaddress
demo: http://127.0.0.1:8080
-
Hosts
GET /hosts
GET /hosts/{mac_address}
POST /hosts
-
Tasks
GET /tasks
GET /tasks/{mac_address}
POST /tasks
-
Meters
GET /meters/{task_uuid}
POST /meters/{task_uuid}
You can refer to
json.example
file in thepybix/server/examples
directory.HTTP Requset Header must specify
Content-Type: application/json
All plug-ins was inherited the parent class p_class.plugins.plugin
,only to refactoring getData
function , after than created a specify pluginFileName
and pluginClassName
for task.
The CustomPlugin.py
demo code:
from lib import pybixlib
import traceback
from p_class import plugins
class CustomPlugin(plugins.plugin):
def __init__(self, uuid, taskConf, agentType):
plugins.plugin.__init__(
self, uuid, taskConf, agentType)
def getData(self):
try:
redata = {"foo": "bar"}
except Exception:
pybixlib.error(self.logHead + traceback.format_exc())
self.errorInfoDone(traceback.format_exc())
redata = {}
finally:
self.setData({'agentType': self.agentType, 'uuid': self.uuid,
'code': self.code, 'time': self.getCurTime(),
'data': redata, 'error_info': self.error_info})
self.intStatus()
Pybix
is licensed under GPL v3. The license is availabe here.