comparison OrthancServer/OrthancRestApi/OrthancRestSystem.cpp @ 3179:fca730c267d7

New primitives to set and refresh metrics
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 30 Jan 2019 17:12:15 +0100
parents 053e72ff9fc5
children 962e5f00744b
comparison
equal deleted inserted replaced
3178:6d558598d713 3179:fca730c267d7
405 } 405 }
406 406
407 407
408 static void GetMetricsPrometheus(RestApiGetCall& call) 408 static void GetMetricsPrometheus(RestApiGetCall& call)
409 { 409 {
410 #if ORTHANC_ENABLE_PLUGINS == 1
411 OrthancRestApi::GetContext(call).GetPlugins().RefreshMetrics();
412 #endif
413
410 static const float MEGA_BYTES = 1024 * 1024; 414 static const float MEGA_BYTES = 1024 * 1024;
411 415
412 ServerContext& context = OrthancRestApi::GetContext(call); 416 ServerContext& context = OrthancRestApi::GetContext(call);
413 417
414 uint64_t diskSize, uncompressedSize, countPatients, countStudies, countSeries, countInstances; 418 uint64_t diskSize, uncompressedSize, countPatients, countStudies, countSeries, countInstances;
415 context.GetIndex().GetGlobalStatistics(diskSize, uncompressedSize, countPatients, 419 context.GetIndex().GetGlobalStatistics(diskSize, uncompressedSize, countPatients,
416 countStudies, countSeries, countInstances); 420 countStudies, countSeries, countInstances);
417 421
418 unsigned int jobsPending, jobsRunning, jobsCompleted; 422 unsigned int jobsPending, jobsRunning, jobsSuccess, jobsFailed;
419 context.GetJobsEngine().GetRegistry().GetStatistics(jobsPending, jobsRunning, jobsCompleted); 423 context.GetJobsEngine().GetRegistry().GetStatistics(jobsPending, jobsRunning, jobsSuccess, jobsFailed);
420 424
421 MetricsRegistry& registry = context.GetMetricsRegistry(); 425 MetricsRegistry& registry = context.GetMetricsRegistry();
422 registry.SetValue("orthanc_disk_size_mb", static_cast<float>(diskSize) / MEGA_BYTES); 426 registry.SetValue("orthanc_disk_size_mb", static_cast<float>(diskSize) / MEGA_BYTES);
423 registry.SetValue("orthanc_uncompressed_size_mb", static_cast<float>(diskSize) / MEGA_BYTES); 427 registry.SetValue("orthanc_uncompressed_size_mb", static_cast<float>(diskSize) / MEGA_BYTES);
424 registry.SetValue("orthanc_count_patients", static_cast<unsigned int>(countPatients)); 428 registry.SetValue("orthanc_count_patients", static_cast<unsigned int>(countPatients));
425 registry.SetValue("orthanc_count_studies", static_cast<unsigned int>(countStudies)); 429 registry.SetValue("orthanc_count_studies", static_cast<unsigned int>(countStudies));
426 registry.SetValue("orthanc_count_series", static_cast<unsigned int>(countSeries)); 430 registry.SetValue("orthanc_count_series", static_cast<unsigned int>(countSeries));
427 registry.SetValue("orthanc_count_instances", static_cast<unsigned int>(countInstances)); 431 registry.SetValue("orthanc_count_instances", static_cast<unsigned int>(countInstances));
428 registry.SetValue("orthanc_jobs_pending", jobsPending); 432 registry.SetValue("orthanc_jobs_pending", jobsPending);
429 registry.SetValue("orthanc_jobs_running", jobsRunning); 433 registry.SetValue("orthanc_jobs_running", jobsRunning);
430 registry.SetValue("orthanc_jobs_completed", jobsCompleted); 434 registry.SetValue("orthanc_jobs_completed", jobsSuccess + jobsFailed);
435 registry.SetValue("orthanc_jobs_success", jobsSuccess);
436 registry.SetValue("orthanc_jobs_failed", jobsFailed);
431 437
432 std::string s; 438 std::string s;
433 registry.ExportPrometheusText(s); 439 registry.ExportPrometheusText(s);
434 440
435 call.GetOutput().AnswerBuffer(s, MimeType_PrometheusText); 441 call.GetOutput().AnswerBuffer(s, MimeType_PrometheusText);