artdaq_ganglia_plugin  v1_02_15
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 "artdaq-utilities/Plugins/MetricMacros.hh"
11 #include "fhiclcpp/fwd.h"
12 #include "send_gmetric.h"
13 
14 #include <boost/filesystem.hpp>
15 namespace bfs = boost::filesystem;
16 
20 namespace artdaq {
24 class GangliaMetric : public MetricPlugin {
25  private:
26  std::string configFile_;
27  std::string group_;
28  std::string cluster_;
29 
30  public:
37  explicit GangliaMetric(fhicl::ParameterSet const& pset, std::string const& app_name)
38  : MetricPlugin(pset, app_name),
39  configFile_(pset.get<std::string>("configFile", "")),
40  group_(pset.get<std::string>("group", "ARTDAQ")),
41  cluster_(pset.get<std::string>("cluster", "")) {
42  if (configFile_ == "" || bfs::exists(configFile_)) {
43  int sts = init_gmetric(configFile_.c_str());
44  if (sts != 0) {
45  throw cet::exception("GangliaMetric") << "Unable to configure Ganglia";
46  }
47  } else {
48  throw cet::exception("GangliaMetric") << "Configuration file " << configFile_ << " does not exist!";
49  }
50  }
51 
52  virtual ~GangliaMetric() {
53  MetricPlugin::stopMetrics();
55  }
56 
61  std::string getLibName() const override { return "ganglia"; }
65  void stopMetrics_() override {}
69  void startMetrics_() override {}
70 
77  void sendMetric_(const std::string& name, const std::string& value, const std::string& unit) override {
78  send_gmetric(name.c_str(), value.c_str(), "string", unit.c_str(), "both", 15, 0, group_.c_str(), cluster_.c_str(),
79  "", "");
80  }
81 
88  void sendMetric_(const std::string& name, const int& value, const std::string& unit) override {
89  send_gmetric(name.c_str(), std::to_string(value).c_str(), "int32", unit.c_str(), "both", 15, 0, group_.c_str(),
90  cluster_.c_str(), "", "");
91  }
92 
99  void sendMetric_(const std::string& name, const double& value, const std::string& unit) override {
100  send_gmetric(name.c_str(), std::to_string(value).c_str(), "double", unit.c_str(), "both", 15, 0, group_.c_str(),
101  cluster_.c_str(), "", "");
102  }
103 
110  void sendMetric_(const std::string& name, const float& value, const std::string& unit) override {
111  send_gmetric(name.c_str(), std::to_string(value).c_str(), "float", unit.c_str(), "both", 15, 0, group_.c_str(),
112  cluster_.c_str(), "", "");
113  }
114 
121  void sendMetric_(const std::string& name, const unsigned long int& value, const std::string& unit) override {
122  send_gmetric(name.c_str(), std::to_string(value).c_str(), "uint32", unit.c_str(), "both", 15, 0, group_.c_str(),
123  cluster_.c_str(), "", "");
124  }
125 };
126 } // End namespace artdaq
127 
128 DEFINE_ARTDAQ_METRIC(artdaq::GangliaMetric)
129 
130 #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:19
void stopMetrics_() override
Ganglia does not need any specific action on stop.
void destroy_gmetric()
Close connection to gmond.
Definition: send_gmetric.c:50
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:52
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)