Requirements
- Python 2.4 or later
- RRDTool
- MySQL
- Other python modules:
a) matplotlib
b) pyrrdTool
c) numpy
d) pysnmp
e) pysqlite
f)SQLAlchemy
Modules
Currently, existing python scripts are:
- storeCons.py : this scrip has as a function to get the values of power consumption of the data center's machines in real-time via SNMP (Simple Network Management Protocol) and to store them in the database .
NB: A cron job for this script is lunched every 5 minutes
- getLoadFromRRD.py : this is the python script for moving average load values from rrd databases to the PowerMon SQL database
NB: A cron job for this script is lunched every hour
- updateDb.py : update the database1 with the two configuration files: f_config_machines.cfg and f_config_pdus.cfg :
performs adding new pdu or a new machine to the database, and modifying their characteristics.
NB: The table 'PDU' must be modified before the table 'machine' because of foreign keys raisons
- viewCons.py The vizualisation script, that generates different plots via python plotting library
MatplotLib
,representing the power consumption and the average load of a machine during a certan period of time. This vizualisation tool is not finished yet1: PowerMon project supports all types of databases that are tolerated by sqlAlchemy (sqlite,mysql,posgresql,oracle...) Therefore, we can specify which database we want to connect to , in the default section of f_config_pdus.cfg
Classes
1. DbConn Objects: A DbConn object is responsible of database connection management and all the interactions with it, DbConn class is
implemented in module dbConn.py
Constructor:
- class DbConn(dbName,dbType,username,password,host,port):
dbName,dbType,username,password,host,port
are string arguments specified in the configuration file : f_config_pdu.cfg on section default
In PowerMon V1, "dbType" is either 'sqlite' or 'mysql' : other types may also be supported provided that they are supported by sqlAlchemy and that this constructor is appropriately modified
All class methods:
create_tables() :
Have to be called once, to create Powermon tables corresponding to the the following database schema :
updatePDUtable(fConfigPDU):
Collects changes(add or modify existing pdu) from config file f_config_pdus.cfg and updates the table "PDU"
updateMachineTable(fConfigMachines):
Does the same job asupdatePDUtable()
for table "machine"
getIdOutlet(nomPDU,numOutlet):
Returns outlet ID of the outlet numbernumOutlet
belonging to pdunomPDU
viewDb():
Prints the contents of tables : Outlet, machine and PDU
storeCons(nomMachine,cons,date):
Inserts a new line in the table powerCons
viewTableMachine():
Display only the table : machine
viewMachineCons(nomMachine):
Prints the power consumption values of the machine "nomMachine" whith the corresponding dates
getPDUs():
Returns a list of python dictionaries , representing the PDUs registred in the database
getNomMachine(numOutlet,IdPDU):
Get the machine pluged-in on the outlet number "numOutlet" of the PDU whose Id is "IdPDU"
getMachines_Names():
Returns a list of all machines' names registred in the database
getPduMachines(pduName):
Returns a set of machines' names correspondint to the connected machines to PDU "pduName"
getCons(nomMachine,start_date,end_date):
Returns a set of machine "nomMachine"'s power consumption values from "start_date" to "end_date" and
another set of the corresponding dates
getIdMachine(machineName):
Returns the Id of the machine named "machineName"
getLastLoadDate(IdMachine):
Returns the most recent date in table "cpu_charge" where the machine Id is "IdMachine"
storeLoad(IdMachine,dateList,avg1mn_list,avg5mn_list,avg15mn_list):
Inserts a new line to the table cpu_charge whith the given entry values
viewMachineLoad(nomMachine):
Prints the load values of the machine "nomMachine" whith the corresponding dates
2. PDU Objects: A PDU object allows connexion to a supervisable pdu and extraction of machines' power consumption data , pdu class is
implemented in module pdu_snmp.py
Constructor:
- class PDU(nom,hostName,rootOID,nbOutlets,port,community,snmpVersion) :
nom,hostName,rootOID,nbOutlets,port,community,snmpVersion
are arguments collected from the table PDU , which can be modified by the file: f_config_pdu.cfg .
All class methods:
getData(no_outlet):
Performs asynchronous snmp Get and returns real time consumption value on outlet number "no_outlet"
getSetOfData():
Performs snmp walk and returns a set of real time consumption values on the PDU; and an integer representing the correponding timestamp.