EasyMonitor

EasyMonitor 是一个基于 Java 的免费开源跨平台系统运行监控服务应用及引擎框架。即可开箱即用(EasyMonitor Application),又可以作为监控引擎框架扩展(EasyMonitor Engine Framework)。

EasyMonitor 能够为需要运行状态监控的程序场景提供一体化支持,提供集合了运行监控,通知发送,脚本执行等于功能。而这一切,仅需进行简单的配置管理即可完成。

最新版本: 1.3.2-RELEASE

EasyMonitor 特点

EasyMonitor 内部工作三大组件

EasyMonitor Three Components

MonitorConfiguration

Properties

easymonitor.properties 是 EasyMonitor 的核心配置文件,配置了监控所需的所有信息。

配置结构

EasyMonitor Properties

全局配置(作为监控服务配置的全局默认值,可选)

# Monitor ON or OFF, default is ON
# 监控服务默认是否打开,默认为 ON
easymonitor.enable=ON

# Monitor trigger Cron-Expressions; default is '0/10 * * * * ?'
# 监控服务的默认调度 Cron-Expressions; 默认为 '0/10 * * * * ?'
easymonitor.cronexpression=0/10 * * * * ?

# Monitor max failure count; default is 10
# 判断监控服务是否异常的默认最大失败次数;默认为 10
easymonitor.maxfailure=10

# Receive Error Report mail address
# You can specify more than one, separated by a ##
# 接收监控通知提醒的邮箱列表,多个邮箱使用 ## 分隔
easymonitor.mail.receiver=yourmail@domain.com##youmail2@domai2.org

# Send Mail Account Config
# 邮箱发送者账户配置
# Send Mail Account
easymonitor.mail.sender=sendermail@domain.com
# Send Mail password
# 邮箱发送者密码
easymonitor.mail.sender.passowrd=mailpassword
# Send Mail SMTP host
# 邮箱发送者 host
easymonitor.mail.sender.host=smtp.163.com
# Send Mail SMTP port; default is 25
# 邮箱发送者 host 端口
easymonitor.mail.sender.port=25
# Send Mail Whether use SSL; default is false
# 是否使用了 SSL 协议
easymonitor.mail.sender.ssl=false
# Send Mail title
# 邮件发送标题
easymonitor.mail.sender.title=Server Error Notice- EasyMonitor
# The send mail content freemarker template in template directory, default is 'mail.tpl'
# template 目录下的邮件发送模板,默认为 mail.tpl
easymonitor.mail.sender.template=mail.tpl
# When error, repeat send mail interval(seconds); default is 0, not repeat
# 当监控服务发现错误时,是否按周期进行重复提醒(秒);默认为 0,不进行重复提醒
easymonitor.mail.sender.interval=0

# Execute Command 
# You can specify more than one, separated by a ##
# 自动执行的脚本命令,多个脚本命令使用 ## 分隔
easymonitor.cmd=/user/app/startup.sh

监控服务配置(可以覆盖全局配置的默认值)

NAME 是自定义的监控服务名称,每个监控服务由一组相同 NAME 的配置项组成。

######################## Monitor Service configuration
easymonitor.[url|port|process|user].NAME=value
easymonitor.[url|port|process|user].NAME.enable=ON|OFF
easymonitor.[url|port|process|user].NAME.cronexpression=0/10 * * * * ?
easymonitor.[url|port|process|user].NAME.maxfailure=10
easymonitor.port.NAME.server=IP
easymonitor.user.NAME.validatorClass=package.MonitorValidatorClas

easymonitor.[url|port|process|user].NAME.cmd=/user/app/script.sh

easymonitor.[url|port|process|user].NAME.mail.receiver=receivermail@domain.com

easymonitor.[url|port|process|user].NAME.mail.sender=sendermail@domain.com
easymonitor.[url|port|process|user].NAME.mail.sender.passowrd=sendermail_password
easymonitor.[url|port|process|user].NAME.mail.sender.host=sendermail_host
easymonitor.[url|port|process|user].NAME.mail.sender.port=sendermail_port
easymonitor.[url|port|process|user].NAME.mail.sender.ssl=sendermail_ssh
easymonitor.[url|port|process|user].NAME.mail.sender.title=sendermail_title
easymonitor.[url|port|process|user].NAME.mail.sender.template=mail.tpl
easymonitor.[url|port|process|user].NAME.mail.sender.interval=1800

easymonitor.[url|port|process|user].NAME.sender.impl=package.userSenderClass##package.userSenderClass2

完全配置示例

######################## Global Config(Optional) 全局配置(可选)

# Monitor ON or OFF, default is ON
# 监控服务默认是否打开,默认为 ON
easymonitor.enable=ON

# Monitor trigger Cron-Expressions; default is '0/10 * * * * ?'
# 监控服务的默认调度 Cron-Expressions; 默认为 '0/10 * * * * ?'
easymonitor.cronexpression=0/10 * * * * ?

# Monitor max failure count; default is 10
# 判断监控服务是否异常的默认最大失败次数;默认为 10
easymonitor.maxfailure=10

# Receive Error Report mail address
# You can specify more than one, separated by a ##
# 接收监控通知提醒的邮箱列表,多个邮箱使用 ## 分隔
easymonitor.mail.receiver=yourmail@domain.com##youmail2@domai2.org

# Send Mail Account Config
# 邮箱发送者账户配置
# Send Mail Account
easymonitor.mail.sender=sendermail@domain.com
# Send Mail password
# 邮箱发送者密码
easymonitor.mail.sender.passowrd=mailpassword
# Send Mail SMTP host
# 邮箱发送者 host
easymonitor.mail.sender.host=smtp.domain.com
# Send Mail SMTP port; default is 25
# 邮箱发送者 host 端口
easymonitor.mail.sender.port=25
# Send Mail Whether use SSL; default is false
# 是否使用了 SSL 协议
easymonitor.mail.sender.ssl=false
# Send Mail title
# 邮件发送标题
easymonitor.mail.sender.title=Server Error Notice- EasyMonitor
# The send mail content freemarker template in template directory, default is 'mail.tpl'
# template 目录下的邮件发送模板,默认为 mail.tpl
easymonitor.mail.sender.template=mail.tpl
# When error, repeat send mail interval(seconds); default is 0, not repeat
# 当监控服务发现错误时,是否按周期进行重复提醒(秒);默认为 0,不进行重复提醒
easymonitor.mail.sender.interval=0

# Execute Command 
# You can specify more than one, separated by a ##
# 自动执行的脚本命令,多个脚本命令使用 ## 分隔
easymonitor.cmd=/user/app/startup.sh


########################  Monitor Service Configuration 监控配置

############ URL Monitor(can override global config)
## format: 
## 格式:
## easymonitor.url.NAME=urlValue
## easymonitor.url.NAME.enable=ON|OFF
## easymonitor.url.NAME.cronexpression=0/10 * * * * ?
## easymonitor.url.NAME.maxfailure=10
## easymonitor.url.NAME.cmd=/user/app/script.sh
## easymonitor.url.NAME.mail.receiver=receivermail@domain.com
## easymonitor.url.NAME.mail.sender=sendermail@domain.com
## easymonitor.url.NAME.mail.sender.passowrd=sendermail_password
## easymonitor.url.NAME.mail.sender.host=sendermail_host
## easymonitor.url.NAME.mail.sender.port=sendermail_port
## easymonitor.url.NAME.mail.sender.ssl=sendermail_ssh
## easymonitor.url.NAME.mail.sender.title=sendermail_title
## easymonitor.url.NAME.mail.sender.template=mail.tpl
## easymonitor.url.NAME.mail.sender.interval=1800
## easymonitor.url.NAME.sender.impl=package.userSenderClass##package.userSenderClass2

# Example:
easymonitor.url.tomcatServer1=http\://127.0.0.1\:8888
easymonitor.url.tomcatServer1.cronexpression=0/5 * * * * ?
easymonitor.url.tomcatServer1.maxfailure=4
easymonitor.url.tomcatServer1.mail.receiver=yourmail@domain.com##yourmail@domain.org
easymonitor.url.tomcatServer1.mail.sender.interval=30
easymonitor.url.tomcatServer1.cmd=/home/app/tomcat/bin/startup.sh
# easymonitor.url.tomcatServer1.sender.impl=user.SMSSender##user.OtherSender


############ Port Monitor(can override global config)
## format: 
## easymonitor.port.NAME=portValue
## easymonitor.port.NAME.server=IP
## easymonitor.port.NAME.enable=ON|OFF
## easymonitor.port.NAME.cronexpression=0/10 * * * * ?
## easymonitor.port.NAME.maxfailure=10
## easymonitor.port.NAME.cmd=/user/app/script.sh
## easymonitor.port.NAME.mail.receiver=receivermail@domain.com
## easymonitor.port.NAME.mail.sender=sendermail@domain.com
## easymonitor.port.NAME.mail.sender.passowrd=sendermail_password
## easymonitor.port.NAME.mail.sender.host=sendermail_host
## easymonitor.port.NAME.mail.sender.port=sendermail_port
## easymonitor.port.NAME.mail.sender.ssl=sendermail_ssh
## easymonitor.port.NAME.mail.sender.title=sendermail_title
## easymonitor.port.NAME.mail.sender.template=mail.tpl
## easymonitor.port.NAME.mail.sender.interval=1800
## easymonitor.port.NAME.sender.impl=package.userSenderClass##package.userSenderClass2

# Example:
easymonitor.port.tomcatServer1=8080
easymonitor.port.tomcatServer1.server=localhost
easymonitor.port.tomcatServer1.cronexpression=0/3 * * * * ?
easymonitor.port.tomcatServer1.maxfailure=4
easymonitor.port.tomcatServer1.mail.receiver=yourmail@domain.com##yourmail@domain.org
easymonitor.port.tomcatServer1.mail.sender.interval=30
easymonitor.port.tomcatServer1.cmd=/home/app/tomcat/bin/startup.sh


############ Process Monitor(can override global config)
## format: 
## easymonitor.process.NAME=processValue
## easymonitor.process.NAME.enable=ON|OFF
## easymonitor.process.NAME.cronexpression=0/10 * * * * ?
## easymonitor.process.NAME.maxfailure=10
## easymonitor.process.NAME.cmd=/user/app/script.sh
## easymonitor.process.NAME.mail.receiver=receivermail@domain.com
## easymonitor.process.NAME.mail.sender=sendermail@domain.com
## easymonitor.process.NAME.mail.sender.passowrd=sendermail_password
## easymonitor.process.NAME.mail.sender.host=sendermail_host
## easymonitor.process.NAME.mail.sender.port=sendermail_port
## easymonitor.process.NAME.mail.sender.ssl=sendermail_ssh
## easymonitor.process.NAME.mail.sender.title=sendermail_title
## easymonitor.process.NAME.mail.sender.template=mail.tpl
## easymonitor.process.NAME.mail.sender.interval=1800
## easymonitor.process.NAME.sender.impl=package.userSenderClass##package.userSenderClass2

# Example:
easymonitor.process.tomcatServer1=tomcat
easymonitor.process.tomcatServer1.cronexpression=0/3 * * * * ?
easymonitor.process.tomcatServer1.maxfailure=4
easymonitor.process.tomcatServer1.mail.receiver=yourmail@domain.com##yourmail@domain.org
easymonitor.process.tomcatServer1.mail.sender.interval=30
easymonitor.process.tomcatServer1.cmd=/home/app/tomcat/bin/startup.sh


############ User define Monitor(can override global config)
## format: 
## easymonitor.user.NAME=userValue
## easymonitor.user.NAME.validatorClass=validator.UserMonitorValidator
## easymonitor.user.NAME.enable=ON|OFF
## easymonitor.user.NAME.cronexpression=0/10 * * * * ?
## easymonitor.user.NAME.maxfailure=10
## easymonitor.user.NAME.cmd=/user/app/script.sh
## easymonitor.user.NAME.mail.receiver=receivermail@domain.com
## easymonitor.user.NAME.mail.sender=sendermail@domain.com
## easymonitor.user.NAME.mail.sender.passowrd=sendermail_password
## easymonitor.user.NAME.mail.sender.host=sendermail_host
## easymonitor.user.NAME.mail.sender.port=sendermail_port
## easymonitor.user.NAME.mail.sender.ssl=sendermail_ssh
## easymonitor.user.NAME.mail.sender.title=sendermail_title
## easymonitor.user.NAME.mail.sender.template=mail.tpl
## easymonitor.user.NAME.mail.sender.interval=1800
## easymonitor.user.NAME.sender.impl=package.userSenderClass##package.userSenderClass2

# Example:
easymonitor.user.fileExistsMonitor=data.txt
easymonitor.user.fileExistsMonitor.validatorClass=user.YourFileMonitorValidator
easymonitor.user.fileExistsMonitor.cmd=/home/app/create.sh
easymonitor.user.fileExistsMonitor.cronexpression=0/5 * * * * ?
easymonitor.user.fileExistsMonitor.mail.sender.interval=30
easymonitor.user.fileExistsMonitor.mail.receiver=yourmail@domain.com##yourmail@domain.org
easymonitor.user.fileExistsMonitor.maxfailure=4
easymonitor.user.fileExistsMonitor.sender.impl=user.SMSSender##user.OtherSender

邮件模板配置

EasyMonitor 使用了 freemarker 模板技术进行邮件内容渲染,模板必须存放在 template 目录下,默认使用 mail.tpl 模板。

mail.tpl

自定义模板配置

您可以直接修改模板内容,或者编写您自己的邮件发送模板。

### Global configuration
easymonitor.mail.sender.template=yourmail.tpl

### Monitor Service configuration
easymonitor.[url|port|process|user].NAME.mail.sender.template=yourmail.tpl

模板内置 freemarker 变量

${type}: 监控服务类型
${name}: 监控服务名称
${value}: 监控服务值
${stoptime?datetime}: 监控对象停止时间
${monitorConfiguration.XXX}: 监控配置对象属性

EasyMonitor Application

EasyMonitor Application 是开箱即用的 EasyMonitor 监控应用。按需配置您的监控服务,启动即可。

使用步骤

  1. 配置监控服务

    参考 easymonitor.properties 中的示例,配置您的监控服务。

  2. 运行 EasyMonitor

    • Windows(Sometimes you must 'Run as Administrator')

      Start:  startup.bat
      Stop:   shutdown.bat
    • Unix

      Start:  ./startup.sh
      Stop:   ./shutdown.sh
  3. 可选配置

    1. 邮件模板 Mail template

      修改 'template/mail.tpl' 定制您的邮件提醒内容。

    2. 日志 Logger

      配置 log4j.properties 日志输出。

EasyMonitor Engine Framework

EasyMonitor 同时是一个免费开源跨平台的 Java 监控引擎框架(Java Monitor Engine Framework),提供统一规范的监控配置和核心调度。

您只需要开发监控实现(MonitorValidator)和通知发送者(Sender),按需配置即可。

使用步骤

  1. Maven dependency

    <dependency>
       <groupId>cn.easyproject</groupId>
       <artifactId>easymonitor</artifactId>
       <version>1.3.2-RELEASE</version>
    </dependency>
  2. 自定义 MonitorValidator 监控或 Sender 通知发送者实现类

  3. 配置 easymonitor.properties

  4. 启动

    public static void main(String[] args) {
        new EasyMonitor().start();
    }

自定义 MonitorValidator

仅需实现 MonitorValidator 接口,根据判断规则返回 ValidatorResult 结果即可。

自定义 Sender

一个监控服务可以自定义多个 Sender。当监控到服务异常时,可以执行对应的 SenderImpls 发送提醒通知。

仅需实现 Sender 接口即可。

End

官方主页

留言评论

如果您有更好意见,建议或想法,请联系我。

Email:inthinkcolor@gmail.com

http://www.easyproject.cn

支付宝钱包扫一扫捐助