Skip to content
Browse files

delete all metrics in a folder using a command like: delcounters path…

….to.parent.*
  • Loading branch information...
1 parent 3852334 commit d07b90ed67fe45032860ff8923f9cd56b45206d4 @carver committed with Feb 9, 2013
Showing with 37 additions and 2 deletions.
  1. +37 −2 stats.js
View
39 stats.js
@@ -135,12 +135,47 @@ function delete_stats(stats_type, cmdline, stream) {
//for each metric requested on the command line
for (var index in cmdline) {
- delete stats_type[cmdline[index]];
- stream.write("deleted: " + metric + "\n");
+
+ //get a list of deletable metrics that match the request
+ deletable = stats_to_delete(stats_type, cmdline[index]);
+
+ //warn if no matches
+ if (deletable.length == 0) {
+ stream.write("metric " + cmdline[index] + " not found\n");
+ }
+
+ //delete all requested metrics
+ for (var del_idx in deletable) {
+ delete stats_type[deletable[del_idx]];
+ stream.write("deleted: " + deletable[del_idx] + "\n");
+ }
}
stream.write("END\n\n");
}
+function stats_to_delete(stats_type, bucket){
+ deletable = []
+
+ //typical case: one-off deletion
+ if (bucket in stats_type) {
+ deletable.push(bucket);
+ }
+
+ //special case: delete a whole 'folder' (and subfolders) of stats
+ if (bucket.slice(-2) == ".*") {
+ var folder = bucket.slice(0,-1);
+
+ for (var name in stats_type) {
+ //check if stat is in bucket, ie~ name starts with folder
+ if (name.substring(0, folder.length) == folder) {
+ deletable.push(name);
+ }
+ }
+ }
+
+ return deletable;
+}
+
config.configFile(process.argv[2], function (config, oldConfig) {
conf = config;
l = new logger.Logger(config.log || {});

0 comments on commit d07b90e

Please sign in to comment.
Something went wrong with that request. Please try again.