工具癖系统运维专家微服务架构和实践

使用 Prometheus 监控 Ceph

2018-09-12  本文已影响34人  blackpiglet
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 mkdri /var/lib/prometheus/
$ sudo systemctl daemon-reload
$ sudo systemctl enable prometheus.service
$ sudo systemctl start prometheus.service

在下一步装好 ceph_exporter 后,还需要在 Promethues 中添加相应配置,不过现在执行到这一步就可以了。

2. 安装 ceph_exporter

2.1 安装 Go 语言环境

导出 Ceph 信息到 Prometheus 有多种方式,本文采用的是 DigitalOcean 的 ceph_exporter,ceph_exporter 使用 go 语言编写的,所以需要先安装 go 语言环境。还是一条命令解决:

$ 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/user/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

$ source /etc/profile.d/go.sh

已经配置好 Go 环境了,接下来创建 GOPATH 指定的目录:

$ mkdir /home/user/go

2.2 安装 ceph_exporter

Go 环境安装好后,我们接下来下载 ceph_exporter 代码,然后编译出可执行程序。

$ mkdir -p /home/user/go/github.com/digitalocean
$ cd /home/user/go/github.com/digitalocean
$ git clone github.com/digitalocean/ceph_exporter
$ cd ceph_exporter
$ go build

这时编译会报错,原因是需要依赖 ceph rados 相关的头文件,需要安装 librados-dev 包。

$ sudo apt install -y librados-dev

安装好后,在编译,复制可执行文件到对应目录完成安装。
再运行 go build 完成安装。

$ go build 
$ mkdir /home/user/go/bin
$ cp ceph_exporter /home/user/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")

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

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

4. 参考文档

上一篇 下一篇

猜你喜欢

热点阅读