diff --git a/README.md b/README.md index 08d5b427..e10cc588 100644 --- a/README.md +++ b/README.md @@ -9,27 +9,9 @@ The official Python client for [Prometheus](https://prometheus.io). pip install prometheus-client ``` -**Two**: Paste the following into a Python interpreter: -```python -from prometheus_client import start_http_server, Summary -import random -import time - -# Create a metric to track time spent and requests made. -REQUEST_TIME = Summary('request_processing_seconds', 'Time spent processing request') - -# Decorate function with metric. -@REQUEST_TIME.time() -def process_request(t): - """A dummy function that takes some time.""" - time.sleep(t) - -if __name__ == '__main__': - # Start up the server to expose the metrics. - start_http_server(8000) - # Generate some requests. - while True: - process_request(random.random()) +**Two**: Execute the start service command: +```shell +python start/run.py ``` **Three**: Visit [http://localhost:8000/](http://localhost:8000/) to view the metrics. diff --git a/start/run.py b/start/run.py new file mode 100644 index 00000000..146d0622 --- /dev/null +++ b/start/run.py @@ -0,0 +1,21 @@ +from prometheus_client import start_http_server, Summary +import random +import time + +# Create a metric to track time spent and requests made. +REQUEST_TIME = Summary('request_processing_seconds', 'Time spent processing request') + + +# Decorate function with metric. +@REQUEST_TIME.time() +def process_request(t): + """A dummy function that takes some time.""" + time.sleep(t) + + +if __name__ == '__main__': + # Start up the server to expose the metrics. + start_http_server(8000) + # Generate some requests. + while True: + process_request(random.random())