Skip to content

Commit

Permalink
handle both 2.x and 5.x cpu / load information
Browse files Browse the repository at this point in the history
closes #38
  • Loading branch information
Leonardo Menezes committed Dec 1, 2016
1 parent 3e504bc commit ca3b61d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
22 changes: 16 additions & 6 deletions app/models/overview/ClusterOverview.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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),
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,8 @@ angular.module('cerebro').directive('ngProgress',
template: function(elem, attrs) {
return '<span class="detail"><small>{{text}}</small></span>' +
'<div class="progress progress-thin">' +
'<div class="progress-bar-info" style="width: {{value}}%"' +
'<div class="progress-bar-info"' +
'style="width: {{(value / max) * 100}}%"' +
'ng-class="{\'progress-bar-danger\': {{(value / max) > 0.75}}}">' +
'{{value}}%' +
'</div></div>';
Expand Down
3 changes: 2 additions & 1 deletion src/app/shared/progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ angular.module('cerebro').directive('ngProgress',
template: function(elem, attrs) {
return '<span class="detail"><small>{{text}}</small></span>' +
'<div class="progress progress-thin">' +
'<div class="progress-bar-info" style="width: {{value}}%"' +
'<div class="progress-bar-info"' +
'style="width: {{(value / max) * 100}}%"' +
'ng-class="{\'progress-bar-danger\': {{(value / max) > 0.75}}}">' +
'{{value}}%' +
'</div></div>';
Expand Down

0 comments on commit ca3b61d

Please sign in to comment.