The first two days have received a new requirement to monitor the maximum number of MongoDB connections, memory usage, etc. in a Linux shell script.
But I do not know about the Linux Shel, but will be some simple common Linux operation, as long as a crazy search, eventually try to finally get these values.
The steps for success are as follows:
0.
writes a row of mongodb-monitored data to a aaa.txt file in JSON format
1.
A= ' Cat aaa.txt '
read the contents of the Aaa.txt and assign a value to a
gets the size of the data mapped mapped to memory:
2.
Gets the subscript for the substring "mapped" in the string variable A, and assigns the value to INDMA
3.
Add 8 to the variable ind and assign the result to INDMA1
4.
Indma0= ' echo $a | awk ' {printf ("%d\n", Match ($, "Netin")} "
Gets the subscript for the substring "Netin" in the string variable A, and assigns the value to Indma0
5.
give the variable indma0 minus 4 and assign the result to Indma2
6.
gets the substring between the indma1 and Indma2 in string A and assigns a value to Mastr, which is the value of mapped
Get Physical memory usage:
7.
Gets the subscript for the substring "res" in the string variable A, and assigns the value to Indre
8.
add 5 to the variable Indre and assign the result to Indre1
9.
Indre0= ' echo $a | awk ' {printf ("%d\n", Match ($, "Time")} "
Gets the subscript for the substring "time" in the string variable A, and assigns the value to Indre0
10.
give the variable indre0 minus 4 and assign the result to Indre2
11.
gets the substring between Indre1 and Indre2 in string A and assigns a value to RESTR, which is the value of res
Get Virtual Memory usage:
12.
Gets the subscript for the substring "Vsize" in the string variable A, and assigns the value to Indvs
13.
add 5 to the variable Indvs and assign the result to INDVS1
14.
gets the total length of the string variable a
15.
give the variable indvs0 minus 3 and assign the result to INDVS2
16.
gets the substring between the INDVS1 and INDVS2 in string A and assigns a value to Vsstr, which is the value of Vsize
Get current number of connections:
17.
Gets the subscript for the substring "conn" in the string variable A, and assigns the value to Indco
18.
Add 6 to the variable Indco and assign the result to Indco1
19.
Gets the subscript for the substring "Delete" in the string variable A and assigns the value to Indco0
20.
give the variable indco0 minus 4 and assign the result to Indco2
21.
gets the substring between the Indco1 and Indco2 in string A and assigns a value to CoSTR, which is the value of conn
The maximum number of connections is 819, and the number of idle connections can be calculated based on the maximum number of connections and current connections.
Get the maximum number of MongoDB connections, memory usage, etc. in the Linux shell