Skip to content

Commit 30b50d1

Browse files
docs: fix server metrics example (#547)
The existing examples/get_server_metrics.py version has 2 problems: - the iso-formatted dates need a timezone in order to work with the API - Object of type Metrics is not JSON serializable anymore. So i added an explicit UTC timezone for the datetime objects, and got rid of the json.dumps() at the end of the script.
1 parent 14ecce2 commit 30b50d1

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

examples/get_server_metrics.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

3-
import json
4-
from datetime import datetime, timedelta
3+
from datetime import datetime, timedelta, timezone
54
from os import environ
65

76
from hcloud import Client
@@ -24,7 +23,7 @@
2423
)
2524
server = response.server
2625

27-
end = datetime.now()
26+
end = datetime.now(timezone.utc)
2827
start = end - timedelta(hours=1)
2928

3029
response = server.get_metrics(
@@ -33,4 +32,4 @@
3332
end=end,
3433
)
3534

36-
print(json.dumps(response.metrics))
35+
print(response.metrics)

0 commit comments

Comments
 (0)