How can I implement real-time alarm functions through shell scripts and enterprises ?, Shell Information
At work, we will have some applications running on the server online, so these applications have problems. For example, after the memory and CPU exceed the threshold, we must first know and handle these problems as soon as possible, try to make the user feel the exceptions of the application.
Some companies have O & M personnel. Congratulations, O & M should have a monitoring system, so developers can concentrate on business logic. However, some companies may not, the application status needs to be monitored by our developers.
For monitoring, there are emails, Zabbix, and enterprise emails. I do not hesitate to choose, which is simple and convenient. Someone in my mailbox sends spam every day, directly shielded, zabbix (same as z? Bix) is an enterprise-level open-source solution that provides distributed system monitoring and network monitoring functions based on the WEB interface. It is too heavy.
The following describes how to implement alarm
Registered enterprise number
I thought that the enterprise number needed enterprise-related information and so on. I didn't expect anything. I only needed a number. I suggest you register one here ~ Registration address
Create an application after registration. After filling in some basic information, the application can be created successfully. Some interfaces are as follows:
Shell script
I was going to write it in python. I thought about it later. No! Writing in any language is inferior to using shell, because linux itself supports shell and does not need to install any environment. This is the most important thing!
First, I analyzed the enterprise's API documentation.
Official documentation
Online debugging
Note the following for the API:
Access_token has an expiration time of 2 hours. Do not frequently obtain the token and save it once.
I am not sure about shell. It took about three hours to complete it. It seems that I will learn more about shell programming in the future.
Note:
For how to process json in shell, refer to the curl parameter in the blog shell. Use the if else shell to write data to a file.
The final effect is as follows:
Here, the process of sending alarm information via shell is broken through. As for how to monitor the application status and server status, I will implement it later.