Commit 8e970855 authored by cvs2svn's avatar cvs2svn
Browse files

This commit was manufactured by cvs2svn to create tag

'GAUDI_v19r3-pre'.

git-svn-id: svn+ssh://svn.cern.ch/reps/gaudi/distribution/tags/GAUDI/GAUDI_v19r3-pre@3785 53ecefc3-a64d-0410-9bdf-b8581fa3287e
parent 649a36b3
package GaudiMonitor
version v1r0
branches src cmt doc
use GaudiKernel v*
# build the component library
library GaudiMonitor \
DataListenerSvc/*.cpp \
Dll/GaudiMonitor*.cpp
# define component library link options
apply_pattern component_library library=GaudiMonitor
macro_append GaudiMonitor_use_linkopts " -pthread " \
WIN32 ""
private
macro_append cppflags "" \
Linux " -pedantic -Wwrite-strings -Wpointer-arith -Woverloaded-virtual -Wno-long-long " \
Darwin "" \
WIN32 ""
Package: GaudiMonitor
Package manager : Hubert Degaudenzi
================ GaudiMonitor v1r0 ==========================================
! 2007-01-15 - Hubert Degaudenzi
New package.
!============================================================================
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#ifndef GAUDIKERNEL_DATALISTENERSVC_H
#define GAUDIKERNEL_DATALISTENERSVC_H
#include "GaudiKernel/Service.h"
#include "GaudiKernel/IIncidentSvc.h"
#include "GaudiKernel/IMonitorSvc.h"
#include "GaudiKernel/IIncidentListener.h"
#include "ValueMap.h"
#include "XmlCode.h"
#include "ApMon.h"
#include <iostream>
#include <fstream>
#include <ctime>
#include <string>
#include <map>
#include <set>
#include <stdio.h>
// Forward declarations
class ISvcLocator;
/** @class DataListenerSvc DataListenerSvc.h bking/DataListenerSvc.h
*
* DataListenerSvc inherits from IMonitorSvc and allows the GAUDI user to monitor
* variables declared in an algorithm. DataListenerSvc generates XML files on the
* individual machines where the algorithm is run, which can then be parsed by e.g.
* GANGA and sent to a monitoring server such as MonALISA. XML files are written at
* a frequency specified by the user and are consumed as they are created when used
* within GANGA.
*
* @subpage Usage
*
* \par In Algorithm header file
*
* \li Include DataListenerSvc <tt> #include DataListenerSvc/DataListenerSvc.h </tt>
* \li define IMonitorSvc object: e.g. <tt> IMonitorSvc *m_DataListenerSvcSvc; </tt>
*
* \par In Algorithm cpp file
*
* \li instantiate IMonitorSvc object: e.g. <tt> sc = service("DataListenerSvc", m_DataListenerSvcSvc, true);</tt>
* \li declare monitored variables: e.g.
* <tt> m_DataListenerSvcSvc->declareInfo("Psi ID", m_jPsiID, "The Psi ID", this); </tt> (for variable \c m_jPsiID)
*
* Supports declaration of variables of type: <tt> int, long, bool, double, string </tt>
*
* \par In GAUDI options file
*
* \li Include DLL in ApplicationMgr.DLLs \c DataListenerSvc
* \li Include Service in ApplicationMgr.ExtSvc \c DataListenerSvc/DataListenerSvc
* \li Set job options e.g. <tt> DataListenerSvc.EventFrequency = 50 </tt>
*
* \par Job options available
* @param EventFrequency How data is sent to - default is <em> every 100 events </em>
*
* <hr>
* \par XML file format
*
*
* XML tag format is the following:
*
* Opening parent tags of the form:
*
* <tt>\<?xml version="1.0" encoding="ASCII" standalone="yes"?\></tt>\n
* <tt>\<Results Time="Tue Aug 22 10:17:22 2006"\></tt>
* <table border=0>
* <tr>
* <td>&nbsp; &nbsp; &nbsp; &nbsp;</td>
* <td><tt>\<Run\></tt></td>
* </tr>
* </table>
*
* With then an entry for each monitored variable of the form:\n
*
*
* <table border=0>
* <tr>
* <td>&nbsp; &nbsp; &nbsp; &nbsp;</td>
* <td><tt>\<Incident\></tt> </td>
* <td></td>
* </tr>
* <tr>
* <td>&nbsp; &nbsp; &nbsp; &nbsp;</td>
* <td>&nbsp; &nbsp; &nbsp; &nbsp;</td>
* <td>
* <tt>\<IncType\>EndEvent \</IncType\> </tt> \n
* <tt>\<IncSource\>EventLoopMgr \</IncSource\> </tt>\n
* <tt>\<VarName\>Psi ID \</VarName\> </tt>\n
* <tt>\<Value Result="8"\>443\</Value\> </tt>
* </td>
* </tr>
* <tr>
* <td>&nbsp; &nbsp; &nbsp; &nbsp;</td>
* <td><tt>\</Incident\></tt> </td>
* <td></td>
* </tr>
* </table>
*
* @param IncType What type of incident triggered the handle method
* @param IncSource What triggered the IIncident handle method
* @param VarName Name of the variable monitored
* @param Value Value of the variable
* @param Result Number of times the variable already read
*
* @author Ben KING
* @date 2006-08-24
*/
class DataListenerSvc : public Service,
virtual public IMonitorSvc,
virtual public IIncidentListener {
public:
DataListenerSvc(const std::string& name, ISvcLocator* sl);
virtual ~DataListenerSvc() {}
//IInterface pure virtual member functions
StatusCode queryInterface(const InterfaceID& riid, void** ppvIF);
// Service pure virtual member functions
StatusCode initialize();
StatusCode finalize();
/** Declare monitoring information
@param name Monitoring information name known to the external system
@param var Monitoring Listener address
@param desc Textual description
@param owner Owner identifier of the monitoring information
(needed to peform clean up
*/
void declareInfo(const std::string& name, const bool& var,
const std::string& desc, const IInterface* owner) ;
void declareInfo(const std::string& name, const int& var,
const std::string& desc, const IInterface* owner) ;
void declareInfo(const std::string& name, const long& var,
const std::string& desc, const IInterface* owner) ;
void declareInfo(const std::string& name, const double& var,
const std::string& desc, const IInterface* owner) ;
void declareInfo(const std::string& name, const std::string& var,
const std::string& desc, const IInterface* owner) ;
void declareInfo(const std::string& name, const std::pair<double,double>&var,
const std::string& desc, const IInterface* owner) ;
void declareInfo(const std::string& name, const AIDA::IBaseHistogram* var,
const std::string& desc, const IInterface* owner) ;
void declareInfo(const std::string& name, const std::string& format,
const void * var, int size, const std::string& desc,
const IInterface* owner) ;
// Declaration of declareProperty which is virtual in one of my includes
// (that would be service.h)
// StatusCode declareProperty(const std::string& name, const int& var);
/** Undeclare monitoring information
@param name Monitoring information name known to the external system
@param owner Owner identifier of the monitoring information
*/
void undeclareInfo( const std::string& name, const IInterface* owner ) ;
/** Undeclare monitoring information
@param owner Owner identifier of the monitoring information
*/
void undeclareAll( const IInterface* owner ) ;
/// Implementation of the IIncidentListener.h virtual method
virtual void handle(const Incident&);
/** Get the names for all declared monitoring informations for a given
owner. If the owner is NULL, then it returns for all owners
*/
std::set<std::string> * getInfos(const IInterface* owner = 0);
/** Send (key,value) pairs to MonALISA server
@param clusterName Name of cluster where information will be stored
@param moduleName Name of module where information will be stored
@param key Key of the (key,value) pair sent to MonALISA
@param value Value of the (key,value) pair sent to MonALISA
*/
/// Send a (char*,double) pair to MonALISA
void apmSend(char* clusterName, char* moduleName, char* key, double val);
/// Send a (char*,int) pair to MonALISA
void apmSend(char* clusterName, char* moduleName, char* key, int val);
/// Send a (char*,long) pair to MonALISA
void apmSend(char* clusterName, char* moduleName, char* key, long val);
/// Send a (char*,bool) pair to MonALISA
void apmSend(char* clusterName, char* moduleName, char* key, bool val);
/// Send a (char*,char*) pair to MonALISA
void apmSend(char* clusterName, char* moduleName, char* key, char* val);
private:
ApMon *apm;
// ValueMap stores declared data information
ValueMap m_ValueMap;
ValueMap m_ValueMapTemp;
time_t rawTime;
time_t rawTime2;
char buffer[50];
char buffer2[50];
std::string timeDate;
std::string timeDate2;
std::string valToWrite;
// Used to hold variable name and data information
typedef std::pair< std::string, ValueMap > Entry;
typedef std::map<const IInterface*, std::set<std::string> > InfoNamesMap;
typedef std::map< std::string, ValueMap > ValNamesMap;
void writeMap(ValNamesMap*, const Incident&, std::ofstream*);
void writeXML(ValNamesMap*, const Incident&, std::ofstream*);
std::string resizeString ( const std::string, const unsigned int );
// Converts types INTO a string with a stringstream
std::string stringConverter ( const int convertee );
std::string stringConverter ( const double convertee );
std::string stringConverter ( const bool convertee );
std::string stringConverter ( const long convertee );
InfoNamesMap m_InfoNamesMap;
InfoNamesMap::iterator m_InfoNamesMapIt;
ValNamesMap m_ValNamesMap;
ValNamesMap::iterator m_ValNamesMapIt;
XmlCode xml;
// Map associating to each algorithm name a set with the info
// names from this algorithm
IIncidentSvc* m_incidentSvc;
FILE* MonitorLog;
std::ofstream Log4;
std::ofstream XMLLog;
int FreqCriterion;
int m_EventFrequency;
/// MonALISA sender method to send Data to MonALISA server
void sendData(ValNamesMap*);
// The container below is necessary because usually the descriptions of
// the services are constant strings, not variables. DimService expects
// a variable address to monitor as its second argument and we are using
// a DimService for strings to publish the descriptions.
std::map<std::string,std::string> m_infoDescriptions;
std::string infoOwnerName( const IInterface* owner );
// MonALISA optionsfile variables
int m_MLjobID;
int m_MLEventFrequency;
std::string m_MLClusterName;
std::string m_ApMonSettingsFile;
std::string jobIDString;
int m_MonALISAMonitoring;
int m_XMLMonitoring;
int m_FileMonitoring;
char *keyToSend;
};
#endif // GAUDIKERNEL_DATALISTENERSVC_H
#ifndef DATALISTENERSVC_VALUEMAP_H
#define DATALISTENERSVC_VALUEMAP_H 1
// Include files
// from STL
#include <string>
/** @class ValueMap ValueMap.h Scouter/ValueMap.h
*
* ValueMap is used in conjunction with Scouter and MLSender to carry the information declared by IMonitorSvc's declareInfo.
* It converts the variable to a void* pointer and stores its type information in an enum. This way, the variable can be converted
* to its original form when being written or published.
*
* @author Ben King
* @date 2006-07-03
*/
class ValueMap {
public:
enum m_type {
m_int,
m_long,
m_double,
m_bool,
m_string,
m_null
};
/// standard Constructor
ValueMap (void *pointer, m_type pointerType)
{
ptr = pointer;
ptrType = pointerType;
}
/// default Constructor
ValueMap()
{
ptr = NULL;
ptrType = m_null;
}
/// Destructor
virtual ~ValueMap() {};
// SET METHODS
/// Sets pointer
void set_ptr(void *pointer) { ptr = pointer;}
/// Sets pointer type (enum)
void set_ptrType (m_type pointerType) { ptrType = pointerType; }
// ACCESS METHODS
/// Return pointer
void* get_ptr() { return ptr; }
/// Return pointer type (enum)
m_type get_ptrType() { return ptrType; }
private:
void* ptr;
m_type ptrType;
};
#endif // DATALISTENERSVC_VALUEMAP_H
// $Id: XmlCode.h,v 1.1.1.1 2007/01/15 13:56:38 hmd Exp $
#ifndef DATALISTENERSVC_XMLCODE_H
#define DATALISTENERSVC_XMLCODE_H 1
#include <iostream>
// Include files
/** @class XmlCode XmlCode.h DataListenerSvc/XmlCode.h
*
* XmlCode contains methods to write out XML tags. It is used in conjunction with DataListenerSvc to create the XML log files
* which can be subsequently later parsed. Indent levels are specified manually by the user who must make sure everything is
* consistent.
*
* @author Ben King
* @date 2006-07-06
*/
//template <class Type> class XmlStream {
class XmlCode {
public:
/// Standard constructor
XmlCode() {};
/// Destructor
virtual ~XmlCode() {};
/** returns an opening XML tag
* @param data Name of the tag
* @param level Amount of indenting to print, i.e. what generation of tag
* @param attribute Attribute to include in tag (if used)
* @param val Value of the Attribute (if used)
* with this class.
*/
/// Return an opening XML tag which takes "attribute:value" pair
std::string tagBegin(std::string data, int level, std::string attribute, std::string val)
{
std::string indent="";
for (int i=0; i<level; i++){
indent = indent + " ";
}
return "\n" + indent + "<" + data + " " + attribute + "=\"" + val + "\">"; // A start tag will start a line
}
/// return an opening XML tag
std::string tagBegin(std::string data, int level)
{
std::string indent="";
for (int i=0; i<level; i++){
indent = indent + " ";
}
return "\n" + indent + "<" + data + ">"; // A start tag will start a line
}
/// return a closing XML tag
/**
* Will return a new line if the tag is given any indent, i.e. it is a parent tag
*/
std::string tagEnd(std::string data, int level)
{
if (level != 0) {
std::string indent="";
for (int i=0; i<level; i++){
indent = indent + " ";
}
return "\n" + indent + "</" + data + ">\n";
}
else {
return "</" + data + ">"; // An end tag will end a line
}
}
/// Return just the data given to the function
std::string data(std::string data)
{
return data; // Data will come after a string so no new line
}
// XML declaration
/** XML declaration
*
* @param vers XML version number
* @param cod XML encoding
* @param stand XML standalone
*
*/
std::string declaration(std::string vers, std::string cod, std::string stand)
{
return "<?xml version=\"" + vers + "\" encoding=\"" + cod + "\" standalone=\"" + stand + "\"?>";
}
protected:
private:
std::string tag;
};
#endif // DATALISTENERSVC_XMLCODE_H
/**
* \file mon_constants.cpp
* Here we define the names of the parameters provided by the automatic
* job and system monitoring.
*/
/*
* ApMon - Application Monitoring Tool
* Version: 2.2.0
*
* Copyright (C) 2006 California Institute of Technology
*
* Permission is hereby granted, free of charge, to use, copy and modify
* this software and its documentation (the "Software") for any
* purpose, provided that existing copyright notices are retained in
* all copies and that this notice is included verbatim in any distributions
* or substantial portions of the Software.
* This software is a part of the MonALISA framework (http://monalisa.cacr.caltech.edu).
* Users of the Software are asked to feed back problems, benefits,
* and/or suggestions about the software to the MonALISA Development Team
* (developers@monalisa.cern.ch). Support for this software - fixing of bugs,
* incorporation of new features - is done on a best effort basis. All bug
* fixes and enhancements will be made available under the same terms and
* conditions as the original software,
* IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
* EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS
* PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
* OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
* MODIFICATIONS.
*/
#include "mon_constants.h"
int initSysParams(char *sysMonitorParams[])
{
/* percent of the time spent by the CPU in user mode */
sysMonitorParams[SYS_CPU_USR] = (char *)"cpu_usr";
/* percent of the time spent by the CPU in system mode */
sysMonitorParams[SYS_CPU_SYS] = (char *)"cpu_sys";
/* percent of the CPU idle time */
sysMonitorParams[SYS_CPU_IDLE] = (char *)"cpu_idle";
/* percent of the time spent by the CPU in nice mode */
sysMonitorParams[SYS_CPU_NICE] = (char *)"cpu_nice";
/* CPU usage percent */
sysMonitorParams[SYS_CPU_USAGE] = (char *)"cpu_usage";
/* number of pages paged in (in the last interval) */
sysMonitorParams[SYS_PAGES_IN] = (char *)"pages_in";
/* number of pages paged out (in the last interval) */
sysMonitorParams[SYS_PAGES_OUT] = (char *)"pages_out";
/* number of swap pages brought in (in the last interval) */;
sysMonitorParams[SYS_SWAP_IN] = (char *)"swap_in";
/* number of swap pages brought out (in the last interval) */;
sysMonitorParams[SYS_SWAP_OUT] = (char *)"swap_out";
/* average system load over the last minute */
sysMonitorParams[SYS_LOAD1] = (char *)"load1";
/* average system load over the last 5 min */
sysMonitorParams[SYS_LOAD5] = (char *)"load5";
/* average system load over the last 15 min */;
sysMonitorParams[SYS_LOAD15] = (char *)"load15";
/* amount of currently used memory, in MB */
sysMonitorParams[SYS_MEM_USED] = (char *)"mem_used";
/* amount of free memory, in MB */
sysMonitorParams[SYS_MEM_FREE] = (char *)"mem_free";
/* used system memory in percent */
sysMonitorParams[SYS_MEM_USAGE] = (char *)"mem_usage";
/* amount of currently used swap, in MB */
sysMonitorParams[SYS_SWAP_USED] = (char *)"swap_used";
/* amount of free swap, in MB */
sysMonitorParams[SYS_SWAP_FREE] = (char *)"swap_free";
/* swap usage in percent */
sysMonitorParams[SYS_SWAP_USAGE] = (char *)"swap_usage";
/* network (input) transfer in KBps */
sysMonitorParams[SYS_NET_IN] = (char *)"net_in";
/* network (output) transfer in KBps */
sysMonitorParams[SYS_NET_OUT] = (char *)"net_out";
/* number of network errors */
sysMonitorParams[SYS_NET_ERRS] = (char *)"net_errs";
/* number of processes in the system */
sysMonitorParams[SYS_PROCESSES] = (char *)"processes";
/* system uptime in days */
sysMonitorParams[SYS_UPTIME] = (char *)"uptime";
/* number of sockets */
sysMonitorParams[SYS_NET_SOCKETS] = (char *)"net_sockets";
/* number of TCP sockets in different states */
sysMonitorParams[SYS_NET_TCP_DETAILS] = (char *)"net_tcp_details";
return 25;
}