使用 Promwww9992019comI8I2222IIIIetheus 监控 Ceph
Prometheus
本文是在 Ubuntu 16.04 最新版基础上安装 Prometheus 监控系统,Ceph 版本为 Luminous 12.2.8。
- 安装 Prometheus
直接使用 apt 安装的 Prometheus 版本较低,很多新的配置选项都已不再支持,建议使用 Prometheus 的安装包,接下来看看安
装包部署的步骤。
先下载安装包,这里用的是 2.0.0 版本,目前为止,最新的应该为 2.4.0,安装方法都是一样的。
$ wget https://github.com/prometheus/prometheus/releases/download/v2.0.0/prometheus-2.0.0.linux-amd64.tar.gz
$ tar zxvf prometheus-2.0.0.linux-amd64.tar.gz
$ cd prometheus-2.0.0.linux-amd64/
$ sudo cp prometheus /usr/bin/
$ sudo cp promtool /usr/bin/
$ vim /lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus: the monitoring system
Documentation=http://prometheus.io/docs/
[Service]
ExecStart=/usr/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus --web.console.templates=/etc/prometheus/consoles --web.console.libraries=/etc/prometheus/console_libraries --web.listen-address=0.0.0.0:9090 --web.external-url=
Restart=always
StartLimitInterval=0
RestartSec=10
[Install]
WantedBy=multi-user.target
$ sudo mkdir /etc/prometheus/
$ sudo cp -R consoles console_libraries prometheus.yml /etc/prometheus/
$ sudo mkdir /var/lib/prometheus/
$ sudo systemctl daemon-reload
$ sudo systemctl enable prometheus.service
$ sudo systemctl start prometheus.service
在下一步装好 ceph_exporter 后,还需要在 Promethues 中添加相应配置,不过现在执行到这一步就可以了。
- 安装 ceph_exporter
2.1 安装 Go 语言环境
导出 Ceph 信息到 Prometheus 有多种方式,本文采用的是 DigitalOcean 的 ceph_exporter,ceph_exporter 使用 go 语言编写的,所以需要先安装 go 语言环境。还是一条命令解决:
$ sudo apt install -y golang
安装好后执行 $ go env 命令验证并查看一下 go 环境信息。
$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/lib/go-1.6"
GOTOOLDIR="/usr/lib/go-1.6/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
然后需要设置 Go 环境变量:
$ cat /etc/profile.d/go.sh
export GOROOT=/usr/lib/go-1.6
export GOBIN=$GOROOT/bin
export GOPATH=/home//go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
$ source /etc/profile.d/go.sh
已经配置好 Go 环境了,接下来创建 GOPATH 指定的目录:
$ mkdir /home//go
2.2 安装 ceph_exporter
Go 环境安装好后,我们接下来下载 ceph_exporter 代码,然后编译出可执行程序。
$ mkdir -p /home//go/src/github.com/digitalocean
$ cd /home//go/github.com/src/digitalocean
$ git clone https://github.com/digitalocean/ceph_exporter
$ cd ceph_exporter
$ go build
这时编译会报错,原因是需要依赖 ceph rados 相关的头文件,需要安装 librados-dev 包。
$ sudo apt install -y librados-dev
安装好后,在编译,复制可执行文件到对应目录完成安装。
再运行 go build 完成安装。
$ go get
$ go build
$ mkdir /home//go/bin
$ cp ceph_exporter /home//go/bin
执行 ceph_exporter 来验证一下是否可以正常使用
$ ceph_exporter --help
Usage of ceph_exporter:
-ceph.config string
path to ceph config file
-ceph.user string
Ceph user to connect to cluster. (default "admin")
-exporter.config string
Path to ceph exporter config. (default "/etc/ceph/exporter.yml")
-rgw.mode int
Enable collection of stats from RGW (0:disabled 1:enabled 2:background)
-telemetry.addr string
host:port for ceph exporter (default ":9128")
-telemetry.path string
URL path for surfacing collected metrics (default "/metrics")
接下来要配置 ceph_exporter 的自动启动:
$ cat /lib/systemd/system/ceph_exporter.service
[Unit]
Description=Prometheus's ceph metrics exporter
After=prometheus.ervice
[Service]
User=
Group=
ExecStart=/home//go/bin/ceph_exporter
[Install]
WantedBy=multi-user.target
Alias=ceph_exporter.service
$ sudo systemctl daemon-reload
$ sudo systemctl enable ceph_exporter.service
$ sudo systemctl start ceph_exporter.service
2.3 修改 Promethues 配置
接下来需要修改 Prometheus 的配置,添加一会要安装的 ceph_exporter 的相关信息:
$ sudo vim /etc/prometheus/prometheus.yml
...
scrape_configs:
-
job_name: 'ceph_exporter'
static_configs:-
targets: ['localhost:9128']
labels:alias: ceph_exporter
...
-
改好后,重启:
$ sudo systemctl restart prometheus.service
- 安装 Grafana
3.1 安装
Grafana 也不推荐使用 APT 安装,原因也是版本太低,安装官方打包好的版本是更优的选择。
$ sudo apt-get install -y adduser libfontconfig
$ wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana_5.2.4_amd64.deb
$ sudo dpkg -i grafana_5.2.4_amd64.deb
$ sudo systemctl enable grafana-server
$ sudo systemctl start grafana-server
至此 Grafana 也已经安装好了,接下来登录 grafana 界面。
3.2 配置 dashboard
Grafana
访问 http://localhost:3000 来登录 Grafana,默认用户为 admin,密码也是 admin。
data-source
登录后首先需要配置 data source,访问地址 http://localhost:3000/datasources,会出现如上图所示的界面,按照图中显示的信息配置即可。
import
最后需要导入 Ceph 相关的界面,如图所示,导入的是编号为 917 的 dashboard(从 grafana.com 上,导入编号为 917 的 dashboard)。
ceph-cluster
完成后,终于可以看到 Ceph 的监控信息了。
- 告警系统
现在已经有了图形化界面的状态监控,但出现紧急情况我们肯定不希望要登录到界面上才能察觉到,在 Prometheus 系统中,这个工作由 AlertManager 组件负责,接下来我们就以钉钉消息通知为例,看一下如何配置告警系统。
4.1 安装 AlertManager
AlertManager 的安装流程和 Prometheus 很像,也是需要下载对应的安装包。
$ wget https://github.com/prometheus/alertmanager/releases/download/v0.15.2/alertmanager-0.15.2.linux-amd64.tar.gz
$ tar zxvf alertmanager-0.15.2.linux-amd64.tar.gz
$ cd alertmanager-0.15.2.linux-amd64
$ sudo cp alertmanager amtool /usr/bin/
$ sudo cp alertmanager.yml /etc/prometheus/
接下来配置 systemd 的 unit 文件。
$ cat /lib/systemd/system/alertmanager.service
[Unit]
Description=Prometheus: the alerting system
Documentation=http://prometheus.io/docs/
After=prometheus.service
[Service]
ExecStart=/usr/bin/alertmanager --config.file=/etc/prometheus/alertmanager.yml
Restart=always
StartLimitInterval=0
RestartSec=10
[Install]
WantedBy=multi-user.target
启动 alermanager 服务,并配置开机启动。
$ sudo systemctl enable alertmanager.service
$ sudo systemctl start alertmanager.service
在 Prometheus 中添加 AlertManager 的信息,并重启 Prometheus。
$ cat /etc/prometheus/prometheus.yml
...
alerting:
alertmanagers:
- static_configs: - targets: ["localhost:9093"]
$ sudo systemctl restart prometheus.service
4.2 获取钉钉的 webhook
要往钉钉发消息,当然要先知道 webhook 是多少,首先是在钉钉群里添加一个机器人,然后查看机器人的设置,就可以看到 webhook:
Dingtalk robot API
4.3 配置消息转发的 API
配置 Prometheus 直接向钉钉 Webhook 发消息应该是发不过去的,Prometheus 的消息格式和钉钉 webhook 并不兼容,而且就算是拿到消息中的字符串再发过去,没经过格式化的消息也太难看了。截个未经处理的钉钉消息的图给大家感受一下:
Unformatted prometheus message
所以我们需要配置一个转发并格式化 Prometheus 消息的 API 服务器,在网上搜了一下还真的找到一个已经做好的格式化 Prometheus 消息的开源项目,完全满足需求:https://github.com/timonwong/prometheus-webhook-dingtalk,感谢 Timon Wong 的贡献。接下来介绍一下如何以 Docker 形式部署该 API 服务。
4.3.1 安装 Docker
首先当然是要先安装 Docker ,并配置 Docker 从国内镜像源下载镜像。
$ sudo apt install -y docker.io
$ sudo vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://registry.docker-cn.com"]
}
$ sudo systemctl restart docker.service
4.3.2 启动 prometheus-webhook-dingtalk
先下载镜像。
$ sudo docker pull timonwong/prometheus-webhook-dingtalk:v0.3.0
启动镜像。
这里解释一下两个变量:
:prometheus-webhook-dingtalk 支持多个钉钉 webhook,不同 webhook 就是靠名字对应到 URL 来做映射的。要支持多个钉钉 webhook,可以用多个 --ding.profile 参数的方式支持,例如:sudo docker run -d --restart always -p 8060:8060 timonwong/prometheus-webhook-dingtalk:v0.3.0 --ding.profile="webhook1=https://oapi.dingtalk.com/robot/send?access_token=token1" --ding.profile="webhook2=https://oapi.dingtalk.com/robot/send?access_token=token2"。而名字和 URL 的对应规则如下,ding.profile="webhook1=......",对应的 API URL 为:http://localhost:8060/dingtalk/webhook1/send
:这个就是之前获取的钉钉 webhook。
$ sudo docker run -d --restart always -p 8060:8060 timonwong/prometheus-webhook-dingtalk:v0.3.0 --ding.profile="="
4.4 配置 AlertManager 告警规则
首先修改 alertmanager.yml,在下面这个例子中指定了名为 web.hook 的消息接收方,url 为刚刚启动的 prometheus-webhook-dingtalk 的地址。
$ cat /etc/prometheus/alertmanager.yml
global:
resolve_timeout: 5m
route:
group_by: ['alertname']
group_wait: 10s
group_interval: 10s
repeat_interval: 1h
receiver: 'web.hook'
receivers:
-
name: 'web.hook'
webhook_configs:- url: 'http://localhost:8060/dingtalk/web.hook/send'
inhibit_rules: -
source_match:
severity: 'critical'
target_match:
severity: 'warning'
equal: ['alertname', 'dev', 'instance']
然后修改 /etc/prometheus/prometheus.yml,添加告警规则文件。
- url: 'http://localhost:8060/dingtalk/web.hook/send'
$ cat /etc/prometheus/prometheus.yml
......
rule_files:
- /etc/prometheus/rules/ceph.yaml
接下来轮到刚刚提到的告警规则文件了,下面这个例子中定义了在 ceph 可用存储空间小于总存储空间 70% 的情况下,发出告警消息。
$ cat /etc/prometheus/rules/ceph.yaml
groups:
-
name: ceph-rule
rules:- alert: CephCapacityUsage
expr: ceph_cluster_available_bytes / ceph_cluster_capacity_bytes * 100 > 70
for: 2m
labels:product: ceph
annotations:
summary: "{{$labels.instance}}: Not enough capacity in Ceph detected" description: "{{$labels.instance}}: Available capacity is used up to 70% (current value is: {{ $value }}"
好了,最后重启 AlertManager 和 Prometheus 就大功告成了。
- alert: CephCapacityUsage
$ sudo systemctl restart alertmanager.service
$ sudo systemctl restart prometheus.service
最后我们来看看发出来的消息效果如何,确实比之前好看多了,总算是没有白费一番功夫。
formatted prometheus message
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
程序羊的2018年终总(gen)结(feng)
时光荏苒,岁月如梭啊,感觉之前写《我的半年技术博客之路》年中总结时好像还是昨天的事,而如今又一年的时间一晃而过,参加工作已有 2年多时间的我,兜子里还是像以前一样一贫如洗,不过还好我用 65篇原创技术博文 给了2018年一个基本交代,基本符合当初定下的目标吧,写了接近7万字,简书粉丝也到了近5000。 让自己最值得庆幸的是,这一年来的坚持,让写作这件事已经不知不觉地成为了自己无法抹去的习惯,我也希望它能更加深入我的骨子里! 今年 9月底自己做了一个重大决定,从之前所在的通信公司离职,转向了自己比较感兴趣的 Java后台开发。由于之前两年一直是从事C语言相关的通信行业系统开(wei)发(hu),并没有接触过任何 Web开发的项目,因此到了新环境之后一切对我来讲都是新鲜事物,而且工作的模式也发生了较大的转变,但好在自己有了十足的心理准备加上自己业余的一些浅薄积累才让自己不至于太过慌乱,从而也深深的体会了行业转换所需要付出的代价,因此大家如果有同类情况还是需要慎而决之。 好了,不扯远了,在这里我总结一下这一年里写的一点微薄的东西。 具体目录如下: 【编程语言】 Java编程思想学习录(连载之...
- 下一篇
企业级分布式应用服务EDAS评测报告
一、测试产品背景: EDAS 是一个围绕应用和微服务的PaaS平台,提供多样的应用发布和轻量级微服务解决方案,帮助用户解决在应用和服务管理过程中监控、诊断和高可用运维问题;提供Spring Cloud和Dubbo的运行环境。根据阿里云官方文档的信息,EDAS是一个面向企业提供分布式应用服务的中间件产品,支持的框架环境为SPRING CLOUD和DUBBO,去除不同版本所提供的增值服务的差异,整个产品提供的核心服务包括以下几个方面:1、 微服务:可以采用SPRING CLOUD或DUBBO开发应用,EDAS提供分布式配置推送和分布式任务调度服务。2、 对系统和服务的状况提供的实时监控服务。3、 应用的生命周期管理。4、 实时日志。5、 基于阿里云计算的弹性伸缩服务。6、 持续集成。7、 离线配
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
-
Docker使用Oracle官方镜像安装(12C,18C,19C)
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- CentOS8编译安装MySQL8.0.19
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- MySQL8.0.19开启GTID主从同步CentOS8
- CentOS7,8上快速安装Gitea,搭建Git服务器
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
推荐阅读
最新文章
- Linux系统CentOS6、CentOS7手动修改IP地址
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- CentOS6,CentOS7官方镜像安装Oracle11G
- SpringBoot2整合Redis,开启缓存,提高访问速度
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- Hadoop3单机部署,实现最简伪集群