In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the method of viewing the resources used by the docker container, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.
In the process of using the container, if we can grasp the system resources used by the container in time, it is very beneficial to the development and operation and maintenance work. Fortunately, docker itself provides such a command: docker stats.
Default output
The docker stats command is used to display the system resources used by the container. Execute the docker stats command without any options:
$docker stats
By default, the stats command refreshes the output every 1 second until you press ctrl + c. Here is the main content of the output:
[CONTAINER]: displays the container's ID in a short format.
[CPU%]: usage of CPU.
[MEM USAGE / LIMIT]: memory currently used and maximum memory that can be used.
[MEM%]: displays memory usage as a percentage.
[NET Izod O]: network IZP O data.
[BLOCK I Dot O]: disk I Dot O data.
[PIDS]: PID number.
Return only to the current state
If you do not want to continuously monitor the use of resources by the container, you can use the-- no-stream option to output only the current status:
$docker stats-no-stream
In this way, the result of the output will not change, and it seems to save a lot of effort.
Output only the specified container
If we only want to see the resource usage of individual containers, we can explicitly specify the name of the target container or ID for the docker stats command:
$docker stats-- no-stream registry 1493
This result looks cleaner when there are a lot of containers running. Here registry and 1493 are the name and ID of the container, respectively. Note that multiple container names or ID need to be separated by spaces.
Careful students may have noticed that the first column no longer shows the default container ID, but shows the container name and ID we passed in. Based on this, we can replace the container ID in the default output with the name of the container in a simple way:
$docker stats $(docker ps-- format= {{.names}})
Isn't the output more friendly after replacing ID with the name of the container?
Format the result of the output
We did a little trick earlier to replace the container ID in the output with the name. In fact, the docker stats command allows us to customize the content and format of the output through the-- format option:
$docker stats-- format "table {{.Name}}\ t {{.CPUPerc}}\ t {{.MemUsage}}"
In the above command, we only output three columns: Name, CPUPerc and Memusage. Here are all the placeholders that can be used in a custom format:
Container displays the name or ID of the container based on the name specified by the user.
.Name container name.
ID container ID.
CPUPerc CPU usage.
.MemUsage memory usage.
.NetIO network Ibig O.
.BlockIO disk Ibank O.
.MemPerc memory usage.
.PIDs PID number.
With this information, we can control the output of docker stats commands completely according to our own needs or preferences.
In addition to exporting results in table format, you can also export results in json format through the format option:
$docker stats-- no-stream-- format\ "{\" container\ ":\" {{.Container}}\ ",\" memory\ ": {\" raw\ ":\" {{.MemUsage}}\ ",\" percent\ ":\" {{.MemPerc}}\ ",\" cpu\ ":\" {{.CPUPerc}}\ "}
We can see how the container uses system resources through the docker stats command. This provides a basis for us to further constrain the resources available to the container or to investigate resource-related problems. In addition to the commands that come with docker, tools such as glances already support viewing the resources used by the container.
Thank you for reading this article carefully. I hope the article "how to View the Resources used by docker containers" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.