]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: Monitor: take advantage of the new HealthMonitor class. 115/head
authorJoao Eduardo Luis <joao.luis@inktank.com>
Sun, 17 Mar 2013 18:41:42 +0000 (18:41 +0000)
committerJoao Eduardo Luis <joao.luis@inktank.com>
Mon, 18 Mar 2013 22:43:55 +0000 (22:43 +0000)
Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
src/mon/Monitor.cc
src/mon/Monitor.h

index 769381ba499aed687e54540d39908e8641d72c12..9f35e0df615b6abb5c15dea94e2368a5e5ad1516 100644 (file)
@@ -49,6 +49,7 @@
 #include "messages/MAuthReply.h"
 
 #include "messages/MTimeCheck.h"
+#include "messages/MMonHealth.h"
 
 #include "common/strtol.h"
 #include "common/ceph_argparse.h"
@@ -68,6 +69,8 @@
 #include "PGMonitor.h"
 #include "LogMonitor.h"
 #include "AuthMonitor.h"
+#include "mon/QuorumService.h"
+#include "mon/HealthMonitor.h"
 
 #include "auth/AuthMethodList.h"
 #include "auth/KeyRing.h"
@@ -163,6 +166,8 @@ Monitor::Monitor(CephContext* cct_, string nm, MonitorDBStore *s,
   paxos_service[PAXOS_LOG] = new LogMonitor(this, paxos, "logm");
   paxos_service[PAXOS_AUTH] = new AuthMonitor(this, paxos, "auth");
 
+  health_monitor = QuorumServiceRef(new HealthMonitor(this));
+
   mon_caps = new MonCaps();
   mon_caps->set_allow_all(true);
   mon_caps->text = "allow *";
@@ -418,6 +423,7 @@ int Monitor::preinit()
   }
 
   init_paxos();
+  health_monitor->init();
 
   // we need to bootstrap authentication keys so we can form an
   // initial quorum.
@@ -565,6 +571,7 @@ void Monitor::shutdown()
   // clean up
   for (vector<PaxosService*>::iterator p = paxos_service.begin(); p != paxos_service.end(); ++p)
     (*p)->shutdown();
+  health_monitor->shutdown();
 
   finish_contexts(g_ceph_context, waitfor_quorum, -ECANCELED);
   finish_contexts(g_ceph_context, maybe_wait_for_quorum, -ECANCELED);
@@ -683,6 +690,7 @@ void Monitor::reset()
 
   for (vector<PaxosService*>::iterator p = paxos_service.begin(); p != paxos_service.end(); ++p)
     (*p)->restart();
+  health_monitor->finish();
 }
 
 set<string> Monitor::get_sync_targets_names() {
@@ -1964,6 +1972,7 @@ void Monitor::win_election(epoch_t epoch, set<int>& active, uint64_t features)
   paxos->leader_init();
   for (vector<PaxosService*>::iterator p = paxos_service.begin(); p != paxos_service.end(); ++p)
     (*p)->election_finished();
+  health_monitor->start(epoch);
 
   finish_election();
   if (monmap->size() > 1)
@@ -1997,6 +2006,7 @@ void Monitor::lose_election(epoch_t epoch, set<int> &q, int l, uint64_t features
   paxos->peon_init();
   for (vector<PaxosService*>::iterator p = paxos_service.begin(); p != paxos_service.end(); ++p)
     (*p)->election_finished();
+  health_monitor->start(epoch);
 
   finish_election();
 }
@@ -2283,6 +2293,9 @@ void Monitor::get_health(string& status, bufferlist *detailbl, Formatter *f)
   if (f)
     f->close_section();
 
+  if (f)
+    health_monitor->get_health(f, (detailbl ? &detail : NULL));
+
   stringstream fss;
   fss << overall;
   status = fss.str() + ss.str();
@@ -3174,6 +3187,10 @@ bool Monitor::_ms_dispatch(Message *m)
       handle_timecheck(static_cast<MTimeCheck *>(m));
       break;
 
+    case MSG_MON_HEALTH:
+      health_monitor->dispatch(static_cast<MMonHealth *>(m));
+      break;
+
     default:
       ret = false;
     }
index 9d2bd5988238143602aac3c0827f80f3915bef47..55f27c7822dffea4d399f12b53470e0a28ee6d30 100644 (file)
@@ -51,6 +51,9 @@
 #include <memory>
 #include <tr1/memory>
 #include <errno.h>
+#include <boost/intrusive_ptr.hpp>
+// Because intusive_ptr clobbers our assert...
+#include "include/assert.h"
 
 
 #define CEPH_MON_PROTOCOL     10 /* cluster internal */
@@ -83,6 +86,7 @@ enum {
   l_cluster_last,
 };
 
+class QuorumService;
 class PaxosService;
 
 class PerfCounters;
@@ -97,6 +101,7 @@ class MAuthRotating;
 class MRoute;
 class MForward;
 class MTimeCheck;
+class MMonHealth;
 
 #define COMPAT_SET_LOC "feature_set"
 
@@ -1135,7 +1140,30 @@ private:
   /**
    * @}
    */
+  /**
+   * @defgroup Monitor_h_stats Keep track of monitor statistics
+   * @{
+   */
+  struct MonStatsEntry {
+    // data dir
+    uint64_t kb_total;
+    uint64_t kb_used;
+    uint64_t kb_avail;
+    unsigned int latest_avail_ratio;
+    utime_t last_update;
+  };
+
+  struct MonStats {
+    MonStatsEntry ours;
+    map<entity_inst_t,MonStatsEntry> others;
+  };
+
+  MonStats stats;
 
+  void stats_update();
+  /**
+   * @}
+   */
 
   Context *probe_timeout_event;  // for probing
 
@@ -1215,6 +1243,7 @@ public:
   friend class PGMonitor;
   friend class LogMonitor;
 
+  boost::intrusive_ptr<QuorumService> health_monitor;
 
   // -- sessions --
   MonSessionMap session_map;