CN105630653A - CPU vacancy rate determination method and device for Docker container - Google Patents
CPU vacancy rate determination method and device for Docker container Download PDFInfo
- Publication number
- CN105630653A CN105630653A CN201610147661.6A CN201610147661A CN105630653A CN 105630653 A CN105630653 A CN 105630653A CN 201610147661 A CN201610147661 A CN 201610147661A CN 105630653 A CN105630653 A CN 105630653A
- Authority
- CN
- China
- Prior art keywords
- cpu
- detected
- clocks
- time
- idle
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 48
- 238000010586 diagram Methods 0.000 description 4
- 241000109539 Conchita Species 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/30—Monitoring
- G06F11/3003—Monitoring arrangements specially adapted to the computing system or computing system component being monitored
- G06F11/3024—Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system component is a central processing unit [CPU]
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/30—Monitoring
- G06F11/34—Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment
- G06F11/3409—Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment for performance assessment
- G06F11/3433—Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment for performance assessment for load management
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- Computing Systems (AREA)
- Quality & Reliability (AREA)
- General Physics & Mathematics (AREA)
- Mathematical Physics (AREA)
- Computer Hardware Design (AREA)
- Debugging And Monitoring (AREA)
Abstract
The embodiment of the invention provides a CPU vacancy rate determination method and device for a Docker container.The method includes the steps that one or more CPU indicators corresponding to the Docker container are obtained; the total clock number and the idle clock number of all the CPUs within the to-be-detected time frame corresponding to the to-be-detected moment are obtained according to indicators of the CPUs; according to the total clock number and the idle clock number of the CPUs within the to-be-detected time frame, the CPU vacancy rate of the Docker container within the to-be-detected time frame is determined.The CPU vacancy rate determination method and device for the Docker container aim at achieving the effect that the Docker container still can precisely determine the CPU vacancy rate of the Docker container within the to-be-detected moment under the condition that the usage condition of the CPUs by other Dockers cannot be known in the Docker container.
Description
Technical Field
The embodiment of the invention relates to the technical field of computers, in particular to a method and a device for determining the CPU idle rate of a Docker container.
Background
The Docker container is an open-source application container engine, and can integrate a plurality of applications into one Docker container and publish the plurality of applications to the terminal through the Docker container.
Currently, a terminal may run multiple Docker containers, and each Docker container may use the same Central Processing Unit (CPU) resource, for example, a terminal includes 3 CPUs, which are respectively denoted as CPU1-CPU3, and a terminal runs 2 Docker containers, which are respectively denoted as Docker container 1 and Docker container 2, so that Docker container 1 may use CPU1 and CPU2, and Docker container 2 uses CPU2 and CPU 3. In an actual application process, in order to ensure that an application program in a Docker container can normally run, the Docker container needs to monitor available remaining CPU resources (CPU idle rate), and when the CPU idle rate of the Docker container is smaller than a preset threshold, alarm information is generated so that an operator can detect and maintain the Docker container.
However, in the prior art, because each Docker container in the terminal is isolated from each other, each Docker container cannot communicate with each other, when a CPU used by one Docker container is used by another Docker container at the same time, the Docker container cannot acquire the use condition of the CPU by another Docker container, so that the Docker container cannot accurately determine the CPU idle rate of the Docker container at the time to be detected.
Disclosure of Invention
The embodiment of the invention provides a method and a device for determining the CPU idle rate of a Docker container, which are used for accurately determining the CPU idle rate of the Docker container at the moment to be detected under the condition that the Docker container cannot know the use condition of other Docker containers to a CPU.
In a first aspect, an embodiment of the present invention provides a method for determining a CPU idle rate of a Docker container, including:
acquiring an identifier of at least one CPU corresponding to the Docker container;
respectively acquiring the total clock number and the idle clock number of each CPU in a to-be-detected time period corresponding to-be-detected time according to the identification of each CPU;
and determining the CPU idle rate of the Docker container at the time to be detected according to the total clock number and the idle clock number of each CPU in the time period to be detected.
The method for acquiring the total number of clocks of the CPU in the period to be detected according to the identifier of the CPU for any one of the at least one CPU includes:
acquiring the duration of the time period to be detected and the clock frequency of the CPU;
and determining the total number of clocks of the CPU in the time period to be detected according to the time length of the time period to be detected and the clock frequency.
The method for acquiring the total number of clocks of the CPU in the period to be detected according to the identifier of the CPU for any one of the at least one CPU includes:
acquiring a first record file corresponding to the CPU identifier according to the CPU identifier, wherein the first record file comprises the total number of clocks between the starting time and each time of the CPU;
acquiring the total number of clocks of the CPU between the starting time and the starting time of the period to be detected and the total number of clocks of the CPU between the starting time and the ending time of the period to be detected in the first recording file;
and acquiring the total clock number of the CPU in the period to be detected according to the total clock number of the CPU between the starting time and the total clock number of the CPU between the starting time and the ending time.
The method for acquiring the number of idle clocks of the CPU in the period to be detected according to the identifier of the CPU for any one of the at least one CPU includes:
acquiring a second recording file corresponding to the CPU identifier according to the CPU identifier, wherein the second recording file comprises the number of idle clocks between the starting time and each time of the CPU;
acquiring the number of idle clocks of the CPU between the starting time and the starting time of the period to be detected and the number of idle clocks of the CPU between the starting time and the ending time of the period to be detected in the second recording file;
and acquiring the number of idle clocks of the CPU in a period to be detected according to the number of idle clocks of the CPU between the starting time and the number of idle clocks of the CPU between the starting time and the ending time.
The method for determining the CPU idle rate of the Docker container at the time to be detected according to the total number of clocks and the number of idle clocks of each CPU in the time period to be detected comprises the following steps:
determining the idle rate of each CPU according to the total number of clocks and the number of idle clocks of each CPU in a period to be detected, and determining the CPU idle rate of the Docker container in the period to be detected as the average value of the idle rate of each CPU; or,
acquiring the sum of the total clock number of each CPU in a period to be detected and the sum of the idle clock number of each CPU in the period to be detected, and determining the CPU idle rate of the Docker container at the moment to be detected according to the sum of the total clock number and the idle clock number.
The determining, by the method described above, the identifier of the CPU corresponding to the Docker container includes:
acquiring a configuration file corresponding to the Docker container;
and acquiring the identification of the CPU corresponding to the Docker container in the configuration file.
The method, after determining the CPU idle rate of the Docker container at the time to be detected according to the total number of clocks and the number of idle clocks of each CPU in the time period to be detected, further includes:
judging whether the CPU idle rate of the Docker container at the moment to be detected is smaller than a preset threshold value or not;
and if the CPU idle rate of the Docker container at the moment to be detected is determined to be smaller than a preset threshold value, generating alarm information.
In a second aspect, an embodiment of the present invention provides an apparatus for determining a CPU idle rate of a Docker container, including:
the first obtaining module is used for obtaining the identifier of at least one CPU corresponding to the Docker container;
the second acquisition module is used for acquiring the total number of clocks of each CPU in a to-be-detected time period corresponding to the to-be-detected moment according to the identification of each CPU;
the third acquisition module is used for acquiring the number of idle clocks of each CPU in a to-be-detected time period corresponding to the to-be-detected moment according to the identification of each CPU;
and the determining module is used for determining the CPU idle rate of the Docker container at the time to be detected according to the total number of clocks and the number of idle clocks of the CPUs in the time period to be detected.
In the above apparatus, the second obtaining module is specifically configured to:
acquiring the duration of the time period to be detected and the clock frequency of the CPU;
and determining the total number of clocks of the CPU in the time period to be detected according to the time length of the time period to be detected and the clock frequency.
In the above apparatus, the second obtaining module is further specifically configured to:
acquiring a first record file corresponding to the CPU identifier according to the CPU identifier, wherein the first record file comprises the total number of clocks between the starting time and each time of the CPU;
acquiring the total number of clocks of the CPU between the starting time and the starting time of the period to be detected and the total number of clocks of the CPU between the starting time and the ending time of the period to be detected in the first recording file;
and acquiring the total clock number of the CPU in the period to be detected according to the total clock number of the CPU between the starting time and the total clock number of the CPU between the starting time and the ending time.
According to the method and the device for determining the CPU idle rate of the Docker container, when the CPU idle rate of the Docker container at the time to be detected needs to be obtained, the total clock number and the idle clock number of each CPU in the time period to be detected corresponding to the time to be detected are obtained respectively according to the identification of each CPU by obtaining the identification of at least one CPU corresponding to the Docker container, and the CPU idle rate of the Docker container at the time to be detected is determined according to the total clock number and the idle clock number of each CPU in the time period to be detected. In the process, the occupation condition of the CPU resource corresponding to the Docker container can be accurately determined through the total number of clocks and the number of idle clocks of the CPU corresponding to the Docker container in the period to be detected, and when the Docker container cannot know the use condition of other Docker containers to the CPU, the Docker container can still accurately determine the CPU idle rate of the Docker container at the moment to be detected.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to these drawings without creative efforts.
Fig. 1 is a schematic view of an application scenario of a Docker container provided by the present invention;
FIG. 2 is a flowchart of a method for determining the CPU idle rate of a Docker container according to the present invention;
FIG. 3 is a first flowchart for acquiring the total number of clocks of a CPU in a period to be detected according to the present invention;
FIG. 4 is a second flowchart for acquiring the total number of clocks of the CPU in the period to be detected according to the present invention;
FIG. 5 is a flowchart for acquiring the number of idle clocks of a CPU in a period to be detected according to the present invention;
FIG. 6 is a first block diagram of a device for determining CPU idle rate of a Docker container according to the present invention;
fig. 7 is a second structural diagram of the determination apparatus of the CPU idle rate of the Docker container according to the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Fig. 1 is a schematic view of an application scenario of a Docker container provided by the present invention, and please refer to fig. 1, a Docker container 1(101-a) and a Docker container 2(101-B) are run in an operating system of a terminal, and a CPU1(102-a), a CPU2(102-B), and a CPU3(102-C) are disposed in the terminal, where the Docker container 1 may use a CPU1 and a CPU2, and the Docker container 2 may use a CPU2 and a CPU 3. In the practical application process, the Docker container 1 and the Docker container 2 independently calculate the respective CPU idle rates. The following describes a method and an apparatus for determining the CPU idle rate of a Docker container in detail by using specific embodiments.
Fig. 2 is a flowchart of a method for determining the CPU idle rate of a Docker container provided in the present invention, please refer to fig. 1, where the method may include:
s201, acquiring an identifier of at least one CPU corresponding to the Docker container;
s202, acquiring the total number of clocks and the number of idle clocks in a to-be-detected time period corresponding to-be-detected time of each CPU according to the identification of each CPU;
s203, determining the CPU idle rate of the Docker container at the time to be detected according to the total number of clocks and the number of idle clocks of each CPU in the time period to be detected.
The execution subject of the embodiment of the present invention may be a determination device (hereinafter, simply referred to as a determination device) of a CPU idle rate of a Docker container, and the determination device may be disposed inside the Docker container.
In the embodiment of the present invention, one Docker container corresponds to at least one CPU, and in an actual application process, the resource management module may allocate a CPU to the Docker container when the Docker container is created, and optionally, after the CPU is allocated to the Docker container, the resource management module may store a correspondence between the Docker container and the CPU in a configuration file, for example, in a linux system, the resource management module may be a cgroups module, and in a community enterprise operating system (centros) in the linux system, the configuration file may be a file in the following path: slice/docker- $ { longid }. Scope/cpu.
In the embodiment of the present invention, each time to be detected is marked with a corresponding time period to be detected, the time period to be detected may be a time period before and/or after the time to be detected, for example, if the time to be detected is 10 o ' clock zero minute and zero second (10:00:00), the time period to be detected may be 9 o ' clock 59 o ' clock 58 s (09:59:58) -10:00:00, or 09:59:59-10:00:01, or 10:00:00-10:00:03, in an actual application process, a duration of the time period to be detected may be set according to actual needs, preferably, a duration of the time period to be detected is 2 seconds, or a corresponding relationship between the time period to be detected and the time to be detected may be set according to actual needs, which is not specifically limited by the present invention.
In an actual application process, when it is determined that the device needs to acquire the CPU idleness of the Docker container at the time to be detected, the identifier of at least one CPU corresponding to the Docker container is acquired first, and optionally, the configuration file corresponding to the Docker container may be acquired first, and the identifier of the CPU corresponding to the Docker container is acquired in the configuration file.
After the determining device obtains the identification of at least one CPU corresponding to the Docker container, the total number of clocks and the number of idle clocks of each CPU in a to-be-detected time period corresponding to-be-detected time are obtained, wherein the total number of clocks of the CPU in the to-be-detected time period refers to the number of clocks experienced by the CPU in the to-be-detected time period, the number of idle clocks of the CPU in the to-be-detected time period refers to the number of idle clocks experienced by the CPU in the to-be-detected time period, and after the determining device obtains the total number of clocks and the number of idle clocks of each CPU in the to-be-detected time period corresponding to-be-detected time, the CPU idle rate of the Docker container at the to-be-detected time is determined according to the total number.
The method shown in the embodiment of fig. 2 is described in detail below by way of specific examples.
For example, assuming that the Docker container 1 corresponds to two CPUs, which are respectively denoted as the CPU1 and the CPU2, when the determining device needs to acquire the CPU idle rate of the Docker container 1 at the time T1 to be detected, the Docker container 1 first determines the time period to be detected corresponding to the time T1 to be detected (T2-T3).
The determination means acquires the total number of clocks 100 of the CPU1 in the time period T2-T3 and the number of idle clocks 20 of the CPU1 in the time period T2-T3, based on the identification of the CPU 1.
The determination means acquires the total number of clocks 200 of the CPU2 in the time period T2-T3 and the number of idle clocks 30 of the CPU2 in the time period T2-T3, based on the identification of the CPU 2.
Then the device is determinedThe CPU idle rate of the Docker container 1 at the time T1 to be detected may be determined as:
according to the method for determining the CPU idle rate of the Docker container provided by the embodiment of the invention, when the CPU idle rate of the Docker container at the time to be detected needs to be obtained, the total clock number and the idle clock number of each CPU in the time period to be detected corresponding to the time to be detected are obtained respectively according to the mark of each CPU by obtaining the mark of at least one CPU corresponding to the Docker container, and the CPU idle rate of the Docker container at the time to be detected is determined according to the total clock number and the idle clock number of each CPU in the time period to be detected. In the process, the occupation condition of the CPU resource corresponding to the Docker container can be accurately determined through the total number of clocks and the number of idle clocks of the CPU corresponding to the Docker container in the period to be detected, and when the Docker container cannot know the use condition of other Docker containers to the CPU, the Docker container can still accurately determine the CPU idle rate of the Docker container at the moment to be detected.
On the basis of the embodiment shown in fig. 2, the total number of clocks of the CPU in the period to be detected can be obtained through the following two possible implementation manners, specifically, please refer to the embodiments shown in fig. 3 to fig. 4.
Fig. 3 is a first flowchart of acquiring the total clock number of the CPU in the period to be detected, please refer to fig. 3, where the method may include:
s301, acquiring the duration of a time period to be detected and the clock frequency of a CPU;
s302, determining the total number of clocks of the CPU in the time period to be detected according to the time length and the clock frequency of the time period to be detected.
In the embodiment shown in fig. 3, when the determining device needs to acquire the total number of clocks of the CPU in the period to be detected, first acquire the duration of the period to be detected and the clock frequency of the CPU, where the clock frequency of the CPU is an attribute value of the CPU, and the duration of the period to be detected may be a duration preset by a user, and after the determining device acquires the duration of the period to be detected and the clock frequency of the CPU, determine the total number of clocks of the CPU in the period to be detected according to the duration of the period to be detected and the clock frequency of the CPU, specifically, the total number of clocks of the CPU in the period to be detected may be: the product of the duration (unit is second) of the time period to be detected and the clock frequency can be used for not only accurately determining the total number of clocks of the CPU in the time period to be detected, but also increasing the speed of obtaining the total number of clocks of the CPU in the time period to be detected, thereby quickly determining the CPU idle rate of the Docker container at the time to be detected.
For example, when the determining device needs to obtain the total number of clocks of the CPU1 in the period to be detected, the determining device first obtains the duration of the period to be detected, and assuming that the duration of the period to be detected is 2 seconds and then the clock frequency of the CPU1 is 100HZ, the determining device may determine that the total number of clocks of the CPU1 in the period to be detected is 2 × 100 — 200.
Fig. 4 is a second flowchart of obtaining the total clock number of the CPU in the period to be detected, please refer to fig. 4, where the method may include:
s401, acquiring a first recording file corresponding to the CPU identifier according to the CPU identifier, wherein the first recording file comprises the total number of clocks between the starting time and each time of the CPU;
s402, acquiring the total number of clocks between the starting time of the CPU and the starting time of the period to be detected and the total number of clocks between the starting time of the CPU and the ending time of the period to be detected in the first recording file;
and S403, acquiring the total number of clocks of the CPU in the period to be detected according to the total number of clocks of the CPU from the starting time to the starting time and the total number of clocks of the CPU from the starting time to the ending time.
In the embodiment shown in fig. 3, before the CPU starts working, the total number of clocks of the CPU is zero, after the CPU starts working (for example, the terminal is turned on), the total number of clocks of the CPU starts to be counted, and each time the CPU goes through one clock, the total number of clocks of the CPU is increased by 1, so as to facilitate recording in the first recording file, the total number of clocks of the CPU can be recorded in the first recording file once per second; illustratively, assuming that the clock frequency of the CPU1 is 100HZ, i.e., the CPU1 goes through 100 clocks in 1 second, then turns on at zero second again, and records the total number of clocks of the CPU1 once per second, the first record file may be as shown in table 1.
TABLE 1
Time of day | Total number of clocks of CPU1 |
00:00:00-00:00:01 | 0 |
00:00:00-00:00:01 | 100 |
00:00:00-00:00:02 | 200 |
…… | …… |
00:00:00-00:00:10 | 1000 |
…… | …… |
In the actual application process, when the total clock number of the CPU in the period to be detected needs to be acquired, a first record file corresponding to the identifier of the CPU is acquired according to the identifier of the CPU, where the first record file may only include the total clock number corresponding to the CPU at each time, or may include the total clock number corresponding to other CPUs at each time.
After the first recording file is obtained, determining that the device needs to obtain the starting time and the terminating time of a time period to be detected, then obtaining the total number of clocks corresponding to the starting time in the first recording file according to the starting time, and obtaining the total number of clocks corresponding to the terminating time in the first recording file according to the terminating time; then, the total number of clocks of the CPU in the period to be detected is obtained according to the total number of clocks corresponding to the start time and the total number of clocks corresponding to the end time, specifically, the total number of clocks of the CPU in the period to be detected may be: the difference between the total number of clocks corresponding to the end time and the total number of clocks corresponding to the start time.
In the feasible implementation mode, the first recording file counts the total clock number of the CPU every time the CPU experiences one clock, and the total clock number of the CPU in the time period to be detected can be accurately obtained through the first recording file, so that the accuracy of determining the CPU idle rate of the Docker container at the time to be detected is improved.
For example, when the determining device needs to acquire the total number of clocks of the CPU1 in the time period to be detected, the determining device acquires the first record file corresponding to the CPU1, acquires the start time (T1) of the time period to be detected and the end time (T2) of the time period to be detected, and then acquires the total number of clocks corresponding to the time T1 (N1) and the total number of clocks corresponding to the time T2 (N2) in the first record file, the determining device may determine that the total number of clocks of the CPU1 in the time period to be detected is N2-N1.
On the basis of any of the above embodiments, the number of idle clocks of the CPU in the period to be detected may be obtained through the following feasible implementation manners, specifically, please refer to the embodiment shown in fig. 5.
Fig. 5 is a flowchart for acquiring the number of idle clocks of the CPU in the period to be detected, please refer to fig. 5, where the method may include:
s501, acquiring a second recording file corresponding to the CPU identifier according to the CPU identifier, wherein the second recording file comprises the number of idle clocks between the starting time and each time of the CPU;
s502, acquiring the number of idle clocks between the starting time of the CPU and the starting time of the period to be detected and the number of idle clocks between the starting time of the CPU and the ending time of the period to be detected in the second recording file;
s503, acquiring the number of idle clocks of the CPU in the period to be detected according to the number of idle clocks of the CPU between the starting time and the number of idle clocks of the CPU between the starting time and the ending time.
In the embodiment shown in fig. 5, before the CPU starts working, the number of idle clocks of the CPU is zero, after the CPU starts working (for example, the terminal is turned on), the idle clocks of the CPU start to be counted, and when the CPU is in an idle state within a certain clock, 1 is added to the number of idle clocks of the CPU, so as to facilitate recording in the second recording file, the total number of clocks of the CPU may be recorded in the second recording file once per second; the storage manner of the second recording file is similar to that of the first recording file in the embodiment shown in fig. 4, and is not described herein again.
It should be noted that the second record file and the first record file in the embodiment shown in fig. 4 may be two independent record files, or may be the same record file, and the present invention is not limited to this.
It should be further noted that, the process of acquiring the number of idle clocks of the CPU in the period to be detected in the embodiment shown in fig. 5 is similar to the process of acquiring the total number of clocks of the CPU in the period to be detected in the embodiment shown in fig. 4, and details are not repeated here.
In the feasible implementation mode, the second recording file counts the number of the idle clocks of the CPU every time the CPU experiences one idle clock, and the number of the idle clocks of the CPU in the period to be detected can be accurately acquired through the second recording file, so that the accuracy of determining the CPU idle rate of the Docker container at the moment to be detected is improved.
On the basis of any one of the above embodiments, optionally, the CPU idle rate of the Docker container at the time to be detected may be determined according to the total number of clocks and the number of idle clocks of each CPU in the period to be detected, which is specifically:
one possible implementation is:
determining the idle rate of each CPU according to the total number of clocks and the number of idle clocks of each CPU in a period to be detected, and determining the CPU idle rate of the Docker container in the period to be detected as the average value of the idle rates of each CPU;
in this feasible implementation manner, after the total number of clocks and the number of idle clocks of each CPU in the period to be detected are obtained, the idle rate of each CPU may be determined first, and then the average value of the idle rates of each CPU is determined as the CPU idle rate of the Docker container in the period to be detected.
For example, suppose Docker container 1 corresponds to two CPUs, denoted as CPU1 and CPU2, respectively.
Assuming that the total number of clocks and the number of idle clocks of the CPU1 in the period to be detected are 100 and 20, the idle rate of the CPU1 in the period to be detected is
Assuming that the total number of clocks and the number of idle clocks of the CPU2 in the period to be detected are 200 and 30, the idle rate of the CPU2 in the period to be detected is
The determining device may determine that the CPU idle rate of the Docker container 1 in the period to be detected is
Another possible implementation:
the method comprises the steps of obtaining the sum of the total number of clocks of each CPU in a period to be detected and the sum of the number of idle clocks of each CPU in the period to be detected, and determining the CPU idle rate of a Docker container at the moment to be detected according to the sum of the total number of clocks and the sum of the number of idle clocks.
In this feasible implementation manner, after obtaining the total clock number and the idle clock number of each CPU in the period to be detected, the sum of the total clock number and the sum of the idle clock number of each CPU in the period to be detected is obtained, and the CPU idle rate of the Docker container at the time to be detected is determined according to the sum of the total clock number and the sum of the idle clock number, specifically, the CPU idle rate of the Docker container at the time to be detected is: the ratio of the sum of the number of idle clocks to the sum of the number of total clocks.
For example, suppose Docker container 1 corresponds to two CPUs, denoted as CPU1 and CPU2, respectively.
Assume that the total number of clocks and the number of idle clocks of the CPU1 in the period to be detected are 100 and 20, and the total number of clocks and the number of idle clocks of the CPU2 in the period to be detected are 200 and 30.
The sum of the total number of clocks of the CPU1 and the CPU2 in the period to be detected is 100+ 200-300, and the sum of the number of idle clocks of the CPU1 and the CPU2 in the period to be detected is 20+ 30-50.
The determining device may determine that the CPU idle rate of the Docker container 1 in the period to be detected is
On the basis of any one of the above embodiments, after the determining device determines that the CPU idle rate of the Docker container at the time to be detected is obtained, it may be further determined whether the CPU idle rate of the Docker container at the time to be detected is smaller than a preset threshold, and if so, an alarm message is generated to notify an operator to detect and maintain the Docker container.
Fig. 6 is a first structural diagram of an apparatus for determining the CPU idle rate of a Docker container provided by the present invention, and referring to fig. 6, the apparatus may include:
a first obtaining module 601, configured to obtain an identifier of at least one CPU corresponding to a Docker container;
a second obtaining module 602, configured to obtain, according to the identifier of each CPU, the total number of clocks of each CPU in a to-be-detected time period corresponding to the to-be-detected time;
a third obtaining module 603, configured to obtain, according to the identifier of each CPU, the number of idle clocks in the to-be-detected time period corresponding to the to-be-detected time of each CPU;
the determining module 604 is configured to determine, according to the total number of clocks and the number of idle clocks of each CPU in the period to be detected, a CPU idle rate of the Docker container at the time to be detected.
In an actual application process, optionally, the second obtaining module 602 may be specifically configured to:
acquiring the duration of a time period to be detected and the clock frequency of a CPU (central processing unit);
and determining the total number of clocks of the CPU in the time period to be detected according to the time length and the clock frequency of the time period to be detected.
Optionally, the second obtaining module 602 may be further specifically configured to:
acquiring a first recording file corresponding to the identification of the CPU according to the identification of the CPU, wherein the first recording file comprises the total number of clocks between the starting time and each time of the CPU;
acquiring the total number of clocks between the starting time of the CPU and the starting time of the period to be detected and the total number of clocks between the starting time of the CPU and the ending time of the period to be detected in the first recording file;
and acquiring the total clock number of the CPU in the period to be detected according to the total clock number of the CPU from the starting time to the starting time and the total clock number of the CPU from the starting time to the ending time.
Optionally, the third obtaining module 603 may be specifically configured to:
acquiring a second recording file corresponding to the identification of the CPU according to the identification of the CPU, wherein the second recording file comprises the number of idle clocks between the starting time and each time of the CPU;
acquiring the number of idle clocks between the starting time of the CPU and the starting time of the period to be detected and the number of idle clocks between the starting time of the CPU and the ending time of the period to be detected in a second recording file;
and acquiring the number of idle clocks of the CPU in a period to be detected according to the number of idle clocks of the CPU between the starting time and the number of idle clocks of the CPU between the starting time and the ending time.
In an actual application process, the determining module 604 may specifically be configured to:
determining the idle rate of each CPU according to the total number of clocks and the number of idle clocks of each CPU in a period to be detected, and determining the CPU idle rate of the Docker container in the period to be detected as the average value of the idle rates of each CPU; or,
the method comprises the steps of obtaining the sum of the total number of clocks of each CPU in a period to be detected and the sum of the number of idle clocks of each CPU in the period to be detected, and determining the CPU idle rate of a Docker container at the moment to be detected according to the sum of the total number of clocks and the sum of the number of idle clocks.
Optionally, the first obtaining module 601 may specifically be configured to:
acquiring a configuration file corresponding to the Docker container;
and acquiring the identification of the CPU corresponding to the Docker container in the configuration file.
Fig. 7 is a second structural diagram of the apparatus for determining the CPU idle rate of a Docker container provided by the present invention, and referring to fig. 7, on the basis of the embodiment shown in fig. 6, the apparatus may further include a determining module 605 and a generating module 606, wherein,
the determining module 605 is configured to determine, after determining the CPU idle rate of the Docker container at the time to be detected according to the total number of clocks and the number of idle clocks of each CPU in the time period to be detected, determine whether the CPU idle rate of the Docker container at the time to be detected is smaller than a preset threshold;
the generating module 606 is configured to generate alarm information when the determining module determines that the CPU idle rate of the Docker container at the to-be-detected time is smaller than a preset threshold.
The device according to the embodiment of the present invention may implement the technical solutions shown in the embodiments of fig. 1 to 5, and the implementation principles and beneficial effects thereof are similar, and are not described herein again.
Those of ordinary skill in the art will understand that: all or a portion of the steps of implementing the above-described method embodiments may be performed by hardware associated with program instructions. The program may be stored in a computer-readable storage medium. When executed, the program performs steps comprising the method embodiments described above; and the aforementioned storage medium includes: various media that can store program codes, such as ROM, RAM, magnetic or optical disks.
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solution of the present invention, and not to limit the same; while the invention has been described in detail and with reference to the foregoing embodiments, it will be understood by those skilled in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present invention.
Claims (10)
1. A method for determining CPU idle rate of a Docker container is characterized by comprising the following steps:
acquiring an identifier of at least one CPU corresponding to the Docker container;
respectively acquiring the total clock number and the idle clock number of each CPU in a to-be-detected time period corresponding to-be-detected time according to the identification of each CPU;
and determining the CPU idle rate of the Docker container at the time to be detected according to the total clock number and the idle clock number of each CPU in the time period to be detected.
2. The method according to claim 1, wherein for any one of the at least one CPU, acquiring the total number of clocks of the CPU in the period to be detected according to the identification of the CPU comprises:
acquiring the duration of the time period to be detected and the clock frequency of the CPU;
and determining the total number of clocks of the CPU in the time period to be detected according to the time length of the time period to be detected and the clock frequency.
3. The method according to claim 1, wherein for any one of the at least one CPU, acquiring the total number of clocks of the CPU in the period to be detected according to the identification of the CPU comprises:
acquiring a first record file corresponding to the CPU identifier according to the CPU identifier, wherein the first record file comprises the total number of clocks between the starting time and each time of the CPU;
acquiring the total number of clocks of the CPU between the starting time and the starting time of the period to be detected and the total number of clocks of the CPU between the starting time and the ending time of the period to be detected in the first recording file;
and acquiring the total clock number of the CPU in the period to be detected according to the total clock number of the CPU between the starting time and the total clock number of the CPU between the starting time and the ending time.
4. The method according to any one of claims 1 to 3, wherein for any one of the at least one CPU, acquiring the number of idle clocks of the CPU in the period to be detected according to the identification of the CPU, comprises:
acquiring a second recording file corresponding to the CPU identifier according to the CPU identifier, wherein the second recording file comprises the number of idle clocks between the starting time and each time of the CPU;
acquiring the number of idle clocks of the CPU between the starting time and the starting time of the period to be detected and the number of idle clocks of the CPU between the starting time and the ending time of the period to be detected in the second recording file;
and acquiring the number of idle clocks of the CPU in a period to be detected according to the number of idle clocks of the CPU between the starting time and the number of idle clocks of the CPU between the starting time and the ending time.
5. The method according to any one of claims 1 to 3, wherein determining the CPU idle rate of the Docker container at the time to be detected according to the total number of clocks and the number of idle clocks of each CPU in the time period to be detected comprises:
determining the idle rate of each CPU according to the total number of clocks and the number of idle clocks of each CPU in a period to be detected, and determining the CPU idle rate of the Docker container in the period to be detected as the average value of the idle rate of each CPU; or,
acquiring the sum of the total clock number of each CPU in a period to be detected and the sum of the idle clock number of each CPU in the period to be detected, and determining the CPU idle rate of the Docker container at the moment to be detected according to the sum of the total clock number and the idle clock number.
6. The method of any of claims 1-3, wherein determining the identity of the CPU to which the Docker container corresponds comprises:
acquiring a configuration file corresponding to the Docker container;
and acquiring the identification of the CPU corresponding to the Docker container in the configuration file.
7. The method according to any one of claims 1 to 3, wherein after determining the CPU idle rate of the Docker container at the time to be detected according to the total number of clocks and the number of idle clocks of each CPU in the time period to be detected, the method further comprises:
judging whether the CPU idle rate of the Docker container at the moment to be detected is smaller than a preset threshold value or not;
and if the CPU idle rate of the Docker container at the moment to be detected is determined to be smaller than a preset threshold value, generating alarm information.
8. An apparatus for determining CPU idle rate of a Docker container, comprising:
the first obtaining module is used for obtaining the identifier of at least one CPU corresponding to the Docker container;
the second acquisition module is used for acquiring the total number of clocks of each CPU in a to-be-detected time period corresponding to the to-be-detected moment according to the identification of each CPU;
the third acquisition module is used for acquiring the number of idle clocks of each CPU in a to-be-detected time period corresponding to the to-be-detected moment according to the identification of each CPU;
and the determining module is used for determining the CPU idle rate of the Docker container at the time to be detected according to the total number of clocks and the number of idle clocks of the CPUs in the time period to be detected.
9. The apparatus of claim 8, wherein the second obtaining module is specifically configured to:
acquiring the duration of the time period to be detected and the clock frequency of the CPU;
and determining the total number of clocks of the CPU in the time period to be detected according to the time length of the time period to be detected and the clock frequency.
10. The apparatus of claim 8, wherein the second obtaining module is further specifically configured to:
acquiring a first record file corresponding to the CPU identifier according to the CPU identifier, wherein the first record file comprises the total number of clocks between the starting time and each time of the CPU;
acquiring the total number of clocks of the CPU between the starting time and the starting time of the period to be detected and the total number of clocks of the CPU between the starting time and the ending time of the period to be detected in the first recording file;
and acquiring the total clock number of the CPU in the period to be detected according to the total clock number of the CPU between the starting time and the total clock number of the CPU between the starting time and the ending time.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610147661.6A CN105630653A (en) | 2016-03-15 | 2016-03-15 | CPU vacancy rate determination method and device for Docker container |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610147661.6A CN105630653A (en) | 2016-03-15 | 2016-03-15 | CPU vacancy rate determination method and device for Docker container |
Publications (1)
Publication Number | Publication Date |
---|---|
CN105630653A true CN105630653A (en) | 2016-06-01 |
Family
ID=56045626
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201610147661.6A Pending CN105630653A (en) | 2016-03-15 | 2016-03-15 | CPU vacancy rate determination method and device for Docker container |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN105630653A (en) |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106897203A (en) * | 2017-03-29 | 2017-06-27 | 北京经纬恒润科技有限公司 | A kind of cpu load rate computational methods and device |
CN107819802A (en) * | 2016-09-13 | 2018-03-20 | 华为软件技术有限公司 | A kind of mirror image acquisition methods, node device and server in node cluster |
CN109298913A (en) * | 2018-09-26 | 2019-02-01 | 武芮 | The method and device of schedules system resources between a kind of multi-vessel system |
CN111552614A (en) * | 2020-04-28 | 2020-08-18 | 杭州迪普科技股份有限公司 | Statistical method and device for CPU utilization rate |
CN114090371A (en) * | 2021-10-28 | 2022-02-25 | 苏州浪潮智能科技有限公司 | Port utilization rate determining method and device, electronic equipment and readable storage medium |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102622290A (en) * | 2012-03-07 | 2012-08-01 | 苏州阔地网络科技有限公司 | Process monitoring method and system |
CN104899126A (en) * | 2015-06-12 | 2015-09-09 | 北京奇虎科技有限公司 | Method, device and system for performing local real-time monitoring on containers in host |
CN104951360A (en) * | 2015-06-30 | 2015-09-30 | 北京奇虎科技有限公司 | Configuration management mode and device based on Docker |
CN104950757A (en) * | 2015-06-12 | 2015-09-30 | 北京奇虎科技有限公司 | Container monitoring method and system |
-
2016
- 2016-03-15 CN CN201610147661.6A patent/CN105630653A/en active Pending
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102622290A (en) * | 2012-03-07 | 2012-08-01 | 苏州阔地网络科技有限公司 | Process monitoring method and system |
CN104899126A (en) * | 2015-06-12 | 2015-09-09 | 北京奇虎科技有限公司 | Method, device and system for performing local real-time monitoring on containers in host |
CN104950757A (en) * | 2015-06-12 | 2015-09-30 | 北京奇虎科技有限公司 | Container monitoring method and system |
CN104951360A (en) * | 2015-06-30 | 2015-09-30 | 北京奇虎科技有限公司 | Configuration management mode and device based on Docker |
Non-Patent Citations (1)
Title |
---|
华为DOCKER实践小组: "《Docker进阶与实战》", 29 February 2016, 机械工业出版社 * |
Cited By (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107819802A (en) * | 2016-09-13 | 2018-03-20 | 华为软件技术有限公司 | A kind of mirror image acquisition methods, node device and server in node cluster |
CN107819802B (en) * | 2016-09-13 | 2021-02-26 | 华为技术有限公司 | Mirror image obtaining method in node cluster, node equipment and server |
CN106897203A (en) * | 2017-03-29 | 2017-06-27 | 北京经纬恒润科技有限公司 | A kind of cpu load rate computational methods and device |
CN109298913A (en) * | 2018-09-26 | 2019-02-01 | 武芮 | The method and device of schedules system resources between a kind of multi-vessel system |
CN111552614A (en) * | 2020-04-28 | 2020-08-18 | 杭州迪普科技股份有限公司 | Statistical method and device for CPU utilization rate |
CN114090371A (en) * | 2021-10-28 | 2022-02-25 | 苏州浪潮智能科技有限公司 | Port utilization rate determining method and device, electronic equipment and readable storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN105630653A (en) | CPU vacancy rate determination method and device for Docker container | |
CN107229555B (en) | Identification generation method and device | |
CN108108127B (en) | File reading method and system | |
WO2017096734A1 (en) | Program detection method and device | |
JP2017532702A5 (en) | ||
RU2015137806A (en) | SYSTEMS AND METHODS FOR HOST DETECTION OF USB ASYNCHRONOUS NOTIFICATION | |
CN107959695B (en) | Data transmission method and device | |
CN109672936B (en) | Method and device for determining video evaluation set and electronic equipment | |
CN106662970A (en) | Method, apparatus and terminal device for setting interrupt threshold for fingerprint identification device | |
RU2017101414A (en) | FILE IDENTIFICATION FOR DATA RECORDING OPERATIONS | |
JP2008310748A (en) | Task execution time recording device, task execution time recording method, and task execution recording program | |
CN109324959B (en) | Method for automatically transferring data, server and computer readable storage medium | |
CN106095832A (en) | Distributed parallel processing method and device | |
CN115576872B (en) | Access detection method and device for multi-level cache | |
CN108667740B (en) | Flow control method, device and system | |
US20130185470A1 (en) | Detection method and apparatus for hot-swapping of sd card | |
WO2014045351A1 (en) | Time sequential data accumulation device | |
RU2016140283A (en) | METHOD AND DEVICE FOR COUNTING CALENDAR EVENTS | |
US9778854B2 (en) | Computer system and method for controlling hierarchical storage therefor | |
CN106600300B (en) | Method and device for analyzing user viscosity of application program | |
CN106909599A (en) | A kind of group system, message treatment method and device | |
KR102233525B1 (en) | Method and apparatus for detecting page redirect loop | |
US9864668B2 (en) | Apparatus, method, and system for event data processing | |
CN109144816A (en) | A kind of node health degree detection method and system | |
CN106990998B (en) | Virtual machine monitoring method and device |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C41 | Transfer of patent application or patent right or utility model | ||
TA01 | Transfer of patent application right |
Effective date of registration: 20161230 Address after: 266100 Shandong Province, Qingdao city Laoshan District Songling Road No. 399 Applicant after: Poly Polytron Technologies Inc Address before: 266100 Laoshan, Qingdao province Hongkong District No. East Road, room 248, room 131 Applicant before: Hisense Media Networks Co., Ltd. |
|
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20160601 |
|
RJ01 | Rejection of invention patent application after publication |