From acc
Generates PHP 8.4 metrics collector: MetricsCollectorInterface, Counter/Gauge/Histogram wrappers, Prometheus adapter, PSR-15 RED metrics middleware, /metrics endpoint, NullMetricsCollector, and unit tests. For observability.
How this skill is triggered — by the user, by Claude, or both
Slash command
/acc:create-metrics-collectorThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Creates metrics collection infrastructure for application observability and monitoring.
Creates metrics collection infrastructure for application observability and monitoring.
| Scenario | Example |
|---|---|
| Request monitoring | Track request rate, errors, duration (RED) |
| Business metrics | Count orders, revenue, active users |
| Performance profiling | Histogram of response times |
| Health dashboards | Expose /metrics for Prometheus scraping |
/metrics endpoint exposing Prometheus formattext/plain with all registered metricsPath: src/Infrastructure/Metrics/
MetricsCollectorInterface.php — Metrics contractCounter.php — Counter metric wrapperGauge.php — Gauge metric wrapperHistogram.php — Histogram metric wrapperPath: src/Infrastructure/Metrics/
PrometheusMetricsCollector.php — Prometheus adapterNullMetricsCollector.php — Null Object for testingPath: src/Infrastructure/Metrics/
MetricsMiddleware.php — PSR-15 RED metrics middlewareMetricsAction.php — /metrics endpoint actionNullMetricsCollectorTest.php — Null object behavior testsMetricsMiddlewareTest.php — Middleware metrics tests| Component | Path |
|---|---|
| All Classes | src/Infrastructure/Metrics/ |
| Unit Tests | tests/Unit/Infrastructure/Metrics/ |
| Component | Pattern | Example |
|---|---|---|
| Interface | MetricsCollectorInterface | MetricsCollectorInterface |
| Counter | Counter | Counter |
| Gauge | Gauge | Gauge |
| Histogram | Histogram | Histogram |
| Prometheus | PrometheusMetricsCollector | PrometheusMetricsCollector |
| Null Object | NullMetricsCollector | NullMetricsCollector |
| Middleware | MetricsMiddleware | MetricsMiddleware |
| Action | MetricsAction | MetricsAction |
| Test | {ClassName}Test | MetricsMiddlewareTest |
interface MetricsCollectorInterface
{
/** @param array<string, string> $labels */
public function increment(string $name, array $labels = [], float $value = 1.0): void;
/** @param array<string, string> $labels */
public function gauge(string $name, float $value, array $labels = []): void;
/** @param array<string, string> $labels */
public function histogram(string $name, float $value, array $labels = []): void;
}
final readonly class MetricsMiddleware implements MiddlewareInterface
{
public function process(
ServerRequestInterface $request,
RequestHandlerInterface $handler
): ResponseInterface;
}
final readonly class NullMetricsCollector implements MetricsCollectorInterface
{
public function increment(string $name, array $labels = [], float $value = 1.0): void {}
public function gauge(string $name, float $value, array $labels = []): void {}
public function histogram(string $name, float $value, array $labels = []): void {}
}
// Middleware auto-collects RED metrics
$middleware = new MetricsMiddleware($collector);
// Manual metrics in use cases
$collector->increment('orders_created_total', ['channel' => 'web']);
$collector->gauge('active_connections', $pool->activeCount());
$collector->histogram('payment_duration_seconds', $elapsed, ['gateway' => 'stripe']);
// Expose via /metrics endpoint
$app->get('/metrics', new MetricsAction($collector));
Rate ──→ http_requests_total{method, path, status}
Errors ──→ http_requests_total{status=~"5.."}
Duration ──→ http_request_duration_seconds{method, path}
| Anti-pattern | Problem | Solution |
|---|---|---|
| High cardinality labels | Prometheus storage explosion | Limit label values, no user IDs |
| No null implementation | Cannot disable metrics in tests | NullMetricsCollector |
| Inline metric names | Typos, inconsistency | Define constants or enum |
| Missing error metrics | Cannot calculate error rate | Track status codes |
| No histogram buckets | Default buckets don't fit use case | Configure per metric |
| Metrics in domain layer | Infrastructure leak | Keep in infrastructure only |
For complete PHP templates and examples, see:
references/templates.md — MetricsCollectorInterface, Counter, Gauge, Histogram, Prometheus, Middleware templatesreferences/examples.md — Integration examples and testsnpx claudepluginhub dykyi-roman/awesome-claude-code --plugin accRecords application metrics with OpenTelemetry counters, histograms, and gauges for monitoring, alerting, and SLI/SLO dashboards. Replaces vendor-specific clients with OpenTelemetry.
Provides observability knowledge base covering three pillars (logs, metrics, traces), structured logging with Monolog, distributed tracing via OpenTelemetry, RED/USE metrics collection, and SLI/SLO/SLA definitions for PHP apps.
StatsD metric instrumentation: push metrics over UDP, choose the right metric type, name consistently. Invoke whenever task involves any interaction with StatsD metrics — emitting counters, gauges, timers, histograms, sets, or distributions; configuring DogStatsD tags; tuning sampling rates; or integrating with Graphite, Prometheus, or Telegraf backends.