pg与osd的对应关系查找

利用pg在pool以及osd的分布关系可以更好的分析pg的分布是否均匀

 pool:      0    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17| SUM 
------------------------------------------------------------------------------------------------------- 
osd.0      29    9   13   12   10   14    9   14    7   13   10    9   11   18  355  329  305   49| 1216 
osd.1      25   11    6   11   16   10    7    7   13   11    9    8   15   14  316  369  339   40| 1227 
osd.2      23   10   12   10   16   13    8   11   14   10   10   11   14   23  344  339  340   37| 1245 
osd.3      22    8    8   10   10    9    9   12   12    9   12    9    8   21  325  337  361   40| 1222 
osd.4      13   15   11   10   12    9   14    6   13   10   10   14   13   25  344  358  358   39| 1274 
osd.5      13    9   11    9    8   12   15   13   10   15    9   12    7   24  339  327  355   46| 1234 
osd.6      25   13   10   10   11    7    8   10    8    8   13    6    9   23  322  337  349   46| 1215 
osd.7      16    9   10   12    5   12   16   11   10   14    9   15    9   18  358  348  335   45| 1252 
osd.8      26   12   15   12    8   10   10   12    9    6   14   12   10   26  369  328  330   42| 1251 
------------------------------------------------------------------------------------------------------- 
SUM:      192   96   96   96   96   96   96   96   96   96   96   96   96  192 3072 3072 3072  384 
MAX:       29   15   15   12   16   14   16   14   14   15   14   15   15   26  369  369  361   49 
MAX osd:   .0   .4   .8   .0   .1   .0   .7   .0   .2   .5   .8   .7   .1   .8   .8   .1   .3   .0 
osd Sum:    9    9    9    9    9    9    9    9    9    9    9    9    9    9    9    9    9    9 
MIN osd:   .5   .3   .1   .5   .7   .6   .1   .4   .0   .8   .1   .6   .5   .1   .1   .5   .0   .2 

首先获取pg的query数据。利用Ansible模块获取数据。数据如下:

    "ceph_facts": {
        "update_pg_state": {
            "osds": {
                "0": {
                    "0": {
                        "pgsize": 29
                    }, 
                    "1": {
                        "pgsize": 9
                    }, 
                    "10": {
                        "pgsize": 10
                    }, 
                    "11": {
                        "pgsize": 9
...
                    "pgsum": 96
                }
            }
        }
    }

利用python分析该数据:

def ceph_pg_parser(stat_dic):
    _str = ""
    pg_stat = stat_dic.get('ceph_facts')
    pool_pgs = pg_stat.get('update_pg_state',[]).get('pools',[])
    osd_pgs = pg_stat.get('update_pg_state',[]).get('osds',[])
    if len(pool_pgs) < 0 and len(osd_pgs) < 0: return
    _str += "pool%-3s" % ":"
    for pg in sorted(pool_pgs,key=int):
       _str += "%5s" %  pg
    _str += "|%5s" % "SUM\n"
    _str += "--------" + "-----" * len(pool_pgs) + "-----\n"
    for osdid in sorted(osd_pgs,key=int):
       _str += "osd.%-4s" % osdid
       for pg in sorted(pool_pgs,key=int):
          if pool_pgs[pg].has_key(osdid):
             _str += "%5s" % pool_pgs[pg][osdid]['pgsize']
          else:
             _str += "%5s" % 0
       _str += "|%5s\n" % osd_pgs[osdid]['pgsum']
    _str += "--------" + "-----" * len(pool_pgs) + "-----\n"
    _str += "SUM:    "
    for pg in sorted(pool_pgs,key=int):
      _str += "%5s" % pool_pgs[pg]['pgsum']
    _str += "\n"
    _str += "MAX:    "
    for pg in sorted(pool_pgs,key=int):
      _str += "%5s" % pool_pgs[pg]['max']
    _str += "\n"
    _str += "MAX osd:"
    for pg in sorted(pool_pgs,key=int):
      _str += "%5s" % ("." + str(pool_pgs[pg]['max_osd_id']))
    _str += "\n"
    _str += "OSD Sum:"
    for pg in sorted(pool_pgs,key=int):
      _str += "%5d" % (len(pool_pgs[pg])-int(5))
    _str += "\n"
    _str += "MIN osd:"
    for pg in sorted(pool_pgs,key=int):
      _str += "%5s" % ("." + str(pool_pgs[pg]['min_osd_id']))
    _str += "\n"
    return _str

发表评论

您的电子邮箱地址不会被公开。