Skip to content

Add Prometheus exporter for metrics #5

@ptarrant

Description

@ptarrant

Add Prometheus Metrics Endpoint

Summary

Add a /metrics endpoint to expose honeypot telemetry data in Prometheus format, enabling integration with monitoring and alerting systems. Access to endpoint only allowed by whitelist IPs, others get an error page.

Motivation

The AccessTracker class already collects valuable data about requests, suspicious activity, and attack patterns. Exposing this data via Prometheus enables:

  • Real-time dashboards (Grafana)
  • Alerting on attack spikes or new threat patterns
  • Long-term trend analysis
  • Integration with existing monitoring infrastructure

Proposed Metrics

Counters

Metric Labels Description
krawl_requests_total method, status_code Total HTTP requests received
krawl_suspicious_requests_total - Requests flagged as suspicious
krawl_honeypot_hits_total path Hits on honeypot trap paths
krawl_attack_detections_total type Attack detections by type (path_traversal, sql_injection, xss_attempt, common_probes, shell_injection)
krawl_suspicious_ua_hits_total pattern Hits from suspicious user agent patterns

Gauges

Metric Labels Description
krawl_unique_ips - Number of unique IPs observed
krawl_unique_paths - Number of unique paths requested
krawl_unique_user_agents - Number of unique user agents seen
krawl_malicious_ips - Number of IPs that triggered honeypot paths

Info Metric

Metric Labels Description
krawl_info version, server_header Build/config information

Endpoint

  • Route: GET /metrics
  • Response: Prometheus text format (text/plain; version=0.0.4)
  • Authentication: None (whitelist of IPs via config file.)

Integration Points

Modify AccessTracker.record_access() to increment Prometheus counters alongside existing tracking.
Add New prometheus.py file to handle metric gathering / emit logic.

High level Tasks

  • Add prometheus_client dependency
  • Create metrics registry with proposed metrics
  • Add /metrics endpoint to HTTP handler
  • Update AccessTracker to increment Prometheus counters
  • Add configuration option to enable/disable metrics endpoint (default disabled)
  • Add configuration option for whitelist IP to access metrics endpoint.
  • Add venv setup to build process if not already completed from earlier issues.
  • Update documentation

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions