Post

Grafana Dashboard To Tell Me How Expensive My Hobby Is

Grafana Dashboard To Tell Me How Expensive My Hobby Is

Grafana Dashboard To Tell Me How Expensive My Hobby Is

Introduction

For many DevOps engineers and system administrators, the homelab is more than just a hobby—it’s a sandbox for testing infrastructure concepts, practicing automation, and running personal services. However, these setups often come with a hidden cost: electricity. Power consumption from servers, networking equipment, and uninterruptible power supplies (UPS) can add up significantly over time, especially when running 24/7. The challenge lies in quantifying these costs to make informed decisions about scaling back, optimizing efficiency, or simply understanding the true expense of our passion projects.

This guide walks you through building a comprehensive monitoring solution using open-source tools to track power consumption and calculate operational costs in real-time. By leveraging Grafana, Prometheus, and Loki—components of a modern observability stack—you’ll create a dashboard that not only shows power usage metrics but translates them into tangible financial insights. This approach transforms abstract kilowatt-hour readings into concrete dollar amounts, helping you manage your homelab’s economics while maintaining the flexibility and control that self-hosted environments provide.

In this comprehensive guide, you’ll learn how to:

  • Set up power monitoring for servers and UPS devices
  • Configure Prometheus to collect power consumption metrics
  • Create Grafana dashboards that calculate daily and monthly costs
  • Integrate with existing Kubernetes-based infrastructure
  • Optimize your homelab for cost efficiency without sacrificing functionality

Let’s dive into building a monitoring solution that brings financial transparency to your infrastructure investments.

Understanding the Topic

What is Power Cost Monitoring?

Power cost monitoring involves tracking electricity consumption of IT infrastructure and converting usage metrics into financial costs. This process typically requires three key components:

  1. Data Collection: Sensors or software agents that measure power draw from devices (servers, UPS units, network gear)
  2. Metric Aggregation: A time-series database to store and process consumption data over time
  3. Cost Calculation: A visualization layer that translates kilowatt-hours into currency based on your utility rates

In the context of homelabs and self-hosted environments, this monitoring serves several critical purposes:

  • Identifying energy-hungry components that could be optimized or replaced
  • Providing justification for infrastructure decisions (e.g., “Does upgrading to more efficient hardware pay for itself?”)
  • Creating accountability for power consumption across different services
  • Enabling capacity planning based on both technical and financial constraints

The Technology Stack

The solution we’ll implement uses three core open-source tools:

Prometheus
A time-series database designed for monitoring and alerting. It collects metrics from configured targets at specified intervals, evaluates rule expressions, and triggers alerts. Prometheus excels at handling high-cardinality time-series data and provides powerful query capabilities through PromQL.

Grafana
An open-source analytics and visualization platform. It connects to data sources like Prometheus to create interactive dashboards. Grafana offers rich visualization options, alerting capabilities, and role-based access control, making it ideal for creating cost monitoring dashboards.

Loki
A log aggregation system inspired by Prometheus. While not directly used in cost calculations, Loki complements our stack by providing contextual logs when investigating anomalies in power consumption.

History and Development

Prometheus was created at SoundCloud in 2012 and donated to the Cloud Native Computing Foundation (CNCF) in 2016. It has since become the de facto standard for Kubernetes monitoring. Grafana, initially developed by Torkel Ödegaard in 2011, gained prominence as it added Prometheus support and became the visualization layer for countless observability stacks. Loki, created by Grafana Labs in 2018, addresses the need for log aggregation that scales similarly to Prometheus.

Key Features

  • Real-time monitoring: Track power consumption as it happens
  • Historical analysis: Compare usage patterns over days, weeks, or months
  • Cost projection: Estimate monthly bills based on current usage
  • Anomaly detection: Identify unusual power draws that might indicate problems
  • Device comparison: Compare efficiency between different hardware components
  • Integration potential: Connect with billing systems for automated cost allocation

Pros and Cons

Pros:

  • Open-source and free to use
  • Highly customizable dashboards
  • Scalable for both small and large deployments
  • Integrates with existing Kubernetes infrastructure
  • Provides both technical and financial insights
  • Community support and extensive documentation

Cons:

  • Initial setup complexity
  • Requires accurate utility rate information
  • May need additional hardware for power monitoring (smart plugs, UPS sensors)
  • Data storage costs can grow with retention periods
  • Requires periodic updates as utility rates change

Use Cases

This monitoring solution is particularly valuable for:

  • Homelab operators managing multiple servers
  • Small businesses with self-hosted infrastructure
  • Educational institutions running computer labs
  • Remote office setups with dedicated server rooms
  • Edge computing deployments with power constraints

The observability landscape continues to evolve, with increasing focus on cost optimization as sustainability and operational expenses become more prominent. Modern trends include:

  • AI-driven cost anomaly detection
  • Carbon footprint tracking alongside financial costs
  • Integration with cloud billing for hybrid environments
  • Predictive cost modeling based on historical data
  • Automated right-sizing recommendations

Comparison to Alternatives

While commercial monitoring solutions like Datadog or Splunk offer turnkey cost tracking, they come with significant licensing costs. The open-source stack provides:

  • Cost control: No vendor lock-in or subscription fees
  • Flexibility: Customizable to exact requirements
  • Transparency: Full control over data and calculations
  • Skill development: Opportunity to learn monitoring best practices

The tradeoff is increased initial setup complexity and ongoing maintenance responsibilities, but for technical teams managing their own infrastructure, this is often an acceptable compromise.

Prerequisites

Before implementing your power cost monitoring solution, ensure you have the following components in place:

System Requirements

  • Kubernetes Cluster: A functional cluster running Proxmox or similar virtualization platform
  • Monitoring Targets: Servers and UPS units with power monitoring capabilities
    • For servers: IPMI sensors or smart power strips
    • For UPS: Network management cards (e.g., AP9600, Liebert NXC)
  • Storage: Adequate persistent storage for Prometheus and Loki data
  • Network: Access between monitoring stack and power monitoring hardware

Required Software

| Component | Version | Purpose | |———–|———|———| | Kubernetes | 1.20+ | Container orchestration platform | | Prometheus | 2.35+ | Metrics collection and storage | | Grafana | 9.0+ | Visualization and dashboarding | | Loki | 2.6+ | Log aggregation | | Node Exporter | 1.4+ | Host metrics collection | | Power Exporters | Varies | Device-specific power metrics | | Helm | 3.8+ | Package manager for Kubernetes |

Network and Security Considerations

  • Firewall Rules: Allow traffic from Prometheus to target ports (typically 9100 for Node Exporter, device-specific ports for UPS monitoring)
  • Network Segmentation: Isolate monitoring traffic in a separate network namespace
  • TLS Encryption: Enable HTTPS for Grafana and Prometheus communication
  • Authentication: Implement OAuth or LDAP for Grafana access

User Permissions

  • Kubernetes cluster admin privileges for component deployment
  • Grafana admin access for dashboard creation
  • Prometheus write access for metric ingestion
  • Target device monitoring permissions (varies by hardware)

Pre-installation Checklist

  1. Verify Kubernetes cluster connectivity and resources
  2. Confirm power monitoring hardware is accessible via network
  3. Document utility rates (cost per kWh)
  4. Identify all devices requiring power monitoring
  5. Prepare persistent storage volumes for time-series data
  6. Review Prometheus and Loki storage requirements based on retention policies

Installation & Setup

Let’s build the monitoring stack component by component. We’ll start with the foundational services and then add power monitoring capabilities.

1. Installing Prometheus

First, deploy Prometheus using Helm for simplified management:

1
2
3
4
5
6
7
8
9
10
11
12
13
# Add Prometheus Helm repository
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update

# Create namespace for monitoring
kubectl create namespace monitoring

# Install Prometheus with custom values
helm install prometheus prometheus-community/kube-prometheus-stack \
  --namespace monitoring \
  --set grafana.enabled=false \
  --set prometheus.prometheusSpec.storageSpec.volumeClaimTemplate.spec.resources.requests.storage=20Gi \
  --set prometheus.prometheusSpec.retention=30d

This command deploys Prometheus with 30-day retention and 20GB of persistent storage. The kube-prometheus-stack includes Prometheus, Alertmanager, and Grafana, but we’ll disable Grafana since we’ll install it separately.

2. Installing Loki

Next, deploy Loki for log aggregation, which will provide context when investigating power anomalies:

1
2
3
4
5
6
7
8
9
10
11
# Add Loki Helm repository
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update

# Install Loki
helm install loki grafana/loki \
  --namespace monitoring \
  --set config.compactor.retention_enabled=true \
  --set config.compactor.retention_period=720h \
  --set storage.bucketNames={index-logs,rule-logs} \
  --set storage.class=fast-ssd

This configuration sets a 30-day retention period and uses SSD storage for better performance. Adjust storage parameters based on your log volume requirements.

3. Installing Grafana

Now install Grafana separately to get the latest version:

1
2
3
4
5
6
7
# Install Grafana
helm install grafana grafana/grafana \
  --namespace monitoring \
  --set persistence.enabled=true \
  --set persistence.size=10Gi \
  --set adminPassword="secure-password-change-me" \
  --set service.type=LoadBalancer

After installation, retrieve the Grafana URL and admin password:

1
2
kubectl get svc -n monitoring grafana
kubectl get secret --namespace monitoring grafana -o jsonpath="{.data.admin-password}" | base64 --decode ; echo

4. Configuring Power Monitoring

Now let’s add power monitoring capabilities. First, deploy Node Exporter on each server to collect system metrics including power consumption:

1
2
3
4
# Add Node Exporter
helm install node-exporter prometheus-community/prometheus-node-exporter \
  --namespace monitoring \
  --set serviceMonitor.enabled=true

For UPS monitoring, we’ll use the apcupsd-exporter. Create a custom values file:

1
2
3
4
5
6
7
8
9
10
11
12
# apcupsd-values.yaml
exporter:
  config:
    ups:
      - name: ups1
        host: ups1.localdomain
        port: 3551
        community: public
      - name: ups2
        host: ups2.localdomain
        port: 3551
        community: public

Install the exporter:

1
2
3
helm install apcupsd-exporter ./apcupsd-exporter \
  --namespace monitoring \
  -f apcupsd-values.yaml

For servers with IPMI sensors, we’ll use the ipmi-exporter. Create a deployment manifest:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# ipmi-exporter-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ipmi-exporter
  namespace: monitoring
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ipmi-exporter
  template:
    metadata:
      labels:
        app: ipmi-exporter
    spec:
      containers:
      - name: ipmi-exporter
        image: quay.io/prometheuscommunity/ipmi-exporter:latest
        ports:
        - containerPort: 9199
        args:
        - --config.file=/etc/ipmi-exporter/config.yaml
        volumeMounts:
        - name: config
          mountPath: /etc/ipmi-exporter
      volumes:
      - name: config
        configMap:
          name: ipmi-exporter-config

Create the ConfigMap:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# ipmi-exporter-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: ipmi-exporter-config
  namespace: monitoring
data:
  config.yaml: |
    modules:
      default:
        ipmi:
          interface: "lanplus"
          user: "admin"
          password: "password"
          privilege: "operator"
          timeout: 10
          retries: 3

Apply the manifests:

1
2
kubectl apply -f ipmi-exporter-deployment.yaml
kubectl apply -f ipmi-exporter-config.yaml

5. Configuring Prometheus

Update Prometheus to scrape power metrics. Create a custom ConfigMap:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# prometheus-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: prometheus-config
  namespace: monitoring
data:
  prometheus.yml: |
    global:
      scrape_interval: 15s
      evaluation_interval: 15s
    
    scrape_configs:
      - job_name: 'prometheus'
        static_configs:
          - targets: ['localhost:9090']
    
      - job_name: 'node-exporter'
        kubernetes_sd_configs:
          - role: pod
        relabel_configs:
          - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
            action: keep
            regex: true
    
      - job_name: 'apcupsd-exporter'
        static_configs:
          - targets: ['apcupsd-exporter.monitoring.svc.cluster.local:9199']
    
      - job_name: 'ipmi-exporter'
        static_configs:
          - targets: ['ipmi-exporter.monitoring.svc.cluster.local:9199']

Apply the configuration:

1
kubectl apply -f prometheus-config.yaml

6. Verifying Components

Check that all services are running:

1
2
kubectl get pods -n monitoring
kubectl get svc -n monitoring

Access Prometheus at http://prometheus.monitoring.svc.cluster.local:9090 and verify metrics are being collected. Test these example queries:

  • Node power consumption:
    1
    
    power_watts
    
  • UPS load percentage:
    1
    
    apcupsd_ups_load_percent
    
  • IPMI power usage:
    1
    
    ipmi_power_watts
    

Configuration & Optimization

Now that our monitoring stack is operational, let’s configure it specifically for power cost tracking.

1. Calculating Power Costs

First, we need to define our utility rate. Create a Prometheus recording rule to calculate costs based on consumption:

1
2
3
4
5
6
7
8
9
10
# cost-calculation-rules.yaml
groups:
  - name: power_cost
    interval: 1m
    rules:
      - record: power_cost_daily_kwh
        expr: sum(power_watts) / 1000 * (1/60)  # Convert watts to kWh per minute
        
      - record: power_cost_daily_dollars
        expr: power_cost_daily_kwh * 0.12  # Replace 0.12
This post is licensed under CC BY 4.0 by the author.