urlooker是一款监控web服务可用性及访问质量的工具,采用go语言编写,易于安装和二次开发。它能提供返回状态码检测,页面访问时间检测,agent多机房部署,指定机房访问,同时支持短信与邮件告警。
一.安装环境依赖
apt-get install MysqL-server
设置用户与密码
wget http://x2know.qiniudn.com/schema.sql
进入数据库,创建urlooker库
set names utf8
source /root/schema.sql ##sql文件路径
(2)安装redis数据库
apt-get install Redis-server
二. 安装编译环境go 1.6
(1) 下载安装包
sudo apt-get update
sudo apt-get -y upgrade
sudo curl -O https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz
sudo tar -xvf go1.6.linux-amd64.tar.gz
sudo mv go /usr/local
(2)设置go路径
sudo vim ~/.profile
export PATH=$PATH:/usr/local/go/bin
export GOROOT=usr/local/go
export PATH=$PATH:$GOROOT/bin
source ~/.profile ##刷新环境变量
运行 go version 能显示go版本信息,代表安装成功。
三. 二进制安装urlooker
wget http://x2know.qiniudn.com/urlooker.tar.gz
tar xzvf urlooker.tar.gz
cd urlooker
(1)urlooker web 组件安装
web组件主要是用来添加监控项,告警组人员管理,查看url访问质量绘图
export GOPATH=/url/local ##设置GOPATH环境变量
mkdir -p $GOPATH/src/github.com/urlooker
cd $GOPATH/src/github.com/urlooker
git clone https://github.com/URLooker/web.git
cd web
./control build ##如果build过程中出错提示找不到go命令,可以修改control文件,将go命令添加为绝对路径
./control start
"debug": true,"salt": "have fun!","past": 30,#查看最近几分钟内的报警历史和绘图,默认为30分钟
"http": {
"listen": "0.0.0.0:1984","secret": "secret"
},"rpc": {
"listen": "0.0.0.0:1985"
},"MysqL": {
"addr": "root:123456@tcp(127.0.0.1:3306)/urlooker?charset=utf8&&loc=Asia%2FShanghai",#与数据库交互的有关信息
"idle": 10,"max": 20
},"alarm":{
"enable": true,"batch": 200,"replicas": 500,"connTimeout": 1000,"callTimeout": 5000,"maxConns": 32,"maxIdle": 32,"sleepTime":30,"cluster":{
"node-1":"127.0.0.1:1986"
}
},"monitorMap": { #配置哪些url由哪个机房的agent去监控,默认均由default列表中的agent去监控
"default":["hostname.1"],#监控指标多了之后agent地址可以填多个,可以通过多个agent去监控
"idc1":["hostname.2"]
},"falcon":{
"enable": false,# 为true表示向falcon推送数据
"addr":"http://falcon.transfer.addr/api/push","interval": 60
},"internalDns":{ #通过公司内部接口获取url对应ip所在机房
"enable": false,"addr":""
}
(2)urlooker agent组件安装
agent组件可以定时从web组件获取带监控url列表,发起模拟访问,然后将访问结果回报给web组件
设置GOPATH环境变量
mkdir -p $GOPATH/src/github.com/urlooker
cd $GOPATH/src/github.com/urlooker
git clone https://github.com/URLooker/agent.git
cd agent
go get ./... ##安装该组件时,尽量使用root用户,否则可能因为权限问题而出错
./control build
./control start
{
"debug": false,"hostname": "hostname.1",#hostname.1 和 web组件配置文件中monitorMap的值对应
"worker": 1000,# 同时访问url的并发数
"web": {
"addrs": ["127.0.0.1:1985"],##如果需要多机房访问,可以将将此地址修改为具体的ip地址
"interval": 60,"timeout": 1000
}
}
(3)urlooker alarm组件
alarm 组件是用于判断是否触发报警条件的组件,alarm会定期从web端获取策略列表,接收到web端发送的检测数据后,对数据进行判断,若触发则产生event数据,将events数据存到redis中
# set $GOPATH and $GOROOT ##设置环境变量
mkdir -p $GOPATH/src/github.com/urlooker
cd $GOPATH/src/github.com/urlooker
git clone https://github.com/URLooker/alarm.git
cd alarm
./control build
./control start
修改alarm/cfg.json
{
"debug": false,"remain":10,#配置策略中支持的最大连续次数
"rpc":{
"listen":"0.0.0.0:1986"
},"web": {
"addrs": ["127.0.0.1:1985"],#可以填多个web地址
"timeout": 300,"alarm": {
"enabled": true,"minInterval": 180,"queuePattern": "event","redis": {
"dsn": "127.0.0.1:6379","maxIdle": 5,"connTimeout": 20000,"readTimeout": 20000,"writeTimeout": 20000
}
},"queue": {
"sms": "/sms","mail": "/mail"
},"worker": {
"sms": 10,"mail": 50
},"sms": "","smtp": {
"addr": "mail.addr:25","username": "mail@mail.com","password": "","from": "mail@mail.com"
}
}
至此urlooker已经部署完成
web/control start alarm/control start agent/control start
可以通过打开浏览器访问 http://127.0.0.1:1984(或者ip)