Skip to main content

Overview

The Metrics Scraper is a specialized Go module that continuously scrapes metrics from the Kubernetes Metrics Server and stores them in a local SQLite database. It provides the API module with historical metrics data for visualizing resource usage over time.
The Metrics Scraper is optional but recommended for viewing CPU and memory usage trends in the Dashboard.

Module Architecture

Design Philosophy

The Metrics Scraper operates independently from other Dashboard modules:
  • Autonomous: Runs its own scraping loop
  • Lightweight: Stores only a small time window of metrics
  • Stateful: Maintains state in SQLite database
  • Simple API: Exposes HTTP endpoints for metrics queries

Entry Point

The module starts in modules/metrics-scraper/main.go:
Reference: modules/metrics-scraper/main.go:42-98

Package Structure

Scraping Architecture

Metrics Collection Flow

Update Function

Core scraping logic:
Reference: modules/metrics-scraper/main.go:103-147

Database Schema

SQLite Tables

The Metrics Scraper uses two main tables:

Node Metrics Table

Pod Metrics Table

Database Operations

Reference: modules/metrics-scraper/pkg/database/database.go

HTTP API

Endpoints

The Metrics Scraper exposes a simple REST API:

GET /api/v1/node

Returns metrics for all nodes:

GET /api/v1/node/

Returns metrics for a specific node.

GET /api/v1/pod/

Returns metrics for all pods in a namespace:

GET /api/v1/pod//

Returns metrics for a specific pod.

GET /api/v1/pod///

Returns metrics for a specific container. Reference: modules/metrics-scraper/pkg/api/dashboard/dashboard.go

API Router Setup

Reference: modules/metrics-scraper/pkg/api/api.go

Configuration

Command-Line Arguments

Reference: modules/metrics-scraper/pkg/args/args.go

Examples

Integration with API Module

The API module queries the Metrics Scraper via HTTP:

Request Flow

Reference: modules/api/main.go:122-135

Performance Considerations

Storage Efficiency

Only stores recent metrics (default 15 minutes):
Typical database size: 1-10 MB depending on cluster size
Database indexes optimize common queries:
For ephemeral storage:

Scraping Efficiency

  • Namespace Filtering: Only scrape required namespaces
  • Batched Inserts: All metrics inserted in single transaction
  • Error Resilience: Failed scrapes don’t stop the loop

Deployment

Helm Chart Configuration

Reference: charts/kubernetes-dashboard/templates/deployments/metrics-scraper.yaml

Resource Requirements

Typical resource usage:

Monitoring and Observability

Logging

Structured logging with klog:

Health Checks

The API module performs health checks:

Troubleshooting

Common Issues

Symptoms: Dashboard shows “No metrics available”Causes:
  • Metrics Server not installed in cluster
  • Metrics Scraper not running
  • API module can’t reach Metrics Scraper
Solutions:
Symptoms: Logs show database errorsCauses:
  • Read-only filesystem
  • Insufficient disk space
  • Corrupted database
Solutions:
Symptoms: Pod using too much memoryCauses:
  • Too many namespaces
  • Long retention period
  • High scrape frequency
Solutions:

Testing

Unit Tests

Reference: modules/metrics-scraper/pkg/database/database_test.go

Manual Testing

Alternative: Disabling Metrics

Metrics are optional. To disable:
Dashboard will still function but won’t show resource usage graphs.

API Module Integration

How API module consumes metrics

Kubernetes Metrics Server

Install Metrics Server in your cluster

SQLite Documentation

SQLite database documentation

Deployment Configuration

Helm chart values for metrics scraper