Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to control the exporter webserver address used #56

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ You can modify environment variables to change the behavior of the exporter.
| --- | --- | --- |
| `LOG_LEVEL` | Logging level | `INFO` |
| `MAX_RETRIES` | Number of retries to attempt when fetching metrics from Prefect API | `3` |
| `METRICS_ADDR` | Address to expose metrics on | `0.0.0.0` |
| `METRICS_PORT` | Port to expose metrics on | `8000` |
| `OFFSET_MINUTES` | Number of minutes to offset the start time when fetching metrics from Prefect API | `5` |
| `PREFECT_API_URL` | Prefect API URL | `https://localhost:4200/api` |
Expand Down
5 changes: 3 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def metrics():
# Get environment variables or use default values
loglevel = str(os.getenv("LOG_LEVEL", "INFO"))
max_retries = int(os.getenv("MAX_RETRIES", "3"))
metrics_addr = os.getenv("METRICS_ADDR", "0.0.0.0")
metrics_port = int(os.getenv("METRICS_PORT", "8000"))
offset_minutes = int(os.getenv("OFFSET_MINUTES", "3"))
url = str(os.getenv("PREFECT_API_URL", "http://localhost:4200/api"))
Expand Down Expand Up @@ -69,8 +70,8 @@ def metrics():
REGISTRY.register(metrics)

# Start the HTTP server to expose Prometheus metrics
start_http_server(metrics_port)
logger.info(f"Exporter listening on port :{metrics_port}")
start_http_server(metrics_port, metrics_addr)
r0ro marked this conversation as resolved.
Show resolved Hide resolved
logger.info(f"Exporter listening on {metrics_addr}:{metrics_port}")

# Run the loop to collect Prefect metrics
while True:
Expand Down