Skip to content

Commit 069fced

Browse files
authored
Merge pull request #257 from jichenjc/bug/237-1
add healthy for exporter
2 parents fc425e9 + f19bbce commit 069fced

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

cmd/exporter.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ var (
4242
enabledEBPFCgroupID = flag.Bool("enable-cgroup-id", true, "whether enable eBPF to collect cgroup id (must have kernel version >= 4.18 and cGroup v2)")
4343
)
4444

45+
func healthProbe(w http.ResponseWriter, req *http.Request) {
46+
w.WriteHeader(http.StatusOK)
47+
_, err := w.Write([]byte(`ok`))
48+
if err != nil {
49+
klog.Fatalf("%s", fmt.Sprintf("failed to write response: %v", err))
50+
}
51+
}
52+
4553
func main() {
4654
klog.InitFlags(nil)
4755
flag.Parse()
@@ -80,6 +88,7 @@ func main() {
8088
}
8189

8290
http.Handle(*metricsPath, promhttp.Handler())
91+
http.HandleFunc("/healthz", healthProbe)
8392
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
8493
_, err = w.Write([]byte(`<html>
8594
<head><title>Energy Stats Exporter</title></head>

manifests/kubernetes/deployment.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ spec:
7878
- containerPort: 9102
7979
hostPort: 9102
8080
name: http
81+
livenessProbe:
82+
failureThreshold: 5
83+
httpGet:
84+
path: /healthz
85+
port: 9102
86+
scheme: HTTP
87+
initialDelaySeconds: 10
88+
periodSeconds: 60
89+
successThreshold: 1
90+
timeoutSeconds: 10
8191
volumeMounts:
8292
- mountPath: /lib/modules
8393
name: lib-modules

0 commit comments

Comments
 (0)