From 46fb86aaab30a1c1c99fc12181055069f39c4a64 Mon Sep 17 00:00:00 2001 From: Joao Eduardo Luis Date: Thu, 22 Aug 2013 16:05:17 +0100 Subject: [PATCH] mon: mon_types: DataStats: add 'dump(Formatter*)' method ... and use it on DataHealthService.cc, instead of building our own version of the classes' formatted output. Signed-off-by: Joao Eduardo Luis --- src/mon/DataHealthService.cc | 10 +++------- src/mon/mon_types.h | 13 ++++++++++++- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/mon/DataHealthService.cc b/src/mon/DataHealthService.cc index 6e8aa313a3616..e74e00864ccc2 100644 --- a/src/mon/DataHealthService.cc +++ b/src/mon/DataHealthService.cc @@ -95,18 +95,14 @@ health_status_t DataHealthService::get_health( if (f) { f->open_object_section("mon"); f->dump_string("name", mon_name.c_str()); - f->dump_int("kb_total", stats.kb_total); - f->dump_int("kb_used", stats.kb_used); - f->dump_int("kb_avail", stats.kb_avail); - f->dump_int("avail_percent", stats.latest_avail_percent); - f->dump_stream("last_updated") << stats.last_update; + stats.dump(f); f->dump_stream("health") << health_status; if (health_status != HEALTH_OK) - f->dump_string("health_detail", health_detail); + f->dump_string("health_detail", health_detail); f->close_section(); } } - + if (f) { f->close_section(); // mons f->close_section(); // data_health diff --git a/src/mon/mon_types.h b/src/mon/mon_types.h index 0eae3b172bff0..f94f6c7e33e95 100644 --- a/src/mon/mon_types.h +++ b/src/mon/mon_types.h @@ -50,6 +50,18 @@ struct DataStats { int latest_avail_percent; utime_t last_update; + void dump(Formatter *f) const { + assert(f != NULL); + f->open_object_section("data_stats"); + f->dump_int("kb_total", kb_total); + f->dump_int("kb_used", kb_used); + f->dump_int("kb_avail", kb_avail); + f->dump_int("avail_percent", latest_avail_percent); + f->dump_stream("last_updated") << last_update; + + f->close_section(); + } + void encode(bufferlist &bl) const { ENCODE_START(1, 1, bl); ::encode(kb_total, bl); @@ -69,7 +81,6 @@ struct DataStats { DECODE_FINISH(p); } }; - WRITE_CLASS_ENCODER(DataStats); struct ScrubResult { -- 2.39.5