From: Jason Dillaman Date: Tue, 30 Oct 2018 14:21:17 +0000 (-0400) Subject: rbd: added new 'pool stats' action X-Git-Tag: v14.1.0~944^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=1a14963aeb67e82e1b87f622b1d0b46cafbb5a76;p=ceph-ci.git rbd: added new 'pool stats' action This provides a quick summary of provisioned pool usage. Signed-off-by: Jason Dillaman --- diff --git a/src/test/cli/rbd/help.t b/src/test/cli/rbd/help.t index 1b9e4d0fee1..84e0fbdacd8 100644 --- a/src/test/cli/rbd/help.t +++ b/src/test/cli/rbd/help.t @@ -107,6 +107,7 @@ object-map check Verify the object map is correct. object-map rebuild Rebuild an invalid object map. pool init Initialize pool for use by RBD. + pool stats Display pool statistics. remove (rm) Delete an image. rename (mv) Rename image within pool. resize Resize (expand or shrink) image. @@ -1837,6 +1838,23 @@ --force force initialize pool for RBD use if registered by another application + rbd help pool stats + usage: rbd pool stats [--pool ] [--namespace ] + [--format ] [--pretty-format] + + + Display pool statistics. + + Positional arguments + pool name + + Optional arguments + -p [ --pool ] arg pool name + --namespace arg namespace name + --format arg output format (plain, json, or xml) [default: plain] + --pretty-format pretty formatting (json and xml) + + Note: legacy v1 images are not included in stats rbd help remove usage: rbd remove [--pool ] [--namespace ] [--image ] [--no-progress] diff --git a/src/tools/rbd/action/Pool.cc b/src/tools/rbd/action/Pool.cc index 52080a4ba8c..0445ee39032 100644 --- a/src/tools/rbd/action/Pool.cc +++ b/src/tools/rbd/action/Pool.cc @@ -6,7 +6,7 @@ #include "tools/rbd/Utils.h" #include "include/stringify.h" #include "common/errno.h" -#include "osd/osd_types.h" +#include "common/Formatter.h" #include #include @@ -37,8 +37,8 @@ int execute_init(const po::variables_map &vm, return r; } - r = io_ctx.application_enable(pg_pool_t::APPLICATION_NAME_RBD, - vm["force"].as()); + librbd::RBD rbd; + r = rbd.pool_init(io_ctx, vm["force"].as()); if (r == -EOPNOTSUPP) { std::cerr << "rbd: luminous or later release required." << std::endl; } else if (r == -EPERM) { @@ -52,9 +52,101 @@ int execute_init(const po::variables_map &vm, return 0; } -Shell::Action action( +void get_arguments_stats(po::options_description *positional, + po::options_description *options) { + at::add_pool_options(positional, options); + at::add_namespace_option(options, at::ARGUMENT_MODIFIER_NONE); + at::add_format_options(options); +} + +int execute_stats(const po::variables_map &vm, + const std::vector &ceph_global_init_args) { + size_t arg_index = 0; + std::string pool_name = utils::get_pool_name(vm, &arg_index); + std::string namespace_name = utils::get_namespace_name(vm, &arg_index); + + at::Format::Formatter formatter; + int r = utils::get_formatter(vm, &formatter); + if (r < 0) { + return r; + } + + librados::Rados rados; + librados::IoCtx io_ctx; + r = utils::init(pool_name, namespace_name, &rados, &io_ctx); + if (r < 0) { + return r; + } + + librbd::RBD rbd; + uint64_t image_count; + uint64_t provisioned_bytes; + uint64_t snap_count; + uint64_t trash_count; + uint64_t trash_provisioned_bytes; + uint64_t trash_snap_count; + + librbd::PoolStats pool_stats; + pool_stats.add(RBD_POOL_STAT_OPTION_IMAGES, &image_count); + pool_stats.add(RBD_POOL_STAT_OPTION_IMAGE_MAX_PROVISIONED_BYTES, + &provisioned_bytes); + pool_stats.add(RBD_POOL_STAT_OPTION_IMAGE_SNAPSHOTS, &snap_count); + pool_stats.add(RBD_POOL_STAT_OPTION_TRASH_IMAGES, &trash_count); + pool_stats.add(RBD_POOL_STAT_OPTION_TRASH_MAX_PROVISIONED_BYTES, + &trash_provisioned_bytes); + pool_stats.add(RBD_POOL_STAT_OPTION_TRASH_SNAPSHOTS, &trash_snap_count); + + r = rbd.pool_stats_get(io_ctx, &pool_stats); + if (r < 0) { + std::cerr << "rbd: failed to query pool stats: " << cpp_strerror(r) + << std::endl; + return r; + } + + if (formatter) { + formatter->open_object_section("stats"); + formatter->open_object_section("images"); + formatter->dump_unsigned("count", image_count); + formatter->dump_unsigned("provisioned_bytes", provisioned_bytes); + formatter->dump_unsigned("snap_count", snap_count); + formatter->close_section(); + formatter->open_object_section("trash"); + formatter->dump_unsigned("count", trash_count); + formatter->dump_unsigned("provisioned_bytes", trash_provisioned_bytes); + formatter->dump_unsigned("snap_count", trash_snap_count); + formatter->close_section(); + formatter->close_section(); + formatter->flush(std::cout); + } else { + std::cout << "Total Images: " << image_count; + if (trash_count > 0) { + std::cout << " (" << trash_count << " in trash)"; + } + std::cout << std::endl; + + std::cout << "Total Snapshots: " << snap_count; + if (trash_count > 0) { + std::cout << " (" << trash_snap_count << " in trash)"; + } + std::cout << std::endl; + + std::cout << "Provisioned Size: " << byte_u_t(provisioned_bytes); + if (trash_count > 0) { + std::cout << " (" << byte_u_t(trash_provisioned_bytes) << " in trash)"; + } + std::cout << std::endl; + } + + return 0; +} + +Shell::Action init_action( {"pool", "init"}, {}, "Initialize pool for use by RBD.", "", - &get_arguments_init, &execute_init); + &get_arguments_init, &execute_init); +Shell::Action stat_action( + {"pool", "stats"}, {}, "Display pool statistics.", + "Note: legacy v1 images are not included in stats", + &get_arguments_stats, &execute_stats); } // namespace pool } // namespace action