diff --git a/examples/README.md b/examples/README.md index 8b8c264..e1ccd5f 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,6 +1,10 @@ # autometrics-py examples -You should be able to run each example by executing `python examples/.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/.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: diff --git a/examples/example.py b/examples/example.py index f60cbea..bfa2378 100644 --- a/examples/example.py +++ b/examples/example.py @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 5dbdeef..0bfda3b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] license = "MIT OR Apache-2.0"