artdaq_utilities  v1_04_02
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 <iostream>
12 #include <string>
13 #include <algorithm>
14 
15 namespace artdaq
16 {
21  {
22  private:
23  std::string facility_;
24  int outputLevel_;
25  public:
38  explicit MsgFacilityMetric(fhicl::ParameterSet config)
39  : MetricPlugin(config)
40  , facility_(config.get<std::string>("output_message_category_name", "ARTDAQ Metric"))
41  , outputLevel_(0)
42  {
43  try
44  {
45  outputLevel_ = config.get<int>("output_message_severity", 0);
46  }
47  catch (cet::exception)
48  {
49  std::string levelString = config.get<std::string>("output_message_severity", "Info");
50  if (levelString == "Info" || levelString == "info" || levelString == "LogInfo")
51  {
52  outputLevel_ = 0;
53  }
54  else if (levelString == "Debug" || levelString == "debug" || levelString == "LogDebug")
55  {
56  outputLevel_ = 1;
57  }
58  else if (levelString == "Warning" || levelString == "warning" || levelString == "LogWarning" || levelString == "Warn" || levelString == "warn")
59  {
60  outputLevel_ = 2;
61  }
62  else if (levelString == "Error" || levelString == "error" || levelString == "LogError")
63  {
64  outputLevel_ = 3;
65  }
66  }
67  startMetrics();
68  }
69 
78  std::string getLibName() const override { return "msgFacility"; }
79 
86  void sendMetric_(const std::string& name, const std::string& value, const std::string& unit) override
87  {
88  if (!inhibit_)
89  {
90  switch (outputLevel_)
91  {
92  case 0:
93  mf::LogInfo(facility_) << name << ": " << value << " " << unit << "." << std::endl;
94  break;
95  case 1:
96  mf::LogDebug(facility_) << name << ": " << value << " " << unit << "." << std::endl;
97  break;
98  case 2:
99  mf::LogWarning(facility_) << name << ": " << value << " " << unit << "." << std::endl;
100  break;
101  case 3:
102  mf::LogError(facility_) << name << ": " << value << " " << unit << "." << std::endl;
103  break;
104  }
105  }
106  }
107 
114  void sendMetric_(const std::string& name, const int& value, const std::string& unit) override
115  {
116  sendMetric_(name, std::to_string(value), unit);
117  }
118 
125  void sendMetric_(const std::string& name, const double& value, const std::string& unit) override
126  {
127  sendMetric_(name, std::to_string(value), unit);
128  }
129 
136  void sendMetric_(const std::string& name, const float& value, const std::string& unit) override
137  {
138  sendMetric_(name, std::to_string(value), unit);
139  }
140 
147  void sendMetric_(const std::string& name, const unsigned long int& value, const std::string& unit) override
148  {
149  sendMetric_(name, std::to_string(value), unit);
150  }
151 
155  void startMetrics_() override {}
159  void stopMetrics_() override {}
160  };
161 } //End namespace artdaq
162 
163 DEFINE_ARTDAQ_METRIC(artdaq::MsgFacilityMetric)
The MetricPlugin class defines the interface that MetricManager uses to send metric data to the vario...
Definition: MetricPlugin.hh:23
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 config)
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_
Whether to inhibit all metric sending.