1 #include "artdaq/DAQdata/Globals.hh"
3 #include "cetlib/PluginTypeDeducer.h"
4 #include "cetlib/ProvideMakePluginMacros.h"
5 #include "fhiclcpp/ParameterSet.h"
6 #include "fhiclcpp/types/ConfigurationTable.h"
8 #include "cetlib/compiler_macros.h"
9 #include "messagefacility/MessageService/ELdestination.h"
10 #include "messagefacility/Utilities/ELseverityLevel.h"
11 #include "messagefacility/Utilities/exception.h"
13 #define TRACE_NAME "ArtdaqMetric"
16 using mf::ELseverityLevel;
18 using mf::service::ELdestination;
35 fhicl::Atom<bool>{fhicl::Name{
"showDebug"}, fhicl::Comment{
"Send Metrics for Debug messages"},
false};
38 fhicl::Atom<bool>{fhicl::Name{
"showInfo"}, fhicl::Comment{
"Send Metrics for Info messages"},
false};
41 fhicl::Atom<bool>{fhicl::Name{
"showWarning"}, fhicl::Comment{
"Send Metrics for Warning messages"},
true};
44 fhicl::Atom<bool>{fhicl::Name{
"showError"}, fhicl::Comment{
"Send Metrics for Error messages"},
true};
46 fhicl::Atom<size_t>
messageLength = fhicl::Atom<size_t>(fhicl::Name{
"messageLength"}, fhicl::Comment{
"Maximum length of metric titles (0 for unlimited)"}, 40);
48 fhicl::Atom<size_t>
metricLevelOffset = fhicl::Atom<size_t>(fhicl::Name{
"metricLevelOffset"}, fhicl::Comment{
"Offset for Metric Levels (+0: summary rates, +1 errors, ...)"}, 10);
65 void fillPrefix(std::ostringstream& o,
const ErrorObj& msg)
override;
72 void fillUsrMsg(std::ostringstream& o,
const ErrorObj& msg)
override;
77 void fillSuffix(std::ostringstream& ,
const ErrorObj& )
override {}
84 void routePayload(
const std::ostringstream& o,
const ErrorObj& msg)
override;
87 std::string makeMetricName_(
const ErrorObj& msg);
88 bool showDebug_{
false};
89 bool showInfo_{
false};
90 bool showWarning_{
true};
91 bool showError_{
true};
92 size_t messageLength_{20};
93 size_t metricLevelOffset_{10};
104 : ELdestination(pset().elDestConfig())
105 , showDebug_(pset().showDebug())
106 , showInfo_(pset().showInfo())
107 , showWarning_(pset().showWarning())
108 , showError_(pset().showError())
109 , messageLength_(pset().messageLength())
110 , metricLevelOffset_(pset().metricLevelOffset())
112 TLOG(TLVL_INFO) <<
"ELArtdaqMetric MessageLogger destination plugin initialized.";
127 std::ostringstream tmposs;
128 ELdestination::fillUsrMsg(tmposs, msg);
131 std::string tmpStr = tmposs.str();
132 auto cpos = tmpStr.find(
':');
133 if (cpos != std::string::npos)
135 tmpStr.erase(0, cpos + 1);
140 std::copy_if(tmpStr.begin(), tmpStr.end(),
141 std::back_inserter(usrMsg), isalpha);
143 if (messageLength_ > 0 && usrMsg.size() > messageLength_)
145 usrMsg.resize(messageLength_);
156 const auto& xid = msg.xid();
157 auto message = oss.str();
159 auto level = xid.severity().getLevel();
161 bool sendMessageMetric =
false;
165 case mf::ELseverityLevel::ELsev_success:
166 case mf::ELseverityLevel::ELsev_zeroSeverity:
167 case mf::ELseverityLevel::ELsev_unspecified:
168 sendMessageMetric = showDebug_;
172 case mf::ELseverityLevel::ELsev_info:
173 sendMessageMetric = showInfo_;
177 case mf::ELseverityLevel::ELsev_warning:
178 sendMessageMetric = showWarning_;
182 sendMessageMetric = showError_;
189 if (sendMessageMetric)
191 metricMan->sendMetric(message, 1,
"messages", lvlNum + metricLevelOffset_ + 1, artdaq::MetricMode::Rate);
196 metricMan->sendMetric(
"Error Message Rate", 1,
"messages", metricLevelOffset_, artdaq::MetricMode::Rate);
199 metricMan->sendMetric(
"Warning Message Rate", 1,
"messages", metricLevelOffset_, artdaq::MetricMode::Rate);
202 metricMan->sendMetric(
"Info Message Rate", 1,
"messages", metricLevelOffset_, artdaq::MetricMode::Rate);
205 metricMan->sendMetric(
"Debug Message Rate", 1,
"messages", metricLevelOffset_, artdaq::MetricMode::Rate);
218 #ifndef EXTERN_C_FUNC_DECLARE_START
219 #define EXTERN_C_FUNC_DECLARE_START extern "C" {
222 EXTERN_C_FUNC_DECLARE_START
223 auto makePlugin(
const std::string& ,
const fhicl::ParameterSet& pset)
225 return std::make_unique<mfplugins::ELArtdaqMetric>(pset);
229 DEFINE_BASIC_PLUGINTYPE_FUNC(mf::service::ELdestination)
Message Facility destination which logs messages to a TRACE buffer
void fillUsrMsg(std::ostringstream &o, const ErrorObj &msg) override
Fill the "User Message" portion of the message.
void routePayload(const std::ostringstream &o, const ErrorObj &msg) override
Serialize a MessageFacility message to the output.
fhicl::Atom< bool > showInfo
"showInfo" (Default: False): Send metrics for Info messages
ELArtdaqMetric(Parameters const &pset)
ELArtdaqMetric Constructor
fhicl::Atom< bool > showError
"showError" (Default: true): Send metrics for Error messages
fhicl::TableFragment< ELdestination::Config > elDestConfig
ELDestination common parameters.
fhicl::Atom< size_t > messageLength
"messageLength" (Default: 40): Number of characters to use for metric title
void fillSuffix(std::ostringstream &, const ErrorObj &) override
Fill the "Suffix" portion of the message (Unused)
Configuration Parameters for ELArtdaqMetric.
fhicl::Atom< bool > showDebug
"showDebug" (Default: False): Send metrics for Debug messages
fhicl::Atom< bool > showWarning
"showWarning" (Default: true): Send metrics for Warning messages
fhicl::Atom< size_t > metricLevelOffset
"metricLevelOffset" (Default: 10): Offset for Metric Levels (+0: summary rates, +1 errors...
fhicl::WrappedTable< Config > Parameters
Used for ParameterSet validation.
void fillPrefix(std::ostringstream &o, const ErrorObj &msg) override
Fill the "Prefix" portion of the message.