-
-
Notifications
You must be signed in to change notification settings - Fork 5
Implement Prometheus metrics and ELK/Grafana observability stack #90
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
Merged
fuzziecoder
merged 2 commits into
codex/fix-remaining-issues-and-raise-pr
from
codex/implement-monitoring-and-observability-stack
Feb 25, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| """Observability utilities for metrics and logging.""" | ||
|
|
||
| from backend.observability.metrics import observability_metrics | ||
|
|
||
| __all__ = ["observability_metrics"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| """Centralized logging helpers for shipping logs to Logstash/Elasticsearch.""" | ||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import logging | ||
| import logging.handlers | ||
| from datetime import datetime, timezone | ||
|
|
||
| from backend.config import settings | ||
|
|
||
|
|
||
| class JsonTcpLogstashHandler(logging.handlers.SocketHandler): | ||
| """Send structured JSON logs over TCP to a Logstash input.""" | ||
|
|
||
| def makePickle(self, record: logging.LogRecord) -> bytes: # noqa: N802 | ||
| document = { | ||
| "timestamp": datetime.now(timezone.utc).isoformat(), | ||
| "service": "flexiroaster-backend", | ||
| "logger": record.name, | ||
| "level": record.levelname, | ||
| "message": record.getMessage(), | ||
| "pathname": record.pathname, | ||
| "lineno": record.lineno, | ||
| } | ||
| return (json.dumps(document, default=str) + "\n").encode("utf-8") | ||
|
|
||
|
|
||
| def configure_logstash_logging() -> bool: | ||
| """Attach a Logstash TCP handler to the API logger when enabled.""" | ||
| if not settings.ENABLE_LOGSTASH_LOGGING: | ||
| return False | ||
|
|
||
| logger = logging.getLogger("flexiroaster.api") | ||
| for handler in logger.handlers: | ||
| if isinstance(handler, JsonTcpLogstashHandler): | ||
| return True | ||
|
|
||
| handler = JsonTcpLogstashHandler(settings.LOGSTASH_HOST, settings.LOGSTASH_PORT) | ||
| handler.setLevel(getattr(logging, settings.LOG_LEVEL.upper(), logging.INFO)) | ||
| logger.addHandler(handler) | ||
| return True |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 CPU usage metric derived from load average is not a valid CPU percentage
Both
backend/api/routes/metrics.py:75-76andbackend/observability/metrics.py:139-141compute CPU usage asload1 * 100, treating the 1-minute load average fromos.getloadavg()as if it were a CPU utilization fraction.Detailed Explanation
The 1-minute load average represents the average number of processes in the system's run queue — it is not a fraction of CPU capacity. On a multi-core system a load of 4.0 is normal (not 400% CPU). Conversely, a load of 0.5 on an otherwise idle 16-core machine would be reported as 50% CPU usage.
In
backend/api/routes/metrics.py:75-76:And the same logic in
backend/observability/metrics.py:139-141:Note that the Prometheus gauge version at
metrics.py:140doesn't even applymin(..., 100.0), so the gauge can report values above 100 (e.g., load of 2.0 → 200.0), which violates the "percent" semantic of the metric nameflexiroaster_process_cpu_percent.Impact: CPU usage metrics will be misleading in dashboards and SLA tracking. On single-core systems with low load this might look plausible, masking the fact that the numbers are semantically wrong on multi-core systems.
Prompt for agents
Was this helpful? React with 👍 or 👎 to provide feedback.