Installation

Install as Agent Plugin Recommended
copilot plugin marketplace add samueltauil/skills-hub
copilot plugin install infrastructure@skills-hub

Works with GitHub Copilot CLI and VS Code (enable chat.plugins.enabled). Plugin infrastructure v1.0.0 follows the Agent Plugins spec.

Install with the gh extension
gh skills-hub install infrastructure

Don't have the extension? Run gh extension install samueltauil/skills-hub first.

Download and extract to your repository:

.github/skills/infrastructure/

Extract the ZIP to .github/skills/ in your repo. The folder name must match infrastructure for Copilot to auto-discover it.

Skill Files (3)

SKILL.md 4.6 KB
---
name: infrastructure
license: Apache-2.0
description: Ship Kubernetes, host, container, and cloud-provider telemetry into Grafana Cloud — `k8s-monitoring` Helm chart for K8s clusters (metrics + logs + traces + events + cost), Alloy `prometheus.exporter.unix` for Linux hosts, cAdvisor + Docker discovery for containers, and CloudWatch / Azure Monitor / Google Cloud Monitoring datasource setup. Use when onboarding a new cluster or VM fleet to Grafana Cloud, picking the right Helm values for K8s scraping, wiring kube-state-metrics + node-exporter + cAdvisor, alerting on `PodCrashLooping` / node memory / PVC capacity, or pulling AWS / Azure / GCP cloud metrics — even when the user says "monitor my cluster", "send K8s metrics to Grafana", "scrape EC2 metrics", "cluster pod logs", or "install the monitoring helm chart" without naming `k8s-monitoring` or Alloy.
---

# Grafana Cloud Infrastructure Monitoring

> **Docs**: https://grafana.com/docs/grafana-cloud/monitor-infrastructure/

K8s + host + container + cloud-provider telemetry, mostly via the `grafana/k8s-monitoring` Helm chart or Alloy.

## Prerequisites

- Grafana Cloud stack with Prometheus / Loki / Tempo endpoints + API key (`metrics:write`, `logs:write`, `traces:write`)
- For Kubernetes: a cluster + `helm` 3.x + `kubectl` context pointing at it
- For hosts / Docker: Alloy installed on the node

## Common Workflows

### 1. Onboard a Kubernetes cluster (k8s-monitoring chart)

```bash
# 1. Create the namespace + secret
kubectl create namespace monitoring
kubectl create secret generic grafana-cloud-secret \
  -n monitoring --from-literal=api-key=<your-api-key>

# 2. Install — values.yaml in references/k8s-monitoring-values.md
helm repo add grafana https://grafana.github.io/helm-charts && helm repo update
helm install k8s-monitoring grafana/k8s-monitoring \
  --version 4.1.4 -n monitoring -f values.yaml

# 3. Verify every pod is Running
kubectl get pods -n monitoring
# Expect alloy-*, kube-state-metrics-*, node-exporter-*, etc. all Ready.

# 4. Verify no error logs in the metrics/logs/traces Alloys
kubectl -n monitoring logs deploy/k8s-monitoring-alloy-metrics --tail=50 | grep -iE 'error|level=err' || echo "clean"

# 5. Verify telemetry landed in Grafana Cloud
#    PromQL on the metrics datasource (should be > 0):
#      sum(up{cluster="production-us-east"})
#    LogQL on Loki:
#      sum(count_over_time({cluster="production-us-east"}[5m]))
```

Full `values.yaml`, key PromQL, dashboard IDs (15520, 1860, 14282…), and alert rules: [`references/k8s-monitoring-values.md`](references/k8s-monitoring-values.md).

### 2. Monitor a Linux host

```alloy
# 1. /etc/alloy/config.alloy — see references/clouds-and-hosts.md for the full block
prometheus.exporter.unix "host"  { rootfs_path = "/" }
prometheus.scrape         "node" { targets = prometheus.exporter.unix.host.targets
                                   forward_to = [prometheus.remote_write.cloud.receiver] }
```

```bash
# 2. Reload Alloy and verify the unix exporter is up
systemctl reload alloy
curl -s http://localhost:12345/api/v0/web/components | jq '.[] | select(.id|contains("prometheus.exporter.unix"))'

# 3. Verify in Grafana Cloud — open the "Node Exporter Full" dashboard (ID 1860)
#    and pick your host from the `instance` dropdown.
```

### 3. Pull AWS / Azure / GCP metrics

Provision the datasource (full YAML in [`references/clouds-and-hosts.md`](references/clouds-and-hosts.md)), then:

```bash
# 1. After provisioning, restart Grafana to pick up the file
# 2. Verify the datasource — Grafana → Connections → Data sources → "Test"
#    Expect "Successfully queried the CloudWatch metrics API" (or equivalent).
# 3. Confirm a query — Explore → datasource → metric e.g.
#    CloudWatch namespace AWS/EC2 metric CPUUtilization, last 1h.
```

## Troubleshooting

- chart installed but no metrics in Cloud → check the `grafana-cloud-secret` `api-key` value; check Alloy logs for `401`
- `kube-state-metrics` pod Pending → likely RBAC; reapply the chart's CRDs/CRBs
- Node-exporter pod CrashLoopBackOff → typically `hostNetwork: true` collision with the host's :9100; change the port
- CloudWatch "Access denied" → IAM role missing `cloudwatch:GetMetricData`, `cloudwatch:ListMetrics`

## Resources

- [`grafana/k8s-monitoring` chart](https://github.com/grafana/k8s-monitoring-helm)
- [Monitor Infrastructure docs](https://grafana.com/docs/grafana-cloud/monitor-infrastructure/)
- [CloudWatch datasource](https://grafana.com/docs/grafana/latest/datasources/aws-cloudwatch/)
- [Azure Monitor datasource](https://grafana.com/docs/grafana/latest/datasources/azure-monitor/)
- [Google Cloud Monitoring datasource](https://grafana.com/docs/grafana/latest/datasources/google-cloud-monitoring/)
references/
clouds-and-hosts.md 2.2 KB
# Cloud-provider + host / container collection

## AWS CloudWatch

Scrape via the CloudWatch exporter:

```alloy
prometheus.scrape "cloudwatch" {
  targets    = [{__address__ = "cloudwatch-exporter:9106"}]
  forward_to = [prometheus.remote_write.cloud.receiver]
}
```

Or use the CloudWatch datasource directly:

```yaml
# provisioning/datasources/cloudwatch.yaml
apiVersion: 1
datasources:
  - name: CloudWatch
    type: cloudwatch
    jsonData:
      defaultRegion: us-east-1
      authType: default          # uses EC2 instance / ECS task role
      # Or explicit creds:
      # authType: credentials
    secureJsonData:
      accessKey: AKIAIOSFODNN7EXAMPLE
      secretKey: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
```

## Azure Monitor

```yaml
# provisioning/datasources/azure.yaml
apiVersion: 1
datasources:
  - name: Azure Monitor
    type: grafana-azure-monitor-datasource
    jsonData:
      cloudName: AzureCloud
      tenantId:  your-tenant-id
      clientId:  your-client-id
    secureJsonData:
      clientSecret: your-client-secret
```

## Google Cloud Monitoring

```yaml
# provisioning/datasources/google.yaml
apiVersion: 1
datasources:
  - name: Google Cloud Monitoring
    type: stackdriver
    jsonData:
      authenticationType: gce    # uses GCE metadata server
      # Or JWT:
      # authenticationType: jwt
    secureJsonData:
      privateKey: |
        { "type": "service_account", ... }
```

## Node Exporter (Linux host) via Alloy

```alloy
prometheus.exporter.unix "host" {
  rootfs_path = "/"
  enable_collectors = ["cpu", "diskstats", "filesystem", "loadavg", "meminfo", "netdev", "stat", "time", "uname"]
}

prometheus.scrape "node" {
  targets         = prometheus.exporter.unix.host.targets
  forward_to      = [prometheus.remote_write.cloud.receiver]
  scrape_interval = "60s"
}
```

## Docker / cAdvisor via Alloy

```alloy
prometheus.scrape "cadvisor" {
  targets      = [{"__address__" = "localhost:8080"}]
  metrics_path = "/metrics"
  forward_to   = [prometheus.remote_write.cloud.receiver]
}

discovery.docker "containers" {
  host = "unix:///var/run/docker.sock"
}

loki.source.docker "containers" {
  host       = "unix:///var/run/docker.sock"
  targets    = discovery.docker.containers.targets
  forward_to = [loki.write.cloud.receiver]
}
```
k8s-monitoring-values.md 2.8 KB
# `k8s-monitoring` Helm values reference

## Full values.yaml

```yaml
cluster:
  name: production-us-east

externalServices:
  prometheus:
    host: https://prometheus-prod-xx.grafana.net
    basicAuth:
      username: "123456"
      password: { secretName: grafana-cloud-secret, secretKey: api-key }
  loki:
    host: https://logs-prod-xx.grafana.net
    basicAuth:
      username: "234567"
      password: { secretName: grafana-cloud-secret, secretKey: api-key }
  tempo:
    host: https://tempo-prod-xx.grafana.net:443
    basicAuth:
      username: "345678"
      password: { secretName: grafana-cloud-secret, secretKey: api-key }

metrics:
  enabled: true
  cost: { enabled: true }            # Kubernetes cost monitoring
  podMonitors:     { enabled: true }
  serviceMonitors: { enabled: true }
  kube-state-metrics: { enabled: true }
  node-exporter:      { enabled: true }
  cadvisor:           { enabled: true }

logs:
  pod_logs:       { enabled: true }
  cluster_events: { enabled: true }

traces:   { enabled: true }
profiles: { enabled: false }

receivers:
  grpc: { enabled: true, port: 4317 }
  http: { enabled: true, port: 4318 }
```

## Useful Kubernetes PromQL

```promql
# CPU usage by pod
sum(rate(container_cpu_usage_seconds_total{namespace="$namespace", container!=""}[5m])) by (pod)

# Memory by pod
sum(container_memory_working_set_bytes{namespace="$namespace", container!=""}) by (pod)

# Node CPU pressure
1 - avg(rate(node_cpu_seconds_total{mode="idle"}[5m])) by (instance)

# Pod restarts
increase(kube_pod_container_status_restarts_total[1h])

# Deployment readiness
kube_deployment_status_replicas_ready / kube_deployment_spec_replicas

# PVC usage
kubelet_volume_stats_used_bytes / kubelet_volume_stats_capacity_bytes
```

## Pre-built dashboards (grafana.com IDs)

- Kubernetes / Cluster — **15520**
- Kubernetes / Namespace — **15521**
- Kubernetes / Pod — **15522**
- Node Exporter Full — **1860**
- cAdvisor — **14282**

## Infrastructure alert rules

```yaml
groups:
  - name: kubernetes-alerts
    rules:
      - alert: PodCrashLooping
        expr: rate(kube_pod_container_status_restarts_total[15m]) * 60 * 15 > 0
        for: 5m
        labels: { severity: warning }
        annotations:
          summary: "Pod {{ $labels.namespace }}/{{ $labels.pod }} crash looping"

      - alert: NodeMemoryPressure
        expr: (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) < 0.1
        for: 5m
        labels: { severity: critical }
        annotations:
          summary: "Node {{ $labels.instance }} low memory (<10% free)"

      - alert: PersistentVolumeAlmostFull
        expr: kubelet_volume_stats_available_bytes / kubelet_volume_stats_capacity_bytes < 0.1
        for: 5m
        labels: { severity: warning }
        annotations:
          summary: "PVC {{ $labels.namespace }}/{{ $labels.persistentvolumeclaim }} almost full"
```

License (Apache-2.0)

View full license text
Licensed under the Apache License, Version 2.0. See https://github.com/grafana/skills/blob/main/LICENSE