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 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
 
MonitorableObjectoperator= (const MonitorableObject &)=delete
 
 MonitorableObject (MonitorableObject &&)=delete
 
MonitorableObjectoperator= (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 49 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 60 of file OpMonManager.hpp.

62 :
63 OpMonManager( session, name, makeOpMonFacility(opmon_facility_uri, make_origin(session, name)) ){;}
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.

19 : MonitorableObject( name, session) {
20
21 m_facility.store(f_ptr);
22
23}
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 87 of file OpMonManager.hpp.

87{ return m_facility.load(); }

◆ get_opmon_id()

auto dunedaq::opmonlib::MonitorableObject::get_opmon_id ( ) const
inlinenoexcept

Definition at line 93 of file MonitorableObject.hpp.

◆ get_opmon_level()

auto dunedaq::opmonlib::MonitorableObject::get_opmon_level ( ) const
inlinenoexcept

Definition at line 95 of file MonitorableObject.hpp.

95{ return m_opmon_level.load(); }

◆ register_node()

void MonitorableObject::register_node ( ElementId name,
NewNodePtr p )

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

Definition at line 113 of file MonitorableObject.cpp.

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

◆ run()

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

Definition at line 42 of file OpMonManager.cpp.

42 {
43
44 auto sleep_interval = std::chrono::milliseconds(100);
45 auto reporting_interval = m_cfg.load()->get_interval();
46 auto last_collection_time = std::chrono::steady_clock::now();
47
48 while( ! stoken.stop_requested() ) {
49
50 std::this_thread::sleep_for(sleep_interval);
51 auto time_span = std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::steady_clock::now() - last_collection_time);
52
53 if ( time_span >= reporting_interval ) {
54 last_collection_time = std::chrono::steady_clock::now();
55 publish( collect() );
56 // there is no catch here because collect is supposed to catch all possible exceptions
57 // In this way we should garantee the collection of metrics on the system
58 }
59 }
60
61 TLOG() << "Exiting the monitoring thread";
62}
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 78 of file OpMonManager.hpp.

78 {
79 m_cfg.store(c);
80 set_opmon_level( m_cfg.load()->get_level() );
81 }
void set_opmon_level(OpMonLevel) noexcept

◆ start_monitoring()

void OpMonManager::start_monitoring ( )

Definition at line 25 of file OpMonManager.cpp.

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

Friends And Related Symbol Documentation

◆ TestOpMonManager

friend class TestOpMonManager
friend

Definition at line 52 of file OpMonManager.hpp.

Member Data Documentation

◆ m_cfg

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

Definition at line 98 of file OpMonManager.hpp.

98{nullptr};

◆ m_thread

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

Definition at line 97 of file OpMonManager.hpp.


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