Linux under the automatic monitoring of memory, storage space!

Source: Internet
Author: User

Distance from the last update article has been a period of time, small in this period of time because of some trivial, coupled with physical illness can not update the article, today the body gradually restored to update the article, Today's dream for everyone is how to automate the monitoring of our server some basic configuration to ensure that our application can better run and do a good performance bottleneck prediction!

Today's main content includes the Process Control statements, the use of cut, the use of grep, and the use of awk for Linux's basic shell programming to achieve what we say!

The following commands with different parameters have different uses, think dream to everyone is about to achieve the basic use of the said function, small partners if you want to better use the following command can refer to the document to try to experiment with different parameters!

1) First talk about the shell's Process Control statement if, in the form

If Command;then

Logical processing

Else

Logical processing

Fi

It is important to note that there is a fiat the end of the if .

2) The basic use of cut, it can use some regular separators to get a row

For example:a:b such a line of string, we want to get a, then we can write: cut-d ":"-F 1 It means: use: Split and then get the first line,-d followed by what symbol is divided, the topic is " : ", of course, can be " ;" Wait, and then the-F is the number of columns I want to print out

3) grep This command is a powerful text search tool, such as we want to search in a text

For example:

Let's start by creating a simengphp.txt, and then we want to get a simengphp of this string, and we can do that.

So we can get to the simengphp line.

4) awk This command is more complex, we speak directly how to use, awk ' {print $i} ' means to use the default space (irregular, cut to rule) or tab segmentation, followed by examples to explain to you

All right, the basic command is done, and all we need to do now is to write the shell script to get our function done.

First we write the script to monitor the memory, we also use a command: free-h

So we see the first line of memory usage: So what we want is the free value for monitoring, so we'll take a step-by-step way to get the value of this row.

1) Show all of them first, then we'll pass the pipe to the next command to handle

2) We use the grep command to get what we want.

3) by awk command we get to the fourth column and then print it, $ followed by the column we want to print, print is used in conjunction with AWK, Linux print is not used alone

4) After the cut this command using M to cut the score, you can get the value we want

We're just going to show you how to get the value we want, and we'll start writing the shell script right after that:

We run the value returned by the else, because we just saw 204, just over 200 so no alarm operation!

The ability to monitor the memory you see the back of the function of monitoring hard disk space is the same, I directly to everyone on the script

That's what we do with shell scripts to automate the monitoring of memory and the use of hard disk space, and then we can execute the corresponding script with a timed task.

The script is very rough, there are some areas that need to be improved, I hope that the small partners to understand after the study can be optimized and then to monitor your server it!


Linux under the automatic monitoring of memory, storage space!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.