Skip to content

Commit

Permalink
update docs, add meta generator tag in index page
Browse files Browse the repository at this point in the history
  • Loading branch information
albertodonato committed May 19, 2023
1 parent 0c017ef commit 93f644c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
33 changes: 20 additions & 13 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Asyncio library for creating Prometheus exporters

|Latest Version| |Build Status| |Coverage Status|

prometheus-aioexporter is an aysncio-powered library to simplify writing
``prometheus-aioexporter`` is an aysncio-based library to simplify writing
Prometheus_ exporters.

Exporters are usually implemented as small daemons that expose metrics
Expand All @@ -30,22 +30,30 @@ An example usage is the following:
class MyExporter(PrometheusExporterScript):
"""My Prometheus exporter."""
def configure_argument_parser(self, parser):
name = "my-exporter"
def configure_argument_parser(
self, parser: argparse.ArgumentParser
) -> None:
# Additional arguments to the script
parser.add_argument("an-option", help="an option")
parser.add_argument("--custom-option", help="a custom option")
# ...
def configure(self, args):
def configure(self, args: argparse.Namespace) -> None:
# Save attributes that are needed for later
self.data = do_stuff()
# ...
async def on_application_startup(self, application):
async def on_application_startup(
self, application: aiohttp.web.Application
) -> None:
# Start other asyncio tasks at application startup
use(self.data)
# ...
async def on_application_shutdown(self, application):
async def on_application_shutdown(
self, application: aiohttp.web.Application
) -> None:
# Stop other asyncio tasks at application shutdown
use(self.data)
# ...
Expand Down Expand Up @@ -77,17 +85,16 @@ Further options can be added by implementing ``configure_argument_parser()``,
which receives the ``argparse.ArgumentParser`` instance used by the script.

The ``script`` variable from the example above can be referenced in
``setup.cfg`` to generate the script, like
``pyproject.toml`` to generate the script, like

.. code:: ini
.. code:: toml
[options.entry_points]
console_scripts =
script = path.to.script:script
[project.scripts]
my-exporter = "path.to.script:script"
The ``name`` and ``description`` of the exporter can be customized by setting
the respective attributes in the script class.
The ``description`` of the exporter can be customized by setting the docstring
in the script class.


Startup configuration
Expand Down
4 changes: 3 additions & 1 deletion prometheus_aioexporter/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@ async def _handle_home(self, request: Request) -> Response:
<html>
<head>
<title>{title}</title>
<meta name="generator" content="{self.name}">
</head>
<body>
<h1>{title}</h1>
<p>
Metric are exported at the
<a href=".{self.metrics_path}">{self.metrics_path}</a> endpoint.
<a href=".{self.metrics_path}">{self.metrics_path}</a>
endpoint.
</p>
</body>
</html>
Expand Down

0 comments on commit 93f644c

Please sign in to comment.