Skip to content

Commit

Permalink
add stats command
Browse files Browse the repository at this point in the history
Signed-off-by: Mohammed Tayeh <info@tayeh.me>
  • Loading branch information
tayeh authored and muayyad-alsadi committed Aug 8, 2023
1 parent 06587c1 commit cb9cf60
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -2691,6 +2691,35 @@ def compose_kill(compose, args):
compose.podman.run([], "kill", podman_args)


@cmd_run(
podman_compose, "stats", "Display percentage of CPU, memory, network I/O, block I/O and PIDs for services."
)
def compose_stats(compose, args):
container_names_by_service = compose.container_names_by_service
if not args.services:
args.services = container_names_by_service.keys()
targets = []
podman_args = []
if args.interval:
podman_args.extend(["--interval", args.interval])
if args.format:
podman_args.extend(["--format", args.format])
if args.no_reset:
podman_args.append("--no-reset")
if args.no_stream:
podman_args.append("--no-stream")

for service in args.services:
targets.extend(container_names_by_service[service])
for target in targets:
podman_args.append(target)

try:
compose.podman.run([], "stats", podman_args)
except KeyboardInterrupt:
pass


###################
# command arguments parsing
###################
Expand Down Expand Up @@ -3141,6 +3170,35 @@ def compose_kill_parse(parser):
)


@cmd_parse(podman_compose, ["stats"])
def compose_stats_parse(parser):
parser.add_argument(
"services", metavar="services", nargs="*", default=None, help="service names"
)
parser.add_argument(
"-i",
"--interval",
type=int,
help="Time in seconds between stats reports (default 5)",
)
parser.add_argument(
"-f",
"--format",
type=str,
help="Pretty-print container statistics to JSON or using a Go template",
)
parser.add_argument(
"--no-reset",
help="Disable resetting the screen between intervals",
action="store_true",
)
parser.add_argument(
"--no-stream",
help="Disable streaming stats and only pull the first result",
action="store_true",
)


def main():
podman_compose.run()

Expand Down

0 comments on commit cb9cf60

Please sign in to comment.