DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
opmonlib.publisher.OpMonPublisher Class Reference
Inheritance diagram for opmonlib.publisher.OpMonPublisher:
[legend]
Collaboration diagram for opmonlib.publisher.OpMonPublisher:
[legend]

Public Member Functions

None __init__ (self, OpMonConf conf, int|str log_level=logging.INFO, bool rich_handler=False)
None publish_message (self, logging.Logger logger, int|str level, str message)
None publish (self, Msg message, dict[str, str]|None custom_origin=None, int|str|None level=None)
Public Member Functions inherited from opmonlib.publisher_base.OpMonPublisherBase
None __init__ (self)
None __post_init__ (self)
None check_publisher (self)
str extract_topic (self, Msg message)
OpMonId make_origin (self, str session, str app)
dict[str, str] validate_custom_origin (self, dict[str, str]|None custom_origin=None)
dict make_data (self, Msg message, str top_block="")
OpMonValue to_map (self, int|float|bool|str value, int field_type)
OpMonEntry to_entry (self, Msg message, dict[str, str]|None custom_origin)
int log_level_to_int (self, str|int level)
str log_level_to_str (self, str|int level)

Additional Inherited Members

Public Attributes inherited from opmonlib.publisher_base.OpMonPublisherBase
 ts = Timestamp()
 substructure = None
 log
 conf
 publisher
 default_topic

Detailed Description

Publish operational monitoring metrics to file or stream.

Definition at line 17 of file publisher.py.

Constructor & Destructor Documentation

◆ __init__()

None opmonlib.publisher.OpMonPublisher.__init__ ( self,
OpMonConf conf,
int | str log_level = logging.INFO,
bool rich_handler = False )
Construct the object to publish OpMon metrics to stdout.

Definition at line 20 of file publisher.py.

25 ) -> None:
26 """Construct the object to publish OpMon metrics to stdout."""
27 super().__init__()
28 self.log = logging.getLogger("OpMonPublisher")
29 if not isinstance(log_level, int):
30 log_level = self.log_level_to_int(log_level)
31 self.log.setLevel(log_level)
32 self.log.addHandler(setup_rich_handler())
33
34 self.conf = conf
35 self.conf.level = self.log_level_to_int(self.conf.level)
36
37 if self.conf.opmon_type == "stdout":
38 if rich_handler:
39 handler = setup_rich_handler()
40 else:
41 handler = logging.StreamHandler(sys.stdout)
42 handler.setFormatter(LoggingFormatter(fmt=full_log_format))
43 elif self.conf.opmon_type == "file":
44 self.conf.path = extract_opmon_file_path(self.conf.path)
45 handler = logging.FileHandler(self.conf.path)
46 elif self.conf.opmon_type == "stream":
47 self.log.error("Type must not be stream to use file or stdout handling.")
48 sys.exit(1)
49 else:
50 self.log.error("Unsupported OpMon type.")
51 sys.exit(1)
52
53 self.default_topic = "monitoring." + self.conf.topic
54 self.publisher = logging.getLogger(self.default_topic)
55 self.publisher.addHandler(handler)
56 self.publisher.setLevel(self.conf.level)
57
58 super().__post_init__()
59 return
60
Factory couldn t std::string alg_name Invalid configuration error
Definition Issues.hpp:34

Member Function Documentation

◆ publish()

None opmonlib.publisher.OpMonPublisher.publish ( self,
Msg message,
dict[str, str] | None custom_origin = None,
int | str | None level = None )
Publish the message to either a file or the terminal.

Reimplemented from opmonlib.publisher_base.OpMonPublisherBase.

Definition at line 69 of file publisher.py.

74 ) -> None:
75 """Publish the message to either a file or the terminal."""
76 if not isinstance(message, Msg):
77 self.log.error("Passed message needs to be of type google.protobuf.message")
78 return
79
80 if not level:
81 level = self.conf.level
82 if not isinstance(level, int):
83 level = self.log_level_to_int(level)
84 if level < self.conf.level:
85 return
86
87 metric = self.to_entry(message=message, custom_origin=custom_origin)
88 target_topic = self.extract_topic(message)
89 publishing_logger = logging.getLogger(f"{self.publisher.name}.{target_topic}")
90 self.publish_message(publishing_logger, level, MessageToJson(metric))
91 return

◆ publish_message()

None opmonlib.publisher.OpMonPublisher.publish_message ( self,
logging.Logger logger,
int | str level,
str message )
Log the metric with the appropriate level.

Definition at line 61 of file publisher.py.

63 ) -> None:
64 """Log the metric with the appropriate level."""
65 method = getattr(logger, self.log_level_to_str(level).lower(), logger.info)
66 method(message)
67 return
68

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