Some checks failed
🚀 Build & Deploy Image / Determine Build Necessity (push) Failing after 10m14s
🚀 Build & Deploy Image / Build Runtime Base Image (push) Has been skipped
🚀 Build & Deploy Image / Build Docker Image (push) Has been skipped
🚀 Build & Deploy Image / Run Tests & Quality Checks (push) Has been skipped
🚀 Build & Deploy Image / Auto-deploy to Staging (push) Has been skipped
🚀 Build & Deploy Image / Auto-deploy to Production (push) Has been skipped
Security Vulnerability Scan / Check for Dependency Changes (push) Failing after 11m25s
Security Vulnerability Scan / Composer Security Audit (push) Has been cancelled
- Remove middleware reference from Gitea Traefik labels (caused routing issues) - Optimize Gitea connection pool settings (MAX_IDLE_CONNS=30, authentication_timeout=180s) - Add explicit service reference in Traefik labels - Fix intermittent 504 timeouts by improving PostgreSQL connection handling Fixes Gitea unreachability via git.michaelschiemer.de
70 lines
1.7 KiB
PHP
70 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\ExceptionHandling\Metrics;
|
|
|
|
/**
|
|
* Prometheus Exporter
|
|
*
|
|
* Exports exception metrics in Prometheus format.
|
|
*/
|
|
final readonly class PrometheusExporter
|
|
{
|
|
/**
|
|
* Export metrics in Prometheus format
|
|
*
|
|
* @param ExceptionMetrics $metrics Metrics to export
|
|
* @return string Prometheus-formatted metrics
|
|
*/
|
|
public function export(ExceptionMetrics $metrics): string
|
|
{
|
|
$lines = [];
|
|
|
|
// Total exception count
|
|
$lines[] = sprintf(
|
|
'exception_total %d',
|
|
$metrics->totalCount
|
|
);
|
|
|
|
// Exceptions by class
|
|
foreach ($metrics->byClass as $class => $count) {
|
|
$sanitizedClass = $this->sanitizeMetricName($class);
|
|
$lines[] = sprintf(
|
|
'exception_by_class{exception_class="%s"} %d',
|
|
$sanitizedClass,
|
|
$count
|
|
);
|
|
}
|
|
|
|
// Exceptions by component
|
|
foreach ($metrics->byComponent as $component => $count) {
|
|
$sanitizedComponent = $this->sanitizeMetricName($component);
|
|
$lines[] = sprintf(
|
|
'exception_by_component{component="%s"} %d',
|
|
$sanitizedComponent,
|
|
$count
|
|
);
|
|
}
|
|
|
|
// Average execution time
|
|
$lines[] = sprintf(
|
|
'exception_average_execution_time_ms %.2f',
|
|
$metrics->averageExecutionTimeMs
|
|
);
|
|
|
|
return implode("\n", $lines);
|
|
}
|
|
|
|
/**
|
|
* Sanitize metric name for Prometheus
|
|
*/
|
|
private function sanitizeMetricName(string $name): string
|
|
{
|
|
// Replace invalid characters
|
|
$sanitized = preg_replace('/[^a-zA-Z0-9_:]/', '_', $name);
|
|
return $sanitized;
|
|
}
|
|
}
|
|
|