ceph -s分析

1. 源碼跟蹤

1.1 get_cluster_status

https://github.com/ceph/ceph/blob/2a724a2ff313701fd7f6278ce8ed7f440bb355e0/src/mon/Monitor.cc

ceph -s 會執(zhí)行g(shù)et_cluster_status函數(shù), 在函數(shù)的最后會調(diào)用打印
mgrstatmon()->print_summary函數(shù)

void Monitor::get_cluster_status(stringstream &ss, Formatter *f)
{
  if (f)
    f->open_object_section("status");
  if (f) {
    f->dump_stream("fsid") << monmap->get_fsid();
    get_health_status(false, f, nullptr);
    f->dump_unsigned("election_epoch", get_epoch());
    {
      f->open_array_section("quorum");
      for (set<int>::iterator p = quorum.begin(); p != quorum.end(); ++p)
    f->dump_int("rank", *p);
      f->close_section();
      f->open_array_section("quorum_names");
      for (set<int>::iterator p = quorum.begin(); p != quorum.end(); ++p)
    f->dump_string("id", monmap->get_name(*p));
      f->close_section();
    }
    f->open_object_section("monmap");
    monmap->dump(f);
    f->close_section();
    f->open_object_section("osdmap");
    osdmon()->osdmap.print_summary(f, cout, string(12, ' '));
    f->close_section();
    f->open_object_section("pgmap");
    mgrstatmon()->print_summary(f, NULL);
    f->close_section();
    f->open_object_section("fsmap");
    mdsmon()->get_fsmap().print_summary(f, NULL);
    f->close_section();
    f->open_object_section("mgrmap");
    mgrmon()->get_map().print_summary(f, nullptr);
    f->close_section();
    f->dump_object("servicemap", mgrstatmon()->get_service_map());
    f->close_section();
  } else {
    ss << "  cluster:\n";
    ss << "    id:     " << monmap->get_fsid() << "\n";
    string health;
    get_health_status(false, nullptr, &health,
              "\n            ", "\n            ");
    ss << "    health: " << health << "\n";
    ss << "\n \n  services:\n";
    {
      size_t maxlen = 3;
      auto& service_map = mgrstatmon()->get_service_map();
      for (auto& p : service_map.services) {
    maxlen = std::max(maxlen, p.first.size());
      }
      string spacing(maxlen - 3, ' ');
      const auto quorum_names = get_quorum_names();
      const auto mon_count = monmap->mon_info.size();
      ss << "    mon: " << spacing << mon_count << " daemons, quorum "
     << quorum_names;
      if (quorum_names.size() != mon_count) {
    std::list<std::string> out_of_q;
    for (size_t i = 0; i < monmap->ranks.size(); ++i) {
      if (quorum.count(i) == 0) {
        out_of_q.push_back(monmap->ranks[i]);
      }
    }
    ss << ", out of quorum: " << joinify(out_of_q.begin(),
                         out_of_q.end(), std::string(", "));
      }
      ss << "\n";
      if (mgrmon()->in_use()) {
    ss << "    mgr: " << spacing;
    mgrmon()->get_map().print_summary(nullptr, &ss);
    ss << "\n";
      }
      if (mdsmon()->get_fsmap().filesystem_count() > 0) {
    ss << "    mds: " << spacing << mdsmon()->get_fsmap() << "\n";
      }
      ss << "    osd: " << spacing;
      osdmon()->osdmap.print_summary(NULL, ss, string(maxlen + 6, ' '));
      ss << "\n";
      for (auto& p : service_map.services) {
    ss << "    " << p.first << ": " << string(maxlen - p.first.size(), ' ')
       << p.second.get_summary() << "\n";
      }
    }
    ss << "\n \n  data:\n";
    mgrstatmon()->print_summary(NULL, &ss);
    ss << "\n ";
  }
}

1.2 mgrstatmon()->print_summary()

https://github.com/ceph/ceph/blob/6c9d937828910664032fd58959a2ae8dd8678588/src/mon/PGMap.cc
print_summary函數(shù)進(jìn)行計(jì)算泼舱,統(tǒng)計(jì)相關(guān)指標(biāo)

void PGMapDigest::print_summary(Formatter *f, ostream *out) const
{
  if (f)
    f->open_array_section("pgs_by_state");
  // list is descending numeric order (by count)
  multimap<int,int> state_by_count;  // count -> state
  for (auto p = num_pg_by_state.begin();
       p != num_pg_by_state.end();
       ++p) {
    state_by_count.insert(make_pair(p->second, p->first));
  }
  if (f) {
    for (auto p = state_by_count.rbegin();
         p != state_by_count.rend();
         ++p)
    {
      f->open_object_section("pgs_by_state_element");
      f->dump_string("state_name", pg_state_string(p->second));
      f->dump_unsigned("count", p->first);
      f->close_section();
    }
  }
  if (f)
    f->close_section();
  if (f) {
    f->dump_unsigned("num_pgs", num_pg);
    f->dump_unsigned("num_pools", pg_pool_sum.size());
    f->dump_unsigned("num_objects", pg_sum.stats.sum.num_objects);
    f->dump_unsigned("data_bytes", pg_sum.stats.sum.num_bytes);
    f->dump_unsigned("bytes_used", osd_sum.kb_used * 1024ull);
    f->dump_unsigned("bytes_avail", osd_sum.kb_avail * 1024ull);
    f->dump_unsigned("bytes_total", osd_sum.kb * 1024ull);
  } else {
    *out << "    pools:   " << pg_pool_sum.size() << " pools, "
         << num_pg << " pgs\n";
    *out << "    objects: " << si_u_t(pg_sum.stats.sum.num_objects) << " objects, "
         << byte_u_t(pg_sum.stats.sum.num_bytes) << "\n";
    *out << "    usage:   "
         << byte_u_t(osd_sum.kb_used << 10) << " used, "
         << byte_u_t(osd_sum.kb_avail << 10) << " / "
         << byte_u_t(osd_sum.kb << 10) << " avail\n";
    *out << "    pgs:     ";
  }
  bool pad = false;
  if (num_pg_unknown > 0) {
    float p = (float)num_pg_unknown / (float)num_pg;
    if (f) {
      f->dump_float("unknown_pgs_ratio", p);
    } else {
      char b[20];
      snprintf(b, sizeof(b), "%.3lf", p * 100.0);
      *out << b << "% pgs unknown\n";
      pad = true;
    }
  }
  int num_pg_inactive = num_pg - num_pg_active - num_pg_unknown;
  if (num_pg_inactive > 0) {
    float p = (float)num_pg_inactive / (float)num_pg;
    if (f) {
      f->dump_float("inactive_pgs_ratio", p);
    } else {
      if (pad) {
        *out << "             ";
      }
      char b[20];
      snprintf(b, sizeof(b), "%.3f", p * 100.0);
      *out << b << "% pgs not active\n";
      pad = true;
    }
  }
  list<string> sl;
  overall_recovery_summary(f, &sl);
  if (!f && !sl.empty()) {
    for (auto p = sl.begin(); p != sl.end(); ++p) {
      if (pad) {
        *out << "             ";
      }
      *out << *p << "\n";
      pad = true;
    }
  }
  sl.clear();
  if (!f) {
    unsigned max_width = 1;
    for (multimap<int,int>::reverse_iterator p = state_by_count.rbegin();
         p != state_by_count.rend();
         ++p)
    {
      std::stringstream ss;
      ss << p->first;
      max_width = std::max<size_t>(ss.str().size(), max_width);
    }
    for (multimap<int,int>::reverse_iterator p = state_by_count.rbegin();
         p != state_by_count.rend();
         ++p)
    {
      if (pad) {
        *out << "             ";
      }
      pad = true;
      out->setf(std::ios::left);
      *out << std::setw(max_width) << p->first
           << " " << pg_state_string(p->second) << "\n";
      out->unsetf(std::ios::left);
    }
  }
  ostringstream ss_rec_io;
  overall_recovery_rate_summary(f, &ss_rec_io);
  ostringstream ss_client_io;
  overall_client_io_rate_summary(f, &ss_client_io);
  ostringstream ss_cache_io;
  overall_cache_io_rate_summary(f, &ss_cache_io);
  if (!f && (ss_client_io.str().length() || ss_rec_io.str().length()
             || ss_cache_io.str().length())) {
    *out << "\n \n";
    *out << "  io:\n";
  }
  if (!f && ss_client_io.str().length())
    *out << "    client:   " << ss_client_io.str() << "\n";
  if (!f && ss_rec_io.str().length())
    *out << "    recovery: " << ss_rec_io.str() << "\n";
  if (!f && ss_cache_io.str().length())
    *out << "    cache:    " << ss_cache_io.str() << "\n";
}

1.3 ss_client_io

void PGMapDigest::overall_client_io_rate_summary(Formatter *f, ostream *out) const
{
  client_io_rate_summary(f, out, pg_sum_delta, stamp_delta);
}
void PGMapDigest::pool_client_io_rate_summary(Formatter *f, ostream *out,
                                        uint64_t poolid) const
{
  auto p = per_pool_sum_delta.find(poolid);
  if (p == per_pool_sum_delta.end())
    return;
  auto ts = per_pool_sum_deltas_stamps.find(p->first);
  assert(ts != per_pool_sum_deltas_stamps.end());
  client_io_rate_summary(f, out, p->second.first, ts->second);
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末篷朵,一起剝皮案震驚了整個濱河市撒蟀,隨后出現(xiàn)的幾起案子腌巾,更是在濱河造成了極大的恐慌泡态,老刑警劉巖选泻,帶你破解...
    沈念sama閱讀 216,591評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件苇本,死亡現(xiàn)場離奇詭異,居然都是意外死亡摧冀,警方通過查閱死者的電腦和手機(jī)倍踪,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,448評論 3 392
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來索昂,“玉大人建车,你說我怎么就攤上這事〗凡遥” “怎么了缤至?”我有些...
    開封第一講書人閱讀 162,823評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長康谆。 經(jīng)常有香客問我领斥,道長,這世上最難降的妖魔是什么沃暗? 我笑而不...
    開封第一講書人閱讀 58,204評論 1 292
  • 正文 為了忘掉前任月洛,我火速辦了婚禮,結(jié)果婚禮上孽锥,老公的妹妹穿的比我還像新娘嚼黔。我一直安慰自己,他們只是感情好惜辑,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,228評論 6 388
  • 文/花漫 我一把揭開白布唬涧。 她就那樣靜靜地躺著,像睡著了一般盛撑。 火紅的嫁衣襯著肌膚如雪碎节。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,190評論 1 299
  • 那天撵彻,我揣著相機(jī)與錄音钓株,去河邊找鬼。 笑死陌僵,一個胖子當(dāng)著我的面吹牛轴合,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播碗短,決...
    沈念sama閱讀 40,078評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼受葛,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了偎谁?” 一聲冷哼從身側(cè)響起总滩,我...
    開封第一講書人閱讀 38,923評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎巡雨,沒想到半個月后闰渔,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,334評論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡铐望,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,550評論 2 333
  • 正文 我和宋清朗相戀三年冈涧,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片正蛙。...
    茶點(diǎn)故事閱讀 39,727評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡督弓,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出乒验,到底是詐尸還是另有隱情愚隧,我是刑警寧澤,帶...
    沈念sama閱讀 35,428評論 5 343
  • 正文 年R本政府宣布锻全,位于F島的核電站狂塘,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏鳄厌。R本人自食惡果不足惜睹耐,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,022評論 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望部翘。 院中可真熱鬧硝训,春花似錦、人聲如沸新思。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,672評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽夹囚。三九已至纵刘,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間荸哟,已是汗流浹背假哎。 一陣腳步聲響...
    開封第一講書人閱讀 32,826評論 1 269
  • 我被黑心中介騙來泰國打工瞬捕, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人舵抹。 一個月前我還...
    沈念sama閱讀 47,734評論 2 368
  • 正文 我出身青樓肪虎,卻偏偏與公主長得像,于是被迫代替她去往敵國和親惧蛹。 傳聞我的和親對象是個殘疾皇子扇救,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,619評論 2 354

推薦閱讀更多精彩內(nèi)容