From 74c2b732717ba5150e359a0462973da874f33e9e Mon Sep 17 00:00:00 2001 From: David Zafman Date: Fri, 10 Jan 2020 23:42:19 +0000 Subject: [PATCH] mon mgr osd: Add dump_osd_times interface for python The dump_osd_times interface is here for future use of a manager module. The osd_stats and pg_dump python interfaces don't return network ping information. User facing ping time information is formatted 3 decimal places Use dump_float() (low overhead) for network ping times used by python dump_osd_times and dump commands like "ceph --formet=json pg dump osds" which for now yields output like >>>> "1min": 0.61599999999999999, Signed-off-by: David Zafman --- src/mgr/ActivePyModules.cc | 7 +++++ src/mon/PGMap.cc | 12 ++++++++ src/mon/PGMap.h | 1 + src/osd/osd_types.cc | 47 +++++++++++++++++-------------- src/osd/osd_types.h | 1 + src/pybind/mgr/mgr_module.py | 2 +- src/pybind/mgr/selftest/module.py | 1 + 7 files changed, 49 insertions(+), 22 deletions(-) diff --git a/src/mgr/ActivePyModules.cc b/src/mgr/ActivePyModules.cc index 6546711aa7a0..cf1d5cf90879 100644 --- a/src/mgr/ActivePyModules.cc +++ b/src/mgr/ActivePyModules.cc @@ -394,6 +394,13 @@ PyObject *ActivePyModules::get_python(const std::string &what) pg_map.dump_osd_stats(&f, false); }); return f.get(); + } else if (what == "osd_ping_times") { + cluster_state.with_pgmap( + [&f, &tstate](const PGMap &pg_map) { + PyEval_RestoreThread(tstate); + pg_map.dump_osd_ping_times(&f); + }); + return f.get(); } else if (what == "osd_pool_stats") { int64_t poolid = -ENOENT; cluster_state.with_osdmap_and_pgmap([&](const OSDMap& osdmap, diff --git a/src/mon/PGMap.cc b/src/mon/PGMap.cc index 80b1a2937dda..da59eac8c684 100644 --- a/src/mon/PGMap.cc +++ b/src/mon/PGMap.cc @@ -1609,6 +1609,18 @@ void PGMap::dump_osd_stats(ceph::Formatter *f, bool with_net) const f->close_section(); } +void PGMap::dump_osd_ping_times(ceph::Formatter *f) const +{ + f->open_array_section("osd_ping_times"); + for (auto& [osd, stat] : osd_stat) { + f->open_object_section("osd_ping_time"); + f->dump_int("osd", osd); + stat.dump_ping_time(f); + f->close_section(); + } + f->close_section(); +} + void PGMap::dump_pg_stats_plain( ostream& ss, const mempool::pgmap::unordered_map& pg_stats, diff --git a/src/mon/PGMap.h b/src/mon/PGMap.h index 11ba76136986..e88fdf03af05 100644 --- a/src/mon/PGMap.h +++ b/src/mon/PGMap.h @@ -444,6 +444,7 @@ public: void dump_pg_stats(ceph::Formatter *f, bool brief) const; void dump_pool_stats(ceph::Formatter *f) const; void dump_osd_stats(ceph::Formatter *f, bool with_net = true) const; + void dump_osd_ping_times(ceph::Formatter *f) const; void dump_delta(ceph::Formatter *f) const; void dump_filtered_pg_stats(ceph::Formatter *f, std::set& pgs) const; void dump_pool_stats_full(const OSDMap &osd_map, std::stringstream *ss, diff --git a/src/osd/osd_types.cc b/src/osd/osd_types.cc index 6151450472e0..cc5d91d528f9 100644 --- a/src/osd/osd_types.cc +++ b/src/osd/osd_types.cc @@ -430,6 +430,12 @@ void osd_stat_t::dump(Formatter *f, bool with_net) const ::dump(f, os_alerts); f->close_section(); if (with_net) { + dump_ping_time(f); + } +} + +void osd_stat_t::dump_ping_time(Formatter *f) const +{ f->open_array_section("network_ping_times"); for (auto &i : hb_pingtime) { f->open_object_section("entry"); @@ -443,49 +449,48 @@ void osd_stat_t::dump(Formatter *f, bool with_net) const f->open_object_section("interface"); f->dump_string("interface", "back"); f->open_object_section("average"); - f->dump_format_unquoted("1min", "%s", fixed_u_to_string(i.second.back_pingtime[0],3).c_str()); - f->dump_format_unquoted("5min", "%s", fixed_u_to_string(i.second.back_pingtime[1],3).c_str()); - f->dump_format_unquoted("15min", "%s", fixed_u_to_string(i.second.back_pingtime[2],3).c_str()); + f->dump_float("1min", i.second.back_pingtime[0]/1000.0); + f->dump_float("5min", i.second.back_pingtime[1]/1000.0); + f->dump_float("15min", i.second.back_pingtime[2]/1000.0); f->close_section(); // average f->open_object_section("min"); - f->dump_format_unquoted("1min", "%s", fixed_u_to_string(i.second.back_min[0],3).c_str()); - f->dump_format_unquoted("5min", "%s", fixed_u_to_string(i.second.back_min[1],3).c_str()); - f->dump_format_unquoted("15min", "%s", fixed_u_to_string(i.second.back_min[2],3).c_str()); + f->dump_float("1min", i.second.back_min[0]/1000.0); + f->dump_float("5min", i.second.back_min[1]/1000.0); + f->dump_float("15min", i.second.back_min[2]/1000.0); f->close_section(); // min f->open_object_section("max"); - f->dump_format_unquoted("1min", "%s", fixed_u_to_string(i.second.back_max[0],3).c_str()); - f->dump_format_unquoted("5min", "%s", fixed_u_to_string(i.second.back_max[1],3).c_str()); - f->dump_format_unquoted("15min", "%s", fixed_u_to_string(i.second.back_max[2],3).c_str()); + f->dump_float("1min", i.second.back_max[0]/1000.0); + f->dump_float("5min", i.second.back_max[1]/1000.0); + f->dump_float("15min", i.second.back_max[2]/1000.0); f->close_section(); // max - f->dump_format_unquoted("last", "%s", fixed_u_to_string(i.second.back_last,3).c_str()); + f->dump_float("last", i.second.back_last/1000.0); f->close_section(); // interface if (i.second.front_pingtime[0] != 0) { f->open_object_section("interface"); f->dump_string("interface", "front"); f->open_object_section("average"); - f->dump_format_unquoted("1min", "%s", fixed_u_to_string(i.second.front_pingtime[0],3).c_str()); - f->dump_format_unquoted("5min", "%s", fixed_u_to_string(i.second.front_pingtime[1],3).c_str()); - f->dump_format_unquoted("15min", "%s", fixed_u_to_string(i.second.front_pingtime[2],3).c_str()); + f->dump_float("1min", i.second.front_pingtime[0]/1000.0); + f->dump_float("5min", i.second.front_pingtime[1]/1000.0); + f->dump_float("15min", i.second.front_pingtime[2]/1000.0); f->close_section(); // average f->open_object_section("min"); - f->dump_format_unquoted("1min", "%s", fixed_u_to_string(i.second.front_min[0],3).c_str()); - f->dump_format_unquoted("5min", "%s", fixed_u_to_string(i.second.front_min[1],3).c_str()); - f->dump_format_unquoted("15min", "%s", fixed_u_to_string(i.second.front_min[2],3).c_str()); + f->dump_float("1min", i.second.front_min[0]/1000.0); + f->dump_float("5min", i.second.front_min[1]/1000.0); + f->dump_float("15min", i.second.front_min[2]/1000.0); f->close_section(); // min f->open_object_section("max"); - f->dump_format_unquoted("1min", "%s", fixed_u_to_string(i.second.front_max[0],3).c_str()); - f->dump_format_unquoted("5min", "%s", fixed_u_to_string(i.second.front_max[1],3).c_str()); - f->dump_format_unquoted("15min", "%s", fixed_u_to_string(i.second.front_max[2],3).c_str()); + f->dump_float("1min", i.second.front_max[0]/1000.0); + f->dump_float("5min", i.second.front_max[1]/1000.0); + f->dump_float("15min", i.second.front_max[2]/1000.0); f->close_section(); // max - f->dump_format_unquoted("last", "%s", fixed_u_to_string(i.second.front_last,3).c_str()); + f->dump_float("last", i.second.front_last/1000.0); f->close_section(); // interface } f->close_section(); // interfaces f->close_section(); // entry } f->close_section(); // network_ping_time - } } void osd_stat_t::encode(ceph::buffer::list &bl, uint64_t features) const diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index 3102bcb8903c..eec67724f24a 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -2417,6 +2417,7 @@ struct osd_stat_t { } } void dump(ceph::Formatter *f, bool with_net = true) const; + void dump_ping_time(ceph::Formatter *f) const; void encode(ceph::buffer::list &bl, uint64_t features) const; void decode(ceph::buffer::list::const_iterator &bl); static void generate_test_instances(std::list& o); diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 63e4353517bc..c9a6ae0f62bb 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -796,7 +796,7 @@ class MgrModule(ceph_module.BaseMgrModule, MgrModuleLoggingMixin): osd_map, osd_map_tree, osd_map_crush, config, mon_map, fs_map, osd_metadata, pg_summary, io_rate, pg_dump, df, osd_stats, health, mon_status, devices, device , pg_stats, - pool_stats, pg_ready. + pool_stats, pg_ready, osd_ping_times. Note: All these structures have their own JSON representations: experiment diff --git a/src/pybind/mgr/selftest/module.py b/src/pybind/mgr/selftest/module.py index d9c38ac1df08..136984bc76ad 100644 --- a/src/pybind/mgr/selftest/module.py +++ b/src/pybind/mgr/selftest/module.py @@ -242,6 +242,7 @@ class Module(MgrModule): "pg_stats", "pool_stats", "osd_stats", + "osd_ping_times", "health", "mon_status", "mgr_map" -- 2.47.3