# OpenTelemetry Collector — ready-to-use Proxmox VE node config
# Pairs with: https://linkmesh.io/blog/monitor-proxmox-ve-opentelemetry/
#
# 1. Install a pinned otelcol-contrib release (see the guide, Step 1).
# 2. Save this file as:  /etc/otelcol-contrib/config.yaml
# 3. Pick ONE exporter section below: Grafana Cloud (default) or self-hosted.
# 4. Let the service user read the journal:
#        usermod -aG systemd-journal otelcol-contrib
# 5. Validate, then restart:
#        otelcol-contrib validate --config /etc/otelcol-contrib/config.yaml
#        systemctl restart otelcol-contrib
# 6. In the Proxmox web UI: Datacenter → Metric Server → Add → OpenTelemetry,
#    endpoint http://localhost:4318  (Proxmox VE 9.0 or newer).

receivers:
  # Receives Proxmox VE's native metric push (node, guest, and storage metrics).
  # Loopback on purpose: each node runs its own collector, so nothing needs to
  # listen on the network. If a REMOTE node pushes here instead, bind
  # 0.0.0.0:4318, open TCP 4318 in the Proxmox firewall, and configure TLS.
  otlp:
    protocols:
      http:
        endpoint: 127.0.0.1:4318

  # htop-style node metrics: CPU (incl. IO delay), memory, disks, network.
  hostmetrics:
    collection_interval: 30s
    scrapers:
      cpu: {}
      memory: {}
      load: {}
      disk: {}
      filesystem: {}       # per-mount usage (% and bytes)
      network: {}
      paging: {}

  # The same journal you'd read with journalctl — cluster, HA, and daemon
  # activity, including backup-related vzdump messages via pvedaemon.
  # NOTE: full per-task output stays in /var/log/pve/tasks (not collected here).
  # NOTE: requires the service user to be in the systemd-journal group (step 4).
  journald:
    units:
      - pvedaemon
      - pveproxy
      - pvestatd
      - pve-cluster
      - pve-ha-lrm
      - pve-ha-crm
      - corosync
    priority: info

  # --- Ceph (hyper-converged setups only) -----------------------------------
  # Ceph metrics come from the MANAGER's prometheus module, not from every node:
  #     ceph mgr module enable prometheus
  # Uncomment on the node(s) where you scrape it, list ALL manager addresses
  # (standby managers return an empty page — that's fine), and add
  # "prometheus/ceph" to the metrics pipeline receivers below.
  # Do NOT point every node at localhost:9283 — most nodes run no manager.
  #
  # prometheus/ceph:
  #   config:
  #     scrape_configs:
  #       - job_name: ceph
  #         scrape_interval: 15s     # matches the mgr module's default
  #         honor_labels: true
  #         static_configs:
  #           - targets:
  #               - "pve1.example.net:9283"
  #               - "pve2.example.net:9283"
  #               - "pve3.example.net:9283"

processors:
  # Hard memory cap so the collector never eats the hypervisor's RAM.
  memory_limiter:
    check_interval: 1s
    limit_mib: 256
    spike_limit_mib: 64

  # Stamps host.name on every metric and log line — this becomes the
  # host_name label you filter on in Grafana. Do not remove.
  resourcedetection/system:
    detectors: [system]
    system:
      hostname_sources: [os]

  # Batches telemetry before export.
  batch: {}

exporters:
  # --- Option A: Grafana Cloud (default) ------------------------------------
  # Paste your values from Grafana Cloud → Connections → OTLP → "Send data".
  otlphttp/grafana:
    endpoint: "https://otlp-gateway-<zone>.grafana.net/otlp"
    headers:
      Authorization: "Basic <base64 of instanceID:token>"

  # --- Option B: self-hosted Prometheus + Loki ------------------------------
  # Prometheus must run with --web.enable-otlp-receiver.
  # Loki 3.x accepts OTLP natively under /otlp.
  # Uncomment these two and swap them into the pipelines below.
  #
  # otlphttp/prometheus:
  #   metrics_endpoint: "http://prometheus.example.net:9090/api/v1/otlp/v1/metrics"
  # otlphttp/loki:
  #   endpoint: "http://loki.example.net:3100/otlp"

service:
  pipelines:
    metrics:
      receivers: [otlp, hostmetrics]          # + prometheus/ceph on mgr-scraping nodes
      processors: [memory_limiter, resourcedetection/system, batch]
      exporters: [otlphttp/grafana]           # or: [otlphttp/prometheus]
    logs:
      receivers: [journald]
      processors: [memory_limiter, resourcedetection/system, batch]
      exporters: [otlphttp/grafana]           # or: [otlphttp/loki]
