2022-12-11 06:58:22 +00:00
|
|
|
package system
|
2022-11-16 16:38:39 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
httperror "github.com/portainer/libhttp/error"
|
|
|
|
"github.com/portainer/libhttp/response"
|
|
|
|
"github.com/portainer/portainer/api/internal/endpointutils"
|
2022-12-11 06:58:22 +00:00
|
|
|
plf "github.com/portainer/portainer/api/platform"
|
2022-11-16 16:38:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type systemInfoResponse struct {
|
2022-12-25 08:47:21 +00:00
|
|
|
Platform plf.ContainerPlatform `json:"platform"`
|
|
|
|
EdgeAgents int `json:"edgeAgents"`
|
|
|
|
EdgeDevices int `json:"edgeDevices"`
|
|
|
|
Agents int `json:"agents"`
|
2022-11-16 16:38:39 +00:00
|
|
|
}
|
|
|
|
|
2022-12-11 06:58:22 +00:00
|
|
|
// @id systemInfo
|
2022-11-16 16:38:39 +00:00
|
|
|
// @summary Retrieve system info
|
|
|
|
// @description **Access policy**: authenticated
|
|
|
|
// @security ApiKeyAuth
|
|
|
|
// @security jwt
|
2022-12-11 06:58:22 +00:00
|
|
|
// @tags system
|
2022-11-16 16:38:39 +00:00
|
|
|
// @produce json
|
|
|
|
// @success 200 {object} systemInfoResponse "Success"
|
|
|
|
// @failure 500 "Server error"
|
2022-12-11 06:58:22 +00:00
|
|
|
// @router /system/info [get]
|
|
|
|
func (handler *Handler) systemInfo(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
2022-11-16 16:38:39 +00:00
|
|
|
environments, err := handler.dataStore.Endpoint().Endpoints()
|
|
|
|
if err != nil {
|
|
|
|
return httperror.InternalServerError("Failed to get environment list", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
agents := 0
|
|
|
|
edgeAgents := 0
|
|
|
|
edgeDevices := 0
|
|
|
|
|
|
|
|
for _, environment := range environments {
|
|
|
|
if endpointutils.IsAgentEndpoint(&environment) {
|
|
|
|
agents++
|
|
|
|
}
|
|
|
|
|
|
|
|
if endpointutils.IsEdgeEndpoint(&environment) {
|
|
|
|
edgeAgents++
|
|
|
|
}
|
|
|
|
|
|
|
|
if environment.IsEdgeDevice {
|
|
|
|
edgeDevices++
|
|
|
|
}
|
2022-12-11 06:58:22 +00:00
|
|
|
}
|
2022-11-16 16:38:39 +00:00
|
|
|
|
2022-12-11 06:58:22 +00:00
|
|
|
platform, err := plf.DetermineContainerPlatform()
|
|
|
|
if err != nil {
|
|
|
|
return httperror.InternalServerError("Unable to determine container platform", err)
|
2022-11-16 16:38:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return response.JSON(w, &systemInfoResponse{
|
|
|
|
EdgeAgents: edgeAgents,
|
|
|
|
EdgeDevices: edgeDevices,
|
|
|
|
Agents: agents,
|
2022-12-11 06:58:22 +00:00
|
|
|
Platform: platform,
|
2022-11-16 16:38:39 +00:00
|
|
|
})
|
|
|
|
}
|