from bottle import response
from prometheus_client import CollectorRegistry, generate_latest, CONTENT_TYPE_LATEST, Counter, disable_created_metrics, \
    Gauge

disable_created_metrics()
# Prometheus metrics registry
registry = CollectorRegistry()

page_requests_counter = Counter(
    "spothole_page_requests",
    "Total number of page requests received",
    registry=registry,
)
api_requests_counter = Counter(
    "spothole_api_requests",
    "Total number of API requests received",
    registry=registry
)
spots_gauge = Gauge(
    "spothole_spots",
    "Number of spots currently in the software",
    registry=registry
)
alerts_gauge = Gauge(
    "spothole_alerts",
    "Number of alerts currently in the software",
    registry=registry
)
memory_use_gauge = Gauge(
    "spothole_memory_usage_bytes",
    "Current memory usage of the software in bytes",
    registry=registry
)


# Get a Prometheus metrics response for Bottle
def get_metrics():
    response.content_type = CONTENT_TYPE_LATEST
    response.status = 200
    return generate_latest(registry)
