You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ya...@apache.org on 2015/06/09 02:41:09 UTC
[2/2] mesos git commit: Introduced metrics for revocable resources.
Introduced metrics for revocable resources.
Review: https://reviews.apache.org/r/35119
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b24da74e
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b24da74e
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b24da74e
Branch: refs/heads/master
Commit: b24da74e48aa2566e1410d39054f863bd469c393
Parents: baf80d7
Author: Jiang Yan Xu <ya...@jxu.me>
Authored: Fri Jun 5 14:03:44 2015 -0700
Committer: Jiang Yan Xu <ya...@jxu.me>
Committed: Mon Jun 8 17:40:08 2015 -0700
----------------------------------------------------------------------
src/master/master.cpp | 46 +++++++++++++++++++++++++++++++
src/master/master.hpp | 4 +++
src/master/metrics.cpp | 37 +++++++++++++++++++++++++
src/master/metrics.hpp | 6 ++++
src/tests/oversubscription_tests.cpp | 9 +++++-
5 files changed, 101 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/b24da74e/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index 68ca437..5ed990e 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -5398,6 +5398,52 @@ double Master::_resources_percent(const std::string& name)
}
}
+
+double Master::_resources_revocable_total(const std::string& name)
+{
+ double total = 0.0;
+
+ foreachvalue (Slave* slave, slaves.registered) {
+ foreach (const Resource& resource, slave->totalResources.revocable()) {
+ if (resource.name() == name && resource.type() == Value::SCALAR) {
+ total += resource.scalar().value();
+ }
+ }
+ }
+
+ return total;
+}
+
+
+double Master::_resources_revocable_used(const std::string& name)
+{
+ double used = 0.0;
+
+ foreachvalue (Slave* slave, slaves.registered) {
+ foreachvalue (const Resources& resources, slave->usedResources) {
+ foreach (const Resource& resource, resources.revocable()) {
+ if (resource.name() == name && resource.type() == Value::SCALAR) {
+ used += resource.scalar().value();
+ }
+ }
+ }
+ }
+
+ return used;
+}
+
+
+double Master::_resources_revocable_percent(const std::string& name)
+{
+ double total = _resources_revocable_total(name);
+
+ if (total == 0.0) {
+ return total;
+ } else {
+ return _resources_revocable_used(name) / total;
+ }
+}
+
} // namespace master {
} // namespace internal {
} // namespace mesos {
http://git-wip-us.apache.org/repos/asf/mesos/blob/b24da74e/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index 9f19765..af83d3e 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -1366,6 +1366,10 @@ private:
double _resources_used(const std::string& name);
double _resources_percent(const std::string& name);
+ double _resources_revocable_total(const std::string& name);
+ double _resources_revocable_used(const std::string& name);
+ double _resources_revocable_percent(const std::string& name);
+
process::Time startTime; // Start time used to calculate uptime.
Option<process::Time> electedTime; // Time when this master is elected.
http://git-wip-us.apache.org/repos/asf/mesos/blob/b24da74e/src/master/metrics.cpp
----------------------------------------------------------------------
diff --git a/src/master/metrics.cpp b/src/master/metrics.cpp
index 264252c..d2489c8 100644
--- a/src/master/metrics.cpp
+++ b/src/master/metrics.cpp
@@ -246,6 +246,7 @@ Metrics::Metrics(const Master& master)
// resources the slave exposes.
const std::string resources[] = {"cpus", "mem", "disk"};
+ // Regular (non-revocable) resources.
foreach (const std::string& resource, resources) {
process::metrics::Gauge totalGauge(
"master/" + resource + "_total",
@@ -265,6 +266,27 @@ Metrics::Metrics(const Master& master)
resources_percent.push_back(percentGauge);
process::metrics::add(percentGauge);
}
+
+ // Revocable resources.
+ foreach (const std::string& resource, resources) {
+ process::metrics::Gauge totalGauge(
+ "master/" + resource + "_revocable_total",
+ defer(master, &Master::_resources_revocable_total, resource));
+ resources_revocable_total.push_back(totalGauge);
+ process::metrics::add(totalGauge);
+
+ process::metrics::Gauge usedGauge(
+ "master/" + resource + "_revocable_used",
+ defer(master, &Master::_resources_revocable_used, resource));
+ resources_revocable_used.push_back(usedGauge);
+ process::metrics::add(usedGauge);
+
+ process::metrics::Gauge percentGauge(
+ "master/" + resource + "_revocable_percent",
+ defer(master, &Master::_resources_revocable_percent, resource));
+ resources_revocable_percent.push_back(percentGauge);
+ process::metrics::add(percentGauge);
+ }
}
@@ -363,6 +385,21 @@ Metrics::~Metrics()
}
resources_percent.clear();
+ foreach (const process::metrics::Gauge& gauge, resources_revocable_total) {
+ process::metrics::remove(gauge);
+ }
+ resources_revocable_total.clear();
+
+ foreach (const process::metrics::Gauge& gauge, resources_revocable_used) {
+ process::metrics::remove(gauge);
+ }
+ resources_revocable_used.clear();
+
+ foreach (const process::metrics::Gauge& gauge, resources_revocable_percent) {
+ process::metrics::remove(gauge);
+ }
+ resources_revocable_percent.clear();
+
foreachvalue (const auto& source_reason, tasks_states) {
foreachvalue (const auto& reason_counter, source_reason) {
foreachvalue (const process::metrics::Counter& counter, reason_counter) {
http://git-wip-us.apache.org/repos/asf/mesos/blob/b24da74e/src/master/metrics.hpp
----------------------------------------------------------------------
diff --git a/src/master/metrics.hpp b/src/master/metrics.hpp
index 833033c..3d389e6 100644
--- a/src/master/metrics.hpp
+++ b/src/master/metrics.hpp
@@ -174,10 +174,16 @@ struct Metrics
process::metrics::Counter slave_shutdowns_canceled;
// Resource metrics.
+ // Regular (non-revocable) resources.
std::vector<process::metrics::Gauge> resources_total;
std::vector<process::metrics::Gauge> resources_used;
std::vector<process::metrics::Gauge> resources_percent;
+ // Revocable resources.
+ std::vector<process::metrics::Gauge> resources_revocable_total;
+ std::vector<process::metrics::Gauge> resources_revocable_used;
+ std::vector<process::metrics::Gauge> resources_revocable_percent;
+
void incrementTasksStates(
TaskState state, TaskStatus::Source source, TaskStatus::Reason reason);
};
http://git-wip-us.apache.org/repos/asf/mesos/blob/b24da74e/src/tests/oversubscription_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/oversubscription_tests.cpp b/src/tests/oversubscription_tests.cpp
index afd7ff4..59cf07e 100644
--- a/src/tests/oversubscription_tests.cpp
+++ b/src/tests/oversubscription_tests.cpp
@@ -181,7 +181,7 @@ TEST_F(OversubscriptionTest, ForwardUpdateSlaveMessage)
AWAIT_READY(update);
- EXPECT_EQ(Resources(update.get().oversubscribed_resources()), resources);
+ EXPECT_EQ(update.get().oversubscribed_resources(), resources);
// Ensure the metric is updated.
JSON::Object metrics = Metrics();
@@ -192,6 +192,13 @@ TEST_F(OversubscriptionTest, ForwardUpdateSlaveMessage)
1u,
metrics.values["master/messages_update_slave"]);
+ ASSERT_EQ(
+ 1u,
+ metrics.values.count("master/cpus_revocable_total"));
+ ASSERT_EQ(
+ 1.0,
+ metrics.values["master/cpus_revocable_total"]);
+
Shutdown();
}