Skip to content

Commit ff78170

Browse files
author
linuxitux
committed
Reduced size of graphics
1 parent 40cb199 commit ff78170

File tree

5 files changed

+96
-37
lines changed

5 files changed

+96
-37
lines changed

graphics.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,30 @@ function draw() {
1818

1919
case 'cpu':
2020
?>
21-
<div class="metrics">
22-
<h3>CPU</h3>
23-
<canvas id="cpu" width="300" height="160">Your browser doesn't support canvas.</canvas>
21+
<div class="small-metrics">
22+
<h4>CPU</h4>
23+
<canvas id="cpu" width="140" height="85">Your browser doesn't support canvas.</canvas>
2424
</div>
2525
<?php
2626
break;
2727

2828
case 'mem':
2929
?>
30-
<div class="metrics">
31-
<h3>Memory</h3>
32-
<canvas id="mem" width="300" height="160">Your browser doesn't support canvas.</canvas>
30+
<div class="small-metrics">
31+
<h4>Memory</h4>
32+
<canvas id="mem" width="140" height="85">Your browser doesn't support canvas.</canvas>
3333
</div>
3434
<?php
3535
break;
3636

3737
case 'swp':
3838
?>
39-
<div class="metrics">
40-
<h3>Swap</h3>
41-
<canvas id="swp" width="300" height="160">Your browser doesn't support canvas.</canvas>
39+
<div class="small-metrics">
40+
<h4>Swap</h4>
41+
<canvas id="swp" width="140" height="85">Your browser doesn't support canvas.</canvas>
4242
</div>
4343
<?php
44+
4445
break;
4546

4647
case 'top':
@@ -101,7 +102,7 @@ function draw() {
101102
?>
102103
<div class="metrics">
103104
<h3>Metrics</h3>
104-
<table id="metricstable" class="metricstable" border="0" width="300px">
105+
<table id="metricstable" class="metricstable">
105106
<tr><td>CPU</td><td style="text-align: right;"><span id="cpu_value">No data.</span></td></tr>
106107
<tr><td>TPS</td><td style="text-align: right;"><span id="tps_value">No data.</span></td></tr>
107108
<tr><td>Memory</td><td style="text-align: right;"><span id="mem_value">No data.</span></td></tr>

index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
<h1>Stats for <span class="hostname"><?php echo $hostname; ?></span></h1>
3030
<h2><a class="buttons" href=".">LIVE</a>&nbsp;&#8226;&nbsp;<a class="buttons" href="?p=report">REPORT</a></h2>
31-
31+
<div id="debug"></div>
3232
<?php
3333

3434
if (isset($_GET["p"]) && $_GET["p"] == "report") {

jstats.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595

9696
// Get uptime
9797
$output = "";
98-
exec("uptime", $output);
98+
exec("LANG=C uptime", $output);
9999
$metrics['uptime'] = $output[0];
100100

101101
// Get ESTABLISHED connections

sere.js

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ var ift = ''; // ifacetxkB
99
var upt = ''; // uptime
1010
var con = ''; // connections
1111

12+
// Debug
13+
var stop = 0;
14+
1215
// Movement
1316
var speed = 10; // Boxes will move 10 pixels per step
1417
var direction = 1; // 1 moves in the positive direction; -1 vice versa
@@ -66,20 +69,30 @@ function getCanvasContext(x) {
6669
return canvas.getContext('2d');
6770
}
6871

69-
function drawClock(canvas,value) {
72+
function drawClock(canvas,value,width) {
7073
// Limits (pixels)
7174
var minx = 50;
7275
var maxx = 250;
7376
var miny = 10;
74-
var maxy = 150;
77+
var maxy = 160;
78+
79+
if (width != null) {
80+
minx = 0;
81+
maxx = width;
82+
var height = width * 0.6;
83+
miny = 0.05 * height;
84+
maxy = height;
85+
}
7586

7687
// Center coordinates
7788
cx = minx+(maxx-minx)/2;
78-
//cy = miny+(maxy-miny)/2;
79-
cy = 150;
89+
cy = maxy;
90+
91+
// Radius
92+
var radius = cx * 0.6;
8093

8194
// Clear canvas
82-
canvas.clearRect(0,0,300,160);
95+
canvas.clearRect(0,0,maxx,maxy);
8396

8497
// Draw clock background
8598
var startAngle = 1*Math.PI;
@@ -116,12 +129,16 @@ function drawClock(canvas,value) {
116129

117130
var arcs = colors.length - 1;
118131

132+
//var debug = minx+","+maxx+","+miny+","+maxy+","+radius;
133+
//document.getElementById('debug').innerHTML = debug;
134+
//stop = 1;
135+
119136
// For each color-1 draw a piece of arc
120137
for (var i=0; i<arcs; i++) {
121138

122139
// Begin new arc
123140
canvas.beginPath();
124-
canvas.lineWidth = 90;
141+
canvas.lineWidth = maxy*0.6;
125142

126143
// Select color
127144
startColor = colors[i];
@@ -137,13 +154,13 @@ function drawClock(canvas,value) {
137154
if (endAnglei > endAngle) endAnglei = endAngle;
138155

139156
// Define current arc
140-
canvas.arc(cx,cy,cx-minx-20,startAnglei,endAnglei,false);
157+
canvas.arc(cx,cy,radius,startAnglei,endAnglei,false);
141158

142159
// Compute start and end points for current gradient
143-
startX = cx+(cx-minx-20)*Math.cos(startAnglei);
144-
startY = cy+(cx-minx-20)*Math.sin(startAnglei);
145-
endX = cx+(cx-minx-20)*Math.cos(endAnglei);
146-
endY = cy+(cx-minx-20)*Math.sin(endAnglei);
160+
startX = cx+(radius)*Math.cos(startAnglei);
161+
startY = cy+(radius)*Math.sin(startAnglei);
162+
endX = cx+(radius)*Math.cos(endAnglei);
163+
endY = cy+(radius)*Math.sin(endAnglei);
147164

148165
// Define current gradient
149166
gradient = canvas.createLinearGradient(startX,startY,endX,endY);
@@ -156,20 +173,20 @@ function drawClock(canvas,value) {
156173

157174
// Draw clock hand
158175
canvas.beginPath();
159-
canvas.arc(cx,cy-10,6,2*Math.PI,false);
176+
canvas.arc(cx,cy-maxy*0.05,maxy*0.025,2*Math.PI,false);
160177
canvas.fillStyle='black';
161178
canvas.strokeStyle='black';
162-
canvas.lineWidth = 7;
179+
canvas.lineWidth = maxy*0.05;
163180
canvas.fill();
164181
canvas.stroke();
165182
canvas.beginPath();
166-
canvas.lineWidth = 4;
167-
canvas.moveTo(cx,cy-10); // move to the center
183+
canvas.lineWidth = maxy*0.025;
184+
canvas.moveTo(cx,cy-maxy*0.05); // move to the center
168185
angle = Math.PI/2 + (Math.PI * (value/100));
169186
// Calculate displacements based on radius and angle
170-
dx = -(cx-minx) * Math.sin(angle);
171-
dy = (cx-minx) * Math.cos(angle);
172-
canvas.lineTo(cx+dx,cy+dy-5);
187+
dx = -(radius*1.3) * Math.sin(angle);
188+
dy = (radius*1.3) * Math.cos(angle);
189+
canvas.lineTo(cx+dx,cy+dy-maxy*0.03);
173190
canvas.strokeStyle = 'black';
174191
canvas.stroke();
175192

@@ -226,6 +243,11 @@ function drawUptime() {
226243

227244
function updateGraphics(data) {
228245

246+
// Debug
247+
if (stop) {
248+
return;
249+
}
250+
229251
// Update Metrics chart
230252
if ((cpu !== '') && (document.getElementById('metricstable') != null)) {
231253
// Update values
@@ -243,15 +265,15 @@ function updateGraphics(data) {
243265

244266
// Update CPU chart
245267
if (document.getElementById('cpu') != null)
246-
drawClock(getCanvasContext('cpu'),cpu);
268+
drawClock(getCanvasContext('cpu'),cpu,140);
247269

248270
// Update memfree chart
249271
if (document.getElementById('mem') != null)
250-
drawClock(getCanvasContext('mem'),mem);
272+
drawClock(getCanvasContext('mem'),mem,140);
251273

252274
// Update swp chart
253275
if (document.getElementById('swp') != null)
254-
drawClock(getCanvasContext('swp'),swp);
276+
drawClock(getCanvasContext('swp'),swp,140);
255277

256278
// Update tps chart
257279
if (tps !== '' && document.getElementById('tps_value_big') != null)

template.css

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ text-decoration: underline;
3939
padding: 5px;
4040
}
4141

42+
/*
4243
h3 {
4344
font-weight: 300;
4445
1font-size: 1.1em;
@@ -47,6 +48,24 @@ margin-bottom: 10px;
4748
text-align: center;
4849
color: #666;
4950
}
51+
*/
52+
53+
h3, h4 {
54+
font-weight: 300;
55+
font-size: 1em;
56+
text-align: center;
57+
color: #666;
58+
}
59+
60+
h3 {
61+
margin-top: 5px;
62+
margin-bottom: 5px;
63+
}
64+
65+
h4 {
66+
margin-top: 0px;
67+
margin-bottom: 0px;
68+
}
5069

5170
code {
5271
font-size: 1.2em;
@@ -66,7 +85,18 @@ background-color: #fafafa;
6685
/*border: 2px solid #fafafa;*/
6786
height: 240px;
6887
display: inline-block;
69-
max-width: 300px;
88+
max-width: 280px;
89+
vertical-align: top;
90+
}
91+
92+
.small-metrics {
93+
padding: 10px;
94+
margin: 5px;
95+
background-color: #fafafa;
96+
/*border: 2px solid #fafafa;*/
97+
height: 105px;
98+
display: inline-block;
99+
max-width: 280px;
70100
vertical-align: top;
71101
}
72102

@@ -82,7 +112,7 @@ text-align: right;
82112
.smallnote {
83113
word-wrap: break-word;
84114
font-size: .75em;
85-
width: 300px;
115+
width: 280px;
86116
text-align: left;
87117
}
88118

@@ -110,7 +140,7 @@ font-size:.8em;
110140
}
111141

112142
.toptable {
113-
width: 300px;
143+
width: 280px;
114144
font-family: monospace;
115145
font-size: .9em;
116146
text-align: left;
@@ -130,7 +160,12 @@ color: #f00;
130160

131161
.uptime {
132162
text-align: left;
133-
width: 300px;
163+
width: 280px;
164+
}
165+
166+
.metricstable {
167+
width: 280px;
168+
border: 0;
134169
}
135170

136171
.metricstable td {
@@ -148,6 +183,7 @@ font-size: 0.75em;
148183
height: 360px;
149184
position: relative;
150185
z-index: 50;
186+
margin-bottom: 50px;
151187
}
152188

153189
.graph h2 {

0 commit comments

Comments
 (0)