$treeview $search $mathjax $extrastylesheet
artdaq_utilities
v1_04_10
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #ifndef artdaq_DAQrate_MetricManager_hh 00002 #define artdaq_DAQrate_MetricManager_hh 00003 00004 // MetricManager class definition file 00005 // Author: Eric Flumerfelt 00006 // Last Modified: 11/14/2014 00007 // 00008 // MetricManager loads a user-specified set of plugins, sends them their configuration, 00009 // and sends them data as it is recieved. It also maintains the state of the plugins 00010 // relative to the application state. 00011 00012 #include "artdaq-utilities/Plugins/MetricData.hh" 00013 #include "artdaq-utilities/Plugins/MetricPlugin.hh" 00014 #include "fhiclcpp/fwd.h" 00015 #include "fhiclcpp/types/OptionalTable.h" 00016 #include "messagefacility/MessageLogger/MessageLogger.h" 00017 00018 #include <atomic> 00019 #include <boost/thread.hpp> 00020 #include <condition_variable> 00021 #include <queue> 00022 #include <sstream> 00023 00024 namespace artdaq { 00025 class MetricManager; 00026 } 00027 00033 class artdaq::MetricManager { 00034 public: 00038 struct Config { 00041 fhicl::Atom<size_t> metric_queue_size{ 00042 fhicl::Name{"metric_queue_size"}, 00043 fhicl::Comment{"The maximum number of metric entries which can be stored in the metric queue."}, 1000}; 00046 fhicl::Atom<size_t> metric_queue_notify_size{ 00047 fhicl::Name{"metric_queue_notify_size"}, 00048 fhicl::Comment{ 00049 "The number of metric entries in the list which will cause reports of the queue size to be printed."}, 00050 10}; 00053 fhicl::Atom<int> metric_send_maximum_delay_ms{ 00054 fhicl::Name{"metric_send_maximum_delay_ms"}, 00055 fhicl::Comment{"The maximum amount of time between metric send calls (will send 0s for metrics which have not " 00056 "reported in this interval)"}, 00057 15000}; 00059 fhicl::OptionalTable<artdaq::MetricPlugin::Config> metricConfig{ fhicl::Name{"metricConfig"} }; 00060 }; 00061 using Parameters = fhicl::WrappedTable<Config>; 00062 00066 MetricManager(); 00067 00071 MetricManager(MetricManager const&) = delete; 00072 00078 virtual ~MetricManager() noexcept; 00079 00084 MetricManager& operator=(MetricManager const&) = delete; 00085 00099 void initialize(fhicl::ParameterSet const& pset, std::string const& prefix = ""); 00100 00104 void do_start(); 00105 00109 void do_stop(); 00110 00114 void do_pause(); 00115 00119 void do_resume(); 00120 00128 void reinitialize(fhicl::ParameterSet const& pset, std::string const& prefix = ""); 00129 00133 void shutdown(); 00134 00148 void sendMetric(std::string const& name, std::string const& value, std::string const& unit, int level, 00149 MetricMode mode, std::string const& metricPrefix = "", bool useNameOverride = false); 00150 00164 void sendMetric(std::string const& name, int const& value, std::string const& unit, int level, MetricMode mode, 00165 std::string const& metricPrefix = "", bool useNameOverride = false); 00166 00180 void sendMetric(std::string const& name, double const& value, std::string const& unit, int level, MetricMode mode, 00181 std::string const& metricPrefix = "", bool useNameOverride = false); 00182 00196 void sendMetric(std::string const& name, float const& value, std::string const& unit, int level, MetricMode mode, 00197 std::string const& metricPrefix = "", bool useNameOverride = false); 00198 00212 void sendMetric(std::string const& name, long unsigned int const& value, std::string const& unit, int level, 00213 MetricMode mode, std::string const& metricPrefix = "", bool useNameOverride = false); 00214 00219 void setPrefix(std::string const& prefix) { prefix_ = prefix; } 00220 00225 bool Initialized() { return initialized_; } 00226 00231 bool Running() { return running_; } 00232 00237 bool Active() { return active_; } 00238 00243 bool metricQueueEmpty(); 00244 00250 size_t metricQueueSize(std::string const& name = ""); 00251 00252 private: 00253 void sendMetricLoop_(); 00254 00255 void startMetricLoop_(); 00256 00257 std::vector<std::unique_ptr<artdaq::MetricPlugin>> metric_plugins_; 00258 boost::thread metric_sending_thread_; 00259 std::mutex metric_mutex_; 00260 std::condition_variable metric_cv_; 00261 int metric_send_interval_ms_; 00262 00263 std::atomic<bool> initialized_; 00264 std::atomic<bool> running_; 00265 std::atomic<bool> active_; 00266 std::string prefix_; 00267 00268 std::unordered_map<std::string, std::unique_ptr<MetricData>> metric_cache_; 00269 std::mutex metric_cache_mutex_; 00270 std::atomic<size_t> missed_metric_calls_; 00271 std::atomic<size_t> metric_calls_; 00272 size_t metric_cache_max_size_; 00273 size_t metric_cache_notify_size_; 00274 }; 00275 00276 #endif /* artdaq_DAQrate_MetricManager_hh */