Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnishapi
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
varnishapi
Commits
8133dc3c
Commit
8133dc3c
authored
Aug 19, 2018
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
govarnishstat: Refactor and implement scale toggling.
parent
5c9b33ee
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
101 additions
and
75 deletions
+101
-75
table.go
cmd/govarnishstat/table.go
+101
-75
No files found.
cmd/govarnishstat/table.go
View file @
8133dc3c
...
@@ -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 = ". "
var uptime_mgt
var uptime_child
var suffix = [" ", "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) + " "
if (classList.contains("avg")) {
cell.innerHTML = parseFloat(val).toFixed(2) + " "
return
return
}
}
cell.innerHTML = val + " "
cell.innerHTML = val + " "
}
}
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 + " "
cell.innerHTML = days + "+" + hours + ":" + mins + ":" + secs + " "
}
}
function format_bytes(cell,
val
) {
function format_bytes(cell,
classList
) {
var
suffix = [" ", "K", "M", "G", "T", "P", "E", "Z", "Y"]
var
val = parseFloat(cell.getAttribute("data-raw"))
var i
var i
if (c
ell.c
lassList.contains("int") && val < 1024) {
if (classList.contains("int") && val < 1024) {
cell.innerHTML = val.toFixed(0) + " "
cell.innerHTML = val.toFixed(0) + " "
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") + " "
return
return
}
}
cell.innerHTML = bitmap + " "
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 = ". "
avgCell.innerHTML = ". "
}
}
row.id = d9n
s[i]
.name
row.id = d9n.name
nameCell.innerHTML = d9n
s[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_ch
i
ld"></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 </th>
<th
class="int"
>CURRENT </th>
<th>CHANGE </th>
<th
class="avg current"
>CHANGE </th>
<th>AVERAGE </th>
<th
class="avg uptime"
>AVERAGE </th>
<th>AVG_10 </th>
<th
class="avg moving"
>AVG_10 </th>
<th>AVG_100 </th>
<th
class="avg moving"
>AVG_100 </th>
<th>AVG_1000 </th>
<th
class="avg moving"
>AVG_1000 </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> </p>
<input type="checkbox" id="scaling" checked>Scaling
</div>
</div>
</div>
</div>
</div>
</body>
</body>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment