PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
kcenon::pacs::integration::monitoring_adapter Class Reference

Adapter for PACS performance metrics and distributed tracing. More...

#include <monitoring_adapter.h>

Collaboration diagram for kcenon::pacs::integration::monitoring_adapter:
Collaboration graph

Classes

struct  health_status
 Health check result containing component status. More...
 
class  impl
 
class  span
 Represents a unit of work in distributed tracing. More...
 

Static Public Member Functions

static void initialize (const monitoring_config &config)
 Initialize the monitoring adapter with configuration.
 
static void shutdown ()
 Shutdown the monitoring adapter.
 
static auto is_initialized () noexcept -> bool
 Check if the monitoring adapter is initialized.
 
static void increment_counter (std::string_view name, std::int64_t value=1)
 Increment a counter metric.
 
static void set_gauge (std::string_view name, double value)
 Set a gauge metric value.
 
static void record_histogram (std::string_view name, double value)
 Record a histogram sample.
 
static void record_timing (std::string_view name, std::chrono::nanoseconds duration)
 Record a timing measurement.
 
static void record_c_store (std::chrono::nanoseconds duration, std::size_t bytes, bool success)
 Record C-STORE operation metrics.
 
static void record_c_find (std::chrono::nanoseconds duration, std::size_t matches, query_level level)
 Record C-FIND operation metrics.
 
static void record_association (const std::string &calling_ae, bool established)
 Record DICOM association metrics.
 
static void update_storage_stats (std::size_t total_instances, std::size_t total_bytes)
 Update storage statistics.
 
static auto start_span (std::string_view operation) -> span
 Start a new trace span.
 
static auto get_health () -> health_status
 Get current health status.
 
static void register_health_check (std::string_view component, std::function< bool()> check)
 Register a health check for a component.
 
static void unregister_health_check (std::string_view component)
 Unregister a health check.
 
static auto get_config () -> const monitoring_config &
 Get the current configuration.
 

Static Private Member Functions

static auto query_level_to_string (query_level level) -> std::string
 

Static Private Attributes

static std::unique_ptr< impl > pimpl_
 

Detailed Description

Adapter for PACS performance metrics and distributed tracing.

This class provides a unified interface for monitoring in the PACS system, including:

  • Performance metrics (counters, gauges, histograms, timing)
  • DICOM-specific metrics (C-STORE, C-FIND, associations, storage)
  • Distributed tracing for request tracking across services
  • Health check endpoints for component status

The adapter uses monitoring_system's high-performance profiling internally while providing a PACS-specific API.

Thread Safety: All methods are thread-safe.

Example:
// Initialize the monitoring adapter
config.metrics_port = 9090;
config.service_name = "pacs_server";
// Record DICOM metrics
std::chrono::milliseconds(150),
1024 * 1024, // 1MB
true);
// Use distributed tracing
{
auto span = monitoring_adapter::start_span("c_store_operation");
span.set_tag("sop_class", "1.2.840.10008.5.1.4.1.1.2");
// ... do work ...
} // span automatically finished
// Health check
if (!health.healthy) {
// Handle unhealthy state
}
// Shutdown
Represents a unit of work in distributed tracing.
void set_tag(std::string_view key, std::string_view value)
Set a tag on the span.
static auto get_health() -> health_status
Get current health status.
static void record_c_store(std::chrono::nanoseconds duration, std::size_t bytes, bool success)
Record C-STORE operation metrics.
static auto start_span(std::string_view operation) -> span
Start a new trace span.
static void initialize(const monitoring_config &config)
Initialize the monitoring adapter with configuration.
static void shutdown()
Shutdown the monitoring adapter.
Configuration options for the monitoring adapter.
std::optional< std::uint16_t > metrics_port
Prometheus-style metrics endpoint port (nullopt = disabled)
std::string service_name
Service name for tracing.

Definition at line 128 of file monitoring_adapter.h.

Member Function Documentation

◆ get_config()

auto kcenon::pacs::integration::monitoring_adapter::get_config ( ) -> const monitoring_config&
staticnodiscard

Get the current configuration.

Returns
Current monitoring configuration

Definition at line 489 of file monitoring_adapter.cpp.

489 {
490 return pimpl_->get_config();
491}
auto get_config() const -> const monitoring_config &

References kcenon::pacs::integration::monitoring_adapter::impl::get_config(), and pimpl_.

Here is the call graph for this function:

◆ get_health()

auto kcenon::pacs::integration::monitoring_adapter::get_health ( ) -> health_status
staticnodiscard

Get current health status.

Returns
Health status of all registered components

Definition at line 472 of file monitoring_adapter.cpp.

472 {
473 return pimpl_->get_health();
474}
auto get_health() -> monitoring_adapter::health_status

References kcenon::pacs::integration::monitoring_adapter::impl::get_health(), and pimpl_.

Here is the call graph for this function:

◆ increment_counter()

void kcenon::pacs::integration::monitoring_adapter::increment_counter ( std::string_view name,
std::int64_t value = 1 )
static

Increment a counter metric.

Parameters
nameThe counter name
valueThe value to add (default: 1)

Definition at line 416 of file monitoring_adapter.cpp.

417 {
419}
void increment_counter(std::string_view name, std::int64_t value)
std::string_view name

References kcenon::pacs::integration::monitoring_adapter::impl::increment_counter(), name, and pimpl_.

Referenced by kcenon::pacs::workflow::auto_prefetch_service::execute_cycle(), kcenon::pacs::workflow::task_scheduler::execute_cycle(), kcenon::pacs::workflow::task_scheduler::execute_task(), ai_service_connector::impl::request_inference(), and job_tracker::update_status().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialize()

void kcenon::pacs::integration::monitoring_adapter::initialize ( const monitoring_config & config)
static

Initialize the monitoring adapter with configuration.

Must be called before any monitoring operations. Sets up metrics collection, tracing, and health check endpoints if configured.

Parameters
configConfiguration options

Definition at line 402 of file monitoring_adapter.cpp.

402 {
403 pimpl_->initialize(config);
404}

References kcenon::pacs::integration::monitoring_adapter::impl::initialize(), and pimpl_.

Here is the call graph for this function:

◆ is_initialized()

auto kcenon::pacs::integration::monitoring_adapter::is_initialized ( ) -> bool
staticnodiscardnoexcept

Check if the monitoring adapter is initialized.

Returns
true if initialized, false otherwise

Definition at line 408 of file monitoring_adapter.cpp.

408 {
409 return pimpl_->is_initialized();
410}

References kcenon::pacs::integration::monitoring_adapter::impl::is_initialized(), and pimpl_.

Here is the call graph for this function:

◆ query_level_to_string()

auto kcenon::pacs::integration::monitoring_adapter::query_level_to_string ( query_level level) -> std::string
staticnodiscardprivate

Definition at line 497 of file monitoring_adapter.cpp.

497 {
498 switch (level) {
500 return "PATIENT";
502 return "STUDY";
504 return "SERIES";
506 return "IMAGE";
507 default:
508 return "UNKNOWN";
509 }
510}

References kcenon::pacs::integration::image, kcenon::pacs::integration::patient, kcenon::pacs::integration::series, and kcenon::pacs::integration::study.

◆ record_association()

void kcenon::pacs::integration::monitoring_adapter::record_association ( const std::string & calling_ae,
bool established )
static

Record DICOM association metrics.

Records metrics for DICOM association establishment/release.

Metrics recorded:

  • pacs_associations_total (counter)
  • pacs_associations_active (gauge)
Parameters
calling_aeAE title of the remote system
establishedtrue if association was established, false if released

Definition at line 450 of file monitoring_adapter.cpp.

451 {
452 pimpl_->record_association(calling_ae, established);
453}
void record_association(const std::string &calling_ae, bool established)

References pimpl_, and kcenon::pacs::integration::monitoring_adapter::impl::record_association().

Here is the call graph for this function:

◆ record_c_find()

void kcenon::pacs::integration::monitoring_adapter::record_c_find ( std::chrono::nanoseconds duration,
std::size_t matches,
query_level level )
static

Record C-FIND operation metrics.

Records performance metrics for a DICOM C-FIND query operation.

Metrics recorded:

  • pacs_c_find_total (counter)
  • pacs_c_find_duration_seconds (histogram)
  • pacs_c_find_matches (histogram)
Parameters
durationTime taken for the query
matchesNumber of matching records returned
levelQuery retrieve level (patient, study, series, image)

Definition at line 444 of file monitoring_adapter.cpp.

446 {
447 pimpl_->record_c_find(duration, matches, level);
448}
void record_c_find(std::chrono::nanoseconds duration, std::size_t matches, query_level level)

References pimpl_, and kcenon::pacs::integration::monitoring_adapter::impl::record_c_find().

Here is the call graph for this function:

◆ record_c_store()

void kcenon::pacs::integration::monitoring_adapter::record_c_store ( std::chrono::nanoseconds duration,
std::size_t bytes,
bool success )
static

Record C-STORE operation metrics.

Records performance metrics for a DICOM C-STORE operation including duration, bytes transferred, and success/failure status.

Metrics recorded:

  • pacs_c_store_total (counter)
  • pacs_c_store_duration_seconds (histogram)
  • pacs_c_store_bytes_total (counter)
Parameters
durationTime taken for the operation
bytesNumber of bytes transferred
successWhether the operation succeeded

Definition at line 438 of file monitoring_adapter.cpp.

440 {
441 pimpl_->record_c_store(duration, bytes, success);
442}
void record_c_store(std::chrono::nanoseconds duration, std::size_t bytes, bool success)

References pimpl_, kcenon::pacs::integration::monitoring_adapter::impl::record_c_store(), and kcenon::pacs::integration::success.

Here is the call graph for this function:

◆ record_histogram()

void kcenon::pacs::integration::monitoring_adapter::record_histogram ( std::string_view name,
double value )
static

Record a histogram sample.

Parameters
nameThe histogram name
valueThe sample value

Definition at line 425 of file monitoring_adapter.cpp.

425 {
427}
void record_histogram(std::string_view name, double value)

References name, pimpl_, and kcenon::pacs::integration::monitoring_adapter::impl::record_histogram().

Referenced by kcenon::pacs::workflow::auto_prefetch_service::execute_cycle(), and kcenon::pacs::workflow::task_scheduler::execute_task().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ record_timing()

void kcenon::pacs::integration::monitoring_adapter::record_timing ( std::string_view name,
std::chrono::nanoseconds duration )
static

Record a timing measurement.

Parameters
nameThe timing metric name
durationThe duration to record

Definition at line 429 of file monitoring_adapter.cpp.

430 {
431 pimpl_->record_timing(name, duration);
432}
void record_timing(std::string_view name, std::chrono::nanoseconds duration)

References name, pimpl_, and kcenon::pacs::integration::monitoring_adapter::impl::record_timing().

Referenced by job_tracker::update_status().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_health_check()

void kcenon::pacs::integration::monitoring_adapter::register_health_check ( std::string_view component,
std::function< bool()> check )
static

Register a health check for a component.

The provided function will be called during health checks. It should return true if the component is healthy.

Parameters
componentName of the component
checkFunction that returns true if healthy

Definition at line 476 of file monitoring_adapter.cpp.

477 {
478 pimpl_->register_health_check(component, std::move(check));
479}
void register_health_check(std::string_view component, std::function< bool()> check)

References pimpl_, and kcenon::pacs::integration::monitoring_adapter::impl::register_health_check().

Here is the call graph for this function:

◆ set_gauge()

void kcenon::pacs::integration::monitoring_adapter::set_gauge ( std::string_view name,
double value )
static

Set a gauge metric value.

Parameters
nameThe gauge name
valueThe current value

Definition at line 421 of file monitoring_adapter.cpp.

421 {
422 pimpl_->set_gauge(name, value);
423}
void set_gauge(std::string_view name, double value)

References name, pimpl_, and kcenon::pacs::integration::monitoring_adapter::impl::set_gauge().

Referenced by job_tracker::add_job(), ai_service_connector::impl::initialize(), and job_tracker::remove_job().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ shutdown()

void kcenon::pacs::integration::monitoring_adapter::shutdown ( )
static

Shutdown the monitoring adapter.

Flushes all pending metrics and releases resources. Should be called before application exit.

Definition at line 406 of file monitoring_adapter.cpp.

References pimpl_, and kcenon::pacs::integration::monitoring_adapter::impl::shutdown().

Here is the call graph for this function:

◆ start_span()

auto kcenon::pacs::integration::monitoring_adapter::start_span ( std::string_view operation) -> span
staticnodiscard

Start a new trace span.

Parameters
operationName of the operation
Returns
A new span for the operation

Definition at line 464 of file monitoring_adapter.cpp.

464 {
465 return span(operation);
466}

◆ unregister_health_check()

void kcenon::pacs::integration::monitoring_adapter::unregister_health_check ( std::string_view component)
static

Unregister a health check.

Parameters
componentName of the component to unregister

Definition at line 481 of file monitoring_adapter.cpp.

481 {
483}

References pimpl_, and kcenon::pacs::integration::monitoring_adapter::impl::unregister_health_check().

Here is the call graph for this function:

◆ update_storage_stats()

void kcenon::pacs::integration::monitoring_adapter::update_storage_stats ( std::size_t total_instances,
std::size_t total_bytes )
static

Update storage statistics.

Updates gauge metrics for storage usage.

Metrics recorded:

  • pacs_storage_instances (gauge)
  • pacs_storage_bytes (gauge)
Parameters
total_instancesTotal number of stored DICOM instances
total_bytesTotal storage used in bytes

Definition at line 455 of file monitoring_adapter.cpp.

456 {
457 pimpl_->update_storage_stats(total_instances, total_bytes);
458}
void update_storage_stats(std::size_t total_instances, std::size_t total_bytes)

References pimpl_, and kcenon::pacs::integration::monitoring_adapter::impl::update_storage_stats().

Here is the call graph for this function:

Member Data Documentation

◆ pimpl_

std::unique_ptr< monitoring_adapter::impl > kcenon::pacs::integration::monitoring_adapter::pimpl_
staticprivate

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