Skip to content

Metrics API

The AlertHawk.Metrics.API service receives Kubernetes metrics and logs from the Metrics Agent (and other sources), stores them in ClickHouse, and exposes APIs to query metrics, pod logs, Kubernetes events, cluster/node status, and (optionally) Azure/cluster prices. It can publish node-status alerts to the Notification service via a message queue.

All API routes are prefixed with /metrics (e.g. /metrics/api/metrics/namespace). Most read endpoints require JWT Bearer or Azure AD; ingest endpoints (pod/node metrics, pod logs, events) are AllowAnonymous so the agent can push without a user token.


Overview

  • ClickHouse: Stores pod/container metrics, node metrics, pod logs, Kubernetes events, and cluster prices
  • Ingest: Metrics Agent (or other clients) POST pod metrics, node metrics, pod logs, and events; node status changes can trigger notifications
  • Query: Get metrics by namespace/node, pod logs, events; list clusters and namespaces; cleanup/retention
  • Prices: Optional Azure price fetch on node ingest; query cluster prices from ClickHouse
  • Message queue: RabbitMQ or Azure Service Bus for node-status notifications to AlertHawk.Notification
  • SQL Server: Used for metrics alerts and metrics notifications (cluster–notification mapping)

Environment Variables

Configuration can be set in appsettings.json or via environment variables (e.g. Helm chart under metrics-api.env). Use __ for nested keys.

General

VariableDescription
ASPNETCORE_ENVIRONMENTRuntime environment (Development, Production)
basePathBase path for Swagger (dev)

ClickHouse

VariableDescription
CLICKHOUSE_CONNECTION_STRINGRequired. ClickHouse connection (e.g. http://clickhouse:8123/default or connection-string format)
CLICKHOUSE_TABLE_NAMEBase table name for metrics (default: k8s_metrics)
CLUSTER_NAMEOptional cluster name used when not provided per request

SQL Server

VariableDescription
ConnectionStrings__SqlConnectionStringSQL Server connection string (for metrics alerts and metrics notifications)

Message queue (RabbitMQ or Azure Service Bus)

VariableDescription
RabbitMq__HostRabbitMQ host
RabbitMq__UserRabbitMQ username
RabbitMq__PassRabbitMQ password
QueueTypeRABBITMQ or SERVICEBUS
ServiceBus__ConnectionStringAzure Service Bus connection string
ServiceBus__QueueNameService Bus queue name (e.g. notifications)

Log cleanup (Hangfire)

VariableDescription
ENABLE_LOG_CLEANUPEnable scheduled log cleanup (true / false)
LOG_CLEANUP_INTERVAL_HOURSCron expression for cleanup (e.g. 0 0 * * * = daily midnight)

Azure AD / JWT

VariableDescription
AzureAd__ClientId, AzureAd__TenantId, AzureAd__ClientSecret, AzureAd__InstanceAzure AD (for token validation)
Jwt__Key, Jwt__Issuers, Jwt__AudiencesJWT validation

Cache

VariableDescription
CacheSettings__CacheProviderCache provider (e.g. MemoryCache)

Sentry and logging

VariableDescription
Sentry__Enabled, Sentry__Dsn, Sentry__EnvironmentSentry error tracking
Logging__LogLevel__DefaultDefault log level
Logging__LogLevel__Microsoft.IdentityModel.LoggingExtensions.IdentityLoggerAdapterIdentity logger level

Swagger (development)

VariableDescription
SwaggerUICredentials__username, SwaggerUICredentials__passwordBasic auth for Swagger UI (if used)

API Controllers

Base path: /metrics/api. Auth: JWT Bearer or Azure AD unless noted.

Metrics — /metrics/api/metrics/*

MethodRouteAuthDescription
GET/metrics/namespaceBearerPod metrics by query (namespace, minutes, clusterName)
GET/metrics/namespace/{namespace}BearerPod metrics for a namespace
GET/metrics/nodeBearerNode metrics by query (nodeName, minutes, clusterName)
GET/metrics/node/{nodeName}BearerNode metrics for a node
POST/metrics/podNoneWrite pod/container metrics (ingest)
POST/metrics/nodeNoneWrite node metrics (ingest); may trigger node-status notification and Azure price fetch
GET/metrics/clustersBearerList unique cluster names
GET/metrics/namespacesBearerList unique namespaces (optional clusterName)
DELETE/metrics/cleanupBearerCleanup metrics tables (query: days; 0 = truncate)
POST/metrics/pod/logNoneWrite pod log (ingest)
GET/metrics/pod/logBearerGet pod logs (namespace, pod, container, minutes, limit, clusterName)
GET/metrics/pod/log/namespace/{namespace}BearerPod logs for namespace
GET/metrics/pod/log/namespace/{namespace}/pod/{pod}BearerPod logs for pod

Events — /metrics/api/events/*

MethodRouteAuthDescription
POST/eventsNoneWrite Kubernetes event (ingest)
GET/eventsBearerGet Kubernetes events (filters: namespace, involvedObjectKind/Name, eventType, minutes, limit, clusterName)
GET/events/namespace/{namespace}BearerEvents for namespace

ClickHouse — /metrics/api/clickhouse/*

MethodRouteAuthDescription
GET/clickhouse/table-sizesBearerTable sizes from ClickHouse system.parts

MetricsAlert — /metrics/api/MetricsAlert/*

MethodRouteAuthDescription
GET/MetricsAlert/metricsAlertsBearerMetrics alerts (clusterName, nodeName, days)
GET/MetricsAlert/metricsAlerts/cluster/{clusterName}BearerAlerts by cluster
GET/MetricsAlert/metricsAlerts/cluster/{clusterName}/node/{nodeName}BearerAlerts by cluster and node

MetricsNotification — /metrics/api/MetricsNotification/*

MethodRouteAuthDescription
GET/MetricsNotification/clusterNotifications/{clusterName}BearerNotifications for cluster
POST/MetricsNotification/addMetricsNotificationBearerAdd notification to cluster
POST/MetricsNotification/removeMetricsNotificationBearerRemove notification from cluster

Cluster prices — /metrics/api/cluster-prices/*

MethodRouteAuthDescription
GET/cluster-pricesBearerCluster prices (clusterName, nodeName, region, instanceType, minutes)
GET/cluster-prices/cluster/{clusterName}BearerPrices by cluster
GET/cluster-prices/cluster/{clusterName}/node/{nodeName}BearerPrices by cluster and node

Azure prices — /metrics/api/azure-prices

MethodRouteAuthDescription
POST/azure-pricesNoneGet Azure prices (body: AzurePriceRequest; region, SKU, OS, etc.)

Version — /metrics/api/Version

MethodRouteAuthDescription
GET/VersionNoneAPI version

Data flow

  1. Metrics Agent (or other clients) sends pod metrics, node metrics, pod logs, and Kubernetes events to the Metrics API (POST endpoints; no auth).
  2. Metrics API writes to ClickHouse (metrics, node metrics, pod logs, events tables).
  3. On node metric ingest, the API may send node status changes to the Notification service via the message queue and may fetch Azure prices and store them in ClickHouse.
  4. Alerts and notification mappings (cluster → notification ID) are stored in SQL Server and queried via MetricsAlert and MetricsNotification controllers.

Helm Chart Reference

In the Helm chart, Metrics API is configured under the metrics-api section. Set metrics-api.env with the variables above (e.g. CLICKHOUSE_CONNECTION_STRING, ConnectionStrings__SqlConnectionString, RabbitMq__* or ServiceBus__*, ENABLE_LOG_CLEANUP, LOG_CLEANUP_INTERVAL_HOURS, Azure AD, JWT, etc.). See Environment variables in the Helm docs.

AlertHawk - Self-hosted monitoring solution.