用K8S+Prometheus四步搭建Ceph监控

用K8S+Prometheus四步搭建Ceph监控
Ceph的监控方案有很多,有专业的Calamari,也有collectd-ceph+influxdb的。不过不管用什么,我们的目的其实是能够第一时间直观的看到Ceph集群的运行状态。在这点上我觉得目前用Grafana+Prometheus的展示Ceph集群的状态还是挺直观方便的,重要的是得益于Prometheus和Kubernetes良好的结合,我们可以非常快的复制几个Ceph集群的监控。

对于Ceph监控,需求也很简单:

  • Cluster、Mon节点、OSD节点和Pools的状态检查
  • pg状态和object数量
  • 存储总容量、使用量、iops和吞吐量
  • Ceph存储网卡流量,CPU内存利用率等
  • 查看数据的延迟
  • 监控多套Ceph集群

目前Ceph网上流行的Grafana模板如下图:

Ceph集群Dashboard
OSD信息
Pool信息

其实可以看到默认的三个展示页面已经能够实现我的大部分需求了,日常工作中大部分时间都是关注集群的监控状态和iops,而且这个基于全开源的方案,基本没有开发成本,挺不错的。

那么如何快速搭建一套基于K8S+Prometheus的Ceph监控呢?

第1步. ceph-exporter

ceph-exporter是采集Ceph集群数据的客户端程序,启动时默认会从/etc/ceph目录下获取Ceph的配置信息。ceph-exporter是一个用Go写的二进制静态程序,运行它的方式可以是Pod,也可是在物理机上独立启动。

Pod
yaml文件如下:

apiVersion: v1
kind: Pod
metadata:
  annotations:
    kubernetes.io/created-by: |
      {"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"DaemonSet","namespace":"monitoring","name":"ceph-exporter","uid":"3c5bf0d4-2fd9-11e7-8834-1866da6d9abb","apiVersion":"extensions","resourceVersion":"1336275"}}
  labels:
    app: ceph-exporter
    pod-template-generation: "1"
  name: ceph-exporter-1wfcd
  namespace: monitoring
  ownerReferences:
  - apiVersion: extensions/v1beta1
    blockOwnerDeletion: true
    controller: true
    kind: DaemonSet
    name: ceph-exporter
spec:
  containers:
  - image: digitalocean/ceph_exporter
    imagePullPolicy: IfNotPresent
    name: ceph-exporter
    resources:
      limits:
        cpu: 100m
        memory: 200Mi
      requests:
        cpu: 100m
        memory: 200Mi
    volumeMounts:
    - mountPath: /etc/ceph
      name: ceph-conf
  hostNetwork: true
  nodeName: <hostname>   #Ceph宿主机的ip
  nodeSelector:
    kubernetes.io/hostname: <hostname>  #Ceph宿主机的ip
  restartPolicy: Always
  serviceAccount: default
  serviceAccountName: default
  volumes:
  - hostPath:
      path: /etc/ceph
    name: ceph-conf

物理机

直接将ceph-exporter文件拷贝到目标节点,可以采用nohup或者手动编写systemd文件启动采集程序。

运行成功后可以在浏览器中直接访问http://目标ip:9128/metrics

metrics

第2步. 定义服务

Pod

---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: ceph-exporter
    k8s-app: ceph-exporter
  name: ceph-exporter
  namespace: monitoring
spec:
  clusterIP: None
  ports:
  - name: web
    port: 9128
    protocol: TCP
    targetPort: 9128
  selector:
    app: ceph-exporter
  type: ClusterIP
---
apiVersion: monitoring.coreos.com/v1alpha1
kind: ServiceMonitor
metadata:
  labels:
    app: ceph-exporter
  name: ceph-exporter
  namespace: monitoring
spec:
  endpoints:
  - interval: 10s
    port: web
  namespaceSelector:
    matchNames:
    - monitoring
  selector:
    matchLabels:
      app: ceph-exporter

物理机

---
apiVersion: v1
kind: Service
metadata:
  labels:
    k8s-app: ocata-ceph
  name: ocata-ceph
  namespace: monitoring
spec:
  clusterIP: None
  ports:
  - name: api
    port: 9128
    protocol: TCP
    targetPort: 9128
  sessionAffinity: None
  type: ClusterIP
---
apiVersion: v1
kind: Endpoints
metadata:
  labels:
    k8s-app: ocata-ceph
  name: ocata-ceph
  namespace: monitoring
subsets:
- addresses:
  - ip: <物理机ip>
    nodeName: <物理机ip>
  ports:
  - name: api
    port: 9128
    protocol: TCP
---
apiVersion: monitoring.coreos.com/v1alpha1
kind: ServiceMonitor
metadata:
  labels:
    app: ocata-ceph
  name: ocata-ceph
  namespace: monitoring
spec:
  endpoints:
  - interval: 10s
    port: api
  namespaceSelector:
    matchNames:
    - monitoring
  selector:
    matchLabels:
      k8s-app: ocata-ceph

创建成功后就可以在Prometheus的状态里面查看job是否被添加上,如果添加上了,prometheus就会定期去目标节点上拉去新数据。

Prometheus config
Prometheus Target

第3步. 测试

简单测试下Prometheus的查询语句,如果没问题就可以在前端Grafana上展示出来了。

metrics
ceph_health_stats
osd状态,根据job过滤

第4步.. Grafana导入模板

原来模板不支持templating,我这里改了下,可以在这个页面上选择多个Ceph集群并展示状态。
我将改好的Grafana模板传到这里,欢迎下载。

Templating
Templating Edit
Templating exporter
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 系统环境: centos73.10.0-514.26.2.el7.x86_64 机器数量:五台 硬盘:四块一块为系...
    think_lonely阅读 10,250评论 0 5
  • 第一章 OpenStack基础 OpenStack管理的资源及提供的服务OpenStack做为一个操作系统,...
    sgt_tiger阅读 14,454评论 4 72
  • 集群管理 每次用命令启动、重启、停止Ceph守护进程(或整个集群)时,必须指定至少一个选项和一个命令,还可能要指定...
    Arteezy_Xie阅读 19,689评论 0 19
  • 2017年春节,早早就计划着这个新年要出去玩一趟,而不是再像着往年那样,在家吃喝,打牌。 年初二出发,从无锡,到安...
    而立青春阅读 3,118评论 0 4
  • 分组可见这事儿一般是由当事人暗中操作的,具有主观能动性,被分组的人基本上都被蒙在鼓里。所以有时候你翻看好友列表会发...
    高芳芳123阅读 2,944评论 0 0