Skip to content

Commit

Permalink
Merge pull request #19 from autometrics-dev/update_example_readme
Browse files Browse the repository at this point in the history
Update examples
  • Loading branch information
v-aparna authored Apr 13, 2023
2 parents c364676 + 5e879bd commit 480c6c2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
6 changes: 5 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# autometrics-py examples

You should be able to run each example by executing `python examples/<example>.py` from the root of the repo.
You should be able to run each example by:

- cloning this repository
- run `poetry install --with examples`
- and execute `poetry run python examples/<example>.py` from the root of the repo.

You can change the base url for Prometheus links via the `PROMETHEUS_URL` environment variable. So, if your local Prometheus were on a non-default port, like 9091, you would run:

Expand Down
30 changes: 24 additions & 6 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,31 @@ def random_error():
# Enter an infinite loop (with a 2 second sleep period), calling the "div_handled", "add", and "div_unhandled" methods,
# in order to generate metrics.
while True:
ops.div_handled(2, 0)
try:
ops.div_handled(2, 0)
except Exception:
pass

ops.add(1, 2)
ops.div_handled(2, 1)
# Randomly call `div_unhandled` with a 50/50 chance of raising an error
div_unhandled(2, random.randint(0, 1))

try:
# Randomly call `div_unhandled` with a 50/50 chance of raising an error
div_unhandled(2, random.randint(0, 1))
except Exception:
pass

ops.add(1, 2)
time.sleep(2)
# Call `div_unhandled` such that it raises an error
div_unhandled(2, 0)
random_error()

try:
# Call `div_unhandled` such that it raises an error
div_unhandled(2, 0)
except Exception:
pass

try:
# Call random_error. It will randomly raise an error or return "ok"
random_error()
except Exception:
pass
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "autometrics"
version = "0.3"
version = "0.4"
description = "Easily add metrics to your system – and actually understand them using automatically customized Prometheus queries"
authors = ["Fiberplane <[email protected]>"]
license = "MIT OR Apache-2.0"
Expand Down

0 comments on commit 480c6c2

Please sign in to comment.