5 #ifndef __NDMC_METRIC_H_ 6 #define __NDMC_METRIC_H_ 10 #include <sys/times.h> 11 #include <boost/algorithm/string.hpp> 13 #include "NovaDAQMonitorClient/Ndmc.h" 14 #include "NovaDAQMonitorClient/NdmcMetricABC.h" 15 #include "NovaDAQMonitorClient/NdmcClientService.h" 39 friend class ::NdmcMetricTest;
40 friend class ::NdmcClientTest;
46 int32_t maxdeltatime=30, int32_t lifetime=60, ganglia_slope_t slope=GANGLIA_SLOPE_BOTH,
126 int32_t maxDeltaTime, int32_t lifeTime, ganglia_slope_t slope,
142 _gMetric = Ganglia_metric_create(globalContext);
143 std::ostringstream oss;
146 <<
"NdmcMetric::ctor - Unable to allocate gmetric structure for metric " 151 oss <<
"NdmcMetric::ctor - Constructed metric " << name.c_str();
155 clock_t wall =
times(&ctime);
164 if ( !title.empty() )
setTitle(title);
282 Ganglia_metadata_add(
_gMetric, (
char*)
"TITLE", (
char*)
_title.c_str());
314 std::ostringstream oss;
345 if ( weight > 0.)
_nw += 1;
370 ::mf::LogError(
"NdmcMetric") <<
"NdmcMetric::setValue - has unknown metric type " <<
389 clock_t lastSendTime = 0;
395 std::stringstream ssval;
399 (
char*)ssval.str().c_str(),(
char*)
getType().c_str(),
404 ::mf::LogError(
"NdmcMetric") <<
"NdmcMetric::send - gmetric parameters invalid for metric: " 409 <<
"NdmcMetric::send - one of the gmetric parameters has an invalid character for metric: " 414 <<
"gmetric type parameter is not a valid type for metric: " 419 <<
"NdmcMetric::send - gmetric value parameter does not represent a number for metric: " 428 LOG_DEBUG(
"NdmcMetric") <<
"NdmcMetric::send() - send value " << sendValue <<
" for metric " 430 rval = Ganglia_metric_send(
_gMetric,sendChannels);
432 ::mf::LogError(
"NdmcMetric") <<
"NdmcMetric::send - Error sending to " << rval
466 if ( timeSinceLastSend != 0 ) sendValue =
T(
double(
_value)/timeSinceLastSend);
483 ::mf::LogError(
"NdmcMetric") <<
"NdmcMetric::_calculateSendValue - unknown metric type " <<
501 if (
typeid(
T) ==
typeid(int8_t) )
return "int8";
502 else if (
typeid(
T) ==
typeid(uint8_t) )
return "uint8";
503 else if (
typeid(
T) ==
typeid(int16_t) )
return "int16";
504 else if (
typeid(
T) ==
typeid(uint16_t) )
return "uint16";
505 else if (
typeid(
T) ==
typeid(int32_t) )
return "int32";
506 else if (
typeid(
T) ==
typeid(uint32_t) )
return "uint32";
507 else if (
typeid(
T) ==
typeid(
float) )
return "float";
508 else if (
typeid(
T) ==
typeid(
double) )
return "double";
524 currenttime =
times(&ctime);
525 double deltaw = ((double)(currenttime -
_lastSendTime))*10000./CLOCKS_PER_SEC;
void setPartition(int32_t partition)
#define LOG_DEBUG(stream)
NdmcMetric(std::string name, std::string unit="", MetricType_t metricType=VALUE, int32_t maxdeltatime=30, int32_t lifetime=60, ganglia_slope_t slope=GANGLIA_SLOPE_BOTH, int32_t partition=-1, std::string appName="", std::string groupName="", std::string title="", std::string desc="")
std::string getName() const
Ganglia_pool_t getGlobalContext() const
Ganglia_udp_send_channels_t getSendChannels() const
#define NDMC_NAMESPACE_BEGIN
std::string _applicationName
std::string getDescription() const
int32_t getMaxDeltaTime() const
ganglia_slope_t getSlope() const
std::string _getType() const
enum MetricType MetricType_t
void setTitle(std::string title)
MetricType_t getMetricType() const
double _timeSinceLastSend(clock_t ¤twalltime)
std::string getTitle() const
#define NDMC_NAMESPACE_END
const XML_Char int const XML_Char * value
std::string getGroupName() const
bool setValue(T value, double weight=1., int npar=0, double *par=0)
std::string getType() const
static NdmcClientService & instance()
std::string getUnit() const
void setDescription(std::string description)
Ganglia_metric_t _gMetric
bool _calculateSendValue(T &sendValue, double timeSinceLastSend=0)
void setApplicationName(std::string appName)
int32_t getPartition() const
std::string getApplicationName() const
std::string getMetricName() const
int32_t getLifeTime() const
void setGroupName(std::string groupName)
bool getLastValueSent(T &lastValueSent) const
double getSumWXSq() const