DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
MonitorableObject.hpp
Go to the documentation of this file.
1
9#ifndef OPMONLIB_INCLUDE_OPMONLIB_MONITORABLEOBJECT_HPP_
10#define OPMONLIB_INCLUDE_OPMONLIB_MONITORABLEOBJECT_HPP_
11
12#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 <type_traits>
23#include <map>
24#include <memory>
25#include <string>
26#include <mutex>
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 )
35
38 "OpMonEntry of type " << type << " has no data",
39 ((std::string)type)
40 )
41
43 ErrorWhileCollecting,
44 "OpMon data collection failed in " << opmon_id,
45 ((std::string)opmon_id) )
46
47}
48
49
50namespace dunedaq::opmonlib {
51
52 using OpMonLevel = std::invoke_result<decltype(&dunedaq::confmodel::OpMonConf::get_level),
54
56 kDisabled = std::numeric_limits<OpMonLevel>::min(),
57 kAll = std::numeric_limits<OpMonLevel>::max()
58 };
59
61 kTopPriority = std::numeric_limits<OpMonLevel>::min(),
62 kEventDriven = std::numeric_limits<OpMonLevel>::max()/4,
63 kDefault = std::numeric_limits<OpMonLevel>::max()/2,
64 kLowestPrioriry = std::numeric_limits<OpMonLevel>::max()-1
65 };
66
67 template <class T>
68 constexpr auto to_level( T v ) {
69 return static_cast<typename std::underlying_type<T>::type>(v);
70 }
71
72
74{
75public:
76
77 using NodePtr = std::weak_ptr<MonitorableObject>;
78 using NewNodePtr = std::shared_ptr<MonitorableObject>;
79 using ElementId = std::string;
80
81 friend class OpMonManager;
82
90
91 virtual ~MonitorableObject() = default;
92
93 auto get_opmon_id() const noexcept { return m_parent_id + m_opmon_name; }
94
95 auto get_opmon_level() const noexcept { return m_opmon_level.load(); }
96
97 static bool publishable_metric( OpMonLevel entry, OpMonLevel system ) noexcept {
98 return (entry < system);
99 }
100
101protected:
102
107 MonitorableObject() = default;
108
113 void register_node( ElementId name, NewNodePtr ) ;
114
127 void publish( google::protobuf::Message &&,
128 CustomOrigin && co = {},
129 OpMonLevel l = to_level(EntryOpMonLevel::kDefault) ) const noexcept ;
130
135 virtual void generate_opmon_data() {return;}
136
137
138private:
139
147
151 void set_opmon_level( OpMonLevel ) noexcept;
152
156 void inherit_parent_properties( const MonitorableObject & parent ); // funcion called on the children as well
157
161 MonitorableObject( ElementId name, ElementId parent_id = "" )
162 : m_parent_id()
163 , m_opmon_name(name) {
164 m_parent_id.set_session(parent_id);
165 }
166
167 std::map<ElementId, NodePtr> m_nodes ;
168 std::mutex m_node_mutex;
169
170 using facility_ptr_t = std::shared_ptr<opmonlib::OpMonFacility>;
171 std::atomic<facility_ptr_t> m_facility{s_default_facility};
175
177
178 // info for monitoring the monitoring structure
181 using metric_counter_t = std::remove_const<const_metric_counter_t>::type;
182 mutable std::atomic<metric_counter_t> m_published_counter{0};
183 mutable std::atomic<metric_counter_t> m_ignored_counter{0};
184 mutable std::atomic<metric_counter_t> m_error_counter{0};
185
188 using time_counter_t = std::remove_const<const_metric_counter_t>::type;
189 mutable std::atomic<time_counter_t> m_cpu_us_counter{0};
190};
191
192
194 public:
196 };
197
198} // namespace dunedaq::opmonlib
199
200#endif // OPMONLIB_INCLUDE_OPMONLIB_MONITORABLEOBJECT_HPP_
#define ERS_DECLARE_ISSUE(namespace_name, class_name, message, attributes)
uint32_t get_level() const
Get "level" attribute value. SystemOpMonLevel.
Definition OpMonConf.hpp:98
void set_session(Arg_ &&arg, Args_... args)
std::shared_ptr< MonitorableObject > NewNodePtr
void inherit_parent_properties(const MonitorableObject &parent)
std::invoke_result< decltype(&dunedaq::opmonlib::opmon::MonitoringTreeInfo::n_published_measurements), dunedaq::opmonlib::opmon::MonitoringTreeInfo >::type const_metric_counter_t
std::atomic< metric_counter_t > m_published_counter
std::shared_ptr< opmonlib::OpMonFacility > facility_ptr_t
std::atomic< metric_counter_t > m_ignored_counter
opmon::MonitoringTreeInfo collect() noexcept
std::atomic< metric_counter_t > m_error_counter
MonitorableObject & operator=(const MonitorableObject &)=delete
std::remove_const< const_metric_counter_t >::type metric_counter_t
void set_opmon_level(OpMonLevel) noexcept
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::cpu_elapsed_time_us), dunedaq::opmonlib::opmon::MonitoringTreeInfo >::type const_time_counter_t
std::map< ElementId, NodePtr > m_nodes
MonitorableObject(const MonitorableObject &)=delete
MonitorableObject(MonitorableObject &&)=delete
std::weak_ptr< MonitorableObject > NodePtr
constexpr auto to_level(T v)
std::invoke_result< decltype(&dunedaq::confmodel::OpMonConf::get_level), dunedaq::confmodel::OpMonConf >::type OpMonLevel
std::map< std::string, std::string > CustomOrigin
Definition Utils.hpp:53
Including Qt Headers.