From: xinxin shu Date: Thu, 29 Jan 2015 23:15:04 +0000 (+0800) Subject: add CLI ceph pg ls [pool] [state] X-Git-Tag: v0.93~65^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a1f634b52fe2c94d4efa67feaf96008a488045f2;p=ceph.git add CLI ceph pg ls [pool] [state] Signed-off-by: xinxin shu --- diff --git a/src/mon/MonCommands.h b/src/mon/MonCommands.h index a915d56c3983..9bbd1fb374c5 100644 --- a/src/mon/MonCommands.h +++ b/src/mon/MonCommands.h @@ -127,6 +127,10 @@ COMMAND("pg dump_stuck " \ "name=threshold,type=CephInt,req=false", "show information about stuck pgs",\ "pg", "r", "cli,rest") +COMMAND("pg ls " \ + "name=pool,type=CephInt,req=false " \ + "name=states,type=CephChoices,strings=active|clean|down|replay|splitting|scrubbing|scrubq|degraded|inconsistent|peering|repair|recovery|backfill_wait|incomplete|stale|remapped|deep_scrub|backfill|backfill_toofull|recovery_wait|undersized,n=N,req=false ", \ + "list pg with specific pool, osd, state", "pg", "r", "cli,rest") COMMAND("pg map name=pgid,type=CephPgid", "show mapping of pg to osds", \ "pg", "r", "cli,rest") COMMAND("pg scrub name=pgid,type=CephPgid", "start scrub on ", \ diff --git a/src/mon/PGMap.cc b/src/mon/PGMap.cc index d8c674a3c769..72dbf2623641 100644 --- a/src/mon/PGMap.cc +++ b/src/mon/PGMap.cc @@ -1450,3 +1450,45 @@ void PGMap::get_filtered_pg_stats(string& state, int64_t poolid, int64_t osdid, pgs.insert(i->first); } } + +void PGMap::dump_filtered_pg_stats(Formatter *f, set& pgs) +{ + f->open_array_section("pg_stats"); + for (set::iterator i = pgs.begin(); i != pgs.end(); i++) { + pg_stat_t& st = pg_stat[*i]; + f->open_object_section("pg_stat"); + f->dump_stream("pgid") << *i; + st.dump(f); + f->close_section(); + } + f->close_section(); +} +void PGMap::dump_filtered_pg_stats(ostream& ss, set& pgs) +{ + ss << "pg_stat\tobjects\tmip\tdegr\tmisp\tunf\tbytes\tlog\tdisklog\tstate\t" + "state_stamp\tv\treported\tup\tup_primary\tacting\tacting_primary\t" + "last_scrub\tscrub_stamp\tlast_deep_scrub\tdeep_scrub_stamp" << std::endl; + for (set::iterator i = pgs.begin(); i != pgs.end(); i++) { + pg_stat_t& st = pg_stat[*i]; + ss << *i + << "\t" << st.stats.sum.num_objects + << "\t" << st.stats.sum.num_objects_missing_on_primary + << "\t" << st.stats.sum.num_objects_degraded + << "\t" << st.stats.sum.num_objects_misplaced + << "\t" << st.stats.sum.num_objects_unfound + << "\t" << st.stats.sum.num_bytes + << "\t" << st.log_size + << "\t" << st.ondisk_log_size + << "\t" << pg_state_string(st.state) + << "\t" << st.last_change + << "\t" << st.version + << "\t" << st.reported_epoch << ":" << st.reported_seq + << "\t" << st.up + << "\t" << st.up_primary + << "\t" << st.acting + << "\t" << st.acting_primary + << "\t" << st.last_scrub << "\t" << st.last_scrub_stamp + << "\t" << st.last_deep_scrub << "\t" << st.last_deep_scrub_stamp + << std::endl; + } +} diff --git a/src/mon/PGMap.h b/src/mon/PGMap.h index c2f1533ad2f1..1e862258e7f8 100644 --- a/src/mon/PGMap.h +++ b/src/mon/PGMap.h @@ -267,6 +267,7 @@ public: void dump_pool_stats(Formatter *f) const; void dump_osd_stats(Formatter *f) const; void dump_delta(Formatter *f) const; + void dump_filtered_pg_stats(Formatter *f, set& pgs); void dump_pg_stats_plain(ostream& ss, const ceph::unordered_map& pg_stats, @@ -283,6 +284,7 @@ public: void dump_pool_stats(ostream& ss, bool header) const; void dump_osd_stats(ostream& ss) const; void dump_osd_sum_stats(ostream& ss) const; + void dump_filtered_pg_stats(ostream& ss, set& pgs); void dump_osd_perf_stats(Formatter *f) const; void print_osd_perf_stats(std::ostream *ss) const; diff --git a/src/mon/PGMonitor.cc b/src/mon/PGMonitor.cc index 8c7e941100a8..963174c6eae8 100644 --- a/src/mon/PGMonitor.cc +++ b/src/mon/PGMonitor.cc @@ -1591,6 +1591,41 @@ bool PGMonitor::preprocess_command(MMonCommand *m) } ss << "dumped " << what << " in format " << format; r = 0; + } else if (prefix == "pg ls") { + int64_t osd = -1; + int64_t pool = -1; + vectorstates; + set pgs; + set what; + cmd_getval(g_ceph_context, cmdmap, "pool", pool); + cmd_getval(g_ceph_context, cmdmap, "osd", osd); + cmd_getval(g_ceph_context, cmdmap, "states", states); + if (pool >= 0 && !mon->osdmon()->osdmap.have_pg_pool(pool)) { + r = -ENOENT; + ss << "pool " << pool << " does not exist"; + goto reply; + } + if (osd >= 0 && !mon->osdmon()->osdmap.is_up(osd)) { + ss << "osd " << osd << " is not up"; + r = -EAGAIN; + goto reply; + } + if (states.empty()) + states.push_back("all"); + while (!states.empty()) { + string state = states.back(); + what.insert(state); + pg_map.get_filtered_pg_stats(state,pool,osd,false,pgs); + states.pop_back(); + } + if (f && !pgs.empty()){ + pg_map.dump_filtered_pg_stats(f.get(),pgs); + f->flush(ds); + } else if (!pgs.empty()){ + pg_map.dump_filtered_pg_stats(ds,pgs); + } + ss << "list states " << what << " pool " << pool << " osd osd." << osd; + r = 0; } else if (prefix == "pg dump_stuck") { vector stuckop_vec; cmd_getval(g_ceph_context, cmdmap, "stuckops", stuckop_vec);