This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (a *App) handleDashboard(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -26,18 +27,58 @@ func (a *App) handleHealthz(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (a *App) handleMetrics(w http.ResponseWriter, r *http.Request) {
|
||||
// Stub metrics (Prometheus format). We'll wire real collectors later.
|
||||
// Collect real-time metrics
|
||||
// ZFS metrics
|
||||
pools, _ := a.zfs.ListPools()
|
||||
datasets, _ := a.zfs.ListDatasets("")
|
||||
zvols, _ := a.zfs.ListZVOLs("")
|
||||
snapshots, _ := a.zfs.ListSnapshots("")
|
||||
|
||||
a.metricsCollector.UpdateZFSMetrics(pools, datasets, zvols, snapshots)
|
||||
|
||||
// Service metrics
|
||||
smbShares := a.smbStore.List()
|
||||
nfsExports := a.nfsStore.List()
|
||||
iscsiTargets := a.iscsiStore.List()
|
||||
|
||||
smbStatus, _ := a.smbService.GetStatus()
|
||||
nfsStatus, _ := a.nfsService.GetStatus()
|
||||
iscsiStatus, _ := a.iscsiService.GetStatus()
|
||||
|
||||
a.metricsCollector.UpdateServiceMetrics(
|
||||
len(smbShares),
|
||||
len(nfsExports),
|
||||
len(iscsiTargets),
|
||||
smbStatus,
|
||||
nfsStatus,
|
||||
iscsiStatus,
|
||||
)
|
||||
|
||||
// Job metrics
|
||||
allJobs := a.jobManager.List("")
|
||||
running := 0
|
||||
completed := 0
|
||||
failed := 0
|
||||
for _, job := range allJobs {
|
||||
switch job.Status {
|
||||
case "running":
|
||||
running++
|
||||
case "completed":
|
||||
completed++
|
||||
case "failed":
|
||||
failed++
|
||||
}
|
||||
}
|
||||
|
||||
a.metricsCollector.UpdateJobMetrics(len(allJobs), running, completed, failed)
|
||||
|
||||
// Update uptime
|
||||
a.metricsCollector.SetUptime(int64(time.Since(a.startTime).Seconds()))
|
||||
|
||||
// Output Prometheus format
|
||||
w.Header().Set("Content-Type", "text/plain; version=0.0.4")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write([]byte(
|
||||
`# HELP atlas_build_info Build info
|
||||
# TYPE atlas_build_info gauge
|
||||
atlas_build_info{version="v0.1.0-dev"} 1
|
||||
# HELP atlas_up Whether the atlas-api process is up
|
||||
# TYPE atlas_up gauge
|
||||
atlas_up 1
|
||||
`,
|
||||
))
|
||||
_, _ = w.Write([]byte(a.metricsCollector.Collect()))
|
||||
}
|
||||
|
||||
func (a *App) render(w http.ResponseWriter, name string, data any) {
|
||||
|
||||
Reference in New Issue
Block a user