Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

1.2 KB
Raw Blame
package api

import (
	"context"
	"net/http"

	"github.com/rcourtman/pulse-go-rewrite/internal/api/chartapi"
	"github.com/rcourtman/pulse-go-rewrite/internal/monitoring"
)

type routerChartMonitorResolver struct {
	router *Router
}

func (r routerChartMonitorResolver) MonitorForContext(ctx context.Context) *monitoring.Monitor {
	if r.router == nil {
		return nil
	}
	return r.router.getTenantMonitor(ctx)
}

func (r *Router) ensureChartService() *chartapi.Service {
	r.chartServiceOnce.Do(func() {
		if r.chartService == nil {
			r.chartService = chartapi.NewService(routerChartMonitorResolver{router: r})
		}
	})
	return r.chartService
}

func (r *Router) handleCharts(w http.ResponseWriter, req *http.Request) {
	r.ensureChartService().HandleCharts(w, req)
}

func (r *Router) handleWorkloadCharts(w http.ResponseWriter, req *http.Request) {
	r.ensureChartService().HandleWorkloadCharts(w, req)
}

func (r *Router) handleInfrastructureCharts(w http.ResponseWriter, req *http.Request) {
	r.ensureChartService().HandleInfrastructureCharts(w, req)
}

func (r *Router) handleStorageCharts(w http.ResponseWriter, req *http.Request) {
	r.ensureChartService().HandleStorageCharts(w, req)
}