Skip to content

Commit

Permalink
format values better
Browse files Browse the repository at this point in the history
  • Loading branch information
matterkkila committed May 2, 2011
1 parent 1e88fd9 commit a73d6db
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 24 deletions.
37 changes: 34 additions & 3 deletions static/js/lib.js
@@ -1,7 +1,22 @@
var format_bytes = function(val_bytes) {
var format_numeric = function(nStr, render) {
nStr = render(nStr);
var prefix = prefix || '';
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1))
x1 = x1.replace(rgx, '$1' + ',' + '$2');
return prefix + x1 + x2;
};

var format_bytes = function(val_bytes, render) {
var new_val = 0;
var suffix = '';

val_bytes = parseInt(render(val_bytes));

if (val_bytes > 1073741824) {
new_val = val_bytes / 1073741824;
suffix = 'GB';
Expand Down Expand Up @@ -30,8 +45,24 @@ var get_stats = function() {
qfilter: $('#qfilter').val(),
},
success: function(data, textStatus, jqXHR) {
$('#servers_content').html(mustache.tmpl_servers({servers: data['servers']}));
$('#queues_content').html(mustache.tmpl_queues({queues: data['queues']}));
$('#servers_content').html(mustache.tmpl_servers({
'servers': data['servers'],
'size': function() {
return format_bytes;
},
'numeric': function() {
return format_numeric;
}
}));
$('#queues_content').html(mustache.tmpl_queues({
'queues': data['queues'],
'size': function() {
return format_bytes;
},
'numeric': function() {
return format_numeric;
}
}));
$('#error_count').html(0);
},
error: function(jqXHR, textStatus, errorThrown) {
Expand Down
42 changes: 21 additions & 21 deletions templates/index.html
Expand Up @@ -78,17 +78,17 @@
<td>{{version}}{{^version}}-{{/version}}</td>
<td>{{uptime}}{{^uptime}}-{{/uptime}}</td>
<td>{{time}}{{^time}}-{{/time}}</td>
<td>{{curr_connections}}</td>
<td>{{total_connections}}</td>
<td>{{curr_items}}</td>
<td>{{total_items}}</td>
<td>{{cmd_set}}</td>
<td>{{cmd_get}}</td>
<td>{{cmd_peek}}</td>
<td>{{get_hits}}</td>
<td>{{get_misses}}</td>
<td>{{bytes_read}}</td>
<td>{{bytes_written}}</td>
<td>{{#numeric}}{{curr_connections}}{{/numeric}}</td>
<td>{{#numeric}}{{total_connections}}{{/numeric}}</td>
<td>{{#numeric}}{{curr_items}}{{/numeric}}</td>
<td>{{#numeric}}{{total_items}}{{/numeric}}</td>
<td>{{#numeric}}{{cmd_set}}{{/numeric}}</td>
<td>{{#numeric}}{{cmd_get}}{{/numeric}}</td>
<td>{{#numeric}}{{cmd_peek}}{{/numeric}}</td>
<td>{{#numeric}}{{get_hits}}{{/numeric}}</td>
<td>{{#numeric}}{{get_misses}}{{/numeric}}</td>
<td>{{#size}}{{bytes_read}}{{/size}}</td>
<td>{{#size}}{{bytes_written}}{{/size}}</td>
{{/stats}}
</tr>
{{/servers}}
Expand Down Expand Up @@ -120,16 +120,16 @@
<tr id="{{server}}.{{queue}}" x-kestrel-server="{{server}}" x-kestrel-queue="{{queue}}">
<td>{{queue}}</td>
<td>{{server}}</td>
<td>{{logsize}}</td>
<td>{{total_items}}</td>
<td>{{expired_items}}</td>
<td>{{items}}</td>
<td>{{mem_items}}</td>
<td>{{bytes}}</td>
<td>{{mem_bytes}}</td>
<td>{{age}}</td>
<td>{{waiters}}</td>
<td>{{open_transactions}}</td>
<td>{{#size}}{{logsize}}{{/size}}</td>
<td>{{#numeric}}{{total_items}}{{/numeric}}</td>
<td>{{#numeric}}{{expired_items}}{{/numeric}}</td>
<td>{{#numeric}}{{items}}{{/numeric}}</td>
<td>{{#numeric}}{{mem_items}}{{/numeric}}</td>
<td>{{#size}}{{bytes}}{{/size}}</td>
<td>{{#size}}{{mem_bytes}}{{/size}}</td>
<td>{{#numeric}}{{age}}{{/numeric}}</td>
<td>{{#numeric}}{{waiters}}{{/numeric}}</td>
<td>{{#numeric}}{{open_transactions}}{{/numeric}}</td>
<td><a href="" class="cmd" x-kestrel-action="flush">flush</a> | <a href="" class="cmd" x-kestrel-action="delete">delete</a></td>
</tr>
{{/queues}}
Expand Down

0 comments on commit a73d6db

Please sign in to comment.