Monit 微服务监控

目录

 

1、Monit 安装与配置

1.1、自动安装

1.2、手动安装

1.3、启动命令:

1.4、随系统自动启动:

1.5、添加配置文件

1.6、配置文件检测

2、各种应用程序本地监控

2.1、Tomcat

2.1.1、Tomcat 启动生成PID.

2.1.2、Monit 配置文件Tomcatrc

2.3、普通Java应用进程

2.4、Spring boot

2.5、Mysql 


1、Monit 安装与配置

1.1、自动安装

yum install -y epel-release && yum install -y monit

1.2、手动安装

下载路径:

https://dl.fedoraproject.org/pub/epel/

https://mmonit.com/monit/dist/

1.3、启动命令:

systemctl restart monit

1.4、随系统自动启动:

chkconfig mysqld on

1.5、添加配置文件

/etc/monitrc会include 下面的配置文件

配置文件目录:/etc/monit.d/

 

1.6、配置文件检测

monit –t

monit -t -c /etc/monitrc

如果有提示如下语句,那么就是可用的:

Control file syntax OK

重启生效:

systemctl restart monit

2、各种应用程序本地监控

2.1、Tomcat

2.1.1、Tomcat 启动生成PID.

# Get standard environment variables

PRGDIR=`dirname "$PRG"`

CATALINA_PID=/var/run/tomcat.pid

2.1.2、Monit 配置文件Tomcatrc

 

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"

2.3、普通Java应用进程

  

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;

    }

2.4、Spring boot

配置文件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);

    }

}

2.5、Mysql 

在 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

October-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值