From ca3b61d056f6882a23bd9e385b477f95a019410a Mon Sep 17 00:00:00 2001 From: Leonardo Menezes Date: Thu, 1 Dec 2016 22:55:57 +0100 Subject: [PATCH] handle both 2.x and 5.x cpu / load information closes #38 --- app/models/overview/ClusterOverview.scala | 22 ++++++++++++++++------ public/js/app.js | 3 ++- src/app/shared/progress.js | 3 ++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/models/overview/ClusterOverview.scala b/app/models/overview/ClusterOverview.scala index f953da1e..44608dcd 100644 --- a/app/models/overview/ClusterOverview.scala +++ b/app/models/overview/ClusterOverview.scala @@ -45,12 +45,8 @@ object Nodes { val nodeRoles = NodeRoles(info) val stats = (nodesStats \ "nodes" \ nodeId).as[JsObject] - // FIXME: 1.X val totalInBytes = (stats \ "fs" \ "total" \ "total_in_bytes").asOpt[Long].getOrElse(0l) - // FIXME: 1.X val diskFreeInBytes = (stats \ "fs" \ "total" \ "free_in_bytes").asOpt[Long].getOrElse(0l) - // FIXME 1.X - val cpuPercent = (stats \ "os" \ "cpu" \ "user").asOpt[JsNumber].getOrElse((stats \ "process" \ "cpu" \ "percent").as[JsNumber]) Json.obj( "id" -> JsString(nodeId), "current_master" -> JsBoolean(nodeId.equals(currentMaster)), @@ -59,9 +55,9 @@ object Nodes { "ip" -> (info \ "ip").as[JsString], "es_version" -> (info \ "version").as[JsString], "jvm_version" -> (info \ "jvm" \ "version").as[JsString], - "load_average" -> JsNumber(BigDecimal((stats \ "os" \ "load_average").asOpt[Int].getOrElse(0))),// FIXME: 1.X + "load_average" -> loadAverage(stats), "available_processors" -> (info \ "os" \ "available_processors").as[JsNumber], - "cpu_percent" -> cpuPercent, + "cpu_percent" -> cpuPercent(stats), "master" -> JsBoolean(nodeRoles.master), "data" -> JsBoolean(nodeRoles.data), "client" -> JsBoolean(nodeRoles.client), @@ -81,6 +77,20 @@ object Nodes { }.toSeq } + def loadAverage(nodeStats: JsValue): JsNumber = { + val load = (nodeStats \ "os" \ "cpu" \ "load_average" \ "1m").asOpt[Float].getOrElse( // 5.X + (nodeStats \ "os" \ "load_average").asOpt[Float].getOrElse(0f) // FIXME: 2.X + ) + JsNumber(BigDecimal(load)) + } + + def cpuPercent(nodeStats: JsValue): JsNumber = { + val cpu = (nodeStats \ "os" \ "cpu" \ "percent").asOpt[Int].getOrElse( // 5.X + (nodeStats \ "os" \ "cpu_percent").asOpt[Int].getOrElse(0) // FIXME 2.X + ) + JsNumber(BigDecimal(cpu)) + } + } object Indices { diff --git a/public/js/app.js b/public/js/app.js index f75cab6c..2b3b0612 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -1798,7 +1798,8 @@ angular.module('cerebro').directive('ngProgress', template: function(elem, attrs) { return '{{text}}' + '
' + - '
' + '{{value}}%' + '
'; diff --git a/src/app/shared/progress.js b/src/app/shared/progress.js index b0408882..6e62331a 100644 --- a/src/app/shared/progress.js +++ b/src/app/shared/progress.js @@ -10,7 +10,8 @@ angular.module('cerebro').directive('ngProgress', template: function(elem, attrs) { return '{{text}}' + '
' + - '
' + '{{value}}%' + '
';