A new requirement was received in the previous two days to monitor the maximum number of MongoDB connections, memory usage, etc. in the Linux shell script.
But I do not understand the Linux Shel, just a few simple common Linux operations, as long as a wild search, and finally many attempts to finally get these values.
The steps for success are as follows:
0,
Write a line of data that MongoDB monitors into 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 data size that mapped maps to memory:
2,
Gets the subscript for the substring "mapped" in the string variable A, and assigns the value to the INDMA
3,
Give the variable IND plus 8 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 the INDMA0
5,
Give the variable indma0 minus 4 and assign the result to Indma2
6,
Gets the substring between the subscript indma1 to Indma2 in the string A and assigns the value to Mastr, 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 the Indre
8,
Give the variable Indre plus 5 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 the INDRE0
10,
Give the variable indre0 minus 4 and assign the result to Indre2
11,
Gets the substring between the subscript indre1 to Indre2 in string A and assigns to RESTR, 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 the INDVS
13,
Give the variable Indvs plus 5 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 subscript indvs1 to INDVS2 in the string A and assigns the value to Vsstr, the value of vsize
get the current number of connections:
17,
Gets the subscript for the substring "conn" in the string variable A, and assigns the value to the Indco
18,
Give the variable Indco plus 6 and assign the result to Indco1
19,
Gets the subscript for the substring "delete" in the string variable A, and assigns the value to the Indco0
20,
Give the variable indco0 minus 4 and assign the result to Indco2
21st
Gets the substring between the subscript indco1 to Indco2 in the string A and assigns the value to CoSTR, 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.