Skip to content

Commit 2cc57e5

Browse files
committed
Update documentation to use datetime and timedelta also
1 parent 9c1044a commit 2cc57e5

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This repository includes the necessary Python client libraries to access Hawkula
77

88
## Introduction
99

10-
Python client to access Hawkular-Metrics, an abstraction to invoke REST-methods on the server endpoint using urllib2. No external dependencies, works with Python 2.7.x (tested on 2.7.5/2.7.6 and 2.7.10) and Python 3.4.x (tested with the Python 3.4.2, might work with newer versions also)
10+
Python client to access Hawkular-Metrics, an abstraction to invoke REST-methods on the server endpoint using urllib2. No external dependencies, works with Python 2.7.x (tested on 2.7.5/2.7.6 and 2.7.10/2.7.13) and Python 3.4.x / Python 3.5.x (tested with the Python 3.4.2 and Python 3.5.3, might work with newer versions also).
1111

1212
## License and copyright
1313

@@ -36,7 +36,7 @@ To install, run ``python setup.py install`` if you installed from source code, o
3636

3737
To use hawkular-client-python in your own program, after installation import from hawkular the class HawkularMetricsClient and instantiate it. After this, push dicts with keys id, timestamp and value with put or use assistant method create to send events. pydoc gives the list of allowed parameters for each function.
3838

39-
Timestamps should be in the milliseconds after epoch and numeric values should be float. The client provides a method to request current time in milliseconds, ``time_millis()``
39+
The client provides a method to request current time in milliseconds, ``time_millis()`` that's accepted by the methods, but you can use ``datetime`` and ``timedelta`` to control the time also when sending requests to the Hawkular-Metrics.
4040

4141
See metrics_test.py for more detailed examples and [Hawkular-Metrics documentation](http://www.hawkular.org/docs/components/metrics/index.html) for more detailed explanation of available features.
4242

@@ -100,8 +100,9 @@ Example pushing a multiple values:
100100

101101
```python
102102
>>> from hawkular.metrics import create_datapoint, create_metric, time_millis
103-
>>> datapoint = create_datapoint(float(4.35), time_millis())
104-
>>> datapoint2 = create_datapoint(float(4.42), time_millis() + 10)
103+
>>> t = datetime.utcnow()
104+
>>> datapoint = create_datapoint(float(4.35), t)
105+
>>> datapoint2 = create_datapoint(float(4.42), t + timedelta(seconds=10))
105106
>>> metric = create_metric(MetricType.Gauge, 'example.doc.1', [datapoint, datapoint2])
106107
>>> client.put(metric)
107108
```

tests/test_metrics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ def test_add_mixed_metrics_and_datapoints(self):
264264

265265
def test_query_options(self):
266266
# Create metric with two values
267-
t = time_millis()
267+
t = datetime.utcnow()
268268
v1 = create_datapoint(float(1.45), t)
269-
v2 = create_datapoint(float(2.00), (t - 2000))
269+
v2 = create_datapoint(float(2.00), (t - timedelta(seconds=2)))
270270

271271
m = create_metric(MetricType.Gauge, 'test.query.gauge.1', [v1, v2])
272272
self.client.put(m)
@@ -276,7 +276,7 @@ def test_query_options(self):
276276
self.assertEqual(2, len(d))
277277

278278
# Query for data which has start time limitation
279-
d = self.client.query_metric(MetricType.Gauge, 'test.query.gauge.1', start=(t - 1000))
279+
d = self.client.query_metric(MetricType.Gauge, 'test.query.gauge.1', start=(t - timedelta(seconds=1)))
280280
self.assertEqual(1, len(d))
281281

282282
def test_stats_queries(self):

0 commit comments

Comments
 (0)