Commit 8133dc3c authored by Geoff Simmons's avatar Geoff Simmons

govarnishstat: Refactor and implement scale toggling.

parent 5c9b33ee
...@@ -95,25 +95,39 @@ table.hitrate { ...@@ -95,25 +95,39 @@ table.hitrate {
<script type="text/javascript"> <script type="text/javascript">
var addr = "ws://" + location.hostname + ":" + location.port var addr = "ws://" + location.hostname + ":" + location.port
var metadata = {}
var tbody var tbody
var colClassList = []
var show0 = false var show0 = false
var show0_checkbox var show0_checkbox
var formatting = true var formatting = true
var scaling_checkbox
var verbosity = "INFO" var verbosity = "INFO"
var verbose_select var verbose_select
var dot = ".&nbsp;&nbsp;&nbsp;"
var uptime_mgt
var uptime_child
var suffix = ["&nbsp;", "K", "M", "G", "T", "P", "E", "Z", "Y"]
function Metadata(short, long, level, format, semantics) {
this.short = short
this.long = long
this.level = level
this.format = format
this.semantics = semantics
}
function format_num(cell, val) { function format_num(cell, classList) {
if (cell.classList.contains("float")) { var val = cell.getAttribute("data-raw")
cell.innerHTML = val.toFixed(2) + "&nbsp;" if (classList.contains("avg")) {
cell.innerHTML = parseFloat(val).toFixed(2) + "&nbsp;"
return return
} }
cell.innerHTML = val + "&nbsp;" cell.innerHTML = val + "&nbsp;"
} }
function format_duration(cell, val) { function format_duration(cell) {
if (cell.classList.contains("float")) { var val = cell.getAttribute("data-raw")
return
}
var days = Math.floor(val/86400).toFixed(0) var days = Math.floor(val/86400).toFixed(0)
var hours = (Math.floor((val % 86400)/3600)).toFixed(0) var hours = (Math.floor((val % 86400)/3600)).toFixed(0)
if (hours < 10) { if (hours < 10) {
...@@ -130,10 +144,10 @@ function format_duration(cell, val) { ...@@ -130,10 +144,10 @@ function format_duration(cell, val) {
cell.innerHTML = days + "+" + hours + ":" + mins + ":" + secs + "&nbsp;" cell.innerHTML = days + "+" + hours + ":" + mins + ":" + secs + "&nbsp;"
} }
function format_bytes(cell, val) { function format_bytes(cell, classList) {
var suffix = ["&nbsp;", "K", "M", "G", "T", "P", "E", "Z", "Y"] var val = parseFloat(cell.getAttribute("data-raw"))
var i var i
if (cell.classList.contains("int") && val < 1024) { if (classList.contains("int") && val < 1024) {
cell.innerHTML = val.toFixed(0) + "&nbsp;" cell.innerHTML = val.toFixed(0) + "&nbsp;"
return return
} }
...@@ -142,34 +156,41 @@ function format_bytes(cell, val) { ...@@ -142,34 +156,41 @@ function format_bytes(cell, val) {
cell.innerHTML = val.toFixed(2) + suffix[i] cell.innerHTML = val.toFixed(2) + suffix[i]
} }
function format_bitmap(cell, val, bitmap) { function format(cell, format, semantics, cur0, classList) {
if (!cell.classList.contains("int")) { if (classList.contains("avg")) {
return switch (format) {
case "b":
case "d":
return
}
if ((cur0 && !classList.contains("moving")) ||
(semantics == "g" && classList.contains("uptime"))) {
cell.innerHTML = dot
return
}
} }
if (!formatting) { if (format == "b") {
format_num(cell, val) cell.innerHTML = cell.getAttribute("data-raw") + "&nbsp;"
return return
} }
cell.innerHTML = bitmap + "&nbsp;" if (formatting)
switch (format) {
case "d":
format_duration(cell)
return
case "B":
format_bytes(cell, classList)
return
}
format_num(cell, classList)
} }
function format(cell, val) { function format_row(row) {
if (!formatting) { var meta = metadata[row.id]
format_num(cell, val) var cur0 = row.cells[1].getAttribute("data-raw") == "0"
return for (i = 1; i <= 6; i++)
} format(row.cells[i], meta.format, meta.semantics, cur0,
if (cell.classList.contains("d")) { colClassList[i])
format_duration(cell, val)
return
}
if (cell.classList.contains("B")) {
format_bytes(cell, val)
return
}
if (cell.classList.contains("b")) {
return
}
format_num(cell, val)
} }
function getD9ns() { function getD9ns() {
...@@ -186,29 +207,19 @@ function getD9ns() { ...@@ -186,29 +207,19 @@ function getD9ns() {
var avg100Cell = row.insertCell(5) var avg100Cell = row.insertCell(5)
var avg1000Cell = row.insertCell(6) var avg1000Cell = row.insertCell(6)
curCell.classList.add("int", d9ns[i].format, var d9n = d9ns[i]
d9ns[i].semantics) metadata[d9n.name] = new Metadata(d9n.short, d9n.long,
changeCell.classList.add("float", d9ns[i].format, d9n.level, d9n.format,
d9ns[i].semantics) d9n.semantics)
avgCell.classList.add("float", d9ns[i].format, if (d9n.semantics == "g") {
d9ns[i].semantics)
avg10Cell.classList.add("float", d9ns[i].format,
d9ns[i].semantics)
avg100Cell.classList.add("float", d9ns[i].format,
d9ns[i].semantics)
avg1000Cell.classList.add("float", d9ns[i].format,
d9ns[i].semantics)
if (d9ns[i].semantics == "g") {
avgCell.innerHTML = ".&nbsp;&nbsp;&nbsp;" avgCell.innerHTML = ".&nbsp;&nbsp;&nbsp;"
} }
row.id = d9ns[i].name row.id = d9n.name
nameCell.innerHTML = d9ns[i].name nameCell.innerHTML = d9n.name
nameCell.className = "name" nameCell.className = "name"
row.id = d9ns[i].name row.classList.add(d9n.level)
row.classList.add(d9ns[i].level) if (d9n.level != "INFO") {
if (d9ns[i].level != "INFO") {
row.classList.add("hidden") row.classList.add("hidden")
} }
} }
...@@ -220,32 +231,30 @@ function getStats() { ...@@ -220,32 +231,30 @@ function getStats() {
ws.onmessage = function (evt) { ws.onmessage = function (evt) {
var stats = JSON.parse(evt.data) var stats = JSON.parse(evt.data)
var row = document.getElementById(stats.name) var row = document.getElementById(stats.name)
row.setAttribute("data-raw", stats.value)
var cells = row.cells var cells = row.cells
if (cells[1].classList.contains("b")) { if (metadata[row.id].semantics != "b") {
format_bitmap(cells[1], stats.value, stats.bitmap) cells[1].setAttribute("data-raw", stats.value)
} }
else { else {
format(cells[1], stats.value) cells[1].setAttribute("data-raw", stats.bitmap)
} }
format(cells[2], stats.change) cells[2].setAttribute("data-raw", stats.change)
if (!cells[3].classList.contains("g")) { cells[3].setAttribute("data-raw", stats.avg)
format(cells[3], stats.avg) cells[4].setAttribute("data-raw", stats.avg10)
} cells[5].setAttribute("data-raw", stats.avg100)
format(cells[4], stats.avg10) cells[6].setAttribute("data-raw", stats.avg1000)
format(cells[5], stats.avg100)
format(cells[6], stats.avg1000)
if (!show0 && stats.value == 0) { if (!show0 && stats.value == 0) {
row.classList.add("hidden") row.classList.add("hidden")
} }
format_row(row)
if (stats.name == "MGT.uptime") { if (stats.name == "MGT.uptime") {
var cell = document.getElementById("uptime_mgt") uptime_mgt.setAttribute("data-raw", stats.value)
format_duration(cell, stats.value) format_duration(uptime_mgt)
} }
if (stats.name == "MAIN.uptime") { if (stats.name == "MAIN.uptime") {
var cell = document.getElementById("uptime_chld") uptime_child.setAttribute("data-raw", stats.value)
format_duration(cell, stats.value) format_duration(uptime_child)
} }
ws.send("ACK"); ws.send("ACK");
}; };
...@@ -321,6 +330,12 @@ function toggleShow0() { ...@@ -321,6 +330,12 @@ function toggleShow0() {
resetVisibility() resetVisibility()
} }
function toggleFormatting() {
formatting = !formatting
for (i = 0; i < tbody.rows.length; i++)
format(tbody.rows[i])
}
function keyUp(evt) { function keyUp(evt) {
var k = evt.which || evt.keyCode; var k = evt.which || evt.keyCode;
switch(k) { switch(k) {
...@@ -357,14 +372,21 @@ function keyUp(evt) { ...@@ -357,14 +372,21 @@ function keyUp(evt) {
window.onload = function() { window.onload = function() {
var tbl = document.getElementById("statsTbl") var tbl = document.getElementById("statsTbl")
tbody = tbl.getElementsByTagName('tbody')[0]; tbody = tbl.getElementsByTagName('tbody')[0];
var headrow = document.getElementById("headrow")
for (i = 0; i < headrow.cells.length; i++)
colClassList[i] = headrow.cells[i].classList
getD9ns() getD9ns()
getStats() getStats()
getHitrate() getHitrate()
uptime_mgt = document.getElementById("uptime_mgt")
uptime_child = document.getElementById("uptime_child")
verbose_select = document.getElementById("verbosity") verbose_select = document.getElementById("verbosity")
verbose_select.addEventListener("change", setVerbosity); verbose_select.addEventListener("change", setVerbosity);
show0_checkbox = document.getElementById("show0") show0_checkbox = document.getElementById("show0")
show0_checkbox.onclick = toggleShow0 show0_checkbox.onclick = toggleShow0
document.addEventListener("keyup", keyUp); document.addEventListener("keyup", keyUp);
scaling_checkbox = document.getElementById("scaling")
scaling_checkbox.onclick = toggleFormatting
} }
</script> </script>
...@@ -380,7 +402,7 @@ window.onload = function() { ...@@ -380,7 +402,7 @@ window.onload = function() {
</tr> </tr>
<tr class="top"> <tr class="top">
<td class="top">Uptime child:</td> <td class="top">Uptime child:</td>
<td class="top" id="uptime_chld"></td> <td class="top" id="uptime_child"></td>
</tr> </tr>
</table> </table>
...@@ -403,14 +425,14 @@ window.onload = function() { ...@@ -403,14 +425,14 @@ window.onload = function() {
<br /> <br />
<table id="statsTbl"> <table id="statsTbl">
<thead> <thead>
<tr> <tr id="headrow">
<th class="name">NAME</th> <th class="name">NAME</th>
<th>CURRENT&nbsp;</th> <th class="int">CURRENT&nbsp;</th>
<th>CHANGE&nbsp;</th> <th class="avg current">CHANGE&nbsp;</th>
<th>AVERAGE&nbsp;</th> <th class="avg uptime">AVERAGE&nbsp;</th>
<th>AVG_10&nbsp;</th> <th class="avg moving">AVG_10&nbsp;</th>
<th>AVG_100&nbsp;</th> <th class="avg moving">AVG_100&nbsp;</th>
<th>AVG_1000&nbsp;</th> <th class="avg moving">AVG_1000&nbsp;</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
...@@ -430,6 +452,10 @@ window.onload = function() { ...@@ -430,6 +452,10 @@ window.onload = function() {
<p>Current=0</p> <p>Current=0</p>
<input type="checkbox" id="show0">Show <input type="checkbox" id="show0">Show
</div> </div>
<div class="controls">
<p>&nbsp;</p>
<input type="checkbox" id="scaling" checked>Scaling
</div>
</div> </div>
</div> </div>
</body> </body>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment