Skip to content

Commit

Permalink
add new Compactions-Page containing the Compactions-Chart moved from …
Browse files Browse the repository at this point in the history
…the Servers-Page #18
  • Loading branch information
Nils Kübler committed Apr 10, 2013
1 parent a0baca1 commit 71a2319
Show file tree
Hide file tree
Showing 13 changed files with 186 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright 2012 Sentric. See LICENSE for details.

$ ->
showCompactionsView = window.showCompactionsView = new ShowCompactionsView
el: $("#show-compactions-view")
52 changes: 52 additions & 0 deletions app/assets/javascripts/views/compactions/ShowCompactions.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2012 Sentric. See LICENSE for details.

class @ShowCompactionsView extends Backbone.View

initialize: ->
@metricsCharts = []
@$(".compaction-metric-chart-view").each (idx, element) =>
@metricsCharts.push @createMetricView(@$(element))

@visualCountDown = new VisualCountDownView
el: @$(".refresh-text")
pattern: "(next refresh in %delay% seconds)"
@visualCountDown.on "done", _.bind(@updateMetrics, @)

if @metricsCharts.length > 0
@compactions = @metricsCharts[0].collection
@compactions.on "reset", _.bind(@updateLongestCompactionDuration, @)

@updateMetrics()

createMetricView: ($el) ->
metrics = Metrics.byNames( $el.data("metric-names") )
view = new MetricChartView
el: $el
collection: metrics
metricFilter: (collection) -> collection.groupedByTable()
doNormalize: false
renderer: 'area'
palette: new RickshawUtil.TablePalette()
view

updateMetrics: ->
view.collection.fetch() for view in @metricsCharts
@visualCountDown.startCountDown(125, 1, 1000)

updateLongestCompactionDuration: ->
max = 0
target = "[none]"
date = new Date()
@compactions.each (metric) ->
begin = metric.begin;
_(metric.getValues()).each (record) ->
if(record.v > 0)
begin = record.ts
else if record.ts - begin > max
max = record.ts - begin
date = new Date(begin)
target = metric.getTargetDesc()

route = Routes.Regions.show
name: target
@$(".longest-compaction").html("<b>#{(max/1000.0).toFixed(1)}s</b> <a href='#{route}'>on Region</a>")
24 changes: 0 additions & 24 deletions app/assets/javascripts/views/servers/ShowCluster.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,9 @@ class @ShowClusterView extends Backbone.View
pattern: "(next refresh in %delay% seconds)"
@visualCountDown.on "done", _.bind(@updateClusterRegions, @)

@clusterMetricCharts = []
@$(".cluster-metric-chart-view").each (idx, element) =>
@clusterMetricCharts.push @createMetricView(@$(element))

@visualCountDown2 = new VisualCountDownView
el: @$(".refresh-text")
pattern: "(next refresh in %delay% seconds)"
@visualCountDown2.on "done", _.bind(@updateMetrics, @)

@updateClusterRegions()
@updateMetrics()

updateClusterRegions: ->
@serverChart.collection.fetch()
@visualCountDown.startCountDown(30, 1, 1000)

createMetricView: ($el) ->
metrics = Metrics.byNames( $el.data("metric-names") )
view = new MetricChartView
el: $el
collection: metrics
metricFilter: (collection) -> collection.groupedByTable()
doNormalize: false
renderer: 'area'
palette: new RickshawUtil.TablePalette()
view

updateMetrics: ->
view.collection.fetch() for view in @clusterMetricCharts
@visualCountDown2.startCountDown(125, 1, 1000)
14 changes: 14 additions & 0 deletions app/controllers/Compactions.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright 2012 Sentric. See LICENSE for details.
*/

package controllers

import play.api.mvc._
import utils.MetricUtil

object Compactions extends Controller {
def index = Action { implicit request =>
Ok(views.html.compactions.index(MetricUtil.findLongestCompactionInLastWeek()))
}
}
3 changes: 2 additions & 1 deletion app/controllers/Regions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.codahale.jerkson.Json
import play.api.libs.concurrent.Akka
import play.api.Play.current
import models.{Table, Metric, MetricDef}
import utils.MetricUtil

object Regions extends Controller {

Expand All @@ -36,7 +37,7 @@ object Regions extends Controller {
else {
val info = region.getRegionInfo()
val table = Table.findByName(region.tableName)
Ok(views.html.regions.show(region, info, table, region.findLongestCompactionInLastWeek()))
Ok(views.html.regions.show(region, info, table, MetricUtil.findLongestCompactionInLastWeek(region.regionName)))
}
}
}
Expand Down
13 changes: 0 additions & 13 deletions app/models/Region.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,6 @@ case class Region(private val regionServer:RegionServer, private val regionLoad
}

def serverInfoUrl() = "http://" + serverHostName + ":" + serverInfoPort

def findLongestCompactionInLastWeek() = {
val metric = MetricDef.COMPACTIONS(regionName).metric(MetricDef.now()-1000*3600*24*7, MetricDef.now())
var begin = metric.begin;
var max = 0L;
metric.values.foreach { record =>
if(record.v > 0)
begin = record.ts
else
max = scala.math.max(max, record.ts - begin)
}
max
}
}

object Region {
Expand Down
39 changes: 39 additions & 0 deletions app/utils/MetricUtil.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package utils

import models.MetricDef
import java.util.Date

/*
* Copyright 2012 Sentric. See LICENSE for details.
*/
object MetricUtil {

def findLongestCompactionInLastWeek(regionName:String) : (Long, Date) = {
findLongestCompactionInLastWeek(MetricDef.COMPACTIONS(regionName))
}

def findLongestCompactionInLastWeek(metricDef:MetricDef) : (Long, Date) = {
val metric = metricDef.metric(MetricDef.now()-1000*3600*24*7, MetricDef.now())
var begin = metric.begin;
var max = 0L;
metric.values.foreach { record =>
if(record.v > 0)
begin = record.ts
else
max = scala.math.max(max, record.ts - begin)
}
(max, new Date(begin))
}

def findLongestCompactionInLastWeek() : (Long, Date, String) = {
val metrics = MetricDef.findByName(MetricDef.COMPACTIONS)
var result = (0L, new Date(), "")
metrics.foreach { metricDef =>
val longest = findLongestCompactionInLastWeek(metricDef)
if(longest._1 > result._1) {
result = (longest._1, longest._2, metricDef.targetDesc)
}
}
result
}
}
63 changes: 63 additions & 0 deletions app/views/compactions/index.scala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
@(longestCompaction: (Long, java.util.Date, String))(implicit request: play.api.mvc.Request[Any])

@import java.text.DateFormat

@includes = {
<link rel="stylesheet" media="screen" href='@routes.Assets.at("stylesheets/metric_chart_view.css")'>
<script src='@routes.Assets.at("javascripts/views/common/VisualCountDown.js")' type="text/javascript"></script>
<script src='@routes.Assets.at("javascripts/views/common/MetricChart.js")' type="text/javascript"></script>
<script src='@routes.Assets.at("javascripts/views/compactions/ShowCompactions.js")' type="text/javascript"></script>
<script src='@routes.Assets.at("javascripts/models/Metric.js")' type="text/javascript"></script>
<script src='@routes.Assets.at("javascripts/models/MetricSeries.js")' type="text/javascript"></script>
<script src='@routes.Assets.at("javascripts/main/compactions/show_compactions.js")' type="text/javascript"></script>
}

@content = {
<div id="show-compactions-view">
<div class="widget">
<div class="title">Compactions <span class="refresh-text"></span></div>
<div class="content">
<ul>
<li>Longest Compaction during last 24 Hours: <span class="longest-compaction">-please wait-</span></li>
<li>Longest Compaction during last 7 Days: <span><b>@(longestCompaction._1/1000.0)s</b> at @(DateFormat.getInstance().format(longestCompaction._2)) on <a href='@routes.Regions.show(longestCompaction._3)'>on Region</a></span></li>
</ul>
</div>
<div>

</div>
</div>

<div class="widget">
<div class="title">History</div>
<div class="content">
@clusterMetricChart(Seq(
models.MetricDef.COMPACTIONS
))
</div>
<div class="description">
<div class="headline"></div>
<div class="body">
</div>
</div>
</div>
</div>
}

@clusterMetricChart(metricNames: Seq[String]) = {
<div class="metric-chart-view compaction-metric-chart-view" data-metric-names="@com.codahale.jerkson.Json.generate(metricNames)">
<div class="x-axis"></div>
<div class="chart"></div>
<div class="legend-container">
<div class="smoother" title="Smoothing"></div>
<div class="legend"></div>
</div>
<div class="timeline"></div>
<div class="slider"></div>
</div>
}

@breadcrumbs = {

}

@main("Compactions")(content)(includes)(breadcrumbs)
3 changes: 3 additions & 0 deletions app/views/jsroutes.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
Servers: {
index: route("@routes.Servers.index()")
},
Compactions: {
index: route("@routes.Compactions.index()")
},
Tables: {
index: route("@routes.Tables.index()"),
show: route("@routes.Tables.show("%name%")")
Expand Down
3 changes: 3 additions & 0 deletions app/views/main.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
<li @if(request.path.toString().startsWith(routes.Regions.index().toString())){ class="active"}>
<a href="@routes.Regions.index()">Regions</a>
</li>
<li @if(request.path.toString().startsWith(routes.Compactions.index().toString())){ class="active"}>
<a href="@routes.Compactions.index()">Compactions</a>
</li>
</ul>
</div>
</div>
Expand Down
5 changes: 3 additions & 2 deletions app/views/regions/show.scala.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@(region: models.Region, info: models.RegionInfo, table: models.Table, longestCompaction: Long)(implicit request: play.api.mvc.Request[Any])
@(region: models.Region, info: models.RegionInfo, table: models.Table, longestCompaction: (Long, java.util.Date))(implicit request: play.api.mvc.Request[Any])

@import helpers.Referer
@import java.text.DateFormat

@regionMetricChart(metricNames: Seq[String]) = {
<div class="metric-chart-view region-metric-chart-view" data-region-name="@region.regionName" data-metric-names="@com.codahale.jerkson.Json.generate(metricNames)">
Expand Down Expand Up @@ -28,7 +29,7 @@
<li>Deployed on: <a href="@region.serverInfoUrl"><b>@region.serverHostName</b></a></li>
<li>Storefile Size : <b>@(region.storefileSizeMB)MB</b></li>
<li>Memstore Flush Size: <b>@(table.memstoreFlushSize/(1024*1024))MB</b></li>
<li>Longest Compaction during last 7 Days: <b>@(longestCompaction/1000.0)s</b></li>
<li>Longest Compaction during last 7 Days: <span><b>@(longestCompaction._1/1000.0)s at @(DateFormat.getInstance().format(longestCompaction._2))</b></span></li>
</ul>
</div>
<div>
Expand Down
31 changes: 0 additions & 31 deletions app/views/servers/index.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
<link rel="stylesheet" media="screen" href='@routes.Assets.at("stylesheets/server_chart.css")'>
<link rel="stylesheet" media="screen" href='@routes.Assets.at("stylesheets/metric_chart_view.css")'>
<script src='@routes.Assets.at("javascripts/views/common/VisualCountDown.js")' type="text/javascript"></script>
<script src='@routes.Assets.at("javascripts/views/common/MetricChart.js")' type="text/javascript"></script>
<script src='@routes.Assets.at("javascripts/views/servers/AbstractServerChart.js")' type="text/javascript"></script>
<script src='@routes.Assets.at("javascripts/views/servers/ServerChart.js")' type="text/javascript"></script>
<script src='@routes.Assets.at("javascripts/views/servers/ShowCluster.js")' type="text/javascript"></script>
<script src='@routes.Assets.at("javascripts/models/Region.js")' type="text/javascript"></script>
<script src='@routes.Assets.at("javascripts/models/Metric.js")' type="text/javascript"></script>
<script src='@routes.Assets.at("javascripts/models/MetricSeries.js")' type="text/javascript"></script>
<script src='@routes.Assets.at("javascripts/main/servers/show_cluster.js")' type="text/javascript"></script>
}

Expand All @@ -28,37 +25,9 @@
</div>
</div>
</div>

<div class="widget">
<div class="title">Compaction History <span class="refresh-text"></span></div>
<div class="content">
@clusterMetricChart(Seq(
models.MetricDef.COMPACTIONS
))
</div>
<div class="description">
<div class="headline"></div>
<div class="body">
</div>
</div>
</div>
</div>
}

@clusterMetricChart(metricNames: Seq[String]) = {
<div class="metric-chart-view cluster-metric-chart-view" data-metric-names="@com.codahale.jerkson.Json.generate(metricNames)">
<div class="x-axis"></div>
<div class="chart"></div>
<div class="legend-container">
<div class="smoother" title="Smoothing"></div>
<div class="legend"></div>
</div>
<div class="timeline"></div>
<div class="slider"></div>
</div>
}


@breadcrumbs = {

}
Expand Down
2 changes: 2 additions & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ GET / controllers.

GET /servers controllers.Servers.index

GET /compactions controllers.Compactions.index

GET /tables controllers.Tables.index()
GET /tables/ controllers.Tables.index()
GET /tables/:tableName controllers.Tables.show(tableName: String)
Expand Down

0 comments on commit 71a2319

Please sign in to comment.