mirror of
https://github.com/containers/podman.git
synced 2026-10-27 12:19:37 -04:00
implement pod stats
Implement pod stats for the local and remote client. Both code paths end up in infra/abi to allow for code share. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
1 parent
efafd99e6d
commit
7ee0f7e14c
12 files changed
+432
-8
No files matched your search
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/containers/libpod/pkg/api/handlers"
|
||||
"github.com/containers/libpod/pkg/api/handlers/utils"
|
||||
"github.com/containers/libpod/pkg/domain/entities"
|
||||
"github.com/containers/libpod/pkg/domain/infra/abi"
|
||||
"github.com/containers/libpod/pkg/specgen"
|
||||
"github.com/containers/libpod/pkg/specgen/generate"
|
||||
"github.com/containers/libpod/pkg/util"
|
||||
@@ -419,3 +420,44 @@ func PodExists(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
utils.WriteResponse(w, http.StatusNoContent, "")
|
||||
}
|
||||
|
||||
func PodStats(w http.ResponseWriter, r *http.Request) {
|
||||
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||
decoder := r.Context().Value("decoder").(*schema.Decoder)
|
||||
|
||||
query := struct {
|
||||
NamesOrIDs []string `schema:"namesOrIDs"`
|
||||
All bool `schema:"all"`
|
||||
}{
|
||||
// default would go here
|
||||
}
|
||||
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
|
||||
utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest,
|
||||
errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
|
||||
return
|
||||
}
|
||||
|
||||
// Validate input.
|
||||
options := entities.PodStatsOptions{All: query.All}
|
||||
if err := entities.ValidatePodStatsOptions(query.NamesOrIDs, &options); err != nil {
|
||||
utils.InternalServerError(w, err)
|
||||
}
|
||||
|
||||
// Collect the stats and send them over the wire.
|
||||
containerEngine := abi.ContainerEngine{Libpod: runtime}
|
||||
reports, err := containerEngine.PodStats(r.Context(), query.NamesOrIDs, options)
|
||||
|
||||
// Error checks as documented in swagger.
|
||||
switch errors.Cause(err) {
|
||||
case define.ErrNoSuchPod:
|
||||
utils.Error(w, "one or more pods not found", http.StatusNotFound, err)
|
||||
return
|
||||
case nil:
|
||||
// Nothing to do.
|
||||
default:
|
||||
utils.InternalServerError(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
utils.WriteResponse(w, http.StatusOK, reports)
|
||||
}
|
||||
@@ -122,6 +122,13 @@ type swagPodTopResponse struct {
|
||||
}
|
||||
}
|
||||
|
||||
// List processes in pod
|
||||
// swagger:response DocsPodStatsResponse
|
||||
type swagPodStatsResponse struct {
|
||||
// in:body
|
||||
Body []*entities.PodStatsReport
|
||||
}
|
||||
|
||||
// Inspect container
|
||||
// swagger:response LibpodInspectContainerResponse
|
||||
type swagLibpodInspectContainerResponse struct {
|
||||
|
||||
@@ -14,6 +14,9 @@ var (
|
||||
ErrLinkNotSupport = errors.New("Link is not supported")
|
||||
)
|
||||
|
||||
// TODO: document the exported functions in this file and make them more
|
||||
// generic (e.g., not tied to one ctr/pod).
|
||||
|
||||
// Error formats an API response to an error
|
||||
//
|
||||
// apiMessage and code must match the container API, and are sent to client
|
||||
|
||||
@@ -286,9 +286,36 @@ func (s *APIServer) registerPodsHandlers(r *mux.Router) error {
|
||||
// 200:
|
||||
// $ref: "#/responses/DocsPodTopResponse"
|
||||
// 404:
|
||||
// $ref: "#/responses/NoSuchContainer"
|
||||
// $ref: "#/responses/NoSuchPod"
|
||||
// 500:
|
||||
// $ref: "#/responses/InternalError"
|
||||
r.Handle(VersionedPath("/libpod/pods/{name}/top"), s.APIHandler(libpod.PodTop)).Methods(http.MethodGet)
|
||||
// swagger:operation GET /libpod/pods/stats pods statsPod
|
||||
// ---
|
||||
// tags:
|
||||
// - pods
|
||||
// summary: Get stats for one or more pods
|
||||
// description: Display a live stream of resource usage statistics for the containers in one or more pods
|
||||
// parameters:
|
||||
// - in: query
|
||||
// name: all
|
||||
// description: Provide statistics for all running pods.
|
||||
// type: boolean
|
||||
// - in: query
|
||||
// name: namesOrIDs
|
||||
// description: Names or IDs of pods.
|
||||
// type: array
|
||||
// items:
|
||||
// type: string
|
||||
// produces:
|
||||
// - application/json
|
||||
// responses:
|
||||
// 200:
|
||||
// $ref: "#/responses/DocsPodTopResponse"
|
||||
// 404:
|
||||
// $ref: "#/responses/NoSuchPod"
|
||||
// 500:
|
||||
// $ref: "#/responses/InternalError"
|
||||
r.Handle(VersionedPath("/libpod/pods/stats"), s.APIHandler(libpod.PodStats)).Methods(http.MethodGet)
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user