diff --git a/components/views/snapshots.templ b/components/views/snapshots.templ index 699b233..cd9cd7e 100644 --- a/components/views/snapshots.templ +++ b/components/views/snapshots.templ @@ -208,52 +208,52 @@ templ VcenterTotalsPage(vcenter string, entries []VcenterTotalsEntry, chart Vcen if chart.PointsVm != "" {
- + - + - - for _, y := range chart.GridY { - - } - for _, x := range chart.GridX { - - } - - - - + + for _, y := range chart.GridY { + + } + for _, x := range chart.GridX { + + } + + + + - - for _, tick := range chart.YTicks { - {tick.Label} - } - - - for _, tick := range chart.XTicks { - {tick.Label} - } - + + for _, tick := range chart.YTicks { + {tick.Label} + } + + + for _, tick := range chart.XTicks { + {tick.Label} + } + - + VMs vCPU RAM (GB) Totals - Snapshot sequence (newest right) - -
- } + Snapshot sequence (newest right) + + + }
diff --git a/components/views/snapshots_templ.go b/components/views/snapshots_templ.go index 196d3c5..24559d6 100644 --- a/components/views/snapshots_templ.go +++ b/components/views/snapshots_templ.go @@ -585,344 +585,448 @@ func VcenterTotalsPage(vcenter string, entries []VcenterTotalsEntry, chart Vcent return templ_7745c5c3_Err } if chart.PointsVm != "" { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 37, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 39, "\" role=\"img\" aria-label=\"Totals over time\"> ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } for _, y := range chart.GridY { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 40, " ") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - } - for _, x := range chart.GridX { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 44, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 45, "\"> ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 47, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } } - var templ_7745c5c3_Var37 string - templ_7745c5c3_Var37, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", chart.Width-20)) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/snapshots.templ`, Line: 228, Col: 68} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var37)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 48, "\" y2=\"230\" stroke=\"#94a3b8\" stroke-width=\"1.5\"> ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 51, "\" x2=\"") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - for _, tick := range chart.YTicks { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, "") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var42 string - templ_7745c5c3_Var42, templ_7745c5c3_Err = templ.JoinStringErrs(tick.Label) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/snapshots.templ`, Line: 237, Col: 70} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var42)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 54, "") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } + var templ_7745c5c3_Var41 string + templ_7745c5c3_Var41, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", chart.Width-20)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/snapshots.templ`, Line: 228, Col: 100} } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 55, " ") + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var41)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - for _, tick := range chart.XTicks { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 56, "") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - var templ_7745c5c3_Var44 string - templ_7745c5c3_Var44, templ_7745c5c3_Err = templ.JoinStringErrs(tick.Label) - if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/snapshots.templ`, Line: 242, Col: 69} - } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var44)) - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "") - if templ_7745c5c3_Err != nil { - return templ_7745c5c3_Err - } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 52, "\" y2=\"") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 59, " VMs vCPU RAM (GB) Totals ") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var47 string - templ_7745c5c3_Var47, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", chart.Width/2)) + for _, tick := range chart.YTicks { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 58, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var48 string + templ_7745c5c3_Var48, templ_7745c5c3_Err = templ.JoinStringErrs(tick.Label) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/snapshots.templ`, Line: 237, Col: 71} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var48)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 60, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 61, " ") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + for _, tick := range chart.XTicks { + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 62, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var51 string + templ_7745c5c3_Var51, templ_7745c5c3_Err = templ.JoinStringErrs(tick.Label) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/snapshots.templ`, Line: 242, Col: 101} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var51)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 65, "") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 66, "VMs vCPU RAM (GB)Totals Snapshot sequence (newest right)
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 69, "\" y=\"") + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + var templ_7745c5c3_Var55 string + templ_7745c5c3_Var55, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", chart.Height+70)) + if templ_7745c5c3_Err != nil { + return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/snapshots.templ`, Line: 253, Col: 89} + } + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var55)) + if templ_7745c5c3_Err != nil { + return templ_7745c5c3_Err + } + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 70, "\" font-size=\"12\" fill=\"#475569\">Snapshot sequence (newest right)") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 63, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 71, "
Snapshot TimeVMsvCPUsRAM (GB)
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } for _, entry := range entries { - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 64, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 76, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 69, "
Snapshot TimeVMsvCPUsRAM (GB)
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 72, "
") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var48 string - templ_7745c5c3_Var48, templ_7745c5c3_Err = templ.JoinStringErrs(entry.Snapshot) + var templ_7745c5c3_Var56 string + templ_7745c5c3_Var56, templ_7745c5c3_Err = templ.JoinStringErrs(entry.Snapshot) if templ_7745c5c3_Err != nil { return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/snapshots.templ`, Line: 271, Col: 29} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var48)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var56)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 65, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 73, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var49 string - templ_7745c5c3_Var49, templ_7745c5c3_Err = templ.JoinStringErrs(entry.VmCount) + var templ_7745c5c3_Var57 string + templ_7745c5c3_Var57, templ_7745c5c3_Err = templ.JoinStringErrs(entry.VmCount) if templ_7745c5c3_Err != nil { return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/snapshots.templ`, Line: 272, Col: 47} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var49)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var57)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 66, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 74, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var50 string - templ_7745c5c3_Var50, templ_7745c5c3_Err = templ.JoinStringErrs(entry.VcpuTotal) + var templ_7745c5c3_Var58 string + templ_7745c5c3_Var58, templ_7745c5c3_Err = templ.JoinStringErrs(entry.VcpuTotal) if templ_7745c5c3_Err != nil { return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/snapshots.templ`, Line: 273, Col: 49} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var50)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var58)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 67, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 75, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - var templ_7745c5c3_Var51 string - templ_7745c5c3_Var51, templ_7745c5c3_Err = templ.JoinStringErrs(entry.RamTotalGB) + var templ_7745c5c3_Var59 string + templ_7745c5c3_Var59, templ_7745c5c3_Err = templ.JoinStringErrs(entry.RamTotalGB) if templ_7745c5c3_Err != nil { return templ.Error{Err: templ_7745c5c3_Err, FileName: `views/snapshots.templ`, Line: 274, Col: 50} } - _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var51)) + _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var59)) if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 68, "
") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 77, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } @@ -930,7 +1034,7 @@ func VcenterTotalsPage(vcenter string, entries []VcenterTotalsEntry, chart Vcent if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } - templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 70, "") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 78, "") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err } diff --git a/server/handler/vcenters.go b/server/handler/vcenters.go index c2dbee3..9c0641a 100644 --- a/server/handler/vcenters.go +++ b/server/handler/vcenters.go @@ -139,6 +139,8 @@ func buildVcenterChart(entries []views.VcenterTotalsEntry) views.VcenterChartDat width := 1200.0 height := 260.0 + plotWidth := width - 60.0 + startX := 40.0 maxVal := float64(0) for _, e := range plot { if float64(e.VmCount) > maxVal { @@ -154,15 +156,15 @@ func buildVcenterChart(entries []views.VcenterTotalsEntry) views.VcenterChartDat if maxVal == 0 { maxVal = 1 } - stepX := width + stepX := plotWidth if len(plot) > 1 { - stepX = width / float64(len(plot)-1) + stepX = plotWidth / float64(len(plot)-1) } pointsVm := "" pointsVcpu := "" pointsRam := "" for i, e := range plot { - x := 40 + float64(i)*stepX + x := startX + float64(i)*stepX yVm := 10 + (1-(float64(e.VmCount)/maxVal))*height yVcpu := 10 + (1-(float64(e.VcpuTotal)/maxVal))*height yRam := 10 + (1-(float64(e.RamTotalGB)/maxVal))*height @@ -179,7 +181,7 @@ func buildVcenterChart(entries []views.VcenterTotalsEntry) views.VcenterChartDat gridX := []float64{} if len(plot) > 1 { for i := 0; i < len(plot); i++ { - gridX = append(gridX, 40+float64(i)*stepX) + gridX = append(gridX, startX+float64(i)*stepX) } } gridY := []float64{} @@ -199,16 +201,16 @@ func buildVcenterChart(entries []views.VcenterTotalsEntry) views.VcenterChartDat stepIdx = (len(plot)-1)/maxTicks + 1 } for idx := 0; idx < len(plot); idx += stepIdx { - x := 40 + float64(idx)*stepX + x := startX + float64(idx)*stepX label := time.Unix(plot[idx].RawTime, 0).Local().Format("01-02 15:04") xTicks = append(xTicks, views.ChartTick{Pos: x, Label: label}) } if len(plot) > 1 { lastIdx := len(plot) - 1 - if (lastIdx % stepIdx) != 0 { - x := 40 + float64(lastIdx)*stepX - label := time.Unix(plot[lastIdx].RawTime, 0).Local().Format("01-02 15:04") - xTicks = append(xTicks, views.ChartTick{Pos: x, Label: label}) + xLast := startX + float64(lastIdx)*stepX + labelLast := time.Unix(plot[lastIdx].RawTime, 0).Local().Format("01-02 15:04") + if len(xTicks) == 0 || xTicks[len(xTicks)-1].Pos != xLast { + xTicks = append(xTicks, views.ChartTick{Pos: xLast, Label: labelLast}) } } return views.VcenterChartData{ diff --git a/server/router/router.go b/server/router/router.go index 1728b95..2415cdc 100644 --- a/server/router/router.go +++ b/server/router/router.go @@ -82,16 +82,16 @@ func New(logger *slog.Logger, database db.Database, buildTime string, sha1ver st if err != nil { logger.Error("failed to load swagger ui assets", "error", err) } else { - mux.Handle("/swagger/", http.StripPrefix("/swagger/", http.FileServer(http.FS(swaggerSub)))) + mux.Handle("/swagger/", middleware.CacheMiddleware(http.StripPrefix("/swagger/", http.FileServer(http.FS(swaggerSub))))) } mux.HandleFunc("/swagger", func(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/swagger/", http.StatusPermanentRedirect) }) - mux.HandleFunc("/swagger.json", func(w http.ResponseWriter, r *http.Request) { + mux.Handle("/swagger.json", middleware.CacheMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) w.Write(swaggerSpec) - }) + }))) // Register pprof handlers mux.HandleFunc("/debug/pprof/", pprof.Index) diff --git a/src/vctp.yml b/src/vctp.yml index dc698ca..eaffdd6 100644 --- a/src/vctp.yml +++ b/src/vctp.yml @@ -7,8 +7,8 @@ settings: bind_ip: bind_port: 9443 bind_disable_tls: false - tls_cert_filename: "/etc/dtms/vctp.crt" - tls_key_filename: "/etc/dtms/vctp.key" + tls_cert_filename: "/var/lib/vctp/vctp.crt" + tls_key_filename: "/var/lib/vctp/vctp.key" vcenter_username: "" vcenter_password: "" vcenter_insecure: false