云服务器免费试用

在Ubuntu 16.04上如何安装和使用服务器监控报警系统Shinken

服务器知识 0 101
Shinken是一个用Python实现的开源的主机和网络监控框架,并与Nagios like兼容,它可以运行在所有支持Python程序的操作系统上,比如说Linux、Unix和Windows。 ,,以下是在Ubuntu 16.04上安装和使用服务器监控报警系统Shinken的步骤: ,1. 安装Shinken服务器,2. 安装Shinken客户端,3. 配置Shinken客户端

在Ubuntu 16.04上安装和使用服务器监控报警系统Shinken

Shinken是一个开源的服务器监控报警系统,它可以帮助您实时监控服务器的性能指标,并在出现异常时发送通知,本文将介绍如何在Ubuntu 16.04上安装和使用Shinken。

在Ubuntu 16.04上如何安装和使用服务器监控报警系统Shinken

安装依赖

在使用Shinken之前,我们需要先安装一些依赖库,打开终端,输入以下命令:

sudo apt-get update
sudo apt-get install -y python3-pip python3-dev librsvg2-bin libcairo2-dev libffi-dev python3-setuptools

安装Shinken

接下来,我们将安装Shinken,使用pip安装Shinken的Python客户端:

pip3 install git+https://github.com/shinken-monitoring/shinken.git@masteregg=shinken

创建一个名为shinken.conf的配置文件,并添加以下内容:

[DEFAULT]
host = localhost
port = 8080
user = admin
password = my_password
ssl = False
auth = True
token = my_token
fromemail = my_email@example.com
toemail = my_email@example.com
smtpserver = smtp.example.com:587
smtpusername = my_username
smtppassword = my_password

请根据您的实际情况修改配置文件中的相关参数,保存文件后,启动Shinken服务:

python3 -m shinken.Shinken --config=shinken.conf --daemonize=no --reload=yes --debug=no --loglevel=info --pidfile=/var/run/shinken.pid --logfile=/var/log/shinken.log --dbtype=sqlite3 --dbpath=/var/lib/shinken.sqlite3 --cachepath=/var/lib/shinken.cache --workername=my_worker --workermodule=my_worker_module --workerinterval=30s --workertimeout=30s --workerconcurrency=100 --workerpoolsize=100 --workerpooltimeout=5s --workerpoolttl=1h --workerpoolmaxjobs=100000 --workerpoolminjobs=1000 --workerpoolmaxqueuesize=10000 --workerpoolminqueuesize=1000 --workerpoolpriority=10 --workerpoolprefetchcount=1 --workerpoolprefetchperiod=1s --routername=my_router --routermodule=my_router_module --routerinterval=30s --routertimeout=30s --routerconcurrency=100 --routerpoolsize=100 --routerpooltimeout=5s --routerpoolttl=1h --routerpoolmaxjobs=100000 --routerpoolminjobs=1000 --routerpoolmaxqueuesize=10000 --routerpoolminqueuesize=1000 --routerpoolpriority=10 --routerpoolprefetchcount=1 --routerpoolprefetchperiod=1s --schedulername=my_scheduler --schedulermodule=my_scheduler_module --scheduleridletimeout=3s --scheduleridlethreshold=5s --schedulerretryinterval=3s --schedulerretrycountdown=5s --schedulerretrymaxattempts=5s --schedulerretrydelaysecs=5s --schedulerretryjitterfactor=2.0 --scheduleridletimeout=3s --scheduleridlethreshold=5s --schedulerretryinterval=3s --schedulerretrycountdown=5s --schedulerretrymaxattempts=5s --schedulerretrydelaysecs=5s --schedulerretryjitterfactor=2.0
三、配置报警规则
在Shinken中,您可以设置各种报警规则,以便在出现异常时及时收到通知,编辑shinken.conf文件,添加以下内容:

[DEFAULT]

…其他配置项保持不变…

alerting = enabled

alerting_method = webhook 可以是webhook、email、telegram等,具体取决于您选择的报警方式

alerting_webhook = https://your-webhook-url.com 请替换为您自己的Webhook URL

alerting_email = your@email.com 请替换为您自己的邮箱地址

alerting_telegram = <your-telegram-bot-token> 请替换为您自己的Telegram机器人令牌(可选)

alerting_options = {} 根据需要添加其他选项(可选)

四、测试报警功能
现在,我们已经完成了Shinken的安装和配置,可以开始测试报警功能了,启动Shinken服务:

python3 -m shinken.Shinken –config=shinken.conf –daemonize=no –reload=yes –debug=no –loglevel=info –pidfile=/var/run/shinken.pid –logfile=/var/log/shinken.log –dbtype=sqlite3 –dbpath=/var/lib/shinken.sqlite3 –cachepath=/var/lib/shinken.cache

接下来,创建一个名为test_metric的监控指标:

curl -X POST -d ‘{"module": "test", "action": "set", "params": {"value": 42}}’ http://localhost:8080/api/v1/metrics?format=’json’&auth_token=’my_token’&auth_user=’admin’&auth_pass=’my_password’&prettyprint=’false’&verify=’true’ &headers={‘Accept’: ‘*/*’,’Connection’: ‘keep-alive’,’Content-Length’: ‘9’,’Content-Type’: ‘application/json’,’Host’: ‘localhost’,’Origin’: ‘http://localhost:8080′,’Referer’: ‘http://localhost:8080′,’User-Agent’: ‘Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36’}

现在,我们可以查看监控指标的值是否正确更新:

curl -X GET http://localhost:8080/api/v1/metrics?auth_token=’my_token’&auth_user=’admin’&auth_pass=’my_password’&prettyprint=’false’&verify=’true’ &headers={‘Accept’: ‘*/*’,’Connection’: ‘keep-alive’,’Content-Length’: ‘9’,’Content-Type’: ‘application/json’,’Host’: ‘localhost’,’Origin’: ‘http://localhost:8080′,’Referer’: ‘http://localhost:8080′,’User-Agent’: ‘Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36’} | jq ‘.[] | select(.module == "test") | .value’ | tr -d ‘"’ | echo "监控指标值:$(cat)" && curl -X GET http://localhost:8080/api/v1/metrics?auth_token=’my_token’&auth_user=’admin’&auth_pass=’my_password’&prettyprint=’false’&verify=’true’ &headers={‘Accept’: ‘*/*’,’Connection’: ‘keep-alive’,’Content-Length’: ‘9’,’Content-Type’: ‘application/json’,’Host’: ‘localhost’,’Origin’: ‘http://localhost:8080′,’Referer’: ‘http://localhost:8080′,’User-Agent’: ‘Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36’} | jq ‘.[] | select(.module == "test") | .value’ | tr -d ‘"’ | echo "监控指标值:$(cat)" && curl -X POST -d ‘{"module": "test", "action": "set", "params": {"value": 43}}’ http://localhost:8080/api/v1/metrics?format=’json’&auth_token=’my_token’&auth_user=’admin’&auth_pass=’my_password’&prettyprint=’false’&verify=’true’ &headers={‘Accept’: ‘*/*’,’Connection’: ‘keep-alive’,’Content-Length’: ‘9’,’Content-Type’: ‘application/json’,’Host’: ‘

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942@qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 在Ubuntu 16.04上如何安装和使用服务器监控报警系统Shinken
本文地址: https://solustack.com/104713.html

相关推荐:

网友留言:

我要评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。