]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: rgw-admin filter usage by categories
authorYehuda Sadeh <yehuda@inktank.com>
Thu, 6 Sep 2012 23:46:26 +0000 (16:46 -0700)
committerYehuda Sadeh <yehuda@inktank.com>
Thu, 6 Sep 2012 23:46:26 +0000 (16:46 -0700)
rgw can now filter usage output by specific op
categories.

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/cls/rgw/cls_rgw_types.h
src/rgw/rgw_admin.cc
src/test/cli/radosgw-admin/help.t

index b6a8f399c7384283f4f82ac70b2f5d22f70421d8..5dbc6168ad5a75f64ff94a416736258326e6c237 100644 (file)
@@ -272,7 +272,7 @@ struct rgw_usage_log_entry {
     DECODE_FINISH(bl);
   }
 
-  void aggregate(const rgw_usage_log_entry& e) {
+  void aggregate(const rgw_usage_log_entry& e, map<string, bool> *categories = NULL) {
     if (owner.empty()) {
       owner = e.owner;
       bucket = e.bucket;
@@ -280,7 +280,18 @@ struct rgw_usage_log_entry {
     }
     map<string, rgw_usage_data>::const_iterator iter;
     for (iter = e.usage_map.begin(); iter != e.usage_map.end(); ++iter) {
-      add(iter->first, iter->second);
+      if (!categories || !categories->size() || categories->count(iter->first)) {
+        add(iter->first, iter->second);
+      }
+    }
+  }
+
+  void sum(rgw_usage_data& usage, map<string, bool>& categories) const {
+    usage = rgw_usage_data();
+    for (map<string, rgw_usage_data>::const_iterator iter = usage_map.begin(); iter != usage_map.end(); ++iter) {
+      if (!categories.size() || categories.count(iter->first)) {
+        usage.aggregate(iter->second);
+      }
     }
   }
 
index 062ffade8681f1801a02e8765646fecf12ac6799..fcbeed78f46839424072cb97f476461600ad9484 100644 (file)
@@ -12,6 +12,7 @@ using namespace std;
 #include "global/global_init.h"
 #include "common/errno.h"
 #include "include/utime.h"
+#include "include/str_list.h"
 
 #include "common/armor.h"
 #include "rgw_user.h"
@@ -94,6 +95,7 @@ void _usage()
   cerr << "   --show-log-sum=<flag>     enable/disable dump of log summation on log show\n";
   cerr << "   --skip-zero-entries       log show only dumps entries that don't have zero value\n";
   cerr << "                             in one of the numeric field\n";
+  cerr << "   --categories=<list>       comma separated list of categories, used in usage show\n";
   cerr << "   --yes-i-really-mean-it    required for certain operations\n";
   cerr << "\n";
   cerr << "<date> := \"YYYY-MM-DD[ hh:mm:ss]\"\n";
@@ -646,11 +648,13 @@ static int remove_bucket(rgw_bucket& bucket, bool delete_children)
   return ret;
 }
 
-void dump_usage_categories_info(Formatter *formatter, const rgw_usage_log_entry& entry)
+void dump_usage_categories_info(Formatter *formatter, const rgw_usage_log_entry& entry, map<string, bool>& categories)
 {
   formatter->open_array_section("categories");
   map<string, rgw_usage_data>::const_iterator uiter;
   for (uiter = entry.usage_map.begin(); uiter != entry.usage_map.end(); ++uiter) {
+    if (categories.size() && !categories.count(uiter->first))
+      continue;
     const rgw_usage_data& usage = uiter->second;
     formatter->open_object_section("entry");
     formatter->dump_string("category", uiter->first);
@@ -705,6 +709,7 @@ int main(int argc, char **argv)
   int yes_i_really_mean_it = false;
   int delete_child_objects = false;
   int max_buckets = -1;
+  map<string, bool> categories;
 
   std::string val;
   std::ostringstream errs;
@@ -781,6 +786,14 @@ int main(int argc, char **argv)
       }
     } else if (ceph_argparse_witharg(args, i, &val, "--format", (char*)NULL)) {
       format = val;
+    } else if (ceph_argparse_witharg(args, i, &val, "--categories", (char*)NULL)) {
+      string cat_str = val;
+      list<string> cat_list;
+      list<string>::iterator iter;
+      get_str_list(cat_str, cat_list);
+      for (iter = cat_list.begin(); iter != cat_list.end(); ++iter) {
+       categories[*iter] = true;
+      }
     } else if (ceph_argparse_binary_flag(args, i, &delete_child_objects, NULL, "--purge-objects", (char*)NULL)) {
       // do nothing
     } else if (ceph_argparse_binary_flag(args, i, &pretty_format, NULL, "--pretty-format", (char*)NULL)) {
@@ -1591,12 +1604,12 @@ next:
           utime_t ut(entry.epoch, 0);
           ut.gmtime(formatter->dump_stream("time"));
           formatter->dump_int("epoch", entry.epoch);
-         dump_usage_categories_info(formatter, entry);
+         dump_usage_categories_info(formatter, entry, categories);
           formatter->close_section(); // bucket
           formatter->flush(cout);
         }
 
-        summary_map[ub.user].aggregate(entry);
+        summary_map[ub.user].aggregate(entry, &categories);
       }
     }
     if (show_log_entries) {
@@ -1614,8 +1627,18 @@ next:
         const rgw_usage_log_entry& entry = siter->second;
         formatter->open_object_section("user");
         formatter->dump_string("user", siter->first);
-       dump_usage_categories_info(formatter, entry);
+       dump_usage_categories_info(formatter, entry, categories);
+       rgw_usage_data total_usage;
+       entry.sum(total_usage, categories);
+        formatter->open_object_section("total");
+        formatter->dump_int("bytes_sent", total_usage.bytes_sent);
+        formatter->dump_int("bytes_received", total_usage.bytes_received);
+        formatter->dump_int("ops", total_usage.ops);
+        formatter->dump_int("successful_ops", total_usage.successful_ops);
+        formatter->close_section(); // total
+
         formatter->close_section(); // user
+
         formatter->flush(cout);
       }
 
index c71de5c2957353775215791a01d86bce94715024..c17e5056713e0d8b6aa5c00147bbaa7079696580 100644 (file)
@@ -64,6 +64,7 @@
      --show-log-sum=<flag>     enable/disable dump of log summation on log show
      --skip-zero-entries       log show only dumps entries that don't have zero value
                                in one of the numeric field
+     --categories=<list>       comma separated list of categories, used in usage show
      --yes-i-really-mean-it    required for certain operations
   
   <date> := "YYYY-MM-DD[ hh:mm:ss]"