重写ceph-lazy

前言

这个工具最开始是从sebastien的blog里面看到的,这个是 Gregory Charot(工具的作者)写的,通常我们在获取一个ceph的信息的时候,需要敲一连串的命令去获得自己需要的信息,可能需要一大堆的解析才能完成,而经常出现的是,使用了后,下次使用的时候,又要重来一遍,所以作者把这些常用的操作做了一些归纳,形成了一个查询的工具,很多人有个相同的观点就是,越懒,就会想办法提高效率,当然,首先得有提高效率的意识,否则只剩下懒了

我做的事情就是把作者用shell的逻辑转换成了python的版本,这样也方便自己以后的扩展,这里感谢作者做的一些工作,让我很快就能完成了,这里并不是重复造车轮,本来自己就不会python,权当练手了

在linux下面我是不建议用中文的,但是这个工具里面还是改成用中文提示,因为中文可能看上去更清楚需要做的是一个什么事情,这个仅仅是一个查询工具

有一段时间没有更新blog了,主要是最近比较忙,没有时间去看太多的资料,没有时间来写下更多的东西,有时间还是会坚持写下去

项目地址

原作者项目地址:https://github.com/gcharot/ceph-lazy
我重写的地址:https://github.com/zphj1987/ceph-lazy/tree/lazy-python

安装方法

1
2
wget -O /sbin/ceph-lazy https://raw.githubusercontent.com/zphj1987/ceph-lazy/lazy-python/ceph-lazy.py
chmod 777 /sbin/ceph-lazy

详细使用说明

列出节点上的所有的OSD

命令:ceph-lazy host-get-osd {hostname}

1
2
3
[root@lab8106 ~]# ceph-lazy host-get-osd lab8106
osd.0
osd.1

列出所有的存储主机节点

命令:ceph-lazy host-get-nodes

1
2
3
[root@lab8106 ~]# ceph-lazy host-get-nodes 
lab8106
lab8107

列出存储节点上的存储使用的情况(detail看详细信息)

命令:ceph-lazy host-osd-usage {hostname} {detail}

1
2
3
4
5
6
[root@lab8106 ceph-lazy]# ceph-lazy  host-osd-usage lab8106
Host:lab8106 | OSDs:2 | Total_Size:556.5GB | Total_Used:13.0GB | Total_Available:543.5GB
[root@lab8106 ceph-lazy]# ceph-lazy host-osd-usage lab8106 detail
OSD:0 | Size:278.3GB | Used:4.6GB | Available:273.6GB
OSD:1 | Size:278.3GB | Used:8.4GB | Available:269.8GB
Host:lab8106 | OSDs:2 | Total_Size:556.5GB | Total_Used:13.0GB | Total_Available:543.5GB

列出所有存储节点上的存储使用的情况(detail看详细信息)

命令:ceph-lazy host-all-usage {detail}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@lab8106 ceph-lazy]# ceph-lazy host-all-usage
----------------------------------------------
Host:lab8106 | OSDs:2 | Total_Size:556.5GB | Total_Used:13.0GB | Total_Available:543.5GB
----------------------------------------------
Host:lab8107 | OSDs:1 | Total_Size:278.3GB | Total_Used:3.8GB | Total_Available:274.4GB

[root@lab8106 ceph-lazy]# ceph-lazy host-all-usage detail
----------------------------------------------
OSD:0 | Size:278.3GB | Used:4.6GB | Available:273.6GB
OSD:1 | Size:278.3GB | Used:8.4GB | Available:269.8GB
Host:lab8106 | OSDs:2 | Total_Size:556.5GB | Total_Used:13.0GB | Total_Available:543.5GB
----------------------------------------------
OSD:2 | Size:278.3GB | Used:3.8GB | Available:274.4GB
Host:lab8107 | OSDs:1 | Total_Size:278.3GB | Total_Used:3.8GB | Total_Available:274.4GB

列出PG所在的节点(first is primary)

命令: ceph-lazy pg-get-host {pg_id}

1
2
3
[root@lab8106 ceph-lazy]# ceph-lazy pg-get-host   10.2
OSD:osd.2 | Host :lab8107
OSD:osd.1 | Host :lab8106

列出写操作最多的PG ( operations number)

命令:ceph-lazy pg-most-write

1
2
[root@lab8106 ceph-lazy]# ceph-lazy pg-most-write
PG:10.3 | OSD:osd.1 | Host:lab8106

列出写操作最少的PG ( operations number)

命令:ceph-lazy pg-less-write

1
2
[root@lab8106 ceph-lazy]# ceph-lazy pg-less-write
PG:11.3 | OSD:osd.1 | Host:lab8106

列出写操作最多的PG (data written)

命令:ceph-lazy pg-most-write-kb

1
2
[root@lab8106 ~]# ceph-lazy pg-most-write-kb
PG:10.0 | OSD:osd.1 | Host:lab8106

####列出写操作最少的PG (data written)
命令:ceph-lazy pg-less-write-kb

1
2
[root@lab8106 ~]# ceph-lazy pg-less-write-kb
PG:11.3 | OSD:osd.1 | Host:lab8106

列出读操作最多的PG (operations number)

命令:ceph-lazy pg-most-read

1
2
[root@lab8106 ~]# ceph-lazy pg-most-read
PG:10.1 | OSD:osd.0 | Host:lab8106

列出读操作最少的PG (operations number)

命令:ceph-lazy pg-less-read

1
2
[root@lab8106 ~]# ceph-lazy pg-less-read
PG:11.3 | OSD:osd.1 | Host:lab8106

列出读操作最多的PG (data read)

命令:ceph-lazy pg-most-read-kb

1
2
[root@lab8106 ~]# ceph-lazy pg-most-read-kb
PG:10.4 | OSD:osd.0 | Host:lab8106

列出读操作最少的PG (data read)

命令:ceph-lazy pg-less-read-kb

1
2
[root@lab8106 ~]# ceph-lazy pg-less-read-kb
PG:11.3 | OSD:osd.1 | Host:lab8106

列出空的PG (没有存储对象)

命令:ceph-lazy pg-empty

1
2
3
4
5
6
7
8
9
[root@lab8106 ~]# ceph-lazy pg-empty
11.3
11.2
11.1
11.0
11.7
11.6
11.5
11.4

列出RBD的prefix

命令:ceph-lazy rbd-prefix {poolname} {imgname}

1
2
[root@lab8106 ~]# ceph-lazy rbd-prefix rbd zp
rbd_data.1b93a6b8b4567

列出RBD的对象数目

命令:ceph-lazy rbd-count {poolname} {imgname}

1
2
3
4
[root@lab8106 ~]# ceph-lazy rbd-count rbd zp

RBD image rbd/zp has prefix rbd_data.1b93a6b8b4567; now couning objects...
count: 27

列出RBD的Primary所在的存储主机

命令:ceph-lazy rbd-host {poolname} {imgname}

1
2
3
[root@lab8106 ~]# ceph-lazy rbd-host rbd zp
Primary Host: lab8107
Primary Host: lab8106

列出RBD的Primary所在的OSD节点

命令:ceph-lazy rbd-osd {poolname} {imgname}

1
2
3
4
[root@lab8106 ~]# ceph-lazy rbd-osd rbd zp
Primary Osd: 0
Primary Osd: 1
Primary Osd: 2

列出RBD的Image的真实大小

命令:ceph-lazy rbd-size rbd zp

1
2
[root@lab8106 ~]# ceph-lazy rbd-size rbd zp
Pool: rbd | Image:zp | Real_size:71.5586 MB

列出容量使用最多的OSD

命令:ceph-lazy osd-most-used

1
2
[root@lab8106 ~]# ceph-lazy osd-most-used
OSD:osd.1 | Host: lab8106 | Used: 8 GB

列出容量使用最少的OSD

命令:ceph-lazy osd-less-used

1
2
[root@lab8106 ~]# ceph-lazy osd-less-used
OSD:osd.2 | Host: lab8107 | Used: 3 GB

列出指定OSD上所有的primary PG

命令: ceph-lazy osd-get-ppg {osd_id}

1
2
3
4
5
6
7
8
9
[root@lab8106 ~]# ceph-lazy osd-get-ppg 1
11.3
10.3
10.0
11.7
10.6
11.6
10.7
11.5

列出指定OSD上的所有PG

命令:ceph-lazy osd-get-pg {osd_id}

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@lab8106 ~]# ceph-lazy osd-get-pg 1
11.3
10.2
10.3
10.0
10.1
11.7
10.6
11.6
10.7
11.5
10.4
10.5

列出指定对象所在的主机(第一个是主)

命令:ceph-lazy object-get-host {poolname} {obj_name}

1
2
3
4
[root@lab8106 ~]# ceph-lazy object-get-host   rbd rbd_data.1b93a6b8b4567.00000000000000a0
Pg: 10.4
OSD:osd.0 | Host :lab8106
OSD:osd.1 | Host :lab8106

总结

本篇只是暂时结束了,目前完成了原作者的一些想法,等有空再写点自己比较注重的数据

最近一直在关注冯大辉的事情,看完后还是原来的感觉,在利益面前,公司总是会追求最大化,当出现分离的时候,总会显得无情,还是自己让自己强大一点,拿到属于自己的那一部分就好

变更记录

Why Who When
创建 武汉-运维-磨渣 2016-08-19