add docker
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"online-back/internal/identity/rbac"
|
||||
"online-back/internal/identity/rbac/perm"
|
||||
"online-back/pkg/logging"
|
||||
"online-back/pkg/sysstats"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@@ -24,15 +25,18 @@ const (
|
||||
type handler struct {
|
||||
logger *logging.Logger
|
||||
repository Repository
|
||||
// diskPaths are the mount points reported by /server-stats.
|
||||
diskPaths []string
|
||||
}
|
||||
|
||||
func NewHandler(logger *logging.Logger, repository Repository) handlers.Handler {
|
||||
return &handler{logger: logger, repository: repository}
|
||||
func NewHandler(logger *logging.Logger, repository Repository, diskPaths []string) handlers.Handler {
|
||||
return &handler{logger: logger, repository: repository, diskPaths: diskPaths}
|
||||
}
|
||||
|
||||
func (h *handler) Register(router *gin.RouterGroup) {
|
||||
group := rbac.Group(router, baseURL, rbac.RequireStaff(perm.Dashboard))
|
||||
group.GET("/overview", h.overview)
|
||||
group.GET("/server-stats", h.serverStats)
|
||||
}
|
||||
|
||||
// overview godoc
|
||||
@@ -65,6 +69,26 @@ func (h *handler) overview(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, appresult.SuccessWithData(result))
|
||||
}
|
||||
|
||||
// serverStats godoc
|
||||
// @Summary Server statistics
|
||||
// @Description Returns host CPU, RAM and disk usage plus the API process's own memory and uptime. CPU usage is sampled over ~250ms; host fields are null when the OS cannot report them.
|
||||
// @Tags dashboard
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @Success 200 {object} appresult.AppSuccess{data=sysstats.Stats}
|
||||
// @Failure 500 {object} appresult.AppError
|
||||
// @Router /dashboard/server-stats [get]
|
||||
func (h *handler) serverStats(c *gin.Context) {
|
||||
stats, err := sysstats.Collect(c.Request.Context(), h.diskPaths)
|
||||
if err != nil {
|
||||
h.logger.Errorf("dashboard server stats failed: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, appresult.SuccessWithData(stats))
|
||||
}
|
||||
|
||||
func parseOverviewFilter(c *gin.Context) (OverviewFilter, bool) {
|
||||
filter := OverviewFilter{
|
||||
Year: time.Now().Year(),
|
||||
|
||||
@@ -80,7 +80,7 @@ func New(cfg *config.Config, client *pgxpool.Pool, logger *logging.Logger) *gin.
|
||||
currencyRepo := currencydb.NewRepository(client, logger)
|
||||
payment.Register(adminGroup, client, logger, currencyRepo, paymentGatewayClient(cfg, logger), cfg.PublicBaseURL)
|
||||
currency.NewHandler(logger, currencyRepo).Register(adminGroup)
|
||||
dashboard.NewHandler(logger, dashboarddb.NewRepository(client, logger)).Register(adminGroup)
|
||||
dashboard.NewHandler(logger, dashboarddb.NewRepository(client, logger), []string{"/", cfg.PublicFilePath}).Register(adminGroup)
|
||||
analytics.NewHandler(logger, analyticsdb.NewRepository(client, logger)).Register(adminGroup)
|
||||
|
||||
backupDir := filepath.Join(cfg.PublicFilePath, "backups")
|
||||
|
||||
Reference in New Issue
Block a user