25#include <shared_mutex>
28#include <unordered_map>
82 std::unordered_map<std::string, std::string>
tags;
89 std::unordered_map<std::string, std::string> tg = {})
93 ,
timestamp(std::chrono::system_clock::now())
94 ,
tags(std::move(tg)) {}
136 std::unordered_map<std::string, std::string>
metadata;
139 :
timestamp(std::chrono::system_clock::now()) {}
276 const std::unordered_map<std::string, std::string>& tags);
309 [[nodiscard]] std::string
to_json()
const;
321 std::function<
bool()> check);
420 std::unordered_map<std::string, std::string> collector_config;
445 std::string_view
name,
447 const std::unordered_map<std::string, std::string>& tags) {
460 std::shared_lock<std::shared_mutex> config_lock(
config_mutex_);
502 const auto start = std::chrono::steady_clock::now();
508 bool all_healthy =
true;
509 bool any_check_failed =
false;
515 result.
metadata[component] =
"unhealthy";
517 result.
metadata[component] =
"healthy";
519 }
catch (
const std::exception& e) {
520 any_check_failed =
true;
521 result.
metadata[component] = std::string(
"error: ") + e.what();
528 result.
metadata[
"association_collector"] =
"unhealthy";
532 result.
metadata[
"service_collector"] =
"unhealthy";
536 result.
metadata[
"storage_collector"] =
"unhealthy";
540 result.
metadata[
"unified_collector"] =
"unhealthy";
543 if (any_check_failed) {
545 result.
message =
"Some health checks threw exceptions";
546 }
else if (!all_healthy) {
548 result.
message =
"Some components are unhealthy";
550 result.
message =
"All components healthy";
553 const auto end = std::chrono::steady_clock::now();
554 result.
check_duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
581 std::string_view component,
582 std::function<
bool()> check) {
Collector for DICOM association lifecycle metrics.
CRTP-based unified DICOM metrics collector.
Collector for DICOM DIMSE service operation metrics.
Collector for DICOM storage and data transfer metrics.
std::string to_prometheus(std::string_view prefix="pacs") const
Export metrics in Prometheus text format.
void reset() noexcept
Reset all metrics to zero.
static pacs_metrics & global_metrics() noexcept
Get the global singleton instance.
std::string to_json() const
Export metrics as JSON string.
Unified PACS monitoring implementing IMonitor interface.
void update_config(const pacs_monitor_config &config)
Update configuration.
pacs_monitor(pacs_monitor &&)=delete
void unregister_health_check(std::string_view component)
Unregister a health check.
void reset()
Reset all metrics.
~pacs_monitor()=default
Destructor.
dicom_storage_collector & storage_collector()
Get the storage collector.
std::vector< metric_value > custom_metrics_
void register_health_check(std::string_view component, std::function< bool()> check)
Register a health check for a component.
std::string to_json() const
Export all metrics as JSON.
std::unique_ptr< dicom_storage_collector > storage_collector_
dicom_service_collector & service_collector()
Get the service collector.
std::unordered_map< std::string, std::function< bool()> > health_checks_
void record_metric(std::string_view name, double value)
Record a metric value.
std::mutex health_checks_mutex_
static pacs_monitor & global_monitor() noexcept
Get the global singleton instance.
dicom_metrics_collector & unified_collector()
Get the unified CRTP-based metrics collector.
std::mutex custom_metrics_mutex_
dicom_association_collector & association_collector()
Get the association collector.
pacs_monitor(const pacs_monitor &)=delete
pacs_monitor(const pacs_monitor_config &config={})
Construct a new PACS monitor.
const pacs_monitor_config & get_config() const
Get current configuration.
health_check_result check_health()
Perform health check.
std::unique_ptr< dicom_metrics_collector > unified_collector_
std::string to_prometheus() const
Export all metrics in Prometheus text format.
std::unique_ptr< dicom_association_collector > association_collector_
std::shared_mutex config_mutex_
pacs_monitor_config config_
pacs_monitor & operator=(const pacs_monitor &)=delete
std::unique_ptr< dicom_service_collector > service_collector_
void initialize_collectors()
void collect_all_metrics(metrics_snapshot &snapshot)
dicom_metrics_snapshot get_unified_snapshot() const
Get a snapshot from the unified collector.
metrics_snapshot get_metrics()
Get current metrics snapshot.
pacs_monitor & operator=(pacs_monitor &&)=delete
DICOM Association metrics collector.
CRTP-based unified DICOM metrics collector.
DICOM DIMSE Service metrics collector.
DICOM Storage metrics collector.
Health check service for PACS system components.
monitor_health_status
Standard health status levels.
metric_type
Types of metrics supported by the monitoring system.
@ gauge
Instant value that can go up or down.
@ counter
Monotonic increasing value.
@ summary
Statistical summary (min, max, mean, percentiles)
@ histogram
Distribution of values across buckets.
constexpr std::string_view to_string(health_level level) noexcept
Convert health level to string representation.
@ healthy
All components healthy, system fully operational.
@ degraded
Some non-critical components degraded, system operational.
@ unhealthy
Critical components failing, system may not function correctly.
std::unordered_map< std::string, std::string > config_map
Type alias for configuration map.
Operation metrics collection for PACS DICOM services.
Snapshot of all DICOM metrics at a point in time.
Result of a health check operation.
monitor_health_status status
std::chrono::system_clock::time_point timestamp
std::chrono::milliseconds check_duration
std::unordered_map< std::string, std::string > metadata
bool is_operational() const
Standard metric value structure with type information.
metric_value(std::string n, double v, metric_type t=metric_type::gauge, std::unordered_map< std::string, std::string > tg={})
std::chrono::system_clock::time_point timestamp
std::unordered_map< std::string, std::string > tags
Complete snapshot of metrics at a point in time.
void add_metric(const std::string &name, double value, metric_type type=metric_type::gauge)
std::chrono::system_clock::time_point capture_time
std::vector< metric_value > metrics
Configuration for the PACS monitor.
bool enable_unified_collector
Enable unified CRTP-based metrics collector.
bool enable_association_metrics
Enable association metrics collection.
bool enable_service_metrics
Enable DIMSE service metrics collection.
bool enable_storage_metrics
Enable storage metrics collection.
std::string metric_prefix
Metric name prefix for Prometheus export.
std::string ae_title
Application Entity title for metric labels.
bool enable_pool_metrics
Enable object pool metrics.