Skip to content

Commit

Permalink
rgw: usage statistics also count num of ops/successful_ops
Browse files Browse the repository at this point in the history
Signed-off-by: Yehuda Sadeh <[email protected]>
  • Loading branch information
yehudasa committed Jun 11, 2012
1 parent 6d8d059 commit a3f86b8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
9 changes: 2 additions & 7 deletions src/cls_rgw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,7 @@ int rgw_user_usage_log_add(cls_method_context_t hctx, bufferlist *in, bufferlist
if (ret < 0)
return ret;
CLS_LOG("rgw_user_usage_log_add aggregating existing bucket\n");
entry.bytes_sent += e.bytes_sent;
entry.bytes_received += e.bytes_received;
entry.aggregate(e);
}

bufferlist new_record_bl;
Expand Down Expand Up @@ -590,11 +589,7 @@ static int usage_log_read_cb(cls_method_context_t hctx, const string& key, rgw_u
map<rgw_user_bucket, rgw_usage_log_entry> *usage = (map<rgw_user_bucket, rgw_usage_log_entry> *)param;
rgw_user_bucket ub(entry.owner, entry.bucket);
rgw_usage_log_entry& le = (*usage)[ub];
le.bytes_sent += entry.bytes_sent;
le.bytes_received += entry.bytes_received;
le.epoch = entry.epoch;
le.owner = entry.owner;
le.bucket = entry.bucket;
le.aggregate(entry);

return 0;
}
Expand Down
4 changes: 4 additions & 0 deletions src/rgw/rgw_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,8 @@ int main(int argc, char **argv)
formatter->dump_int("epoch", entry.epoch);
formatter->dump_int("bytes_sent", entry.bytes_sent);
formatter->dump_int("bytes_received", entry.bytes_received);
formatter->dump_int("ops", entry.ops);
formatter->dump_int("successful_ops", entry.successful_ops);
formatter->close_section(); // bucket
formatter->flush(cout);
}
Expand All @@ -1448,6 +1450,8 @@ int main(int argc, char **argv)
formatter->dump_string("user", siter->first);
formatter->dump_int("bytes_sent", entry.bytes_sent);
formatter->dump_int("bytes_received", entry.bytes_received);
formatter->dump_int("ops", entry.ops);
formatter->dump_int("successful_ops", entry.successful_ops);
formatter->close_section();
formatter->flush(cout);
}
Expand Down
12 changes: 10 additions & 2 deletions src/rgw/rgw_cls_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,11 @@ struct rgw_usage_log_entry {
uint64_t epoch;
uint64_t bytes_sent;
uint64_t bytes_received;
uint64_t ops;
uint64_t successful_ops;

rgw_usage_log_entry() : bytes_sent(0), bytes_received(0) {}
rgw_usage_log_entry(string& o, string& b, uint64_t s, uint64_t r) : owner(o), bucket(b), bytes_sent(s), bytes_received(r) {}
rgw_usage_log_entry() : bytes_sent(0), bytes_received(0), ops(0), successful_ops(0) {}
rgw_usage_log_entry(string& o, string& b, uint64_t s, uint64_t r) : owner(o), bucket(b), bytes_sent(s), bytes_received(r), ops(0), successful_ops(0) {}

void encode(bufferlist& bl) const {
ENCODE_START(1, 1, bl);
Expand All @@ -335,6 +337,8 @@ struct rgw_usage_log_entry {
::encode(epoch, bl);
::encode(bytes_sent, bl);
::encode(bytes_received, bl);
::encode(ops, bl);
::encode(successful_ops, bl);
ENCODE_FINISH(bl);
}

Expand All @@ -346,6 +350,8 @@ struct rgw_usage_log_entry {
::decode(epoch, bl);
::decode(bytes_sent, bl);
::decode(bytes_received, bl);
::decode(ops, bl);
::decode(successful_ops, bl);
DECODE_FINISH(bl);
}

Expand All @@ -357,6 +363,8 @@ struct rgw_usage_log_entry {
}
bytes_sent += e.bytes_sent;
bytes_received += e.bytes_received;
ops += e.ops;
successful_ops += e.successful_ops;
}
};
WRITE_CLASS_ENCODER(rgw_usage_log_entry)
Expand Down
4 changes: 4 additions & 0 deletions src/rgw/rgw_log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ static void log_usage(struct req_state *s)

rgw_usage_log_entry entry(s->bucket_owner, s->bucket.name, s->bytes_sent, s->bytes_received);

entry.ops = 1;
if (!s->err.is_err())
entry.successful_ops = 1;

utime_t ts = ceph_clock_now(s->cct);

usage_logger->insert(ts, entry);
Expand Down

0 comments on commit a3f86b8

Please sign in to comment.