使用 Promwwwzs12558comI3578II9877etheus 监控 Ceph

本文涉及的产品
可观测可视化 Grafana 版,10个用户账号 1个月
简介: 本文是在 Ubuntu 16.04 最新版基础上安装 Prometheus 监控系统,Ceph 版本为 Luminous 12.2.8。 1. 安装 Prometheus 直接使用 apt 安装的 Prometheus 版本较低,很多新的配置选项都已不再支持,建议使用 Prometheus 的安装包,接下来看看安装包部署的步骤。

Prometheus

本文是在 Ubuntu 16.04 最新版基础上安装 Prometheus 监控系统,Ceph 版本为 Luminous 12.2.8。

  1. 安装 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 中添加相应配置,不过现在执行到这一步就可以了。

  1. 安装 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

  1. 安装 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 的监控信息了。

  1. 告警系统
    现在已经有了图形化界面的状态监控,但出现紧急情况我们肯定不希望要登录到界面上才能察觉到,在 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:

    然后修改 /etc/prometheus/prometheus.yml,添加告警规则文件。

$ 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 就大功告成了。

$ sudo systemctl restart alertmanager.service
$ sudo systemctl restart prometheus.service
最后我们来看看发出来的消息效果如何,确实比之前好看多了,总算是没有白费一番功夫。

formatted prometheus message

相关文章
|
存储 算法 关系型数据库
【CEPH-初识篇】ceph详细介绍、搭建集群及使用,带你认识新大陆
你好,我是无名小歌。 今天给大家分享一个分布式存储系统ceph。 什么是ceph? Ceph在一个统一的系统中独特地提供对象、块和文件存储。Ceph 高度可靠、易于管理且免费。Ceph 的强大功能可以改变您公司的 IT 基础架构和管理大量数据的能力。Ceph 提供了非凡的可扩展性——数以千计的客户端访问 PB 到 EB 的数据。ceph存储集群相互通信以动态复制和重新分配数据。
1135 0
【CEPH-初识篇】ceph详细介绍、搭建集群及使用,带你认识新大陆
|
5月前
|
存储 关系型数据库 网络安全
CEPH搭建
CEPH搭建
103 0
|
9月前
|
域名解析 存储 块存储
ceph集群的搭建
ceph集群的搭建
283 1
|
9月前
|
块存储
ceph集群的搭建(下)
ceph集群的搭建
120 0
|
存储 运维 监控
cephadm 安装部署 ceph 集群
块存储:提供像普通硬盘一样的存储,为使用者提供“硬盘” 文件系统存储:类似于NFS的共享方式,为使用者提供共享文件夹 对象存储:像百度云盘一样,需要使用单独的客户端 ceph还是一个分布式的存储系统,非常灵活。如果需要扩容,只要向ceph集中增加服务器即可。ceph存储数据时采用多副本的方式进行存储,生产环境下,一个文件至少要存3份。ceph默认也是三副本存储。
556 0
|
存储 关系型数据库 网络安全
手动部署ceph octopus集群
手动部署ceph octopus集群
手动部署ceph octopus集群
|
存储 关系型数据库 网络安全
使用ansible部署ceph集群
使用ansible部署ceph集群
使用ansible部署ceph集群
|
Prometheus 监控 Cloud Native
|
监控
glusterfs 监控
这里以监控gv_KVM这个卷为例 1.启动 Profiling [root@192_168_174_68 ~]# gluster gluster> volume profile gv_KVM start Starting volume profile on gv_KVM has been successful 2.
1622 0
|
Prometheus 监控 Cloud Native
Ceph 监控中应用 Prometheus relabel 功能
1. 问题描述 工作环境中有三个独立的 Ceph 集群,分别负责对象存储、块存储和文件存储。搭建这几个 Ceph 集群时,我对 Ceph 重命名 Cluster name 的难度没有足够的了解,所以使用的都是默认的 cluster name:ceph,不巧的是 Prometheus 的 ceph_exporter 就是用 cluster name 来区分不同集群,结果是 Grafana 中各个集群的数据无法区分,所有的集群数据都绘制在了一个图标中,非常乱不说,而且部分数据还无法正常显示。
1435 0