DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
MonitorableObject.hpp
Go to the documentation of this file.
1
8
9#ifndef OPMONLIB_INCLUDE_OPMONLIB_MONITORABLEOBJECT_HPP_
10#define OPMONLIB_INCLUDE_OPMONLIB_MONITORABLEOBJECT_HPP_
11
13#include "opmonlib/Utils.hpp"
15
17#include "logging/Logging.hpp" // NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
18
19#include <google/protobuf/message.h>
20
21#include <limits>
22#include <map>
23#include <memory>
24#include <mutex>
25#include <string>
26#include <type_traits>
27
28namespace dunedaq {
29
31 NonUniqueNodeName,
32 name << " already present in the node list of " << opmon_id,
33 ((std::string)name)((std::string)opmon_id))
34
35ERS_DECLARE_ISSUE(opmonlib, EntryWithNoData, "OpMonEntry of type " << type << " has no data", ((std::string)type))
36
38 ErrorWhileCollecting,
39 "OpMon data collection failed in " << opmon_id,
40 ((std::string)opmon_id))
41
42}
43
44namespace dunedaq::opmonlib {
45
48
50{
51 kDisabled = std::numeric_limits<OpMonLevel>::min(),
52 kAll = std::numeric_limits<OpMonLevel>::max()
53};
54
56{
57 kTopPriority = std::numeric_limits<OpMonLevel>::min(),
58 kEventDriven = std::numeric_limits<OpMonLevel>::max() / 4,
59 kDefault = std::numeric_limits<OpMonLevel>::max() / 2,
60 kLowestPrioriry = std::numeric_limits<OpMonLevel>::max() - 1
61};
62
63template<class T>
64constexpr auto
66{
67 return static_cast<typename std::underlying_type<T>::type>(v);
68}
69
71{
72public:
73 using NodePtr = std::weak_ptr<MonitorableObject>;
74 using NewNodePtr = std::shared_ptr<MonitorableObject>;
75 using ElementId = std::string;
76
77 friend class OpMonManager;
78
86
87 virtual ~MonitorableObject() = default;
88
89 auto get_opmon_id() const noexcept { return m_parent_id + m_opmon_name; }
90
91 auto get_opmon_level() const noexcept { return m_opmon_level.load(); }
92
93 static bool publishable_metric(OpMonLevel entry, OpMonLevel system) noexcept { return (entry < system); }
94
95protected:
100 MonitorableObject() = default;
101
107
120 void publish(google::protobuf::Message&&,
121 CustomOrigin&& co = {},
122 OpMonLevel l = to_level(EntryOpMonLevel::kDefault)) const noexcept;
123
128 virtual void generate_opmon_data() { return; }
129
130private:
137 opmon::MonitoringTreeInfo collect() noexcept;
138
142 void set_opmon_level(OpMonLevel) noexcept;
143
147 void inherit_parent_properties(const MonitorableObject& parent); // funcion called on the children as well
148
153 : m_parent_id()
154 , m_opmon_name(name)
155 {
156 m_parent_id.set_session(parent_id);
157 }
158
159 std::map<ElementId, NodePtr> m_nodes;
160 std::mutex m_node_mutex;
161
162 using facility_ptr_t = std::shared_ptr<opmonlib::OpMonFacility>;
163 std::atomic<facility_ptr_t> m_facility{ s_default_facility };
167
169
170 // info for monitoring the monitoring structure
174 using metric_counter_t = std::remove_const<const_metric_counter_t>::type;
175 mutable std::atomic<metric_counter_t> m_published_counter{ 0 };
176 mutable std::atomic<metric_counter_t> m_ignored_counter{ 0 };
177 mutable std::atomic<metric_counter_t> m_error_counter{ 0 };
178
182 using time_counter_t = std::remove_const<const_metric_counter_t>::type;
183 mutable std::atomic<time_counter_t> m_cpu_us_counter{ 0 };
184};
185
187{
188public:
190};
191
192} // namespace dunedaq::opmonlib
193
194#endif // OPMONLIB_INCLUDE_OPMONLIB_MONITORABLEOBJECT_HPP_
uint32_t get_level() const
Get "level" attribute value. SystemOpMonLevel.
Definition OpMonConf.hpp:98
std::shared_ptr< MonitorableObject > NewNodePtr
std::atomic< metric_counter_t > m_published_counter
std::invoke_result< decltype(&dunedaq::opmonlib::opmon::MonitoringTreeInfo::cpu_elapsed_time_us), dunedaq::opmonlib::opmon::MonitoringTreeInfo >::type const_time_counter_t
std::shared_ptr< opmonlib::OpMonFacility > facility_ptr_t
std::atomic< metric_counter_t > m_ignored_counter
std::atomic< metric_counter_t > m_error_counter
MonitorableObject & operator=(MonitorableObject &&)=delete
MonitorableObject & operator=(const MonitorableObject &)=delete
std::remove_const< const_metric_counter_t >::type metric_counter_t
std::atomic< facility_ptr_t > m_facility
void register_node(ElementId name, NewNodePtr)
void publish(google::protobuf::Message &&, CustomOrigin &&co={}, OpMonLevel l=to_level(EntryOpMonLevel::kDefault)) const noexcept
std::remove_const< const_metric_counter_t >::type time_counter_t
static bool publishable_metric(OpMonLevel entry, OpMonLevel system) noexcept
std::atomic< time_counter_t > m_cpu_us_counter
std::invoke_result< decltype(&dunedaq::opmonlib::opmon::MonitoringTreeInfo::n_published_measurements), dunedaq::opmonlib::opmon::MonitoringTreeInfo >::type const_metric_counter_t
std::map< ElementId, NodePtr > m_nodes
MonitorableObject(const MonitorableObject &)=delete
MonitorableObject(MonitorableObject &&)=delete
std::weak_ptr< MonitorableObject > NodePtr
std::invoke_result< decltype(&dunedaq::confmodel::OpMonConf::get_level), dunedaq::confmodel::OpMonConf >::type OpMonLevel
constexpr auto to_level(T v)
std::map< std::string, std::string > CustomOrigin
Definition Utils.hpp:46
The DUNE-DAQ namespace.
ERS_DECLARE_ISSUE(cibmodules, CIBCommunicationError, " CIB Hardware Communication Error: "<< descriptor,((std::string) descriptor)) ERS_DECLARE_ISSUE(cibmodules
default char v[0]