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

Collector for DICOM DIMSE service operation metrics. More...

#include <dicom_service_collector.h>

Collaboration diagram for kcenon::pacs::monitoring::dicom_service_collector:
Collaboration graph

Public Member Functions

 dicom_service_collector (std::string ae_title="PACS_SCP")
 Default constructor.
 
 ~dicom_service_collector ()=default
 Destructor.
 
 dicom_service_collector (const dicom_service_collector &)=delete
 
dicom_service_collectoroperator= (const dicom_service_collector &)=delete
 
 dicom_service_collector (dicom_service_collector &&)=delete
 
dicom_service_collectoroperator= (dicom_service_collector &&)=delete
 
bool initialize (const std::unordered_map< std::string, std::string > &config)
 Initialize the collector with configuration.
 
std::vector< service_metriccollect ()
 Collect current DIMSE service metrics.
 
std::string get_name () const
 Get the collector name.
 
std::vector< std::string > get_metric_types () const
 Get supported metric types.
 
bool is_healthy () const
 Check if the collector is healthy.
 
std::unordered_map< std::string, double > get_statistics () const
 Get collector statistics.
 
void set_ae_title (std::string ae_title)
 Set the AE title for metric labels.
 
std::string get_ae_title () const
 Get the current AE title.
 
void set_operation_enabled (dimse_operation op, bool enabled)
 Enable or disable specific operation metrics.
 
bool is_operation_enabled (dimse_operation op) const
 Check if metrics are enabled for an operation.
 

Private Member Functions

void collect_operation_metrics (std::vector< service_metric > &metrics, dimse_operation op, const operation_counter &counter)
 
service_metric create_metric (const std::string &name, double value, const std::string &type, const std::string &operation) const
 

Private Attributes

std::string ae_title_
 
bool initialized_ {false}
 
std::array< bool, 11 > operation_enabled_
 
std::mutex stats_mutex_
 
std::uint64_t collection_count_ {0}
 
std::chrono::steady_clock::time_point init_time_
 

Detailed Description

Collector for DICOM DIMSE service operation metrics.

This collector gathers metrics for all DIMSE operations including:

  • C-ECHO (Verification Service)
  • C-STORE (Storage Service)
  • C-FIND (Query Service)
  • C-MOVE (Retrieve Service)
  • C-GET (Retrieve Service)
  • N-CREATE, N-SET, N-GET, N-ACTION, N-EVENT, N-DELETE (Normalized Services)

For each operation, the collector reports:

  • Total request count
  • Success/failure counts
  • Duration statistics (average, min, max)
  • Throughput (requests/second)

Thread Safety: All public methods are thread-safe.

Definition at line 87 of file dicom_service_collector.h.

Constructor & Destructor Documentation

◆ dicom_service_collector() [1/3]

kcenon::pacs::monitoring::dicom_service_collector::dicom_service_collector ( std::string ae_title = "PACS_SCP")
inlineexplicit

Default constructor.

Parameters
ae_titleOptional AE title for labeling metrics
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/monitoring/collectors/dicom_service_collector.h.

Definition at line 215 of file dicom_service_collector.h.

◆ ~dicom_service_collector()

kcenon::pacs::monitoring::dicom_service_collector::~dicom_service_collector ( )
default

◆ dicom_service_collector() [2/3]

kcenon::pacs::monitoring::dicom_service_collector::dicom_service_collector ( const dicom_service_collector & )
delete

◆ dicom_service_collector() [3/3]

kcenon::pacs::monitoring::dicom_service_collector::dicom_service_collector ( dicom_service_collector && )
delete

Member Function Documentation

◆ collect()

std::vector< service_metric > kcenon::pacs::monitoring::dicom_service_collector::collect ( )
inlinenodiscard

Collect current DIMSE service metrics.

Returns
Vector of service metrics
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/monitoring/collectors/dicom_service_collector.h.

Definition at line 230 of file dicom_service_collector.h.

230 {
231 std::vector<service_metric> metrics;
232
233 if (!initialized_) {
234 return metrics;
235 }
236
237 const auto& pacs = pacs_metrics::global_metrics();
238
239 // Collect metrics for each enabled DIMSE operation
240 static constexpr std::array<dimse_operation, 11> all_ops = {
252 };
253
254 for (std::size_t i = 0; i < all_ops.size(); ++i) {
255 if (operation_enabled_[i]) {
257 metrics,
258 all_ops[i],
259 pacs.get_counter(all_ops[i]));
260 }
261 }
262
263 // Update statistics
264 {
265 std::lock_guard<std::mutex> lock(stats_mutex_);
267 }
268
269 return metrics;
270}
void collect_operation_metrics(std::vector< service_metric > &metrics, dimse_operation op, const operation_counter &counter)
static pacs_metrics & global_metrics() noexcept
Get the global singleton instance.
@ c_store
C-STORE (Storage Service)
@ c_move
C-MOVE (Retrieve Service)
@ c_echo
C-ECHO (Verification Service)

References kcenon::pacs::monitoring::c_echo, kcenon::pacs::monitoring::c_find, kcenon::pacs::monitoring::c_get, kcenon::pacs::monitoring::c_move, kcenon::pacs::monitoring::c_store, collect_operation_metrics(), collection_count_, kcenon::pacs::monitoring::pacs_metrics::global_metrics(), initialized_, kcenon::pacs::monitoring::n_action, kcenon::pacs::monitoring::n_create, kcenon::pacs::monitoring::n_delete, kcenon::pacs::monitoring::n_event, kcenon::pacs::monitoring::n_get, kcenon::pacs::monitoring::n_set, operation_enabled_, and stats_mutex_.

Here is the call graph for this function:

◆ collect_operation_metrics()

void kcenon::pacs::monitoring::dicom_service_collector::collect_operation_metrics ( std::vector< service_metric > & metrics,
dimse_operation op,
const operation_counter & counter )
inlineprivate
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/monitoring/collectors/dicom_service_collector.h.

Definition at line 272 of file dicom_service_collector.h.

275 {
276
277 const std::string op_name(to_string(op));
278
279 // Total requests (counter)
280 metrics.push_back(create_metric(
281 "dicom_" + op_name + "_requests_total",
282 static_cast<double>(counter.total_count()),
283 "counter",
284 op_name));
285
286 // Successful requests (counter)
287 metrics.push_back(create_metric(
288 "dicom_" + op_name + "_success_total",
289 static_cast<double>(counter.success_count.load(std::memory_order_relaxed)),
290 "counter",
291 op_name));
292
293 // Failed requests (counter)
294 metrics.push_back(create_metric(
295 "dicom_" + op_name + "_failure_total",
296 static_cast<double>(counter.failure_count.load(std::memory_order_relaxed)),
297 "counter",
298 op_name));
299
300 // Duration metrics (only if there have been requests)
301 if (counter.total_count() > 0) {
302 // Average duration in seconds (gauge)
303 metrics.push_back(create_metric(
304 "dicom_" + op_name + "_duration_seconds_avg",
305 static_cast<double>(counter.average_duration_us()) / 1'000'000.0,
306 "gauge",
307 op_name));
308
309 // Min duration in seconds (gauge)
310 const auto min_us = counter.min_duration_us.load(std::memory_order_relaxed);
311 if (min_us != UINT64_MAX) {
312 metrics.push_back(create_metric(
313 "dicom_" + op_name + "_duration_seconds_min",
314 static_cast<double>(min_us) / 1'000'000.0,
315 "gauge",
316 op_name));
317 }
318
319 // Max duration in seconds (gauge)
320 const auto max_us = counter.max_duration_us.load(std::memory_order_relaxed);
321 if (max_us > 0) {
322 metrics.push_back(create_metric(
323 "dicom_" + op_name + "_duration_seconds_max",
324 static_cast<double>(max_us) / 1'000'000.0,
325 "gauge",
326 op_name));
327 }
328
329 // Total duration in seconds (counter) - for calculating rates
330 metrics.push_back(create_metric(
331 "dicom_" + op_name + "_duration_seconds_sum",
332 static_cast<double>(counter.total_duration_us.load(std::memory_order_relaxed)) / 1'000'000.0,
333 "counter",
334 op_name));
335 }
336}
service_metric create_metric(const std::string &name, double value, const std::string &type, const std::string &operation) const
@ counter
Monotonic increasing value.
constexpr std::string_view to_string(health_level level) noexcept
Convert health level to string representation.

References kcenon::pacs::monitoring::counter, create_metric(), and kcenon::pacs::monitoring::to_string().

Referenced by collect().

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

◆ create_metric()

service_metric kcenon::pacs::monitoring::dicom_service_collector::create_metric ( const std::string & name,
double value,
const std::string & type,
const std::string & operation ) const
inlinenodiscardprivate
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/monitoring/collectors/dicom_service_collector.h.

Definition at line 411 of file dicom_service_collector.h.

415 {
416 return service_metric(
417 name,
418 value,
419 type,
420 {{"ae", ae_title_}, {"operation", operation}});
421}
std::string_view name

References ae_title_, and name.

Referenced by collect_operation_metrics().

Here is the caller graph for this function:

◆ get_ae_title()

std::string kcenon::pacs::monitoring::dicom_service_collector::get_ae_title ( ) const
inlinenodiscard

Get the current AE title.

Returns
The Application Entity title
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/monitoring/collectors/dicom_service_collector.h.

Definition at line 397 of file dicom_service_collector.h.

397 {
398 return ae_title_;
399}

References ae_title_.

◆ get_metric_types()

std::vector< std::string > kcenon::pacs::monitoring::dicom_service_collector::get_metric_types ( ) const
inlinenodiscard

Get supported metric types.

Returns
Vector of metric type names
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/monitoring/collectors/dicom_service_collector.h.

Definition at line 342 of file dicom_service_collector.h.

342 {
343 std::vector<std::string> types;
344
345 static constexpr std::array<dimse_operation, 11> all_ops = {
357 };
358
359 for (const auto op : all_ops) {
360 const std::string op_name(to_string(op));
361 types.push_back("dicom_" + op_name + "_requests_total");
362 types.push_back("dicom_" + op_name + "_success_total");
363 types.push_back("dicom_" + op_name + "_failure_total");
364 types.push_back("dicom_" + op_name + "_duration_seconds_avg");
365 types.push_back("dicom_" + op_name + "_duration_seconds_min");
366 types.push_back("dicom_" + op_name + "_duration_seconds_max");
367 types.push_back("dicom_" + op_name + "_duration_seconds_sum");
368 }
369
370 return types;
371}

References kcenon::pacs::monitoring::c_echo, kcenon::pacs::monitoring::c_find, kcenon::pacs::monitoring::c_get, kcenon::pacs::monitoring::c_move, kcenon::pacs::monitoring::c_store, kcenon::pacs::monitoring::n_action, kcenon::pacs::monitoring::n_create, kcenon::pacs::monitoring::n_delete, kcenon::pacs::monitoring::n_event, kcenon::pacs::monitoring::n_get, kcenon::pacs::monitoring::n_set, and kcenon::pacs::monitoring::to_string().

Here is the call graph for this function:

◆ get_name()

std::string kcenon::pacs::monitoring::dicom_service_collector::get_name ( ) const
inlinenodiscard

Get the collector name.

Returns
"dicom_service_collector"
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/monitoring/collectors/dicom_service_collector.h.

Definition at line 338 of file dicom_service_collector.h.

338 {
339 return "dicom_service_collector";
340}

◆ get_statistics()

std::unordered_map< std::string, double > kcenon::pacs::monitoring::dicom_service_collector::get_statistics ( ) const
inlinenodiscard

Get collector statistics.

Returns
Map of statistic name to value
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/monitoring/collectors/dicom_service_collector.h.

Definition at line 378 of file dicom_service_collector.h.

378 {
379 std::lock_guard<std::mutex> lock(stats_mutex_);
380
381 std::unordered_map<std::string, double> stats;
382 stats["collection_count"] = static_cast<double>(collection_count_);
383
384 if (initialized_) {
385 const auto uptime = std::chrono::duration_cast<std::chrono::seconds>(
386 std::chrono::steady_clock::now() - init_time_);
387 stats["uptime_seconds"] = static_cast<double>(uptime.count());
388 }
389
390 return stats;
391}

References collection_count_, init_time_, initialized_, and stats_mutex_.

◆ initialize()

bool kcenon::pacs::monitoring::dicom_service_collector::initialize ( const std::unordered_map< std::string, std::string > & config)
inlinenodiscard

Initialize the collector with configuration.

Parameters
configConfiguration map
Returns
true if initialization succeeded
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/monitoring/collectors/dicom_service_collector.h.

Definition at line 218 of file dicom_service_collector.h.

219 {
220 // Extract AE title from config if provided
221 if (auto it = config.find("ae_title"); it != config.end()) {
222 ae_title_ = it->second;
223 }
224
225 init_time_ = std::chrono::steady_clock::now();
226 initialized_ = true;
227 return true;
228}

References ae_title_, init_time_, and initialized_.

◆ is_healthy()

bool kcenon::pacs::monitoring::dicom_service_collector::is_healthy ( ) const
inlinenodiscard

Check if the collector is healthy.

Returns
true if operational
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/monitoring/collectors/dicom_service_collector.h.

Definition at line 373 of file dicom_service_collector.h.

373 {
374 return initialized_;
375}

References initialized_.

◆ is_operation_enabled()

bool kcenon::pacs::monitoring::dicom_service_collector::is_operation_enabled ( dimse_operation op) const
inlinenodiscard

Check if metrics are enabled for an operation.

Parameters
opThe DIMSE operation
Returns
true if enabled
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/monitoring/collectors/dicom_service_collector.h.

Definition at line 407 of file dicom_service_collector.h.

407 {
408 return operation_enabled_[static_cast<std::size_t>(op)];
409}
@ op
Ophthalmic Photography / Tomography.

References operation_enabled_.

◆ operator=() [1/2]

◆ operator=() [2/2]

dicom_service_collector & kcenon::pacs::monitoring::dicom_service_collector::operator= ( dicom_service_collector && )
delete

◆ set_ae_title()

void kcenon::pacs::monitoring::dicom_service_collector::set_ae_title ( std::string ae_title)
inline

Set the AE title for metric labels.

Parameters
ae_titleThe Application Entity title
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/monitoring/collectors/dicom_service_collector.h.

Definition at line 393 of file dicom_service_collector.h.

393 {
394 ae_title_ = std::move(ae_title);
395}

References ae_title_.

◆ set_operation_enabled()

void kcenon::pacs::monitoring::dicom_service_collector::set_operation_enabled ( dimse_operation op,
bool enabled )
inline

Enable or disable specific operation metrics.

Parameters
opThe DIMSE operation
enabledWhether to collect metrics for this operation
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/monitoring/collectors/dicom_service_collector.h.

Definition at line 401 of file dicom_service_collector.h.

403 {
404 operation_enabled_[static_cast<std::size_t>(op)] = enabled;
405}

References operation_enabled_.

Member Data Documentation

◆ ae_title_

std::string kcenon::pacs::monitoring::dicom_service_collector::ae_title_
private

◆ collection_count_

std::uint64_t kcenon::pacs::monitoring::dicom_service_collector::collection_count_ {0}
private

◆ init_time_

std::chrono::steady_clock::time_point kcenon::pacs::monitoring::dicom_service_collector::init_time_
private

◆ initialized_

bool kcenon::pacs::monitoring::dicom_service_collector::initialized_ {false}
private

◆ operation_enabled_

std::array<bool, 11> kcenon::pacs::monitoring::dicom_service_collector::operation_enabled_
private
Initial value:
{
true, true, true, true, true,
true, true, true, true, true, true
}
Examples
/home/runner/work/pacs_system/pacs_system/include/kcenon/pacs/monitoring/collectors/dicom_service_collector.h.

Definition at line 188 of file dicom_service_collector.h.

188 {
189 true, true, true, true, true, // C-ECHO, C-STORE, C-FIND, C-MOVE, C-GET
190 true, true, true, true, true, true // N-CREATE, N-SET, N-GET, N-ACTION, N-EVENT, N-DELETE
191 };

Referenced by collect(), is_operation_enabled(), and set_operation_enabled().

◆ stats_mutex_

std::mutex kcenon::pacs::monitoring::dicom_service_collector::stats_mutex_
mutableprivate

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