Skip to content

Commit 1ee865e

Browse files
committed
added support for metrics
1 parent e02e1f9 commit 1ee865e

4 files changed

Lines changed: 27 additions & 1 deletion

File tree

orthanc_api_client/api_client.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ def __init__(self, json_stats):
3535
self.total_uncompressed_size = int(json_stats['TotalUncompressedSize'])
3636
self.total_uncompressed_size_mb = json_stats['TotalUncompressedSizeMB']
3737

38+
class Metrics:
39+
40+
def __init__(self, metricsPrometheusText: str):
41+
# mm = self.o.get_binary("/tools/metrics-prometheus").decode("utf-8")
42+
self.metrics = {}
43+
mm = [x.split(" ") for x in metricsPrometheusText.split("\n")]
44+
for m in mm:
45+
if len(m) >= 3:
46+
self.metrics[m[0]] = m[1]
47+
48+
def get(self, metric_name: str) -> Optional[str]:
49+
return self.metrics.get(metric_name)
50+
3851

3952
class OrthancApiClient(HttpClient):
4053

@@ -113,6 +126,9 @@ def get_system(self) -> object:
113126
def get_statistics(self) -> SystemStatistics:
114127
return SystemStatistics(json_stats=self.get_json('statistics'))
115128

129+
def get_metrics(self) -> Metrics:
130+
return Metrics(metricsPrometheusText=self.get_binary("/tools/metrics-prometheus").decode("utf-8"))
131+
116132
def delete_all_content(self):
117133
"""Deletes all content from Orthanc"""
118134
self.patients.delete_all()

release-notes.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
v 0.24.0
2+
========
3+
4+
- Added support for metrics. For example:
5+
`orthanc.get_metrics().get('orthanc_available_dicom_threads')`
6+
17
v 0.23.0
28
========
9+
310
- Added support for `Worklists` plugin
411
- BREAKING CHANGES:
512
- `HttpError` no longer have a `dimse_error_status` field in case of DICOM related errors (it was actually not functional !).

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# For a discussion on single-sourcing the version across setup.py and the
2929
# project code, see
3030
# https://packaging.python.org/guides/single-sourcing-package-version/
31-
version='0.23.0', # Required
31+
version='0.24.0', # Required
3232

3333
# This is a one-line description or tagline of what your project does. This
3434
# corresponds to the "Summary" metadata field:

tests/test_api_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,9 @@ def test_delete_worklist(self):
18601860
wl_list = self.oa.worklists.get_all()
18611861
self.assertEqual(len(wl_list), 0)
18621862

1863+
def test_metrics(self):
1864+
self.assertEqual('4', self.oa.get_metrics().get('orthanc_available_dicom_threads'))
1865+
self.assertIsNone(self.oa.get_metrics().get('name_that_does_not_exist'))
18631866

18641867

18651868
if __name__ == '__main__':

0 commit comments

Comments
 (0)