Skip to content

Commit c2906b3

Browse files
author
Anand Sanmukhani
authored
Merge pull request #216 from vlad-ro/fix-docs-formatting
Fix docs formatting
2 parents 67517b2 + fb2ec71 commit c2906b3

File tree

2 files changed

+44
-34
lines changed

2 files changed

+44
-34
lines changed

prometheus_api_client/metric.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,30 @@ class Metric:
1818
A Class for `Metric` object.
1919
2020
:param metric: (dict) A metric item from the list of metrics received from prometheus
21-
:param oldest_data_datetime: (datetime|timedelta) Any metric values in the dataframe that are \
22-
older than this value will be deleted when new data is added to the dataframe \
21+
:param oldest_data_datetime: (datetime|timedelta) Any metric values in the dataframe that are
22+
older than this value will be deleted when new data is added to the dataframe
2323
using the __add__("+") operator.
2424
25-
* `oldest_data_datetime=datetime.timedelta(days=2)`, will delete the \
26-
metric data that is 2 days older than the latest metric. \
27-
The dataframe is pruned only when new data is added to it. \n
28-
* `oldest_data_datetime=datetime.datetime(2019,5,23,12,0)`, will delete \
29-
any data that is older than "23 May 2019 12:00:00" \n
30-
* `oldest_data_datetime=datetime.datetime.fromtimestamp(1561475156)` \
31-
can also be set using the unix timestamp
25+
* `oldest_data_datetime=datetime.timedelta(days=2)`, will delete the
26+
metric data that is 2 days older than the latest metric.
27+
The dataframe is pruned only when new data is added to it.
28+
* `oldest_data_datetime=datetime.datetime(2019,5,23,12,0)`, will delete
29+
any data that is older than "23 May 2019 12:00:00"
30+
* `oldest_data_datetime=datetime.datetime.fromtimestamp(1561475156)`
31+
can also be set using the unix timestamp
3232
3333
Example Usage:
34-
``prom = PrometheusConnect()``
34+
.. code-block:: python
3535
36-
``my_label_config = {'cluster': 'my_cluster_id', 'label_2': 'label_2_value'}``
36+
prom = PrometheusConnect()
3737
38-
``metric_data = prom.get_metric_range_data(metric_name='up', label_config=my_label_config)``
39-
``Here metric_data is a list of metrics received from prometheus``
38+
my_label_config = {'cluster': 'my_cluster_id', 'label_2': 'label_2_value'}
4039
41-
``# only for the first item in the list``
42-
``my_metric_object = Metric(metric_data[0], datetime.timedelta(days=10))``
40+
metric_data = prom.get_metric_range_data(metric_name='up', label_config=my_label_config)
41+
# Here metric_data is a list of metrics received from prometheus
42+
43+
# only for the first item in the list
44+
my_metric_object = Metric(metric_data[0], datetime.timedelta(days=10))
4345
4446
"""
4547

@@ -85,11 +87,13 @@ def __eq__(self, other):
8587
Check whether two metrics are the same (are the same time-series regardless of their data)
8688
8789
Example Usage:
88-
``metric_1 = Metric(metric_data_1)``
90+
.. code-block:: python
91+
92+
metric_1 = Metric(metric_data_1)
8993
90-
``metric_2 = Metric(metric_data_2)``
94+
metric_2 = Metric(metric_data_2)
9195
92-
``print(metric_1 == metric_2) # will print True if they belong to the same time-series``
96+
print(metric_1 == metric_2) # will print True if they belong to the same time-series
9397
9498
:return: (bool) If two Metric objects belong to the same time-series,
9599
i.e. same name and label config, it will return True, else False
@@ -103,9 +107,11 @@ def __str__(self):
103107
Make it print in a cleaner way when print function is used on a Metric object.
104108
105109
Example Usage:
106-
``metric_1 = Metric(metric_data_1)``
110+
.. code-block:: python
111+
112+
metric_1 = Metric(metric_data_1)
107113
108-
``print(metric_1) # will print the name, labels and the head of the dataframe``
114+
print(metric_1) # will print the name, labels and the head of the dataframe
109115
110116
"""
111117
name = "metric_name: " + repr(self.metric_name) + "\n"
@@ -130,11 +136,11 @@ def __add__(self, other):
130136
# will also be set in ``metric_12``
131137
# (like ``oldest_data_datetime``)
132138
133-
:return: (`Metric`) Returns a `Metric` object with the combined metric data \
134-
of the two added metrics
139+
:return: (`Metric`) Returns a `Metric` object with the combined metric data
140+
of the two added metrics
135141
136-
:raises: (TypeError) Raises an exception when two metrics being added are \
137-
from different metric time-series
142+
:raises: (TypeError) Raises an exception when two metrics being added are
143+
from different metric time-series
138144
"""
139145
if self == other:
140146
new_metric = deepcopy(self)

prometheus_api_client/prometheus_connect.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,13 @@ def get_current_metric_value(
124124
(PrometheusApiClientException) Raises in case of non 200 response status code
125125
126126
Example Usage:
127-
``prom = PrometheusConnect()``
127+
.. code-block:: python
128128
129-
``my_label_config = {'cluster': 'my_cluster_id', 'label_2': 'label_2_value'}``
129+
prom = PrometheusConnect()
130130
131-
``prom.get_current_metric_value(metric_name='up', label_config=my_label_config)``
131+
my_label_config = {'cluster': 'my_cluster_id', 'label_2': 'label_2_value'}
132+
133+
prom.get_current_metric_value(metric_name='up', label_config=my_label_config)
132134
"""
133135
params = params or {}
134136
data = []
@@ -400,21 +402,23 @@ def get_metric_aggregation(
400402
the result of the query and the values are extracted from the result.
401403
402404
:param query: (str) This is a PromQL query, a few examples can be found
403-
at https://prometheus.io/docs/prometheus/latest/querying/examples/
405+
at https://prometheus.io/docs/prometheus/latest/querying/examples/
404406
:param operations: (list) A list of operations to perform on the values.
405-
Operations are specified in string type.
407+
Operations are specified in string type.
406408
:param start_time: (datetime) A datetime object that specifies the query range start time.
407409
:param end_time: (datetime) A datetime object that specifies the query range end time.
408410
:param step: (str) Query resolution step width in duration format or float number of seconds
409411
:param params: (dict) Optional dictionary containing GET parameters to be
410-
sent along with the API request, such as "timeout"
411-
Available operations - sum, max, min, variance, nth percentile, deviation
412-
and average.
412+
sent along with the API request, such as "timeout"
413+
Available operations - sum, max, min, variance, nth percentile, deviation
414+
and average.
413415
414416
:returns: (dict) A dict of aggregated values received in response to the operations
415-
performed on the values for the query sent.
417+
performed on the values for the query sent.
418+
419+
Example output:
420+
.. code-block:: python
416421
417-
Example output :
418422
{
419423
'sum': 18.05674,
420424
'max': 6.009373

0 commit comments

Comments
 (0)