Skip to content

Commit cb9cf60

Browse files
tayehmuayyad-alsadi
authored andcommitted
add stats command
Signed-off-by: Mohammed Tayeh <[email protected]>
1 parent 06587c1 commit cb9cf60

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

podman_compose.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,6 +2691,35 @@ def compose_kill(compose, args):
26912691
compose.podman.run([], "kill", podman_args)
26922692

26932693

2694+
@cmd_run(
2695+
podman_compose, "stats", "Display percentage of CPU, memory, network I/O, block I/O and PIDs for services."
2696+
)
2697+
def compose_stats(compose, args):
2698+
container_names_by_service = compose.container_names_by_service
2699+
if not args.services:
2700+
args.services = container_names_by_service.keys()
2701+
targets = []
2702+
podman_args = []
2703+
if args.interval:
2704+
podman_args.extend(["--interval", args.interval])
2705+
if args.format:
2706+
podman_args.extend(["--format", args.format])
2707+
if args.no_reset:
2708+
podman_args.append("--no-reset")
2709+
if args.no_stream:
2710+
podman_args.append("--no-stream")
2711+
2712+
for service in args.services:
2713+
targets.extend(container_names_by_service[service])
2714+
for target in targets:
2715+
podman_args.append(target)
2716+
2717+
try:
2718+
compose.podman.run([], "stats", podman_args)
2719+
except KeyboardInterrupt:
2720+
pass
2721+
2722+
26942723
###################
26952724
# command arguments parsing
26962725
###################
@@ -3141,6 +3170,35 @@ def compose_kill_parse(parser):
31413170
)
31423171

31433172

3173+
@cmd_parse(podman_compose, ["stats"])
3174+
def compose_stats_parse(parser):
3175+
parser.add_argument(
3176+
"services", metavar="services", nargs="*", default=None, help="service names"
3177+
)
3178+
parser.add_argument(
3179+
"-i",
3180+
"--interval",
3181+
type=int,
3182+
help="Time in seconds between stats reports (default 5)",
3183+
)
3184+
parser.add_argument(
3185+
"-f",
3186+
"--format",
3187+
type=str,
3188+
help="Pretty-print container statistics to JSON or using a Go template",
3189+
)
3190+
parser.add_argument(
3191+
"--no-reset",
3192+
help="Disable resetting the screen between intervals",
3193+
action="store_true",
3194+
)
3195+
parser.add_argument(
3196+
"--no-stream",
3197+
help="Disable streaming stats and only pull the first result",
3198+
action="store_true",
3199+
)
3200+
3201+
31443202
def main():
31453203
podman_compose.run()
31463204

0 commit comments

Comments
 (0)