目录
yum install -y epel-release && yum install -y monit
下载路径:
https://dl.fedoraproject.org/pub/epel/
https://mmonit.com/monit/dist/
systemctl restart monit
chkconfig mysqld on
/etc/monitrc会include 下面的配置文件
配置文件目录:/etc/monit.d/
monit –t
monit -t -c /etc/monitrc
如果有提示如下语句,那么就是可用的:
Control file syntax OK
重启生效:
systemctl restart monit
2、各种应用程序本地监控
# Get standard environment variables
PRGDIR=`dirname "$PRG"`
CATALINA_PID=/var/run/tomcat.pid
check process tomcat with pidfile /var/run/tomcat.pid
start program = "/home/connect/apache-tomcat-8.5.41/bin/startup.sh" with timeout 60 seconds
stop program = "/home/connect/apache-tomcat-8.5.41/bin/shutdown.sh"
public static void main(String[] args) throws Exception {
int pid = getPid();
}
private static int getPid() {
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
String name = runtime.getName(); // format: "pid@hostname"
int pid = -1;
try {
pid = Integer.parseInt(name.substring(0, name.indexOf('@')));
} catch (Exception e) {
pid = -1;
}
return pid;
}
配置文件application.properties文件内容如下,该配置指定了pid文件的位置:
spring.pid.file=/xxx/syb.pid
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication sa = new SpringApplication(App.class);
sa.addListeners(new ApplicationPidFileWriter());
sa.run(args);
}
}
在 my.cnf 中配置 PID
[mysqld]
pid-file= /var/run/mysqld/mysqld.pid
配置脚本
check process mysql with pidfile /run/mysqld/mysqld.pid
start program = "/usr/sbin/service mysql start" with timeout 60 seconds
stop program = "/usr/sbin/service mysql stop"
if failed unixsocket /var/run/mysqld/mysqld.sock then restart