Initial Proxmox dashboard with host and guest metrics
This commit is contained in:
50
main.go
Normal file
50
main.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user