From 0fc8a0da1ae300225bd098d421f3c9bf74b9e38a Mon Sep 17 00:00:00 2001 From: John Spray Date: Wed, 27 Aug 2014 19:03:40 +0100 Subject: [PATCH] mds: populate health metrics in beacon Signed-off-by: John Spray --- src/mds/Beacon.cc | 33 +++++++++++++++++++++++++++++++-- src/mds/Beacon.h | 6 ++++++ src/mds/MDS.cc | 3 +++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/mds/Beacon.cc b/src/mds/Beacon.cc index b4a54e1862b88..83a7efd1b1a8c 100644 --- a/src/mds/Beacon.cc +++ b/src/mds/Beacon.cc @@ -18,6 +18,8 @@ #include "messages/MMDSBeacon.h" #include "mon/MonClient.h" +#include "mds/MDS.h" +#include "mds/MDLog.h" #include "Beacon.h" @@ -166,8 +168,7 @@ void Beacon::_send() beacon->set_standby_for_rank(standby_for_rank); beacon->set_standby_for_name(standby_for_name); - - // include _my_ feature set + beacon->set_health(health); beacon->set_compat(compat); monc->send_mon_message(beacon); @@ -233,3 +234,31 @@ void Beacon::notify_want_state(MDSMap::DaemonState const newstate) } +/** + * We are 'shown' an MDS briefly in order to update + * some health metrics that we will send in the next + * beacon. + */ +void Beacon::notify_health(MDS const *mds) +{ + Mutex::Locker l(lock); + + // I'm going to touch this MDS, so it must be locked + assert(mds->mds_lock.is_locked_by_me()); + + health.metrics.clear(); + + // Detect MDS_HEALTH_TRIM condition + // Arbitrary factor of 2, indicates MDS is not trimming promptly + if (mds->mdlog->get_num_segments() > (size_t)(g_conf->mds_log_max_segments * 2)) { + std::ostringstream oss; + oss << "Behind on trimming (" << mds->mdlog->get_num_segments() + << "/" << g_conf->mds_log_max_segments << ")"; + + MDSHealthMetric m(MDS_HEALTH_TRIM, HEALTH_WARN, oss.str()); + m.metadata["num_segments"] = mds->mdlog->get_num_segments(); + m.metadata["max_segments"] = g_conf->mds_log_max_segments; + health.metrics.push_back(m); + } +} + diff --git a/src/mds/Beacon.h b/src/mds/Beacon.h index 50d17dfd1c8f1..a9ac549d0c585 100644 --- a/src/mds/Beacon.h +++ b/src/mds/Beacon.h @@ -20,10 +20,12 @@ #include "include/Context.h" #include "common/Mutex.h" #include "msg/Dispatcher.h" +#include "messages/MMDSBeacon.h" class MonClient; class MMDSBeacon; class Message; +class MDS; /** @@ -58,6 +60,9 @@ class Beacon : public Dispatcher bool was_laggy; utime_t laggy_until; + // Health status to be copied into each beacon message + MDSHealth health; + // Ticker class C_MDS_BeaconSender : public Context { Beacon *beacon; @@ -87,6 +92,7 @@ public: void notify_mdsmap(MDSMap const *mdsmap); void notify_want_state(MDSMap::DaemonState const newstate); + void notify_health(MDS const *mds); void set_standby_for(int rank_, std::string const &name_); diff --git a/src/mds/MDS.cc b/src/mds/MDS.cc index 37210f945d5ab..53a8cfd42baca 100644 --- a/src/mds/MDS.cc +++ b/src/mds/MDS.cc @@ -757,6 +757,9 @@ void MDS::tick() snapserver->check_osd_map(false); } + // Expose ourselves to Beacon to update health indicators + beacon.notify_health(this); + check_ops_in_flight(); } -- 2.39.5