Initial Proxmox dashboard with host and guest metrics

This commit is contained in:
maxim
2026-07-31 19:51:22 +03:00
commit 584ff7e8ee
21 changed files with 1780 additions and 0 deletions

50
main.go Normal file
View File

@@ -0,0 +1,50 @@
package main
import (
"context"
"errors"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
)
const defaultAddress = ":9105"
func main() {
address := os.Getenv("DASHBOARD_ADDR")
if address == "" {
address = defaultAddress
}
collector, err := newCPUCollector(cpuInfoPath, procStatPath)
if err != nil {
log.Fatalf("Не удалось запустить сборщик CPU: %v", err)
}
server := &http.Server{
Addr: address,
Handler: routes(collector),
ReadHeaderTimeout: 5 * time.Second,
}
go func() {
log.Printf("Proxmox CPU Dashboard запущен на http://0.0.0.0%s", address)
if err := server.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
log.Fatalf("Ошибка веб-сервера: %v", err)
}
}()
stop := make(chan os.Signal, 1)
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
<-stop
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := server.Shutdown(ctx); err != nil {
fmt.Fprintf(os.Stderr, "Ошибка остановки сервера: %v\n", err)
}
}