Skip to content

Commit edc9c8a

Browse files
authored
Update documentation (#14)
* Update sphinx doc stuff * Update docstring for MetricsList class for better sphinx documentation
1 parent abe8178 commit edc9c8a

File tree

3 files changed

+62
-25
lines changed

3 files changed

+62
-25
lines changed

docs/source/prometheus_api_client.rst

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,36 @@ prometheus\_api\_client package
44
Submodules
55
----------
66

7+
prometheus\_api\_client.metric module
8+
-------------------------------------
9+
10+
.. automodule:: prometheus_api_client.metric
11+
:members: Metric
12+
:special-members: __add__, __eq__, __str__
13+
:undoc-members:
14+
:show-inheritance:
15+
16+
prometheus\_api\_client.metrics\_list module
17+
--------------------------------------------
18+
19+
.. automodule:: prometheus_api_client.metrics_list
20+
:members:
21+
:undoc-members:
22+
:show-inheritance:
23+
724
prometheus\_api\_client.prometheus\_connect module
825
--------------------------------------------------
926

1027
.. automodule:: prometheus_api_client.prometheus_connect
11-
:members:
12-
:undoc-members:
13-
:show-inheritance:
28+
:members:
29+
:undoc-members:
30+
:show-inheritance:
1431

1532

1633
Module contents
1734
---------------
1835

1936
.. automodule:: prometheus_api_client
20-
:members:
21-
:undoc-members:
22-
:show-inheritance:
37+
:members:
38+
:undoc-members:
39+
:show-inheritance:

prometheus_api_client/metric.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ class Metric:
2121
A Class for `Metric` object
2222
2323
:param metric: (dict) A metric item from the list of metrics received from prometheus
24-
:param oldest_data_datetime: (str) So any metric values in the dataframe that are older than
25-
this value will be deleted when new data is added to the dataframe using
24+
:param oldest_data_datetime: (str) Any metric values in the dataframe that are older than \
25+
this value will be deleted when new data is added to the dataframe using \
2626
the __add__("+") operator.
27-
Example: oldest_data_datetime="10d", will delete the metric data that is older
28-
than 10 days. The dataframe is pruned only when new data is added to it.
2927
30-
oldest_data_datetime="23 May 2019 12:00:00"
31-
32-
oldest_data_datetime="1561475156" can be set using the unix timestamp
28+
* `oldest_data_datetime="10d"`, will delete the metric data that is older \
29+
than 10 days. The dataframe is pruned only when new data is added to it. \n
30+
* `oldest_data_datetime="23 May 2019 12:00:00"`\n
31+
* `oldest_data_datetime="1561475156"` can also be set using the unix timestamp
3332
3433
Example Usage:
3534
``prom = PrometheusConnect()``
@@ -64,20 +63,19 @@ def __init__(self, metric, oldest_data_datetime=None):
6463

6564
def __eq__(self, other):
6665
"""
67-
overloading operator `=`
66+
overloading operator ``=``
6867
6968
Check whether two metrics are the same (are the same time-series regardless of their data)
7069
71-
:return: (bool) If two Metric objects belong to the same time-series,
72-
i.e. same name and label config, it will return True, else False
73-
7470
Example Usage:
7571
``metric_1 = Metric(metric_data_1)``
7672
7773
``metric_2 = Metric(metric_data_2)``
7874
7975
``print(metric_1 == metric_2) # will print True if they belong to the same time-series``
8076
77+
:return: (bool) If two Metric objects belong to the same time-series,
78+
i.e. same name and label config, it will return True, else False
8179
"""
8280
return bool(
8381
(self.metric_name == other.metric_name) and (self.label_config == other.label_config)
@@ -101,18 +99,24 @@ def __str__(self):
10199

102100
def __add__(self, other):
103101
"""
104-
overloading operator `+`
102+
overloading operator ``+``,
105103
Add two metric objects for the same time-series
106104
107105
Example Usage:
108-
``metric_1 = Metric(metric_data_1)``
106+
.. code-block:: python
109107
110-
``metric_2 = Metric(metric_data_2)``
108+
metric_1 = Metric(metric_data_1)
109+
metric_2 = Metric(metric_data_2)
110+
metric_12 = metric_1 + metric_2 # will add the data in ``metric_2`` to ``metric_1``
111+
# so if any other parameters are set in ``metric_1``
112+
# will also be set in ``metric_12``
113+
# (like ``oldest_data_datetime``)
114+
115+
:return: (`Metric`) Returns a `Metric` object with the combined metric data \
116+
of the two added metrics
111117
112-
``metric_12 = metric_1 + metric_2`` # will add the data in metric_2 to metric_1
113-
# so if any other parameters are set in metric_1
114-
# will also be set in metric_12
115-
# (like `oldest_data_datetime`)
118+
:raises: (TypeError) Raises an exception when two metrics being added are \
119+
from different metric time-series
116120
"""
117121
if self == other:
118122
new_metric = deepcopy(self)

prometheus_api_client/metrics_list.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,23 @@
44

55

66
class MetricsList(list):
7-
"""docstring for MetricsList."""
7+
"""A Class to initialize a list of Metric objects at once.
8+
9+
:param metric_data_list: (list|json) This is an individual metric or list of metrics received
10+
from prometheus as a result of a promql query.
11+
12+
Example Usage:
13+
.. code-block:: python
14+
15+
prom = PrometheusConnect()
16+
my_label_config = {'cluster': 'my_cluster_id', 'label_2': 'label_2_value'}
17+
metric_data = prom.get_metric_range_data(metric_name='up', label_config=my_label_config)
18+
19+
metric_object_list = MetricsList(metric_data) # metric_object_list will be initialized as
20+
# a list of Metric objects for all the
21+
# metrics downloaded using get_metric query
22+
23+
"""
824

925
def __init__(self, metric_data_list):
1026
# if the input is not a list

0 commit comments

Comments
 (0)