artdaq_ganglia_plugin  v1_02_14a
ganglia_metric.cc
1 //ganglia_metric.cc: Ganglia Metric Plugin
2 // Author: Eric Flumerfelt
3 // Last Modified: 11/14/2014
4 //
5 // An implementation of the MetricPlugin interface for Ganglia
6 
7 #ifndef __GANGLIA_METRIC__
8 #define __GANGLIA_METRIC__ 1
9 
10 #include "fhiclcpp/fwd.h"
11 #include "artdaq-utilities/Plugins/MetricMacros.hh"
12 #include "send_gmetric.h"
13 
17 namespace artdaq
18 {
22  class GangliaMetric : public MetricPlugin
23  {
24  private:
25  std::string configFile_;
26  std::string group_;
27  std::string cluster_;
28 
29  public:
35  explicit GangliaMetric(fhicl::ParameterSet const& pset, std::string const& app_name) : MetricPlugin(pset, app_name)
36  , configFile_(pset.get<std::string>("configFile", "/etc/ganglia/gmond.conf"))
37  , group_(pset.get<std::string>("group", "ARTDAQ"))
38  , cluster_(pset.get<std::string>("cluster", ""))
39  {
40  init_gmetric(configFile_.c_str());
41  }
42 
43  virtual ~GangliaMetric()
44  {
45  MetricPlugin::stopMetrics();
47  }
48 
53  std::string getLibName() const override { return "ganglia"; }
57  void stopMetrics_() override { }
61  void startMetrics_() override { }
62 
69  void sendMetric_(const std::string& name, const std::string& value, const std::string& unit) override
70  {
71  send_gmetric(name.c_str(), value.c_str(), "string",
72  unit.c_str(), "both", 15, 0, group_.c_str(), cluster_.c_str(), "", "");
73  }
74 
81  void sendMetric_(const std::string& name, const int& value, const std::string& unit) override
82  {
83  send_gmetric(name.c_str(), std::to_string(value).c_str(),
84  "int32", unit.c_str(), "both", 15, 0, group_.c_str(), cluster_.c_str(), "", "");
85  }
86 
93  void sendMetric_(const std::string& name, const double& value, const std::string& unit) override
94  {
95  send_gmetric(name.c_str(), std::to_string(value).c_str(),
96  "double", unit.c_str(), "both", 15, 0, group_.c_str(), cluster_.c_str(), "", "");
97  }
98 
105  void sendMetric_(const std::string& name, const float& value, const std::string& unit) override
106  {
107  send_gmetric(name.c_str(), std::to_string(value).c_str(),
108  "float", unit.c_str(), "both", 15, 0, group_.c_str(), cluster_.c_str(), "", "");
109  }
110 
117  void sendMetric_(const std::string& name, const unsigned long int& value, const std::string& unit) override
118  {
119  send_gmetric(name.c_str(), std::to_string(value).c_str(),
120  "uint32", unit.c_str(), "both", 15, 0, group_.c_str(), cluster_.c_str(), "", "");
121  }
122  };
123 } //End namespace artdaq
124 
125 DEFINE_ARTDAQ_METRIC(artdaq::GangliaMetric)
126 
127 #endif //End ifndef __GANGLIA_METRIC__
std::string getLibName() const override
Gets the unique library name of this plugin.
void sendMetric_(const std::string &name, const double &value, const std::string &unit) override
Send a double metric to Ganglia.
int init_gmetric(const char *conf)
Initialize Ganglia.
Definition: send_gmetric.c:18
void stopMetrics_() override
Ganglia does not need any specific action on stop.
void destroy_gmetric()
Close connection to gmond.
Definition: send_gmetric.c:48
void sendMetric_(const std::string &name, const float &value, const std::string &unit) override
Send a float metric to Ganglia.
GangliaMetric(fhicl::ParameterSet const &pset, std::string const &app_name)
Construct an instance of the Ganglia metric.
int send_gmetric(const char *name, const char *value, const char *type, const char *units, const char *slope, int tmax, int dmax, const char *group, const char *cluster, const char *desc, const char *title)
Send a metric to gmond.
Definition: send_gmetric.c:53
void sendMetric_(const std::string &name, const std::string &value, const std::string &unit) override
Send a string metric to Ganglia.
void sendMetric_(const std::string &name, const int &value, const std::string &unit) override
Send a integer metric to Ganglia (truncated to int32)
An instance of the MetricPlugin class that sends metric data to Ganglia.
void startMetrics_() override
Ganglia does not need any specific action on start.
void sendMetric_(const std::string &name, const unsigned long int &value, const std::string &unit) override
Send an unsigned long metric to Ganglia (truncated to uint32)