DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::opmonlib::OpMonManager Class Reference

#include <OpMonManager.hpp>

Inheritance diagram for dunedaq::opmonlib::OpMonManager:
[legend]
Collaboration diagram for dunedaq::opmonlib::OpMonManager:
[legend]

Public Member Functions

 OpMonManager (std::string session, std::string name, std::string opmon_facility_uri="stdout")
virtual ~OpMonManager ()=default
void start_monitoring ()
void stop_monitoring ()
void set_opmon_conf (const confmodel::OpMonConf *c)
auto get_opmon_id () const noexcept
auto get_opmon_level () const noexcept
void register_node (ElementId name, NewNodePtr)

Protected Member Functions

auto get_opmon_facility () const
 OpMonManager (std::string session, std::string name, facility_ptr_t)
void run (std::stop_token)
Protected Member Functions inherited from dunedaq::opmonlib::MonitorableObject
 MonitorableObject ()=default
void register_node (ElementId name, NewNodePtr)
void publish (google::protobuf::Message &&, CustomOrigin &&co={}, OpMonLevel l=to_level(EntryOpMonLevel::kDefault)) const noexcept
virtual void generate_opmon_data ()
 MonitorableObject (const MonitorableObject &)=delete
MonitorableObject & operator= (const MonitorableObject &)=delete
 MonitorableObject (MonitorableObject &&)=delete
MonitorableObject & operator= (MonitorableObject &&)=delete
virtual ~MonitorableObject ()=default
auto get_opmon_id () const noexcept
auto get_opmon_level () const noexcept

Private Attributes

std::jthread m_thread
std::atomic< const confmodel::OpMonConf * > m_cfg { nullptr }

Friends

class TestOpMonManager

Additional Inherited Members

Protected Types inherited from dunedaq::opmonlib::MonitorableObject
using NodePtr = std::weak_ptr<MonitorableObject>
using NewNodePtr = std::shared_ptr<MonitorableObject>
using ElementId = std::string
Static Protected Member Functions inherited from dunedaq::opmonlib::MonitorableObject
static bool publishable_metric (OpMonLevel entry, OpMonLevel system) noexcept

Detailed Description

Definition at line 37 of file OpMonManager.hpp.

Constructor & Destructor Documentation

◆ OpMonManager() [1/2]

dunedaq::opmonlib::OpMonManager::OpMonManager ( std::string session,
std::string name,
std::string opmon_facility_uri = "stdout" )
inlineexplicit

Definition at line 47 of file OpMonManager.hpp.

48 : OpMonManager(session, name, makeOpMonFacility(opmon_facility_uri, make_origin(session, name)))
49 {
50 ;
51 }
std::shared_ptr< OpMonFacility > makeOpMonFacility(std::string const &facility, OptionalOrigin=OptionalOrigin())
opmon::OpMonId make_origin(const std::string &session, const std::string &app)
Definition Utils.cpp:12

◆ ~OpMonManager()

virtual dunedaq::opmonlib::OpMonManager::~OpMonManager ( )
virtualdefault

◆ OpMonManager() [2/2]

OpMonManager::OpMonManager ( std::string session,
std::string name,
facility_ptr_t f_ptr )
protected

Definition at line 16 of file OpMonManager.cpp.

17 : MonitorableObject(name, session)
18{
19
20 m_facility.store(f_ptr);
21}
std::atomic< facility_ptr_t > m_facility

Member Function Documentation

◆ get_opmon_facility()

auto dunedaq::opmonlib::OpMonManager::get_opmon_facility ( ) const
inlineprotected

Definition at line 79 of file OpMonManager.hpp.

79{ return m_facility.load(); }

◆ get_opmon_id()

◆ get_opmon_level()

Definition at line 91 of file MonitorableObject.hpp.

91{ return m_opmon_level.load(); }

◆ register_node()

Append a register object to the chain The children will be modified using information from the this parent

Definition at line 106 of file MonitorableObject.cpp.

34{
35
36 std::lock_guard<std::mutex> lock(m_node_mutex);
37
38 // check if the name is already present to ensure uniqueness
39 auto it = m_nodes.find(name);
40 if (it != m_nodes.end()) {
41 // This not desired because names are suppposed to be unique
42 // But if the pointer is expired, there is no harm in override it
43 if (it->second.expired()) {
44 ers::warning(NonUniqueNodeName(ERS_HERE, name, to_string(get_opmon_id())));
45 } else {
46 throw NonUniqueNodeName(ERS_HERE, name, to_string(get_opmon_id()));
47 }
48 }
49
50 m_nodes[name] = p;
51
52 p->m_opmon_name = name;
53 p->inherit_parent_properties(*this);
54
55 TLOG() << "Node " << name << " registered to " << to_string(get_opmon_id());
56}
#define ERS_HERE
std::map< ElementId, NodePtr > m_nodes
#define TLOG(...)
Definition macro.hpp:21
std::string to_string(const dunedaq::opmon::OpMonId &)
Definition Utils.cpp:166
void warning(const Issue &issue)
Definition ers.hpp:150

◆ run()

void OpMonManager::run ( std::stop_token stoken)
protected

Definition at line 54 of file OpMonManager.cpp.

55{
56
57 TLOG() << "Monitoring thread started";
58
59 auto sleep_interval = std::chrono::milliseconds(100);
60 auto reporting_interval = m_cfg.load()->get_interval();
61 auto last_collection_time = std::chrono::steady_clock::now();
62
63 while (!stoken.stop_requested()) {
64
65 std::this_thread::sleep_for(sleep_interval);
66 auto time_span =
67 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - last_collection_time);
68
69 if (time_span < reporting_interval)
70 continue;
71
72 if (stoken.stop_requested())
73 break;
74
75 last_collection_time = std::chrono::steady_clock::now();
77 // there is no catch here because collect is supposed to catch all possible exceptions
78 // In this way we should garantee the collection of metrics on the system
79 }
80
81 TLOG() << "Exiting the monitoring thread";
82}
opmon::MonitoringTreeInfo collect() noexcept
void publish(google::protobuf::Message &&, CustomOrigin &&co={}, OpMonLevel l=to_level(EntryOpMonLevel::kDefault)) const noexcept
std::atomic< const confmodel::OpMonConf * > m_cfg

◆ set_opmon_conf()

void dunedaq::opmonlib::OpMonManager::set_opmon_conf ( const confmodel::OpMonConf * c)
inline

Definition at line 69 of file OpMonManager.hpp.

70 {
71 m_cfg.store(c);
72 set_opmon_level(m_cfg.load()->get_level());
73 }
void set_opmon_level(OpMonLevel) noexcept

◆ start_monitoring()

void OpMonManager::start_monitoring ( )

Definition at line 24 of file OpMonManager.cpp.

25{
26
27 if (!m_cfg)
28 throw MissingConfiguration(ERS_HERE);
29
30 TLOG() << "Starting a new monitoring thread with interval " << m_cfg.load()->get_interval().count()
31 << " seconds, at level " << get_opmon_level();
32
33 auto running_function = std::bind(&OpMonManager::run, this, std::placeholders::_1);
34 m_thread = std::jthread(running_function);
35 auto handle = m_thread.native_handle();
36 auto thread_name = "opmon";
37 auto rc = pthread_setname_np(handle, thread_name);
38 if (rc != 0) {
39 ers::warning(ThreadNameTooLong(ERS_HERE, thread_name));
40 }
41}
auto get_opmon_level() const noexcept

◆ stop_monitoring()

void OpMonManager::stop_monitoring ( )

Definition at line 44 of file OpMonManager.cpp.

45{
46
47 TLOG() << "Gracefully requesting the monitoring thread to stop";
48
49 m_thread.request_stop();
50 m_thread.join();
51}

◆ TestOpMonManager

friend class TestOpMonManager
friend

Definition at line 40 of file OpMonManager.hpp.

Member Data Documentation

◆ m_cfg

std::atomic<const confmodel::OpMonConf*> dunedaq::opmonlib::OpMonManager::m_cfg { nullptr }
private

Definition at line 87 of file OpMonManager.hpp.

◆ m_thread

std::jthread dunedaq::opmonlib::OpMonManager::m_thread
private

Definition at line 86 of file OpMonManager.hpp.


The documentation for this class was generated from the following files: