Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion cmd/nodevitals/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"github.com/KeiaiLab/nodevitals/internal/event"
"github.com/KeiaiLab/nodevitals/internal/history"
"github.com/KeiaiLab/nodevitals/internal/httpapi"
"github.com/KeiaiLab/nodevitals/internal/ksmcompat"
"github.com/KeiaiLab/nodevitals/internal/nodecompat"
"github.com/KeiaiLab/nodevitals/internal/nodeexporter"
"github.com/KeiaiLab/nodevitals/internal/sink"
"github.com/KeiaiLab/nodevitals/internal/smartctlcompat"
Expand All @@ -46,6 +48,7 @@ func main() {
for _, tier := range tiers {
switch tier {
case "core":
reg.Add(collector.NewHeartbeat(cfg.Node, "0.8.5"))
reg.Add(collector.NewLoadAvg(cfg.Node, cfg.ProcRoot))
reg.Add(collector.NewCPU(cfg.Node, cfg.ProcRoot))
reg.Add(collector.NewMem(cfg.Node, cfg.ProcRoot))
Expand Down Expand Up @@ -115,12 +118,25 @@ func main() {
// dashboards and alert rules built on node_* keep working untouched.
neCount := 0
if cfg.NodeExporter.Enabled {
extraFlags := cfg.NodeExporter.ExtraFlags
if cfg.NodeExporter.NativeCollectors {
nc := nodecompat.New(cfg.ProcRoot, cfg.SysRoot, cfg.NodeExporter.RootFSPath, slog.Default())
if err := metrics.Register(nc); err != nil {
slog.Error("register native nodecompat exporter", "err", err)
os.Exit(1)
}
slog.Info("native nodecompat collectors registered")
extraFlags = append(extraFlags,
"--no-collector.loadavg",
"--no-collector.uname",
)
Comment on lines +129 to +132

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Disable every upstream collector replaced by native metrics

When nodeExporter.enabled is used with the Helm default nativeCollectors: true, this only disables upstream loadavg and uname, but the new native exporter also emits node_filefd_*, node_entropy_*, node_procs_*, node_vmstat_*, and node_os_* while node_exporter v1.12.1 keeps its filefd, entropy, stat, vmstat, and os collectors enabled by default. Prometheus gathering treats duplicate series or inconsistent descriptors as scrape errors, so the node_exporter-compatible endpoint becomes partial/noisy by default; disable every upstream collector that native replaces, or don't enable the native replacement by default.

Useful? React with 👍 / 👎.

}
c, err := nodeexporter.New(nodeexporter.Config{
ProcPath: cfg.ProcRoot,
SysPath: cfg.SysRoot,
RootFSPath: cfg.NodeExporter.RootFSPath,
TextfileDir: cfg.NodeExporter.TextfileDir,
ExtraFlags: cfg.NodeExporter.ExtraFlags,
ExtraFlags: extraFlags,
}, slog.Default())
if err != nil {
slog.Error("node_exporter collectors", "err", err)
Expand All @@ -142,6 +158,15 @@ func main() {
slog.Info("node_exporter collectors registered", "count", neCount)
}

if cfg.KSMCompat.Enabled {
ksm := ksmcompat.New(ksmcompat.Config{Node: cfg.Node, Mode: cfg.KSMCompat.Mode})
if err := metrics.Register(ksm); err != nil {
slog.Error("register ksm compat exporter", "err", err)
os.Exit(1)
}
slog.Info("ksm compat surface enabled", "mode", cfg.KSMCompat.Mode)
}

// Long-term downsampled history — local to this node, survives past the
// Prometheus scrape retention window. Opening failure is fatal (not a
// silent skip): the operator explicitly asked for history, and a
Expand Down
3 changes: 3 additions & 0 deletions deploy/chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ Call with (dict "ctx" . "tier" "<core|smart|gpu>").
{{- define "nodevitals.configChecksums" -}}
{{- $ctx := .ctx -}}
{{- $suffix := ternary "" (printf "-%s" .tier) (eq .tier "core") -}}
prometheus.io/scrape: "true"
prometheus.io/port: {{ $ctx.Values.metrics.port | default "9847" | quote }}
prometheus.io/path: "/metrics"
checksum/config: {{ include (print $ctx.Template.BasePath "/configmap" $suffix ".yaml") $ctx | sha256sum }}
checksum/webhook-secret: {{ include (print $ctx.Template.BasePath "/secret.yaml") $ctx | sha256sum }}
{{- end -}}
Expand Down
6 changes: 6 additions & 0 deletions deploy/chart/templates/configmap-single.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ data:
{{- if .Values.nodeExporter.enabled }}
nodeExporter:
enabled: true
nativeCollectors: {{ .Values.nodeExporter.nativeCollectors }}
{{- if .Values.nodeExporter.mountRootFS }}
rootfsPath: /host/root
{{- end }}
Expand All @@ -49,6 +50,11 @@ data:
smartctlCompat:
enabled: true
{{- end }}
{{- if .Values.ksmCompat.enabled }}
ksmCompat:
enabled: true
mode: {{ .Values.ksmCompat.mode | default "node" | quote }}
{{- end }}
{{- if .Values.history.enabled }}
history:
enabled: true
Expand Down
6 changes: 6 additions & 0 deletions deploy/chart/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ data:
{{- if .Values.nodeExporter.enabled }}
nodeExporter:
enabled: true
nativeCollectors: {{ .Values.nodeExporter.nativeCollectors }}
{{- if .Values.nodeExporter.mountRootFS }}
rootfsPath: /host/root
{{- end }}
Expand All @@ -28,6 +29,11 @@ data:
{{ toYaml . | indent 8 }}
{{- end }}
{{- end }}
{{- if .Values.ksmCompat.enabled }}
ksmCompat:
enabled: true
mode: {{ .Values.ksmCompat.mode | default "node" | quote }}
{{- end }}
{{- if .Values.history.enabled }}
history:
enabled: true
Expand Down
40 changes: 40 additions & 0 deletions deploy/chart/tests/compatibility-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
# deploy/chart/tests/compatibility-check.sh
# Verifies that Helm templates render expected compatibility annotations and settings
# for gpu-operator, VictoriaMetrics (vmagent), nodeExporter, dcgmCompat, smartctlCompat, and ksmCompat.
set -euo pipefail

CHART_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"

echo "=== 1. Checking default template rendering ==="
rendered="$(helm template nodevitals "$CHART_DIR")"

echo "=== 2. Checking vmagent auto-discovery annotations ==="
echo "$rendered" | grep -q 'prometheus.io/scrape: "true"' || { echo "FAIL: missing prometheus.io/scrape annotation"; exit 1; }
echo "$rendered" | grep -q 'prometheus.io/port: "9847"' || { echo "FAIL: missing prometheus.io/port annotation"; exit 1; }
echo "PASS: vmagent annotations present"

echo "=== 3. Checking gpu-operator & dcgmCompat rendering ==="
gpu_rendered="$(helm template nodevitals "$CHART_DIR" --set tiers.gpu.enabled=true --set tiers.gpu.runtimeClassName=nvidia --set dcgmCompat.enabled=true)"
echo "$gpu_rendered" | grep -q 'runtimeClassName:.*nvidia' || { echo "FAIL: runtimeClassName nvidia not rendered"; exit 1; }
echo "$gpu_rendered" | grep -q 'dcgmCompat:' || { echo "FAIL: dcgmCompat section missing in configmap"; exit 1; }
echo "PASS: gpu-operator & dcgmCompat rendering valid"

echo "=== 4. Checking smartctlCompat rendering ==="
smart_rendered="$(helm template nodevitals "$CHART_DIR" --set tiers.smart.enabled=true --set tiers.smart.privileged=true --set smartctlCompat.enabled=true)"
echo "$smart_rendered" | grep -q 'privileged: true' || { echo "FAIL: privileged true not rendered for smart tier"; exit 1; }
echo "$smart_rendered" | grep -q 'smartctlCompat:' || { echo "FAIL: smartctlCompat section missing in configmap"; exit 1; }
echo "PASS: smartctlCompat rendering valid"

echo "=== 5. Checking nativeCollectors rendering ==="
node_rendered="$(helm template nodevitals "$CHART_DIR" --set nodeExporter.enabled=true --set nodeExporter.nativeCollectors=true)"
echo "$node_rendered" | grep -q 'nativeCollectors: true' || { echo "FAIL: nativeCollectors true not rendered"; exit 1; }
echo "PASS: nativeCollectors rendering valid"

echo "=== 6. Checking ksmCompat rendering ==="
ksm_rendered="$(helm template nodevitals "$CHART_DIR" --set ksmCompat.enabled=true --set ksmCompat.mode=cluster)"
echo "$ksm_rendered" | grep -q 'ksmCompat:' || { echo "FAIL: ksmCompat section missing in configmap"; exit 1; }
echo "$ksm_rendered" | grep -q 'mode: "cluster"' || { echo "FAIL: ksmCompat mode cluster not rendered"; exit 1; }
echo "PASS: ksmCompat rendering valid"

echo "SUCCESS: All service compatibility assertions PASSED!"
12 changes: 12 additions & 0 deletions deploy/chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ updateStrategy:
# hostNetwork: true 가 필요하다 — upstream node_exporter 도 같은 이유로 그렇게 돈다.
nodeExporter:
enabled: false
# nativeCollectors 가 true 면 nodevitals 의 자체 Go 수집기(internal/nodecompat)가
# /proc 기반 node_* 지표(loadavg, filefd, entropy, procs, vmstat, uname, osrelease)를
# 직접 방출한다.
nativeCollectors: true
# filesystem collector 는 호스트의 모든 마운트를 statfs 해야 하므로 호스트 루트를
# 읽기전용으로 마운트한다(upstream node_exporter 차트와 동일). 이는 컨테이너에
# **호스트 파일시스템 전체 읽기 권한**을 주는 것이므로, 디스크 사용량 메트릭이
Expand Down Expand Up @@ -102,6 +106,14 @@ dcgmCompat:
smartctlCompat:
enabled: false

# kube-state-metrics (KSM) 호환 kube_* 표면. 별도 kube-state-metrics 파드 없이
# nodevitals 가 kube_pod_*, kube_node_*, kube_deployment_*, kube_daemonset_*
# 지표를 동일한 /metrics 로 직접 낸다.
# mode: "node" (DaemonSet 기본값, 노드 단위 분산 수집) / "cluster" (전역 수집)
ksmCompat:
enabled: false
mode: node

# 장기보존 다운샘플링(internal/history) — Prometheus scrape retention 을 훌쩍
# 넘겨 "이 GPU 3달/1년 사용률"에 답할 수 있게, 5분 평균 시계열을 노드 로컬
# 파일(bbolt)에 별도 보관한다. 노드별로 로컬 보관이라(중앙 집계 아님) 조회는
Expand Down
94 changes: 94 additions & 0 deletions docs/COMPATIBILITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# nodevitals — 서비스 전수 호환성 및 연동 명세서 (Compatibility Matrix)

> 저장소: [`github.com/KeiaiLab/nodevitals`](https://github.com/KeiaiLab/nodevitals)
> 기준 버전: `v0.8.5` (Chart v0.8.6)
> 최종 검증 일시: 2026년 8월 12일

본 문서는 `nodevitals`가 연동되는 주요 인프라 서비스, 관측 플랫폼, GPU 오퍼레이터, 가상머신(VM) 환경 간의 명시적 호환성 계약(Compatibility Contract)과 실측 검증 결과를 제공합니다.

---

## 1. 전수 호환성 매트릭스 (Full Service Compatibility Matrix)

| 연동 대상 서비스 / 솔루션 | 호환성 상태 | 연동 메커니즘 & 수집 방식 | 비고 / 주요 구성 |
|---|---|---|---|
| **NVIDIA GPU-Operator** | **100% 호환 (DCGM 대체)** | `dcgmCompat.enabled: true` | `dcgmExporter.enabled: false` 설정 후 `DCGM_FI_*` 18개 메트릭 승계 |
| **VictoriaMetrics (vmagent)** | **100% 호환 (자동 탐지)** | Pod Annotation (`prometheus.io/scrape: "true"`) | `vmagent` kubernetes-pods 잡 자동 수집 (`port: 9847`) |
| **VictoriaMetrics (vmsingle/cluster)** | **100% 호환** | TSDB Scrape & Remote Write | Prometheus TSDB 1.0 표준 데이터 100% 수용 |
| **Prometheus Operator / Alertmanager** | **100% 호환** | `/metrics` + Service/PodMonitor | `node_*`, `DCGM_FI_*`, `smartctl_*` 기존 알림 룰 그대로 동작 |
| **Grafana Dashboard Stack** | **100% 호환** | PromQL 드롭인 쿼리 | 기존 `node_exporter`, `dcgm`, `smartctl` 전용 대시보드 변경 0 |
| **Linux Standalone VM / 베어메탈** | **100% 호환** | `systemd` 데몬 / `nodevitals -config` | K8s 없이 호스트 OS 단독 실행 (`/etc/nodevitals/config.yaml`) |
| **KubeVirt / VM 가상화 노드** | **100% 호환** | K8s DaemonSet 또는 VM 헬퍼 데몬 | KubeVirt 워커 노드 및 가상머신 내부 수집 지원 |
| **Pod Security Admission (PSA)** | **100% 호환 (Tier별 분리)** | Tiered Single-Agent | GPU Tier: Restricted 호환 / Core&Smart: Privileged 안내 |

---

## 2. 세부 서비스별 연동 계약 및 가이드

### 2.1 NVIDIA `gpu-operator` 연동
`gpu-operator` 환경에서 기존 `dcgm-exporter` 팟을 은퇴시키고 `nodevitals`로 대체하는 방법입니다.

- **`gpu-operator` 설정 (`values.yaml`)**:
```yaml
dcgmExporter:
enabled: false # dcgm-exporter 파드 기동 중단 (노드당 150MB+ RSS 절감)
```
- **`nodevitals` 설정 (`values.yaml`)**:
```yaml
tiers:
gpu:
enabled: true
runtimeClassName: nvidia # NVIDIA Container Toolkit 연동 (libnvidia-ml.so 주입)
dcgmCompat:
enabled: true # DCGM_FI_* 18개 메트릭 드롭인 방출
```
- **메트릭 정합성 검증**:
- `DCGM_FI_DEV_GPU_UTIL`, `DCGM_FI_DEV_FB_USED`, `DCGM_FI_DEV_GPU_TEMP` 등 18개 메트릭이 기존과 동일한 라벨(`gpu`, `UUID`, `pci_bus_id`, `device`, `modelName`)로 제공됩니다.

### 2.2 VictoriaMetrics (`vmagent`) 연동
`keiailab-platform`과 같이 Prometheus Operator CRD 대신 `vmagent` 정적 수집 스택을 사용하는 환경의 호환성입니다.

- **자동 발견 어노테이션 (Auto-Discovery Pod Annotations)**:
`nodevitals` 파드 템플릿에 아래 어노테이션이 기본 렌더링됩니다:
```yaml
metadata:
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9847"
prometheus.io/path: "/metrics"
```
- **`vmagent` 수집 동기화**: `vmagent`의 `kubernetes-pods` 메트릭 수집 작업이 해당 어노테이션을 감지하여 별도의 CRD 등록 없이 즉시 `/metrics` 수집을 시작합니다.

### 2.3 Standalone Linux VM / 베어메탈 호스트 연동
Kubernetes 클러스터 외부의 독립 Linux 가상머신(VM) 또는 베어메탈 전용 장비에서의 기동 가이드입니다.

- **실행 바이너리 기동**:
```bash
# 노드 설정 파일 지정 기동
nodevitals -config /etc/nodevitals/config.yaml
```
- **Systemd 서비스 등록 (`/etc/systemd/system/nodevitals.service`)**:
```ini
[Unit]
Description=nodevitals unified hardware telemetry agent
After=network.target

[Service]
ExecStart=/usr/local/bin/nodevitals -config /etc/nodevitals/config.yaml
Restart=always
RestartSec=5s
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
```

---

## 3. 검증 툴킷 및 스크립트

`deploy/chart/tests/compatibility-check.sh` 스크립트를 통해 Helm 템플릿의 호환성 어노테이션 및 렌더링 정합성을 자동으로 검증할 수 있습니다:

```bash
bash deploy/chart/tests/compatibility-check.sh
```
49 changes: 49 additions & 0 deletions internal/collector/heartbeat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package collector

import (
"context"
"runtime"
"time"

"github.com/KeiaiLab/nodevitals/internal/model"
)

type heartbeatCollector struct {
node string
version string
}

// NewHeartbeat returns a collector that emits nodevitals_up and nodevitals_build_info.
func NewHeartbeat(node, version string) Collector {
if version == "" {
version = "0.8.5"
}
return &heartbeatCollector{node: node, version: version}
}

func (c *heartbeatCollector) Name() string { return "heartbeat" }

func (c *heartbeatCollector) Collect(ctx context.Context) ([]model.Sample, error) {
now := time.Now().UTC()
return []model.Sample{
{
Node: c.node,
Tier: "core",
Device: "agent",
Metric: "nodevitals_up",
Kind: model.KindGauge,
Value: 1.0,
Timestamp: now,
},
{
Node: c.node,
Tier: "core",
Device: "agent",
Metric: "nodevitals_build_info",
Kind: model.KindGauge,
Value: 1.0,
Labels: map[string]string{"version": c.version, "goversion": runtime.Version()},
Timestamp: now,
},
}, nil
}
40 changes: 40 additions & 0 deletions internal/collector/heartbeat_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package collector

import (
"context"
"testing"
)

func TestHeartbeatCollector(t *testing.T) {
c := NewHeartbeat("node-1", "0.8.5")
if c.Name() != "heartbeat" {
t.Fatalf("unexpected name: %s", c.Name())
}

samples, err := c.Collect(context.Background())
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

if len(samples) != 2 {
t.Fatalf("expected 2 samples, got %d", len(samples))
}

upFound := false
buildInfoFound := false
for _, s := range samples {
if s.Metric == "nodevitals_up" && s.Value == 1.0 {
upFound = true
}
if s.Metric == "nodevitals_build_info" && s.Labels["version"] == "0.8.5" {
buildInfoFound = true
}
}

if !upFound {
t.Errorf("nodevitals_up missing or invalid")
}
if !buildInfoFound {
t.Errorf("nodevitals_build_info missing or invalid")
}
}
Loading
Loading