artdaq_utilities  v1_05_00
msgFacility_metric.cc
1 // msgFacility_metric.cc: Message Facility Metric Plugin
2 // Author: Eric Flumerfelt
3 // Last Modified: 09/29/2015
4 //
5 // An implementation of the MetricPlugin for Message Facility
6 
7 #include "artdaq-utilities/Plugins/MetricMacros.hh"
8 #include "fhiclcpp/ParameterSet.h"
9 #include "messagefacility/MessageLogger/MessageLogger.h"
10 
11 #include <algorithm>
12 #include <iostream>
13 #include <string>
14 
15 namespace artdaq {
20 {
21 private:
22  std::string facility_;
23  int outputLevel_;
24 
25 public:
39  explicit MsgFacilityMetric(fhicl::ParameterSet const& config, std::string const& app_name)
40  : MetricPlugin(config, app_name)
41  , facility_(config.get<std::string>("output_message_category_name", "ARTDAQ Metric"))
42  , outputLevel_(0)
43  {
44  try
45  {
46  outputLevel_ = config.get<int>("output_message_severity", 0);
47  }
48  catch (const cet::exception&)
49  {
50  std::string levelString = config.get<std::string>("output_message_severity", "Info");
51  if (levelString == "Info" || levelString == "info" || levelString == "LogInfo")
52  {
53  outputLevel_ = 0;
54  }
55  else if (levelString == "Debug" || levelString == "debug" || levelString == "LogDebug")
56  {
57  outputLevel_ = 1;
58  }
59  else if (levelString == "Warning" || levelString == "warning" || levelString == "LogWarning" || levelString == "Warn" || levelString == "warn")
60  {
61  outputLevel_ = 2;
62  }
63  else if (levelString == "Error" || levelString == "error" || levelString == "LogError")
64  {
65  outputLevel_ = 3;
66  }
67  }
68  startMetrics();
69  }
70 
79  std::string getLibName() const override { return "msgFacility"; }
80 
87  void sendMetric_(const std::string& name, const std::string& value, const std::string& unit) override
88  {
89  if (!inhibit_)
90  {
91  switch (outputLevel_)
92  {
93  case 0:
94  mf::LogInfo(facility_) << name << ": " << value << " " << unit << "." << std::endl;
95  break;
96  case 1:
97  mf::LogDebug(facility_) << name << ": " << value << " " << unit << "." << std::endl;
98  break;
99  case 2:
100  mf::LogWarning(facility_) << name << ": " << value << " " << unit << "." << std::endl;
101  break;
102  case 3:
103  mf::LogError(facility_) << name << ": " << value << " " << unit << "." << std::endl;
104  break;
105  }
106  }
107  }
108 
115  void sendMetric_(const std::string& name, const int& value, const std::string& unit) override
116  {
117  sendMetric_(name, std::to_string(value), unit);
118  }
119 
126  void sendMetric_(const std::string& name, const double& value, const std::string& unit) override
127  {
128  sendMetric_(name, std::to_string(value), unit);
129  }
130 
137  void sendMetric_(const std::string& name, const float& value, const std::string& unit) override
138  {
139  sendMetric_(name, std::to_string(value), unit);
140  }
141 
148  void sendMetric_(const std::string& name, const unsigned long int& value, const std::string& unit) override
149  {
150  sendMetric_(name, std::to_string(value), unit);
151  }
152 
156  void startMetrics_() override {}
160  void stopMetrics_() override {}
161 };
162 } //End namespace artdaq
163 
164 DEFINE_ARTDAQ_METRIC(artdaq::MsgFacilityMetric)
The MetricPlugin class defines the interface that MetricManager uses to send metric data to the vario...
Definition: MetricPlugin.hh:29
void startMetrics()
Perform startup actions. Simply calls the virtual startMetrics_ function.
void sendMetric_(const std::string &name, const int &value, const std::string &unit) override
Send a metric to MessageFacility. All metrics are converted to strings.
std::string getLibName() const override
Return the library name of the MetricPlugin.
void sendMetric_(const std::string &name, const float &value, const std::string &unit) override
Send a metric to MessageFacility. All metrics are converted to strings.
void stopMetrics()
Perform shutdown actions. Zeroes out all accumulators, and sends zeros for each metric. Calls stopMetrics_() for any plugin-defined shutdown actions.
void stopMetrics_() override
Perform shutdown actions. No-Op.
void sendMetric_(const std::string &name, const std::string &value, const std::string &unit) override
Send a metric to MessageFacilty. Format is: &quot;name: value unit.&quot;.
void startMetrics_() override
Perform startup actions. No-Op.
virtual ~MsgFacilityMetric()
MsgFacilityMetric Destructor. Calls stopMetrics()
MsgFacilityMetric(fhicl::ParameterSet const &config, std::string const &app_name)
MsgFacilityMetric Constructor.
A MetricPlugin class which sends metric data to MessageFacility.
void sendMetric_(const std::string &name, const unsigned long int &value, const std::string &unit) override
Send a metric to MessageFacility. All metrics are converted to strings.
void sendMetric_(const std::string &name, const double &value, const std::string &unit) override
Send a metric to MessageFacility. All metrics are converted to strings.
bool inhibit_
Flag to indicate that the MetricPlugin is being stopped, and any metric back-ends which do not have a...