Project

General

Profile

Download (3.6 KB) Statistics
| Branch: | Tag: | Revision:
1

    
2
/*   Most widgets update their backend data every 10 seconds.  11 seconds
3
 *   will ensure that we update the GUI right after the stats are updated.
4
 *   Seconds * 1000 = value
5
 */
6
var update_interval = 11000;
7

    
8
function updateMeters() {
9
	url = '/getstats.php'
10

    
11
	new Ajax.Request(url, {
12
		method: 'get',
13
		onSuccess: function(transport) {
14
			response = transport.responseText || "";
15
			if (response != "")
16
				stats(transport.responseText);
17
		}
18
	});
19
	setTimeout('updateMeters()', update_interval);
20
}
21

    
22
function stats(x) {
23
	var values = x.split("|");
24
	if (values.find(function(value){
25
		if (value == 'undefined' || value == null)
26
			return true;
27
		else
28
			return false;
29
	}))
30
		return;
31

    
32
	updateCPU(values[0]);
33
	updateMemory(values[1]);
34
	updateUptime(values[2]);
35
	updateState(values[3]);
36
	updateTemp(values[4]);
37
	updateDateTime(values[5]);
38
	updateInterfaceStats(values[6]);
39
	updateInterfaces(values[7]);
40
	updateGatewayStats(values[8]);
41
}
42

    
43
function updateMemory(x) {
44
	if($('memusagemeter'))
45
		$("memusagemeter").value = x + '%';
46
	if($('memwidtha'))
47
		$("memwidtha").style.width = x + 'px';
48
	if($('memwidthb'))
49
		$("memwidthb").style.width = (100 - x) + 'px';
50
}
51

    
52
function updateCPU(x) {
53
	if($('cpumeter'))
54
		$("cpumeter").value = x + '%';
55
	if($('cpuwidtha'))
56
		$("cpuwidtha").style.width = x + 'px';
57
	if($('cpuwidthb'))
58
		$("cpuwidthb").style.width = (100 - x) + 'px';
59
		/* Load CPU Graph widget if enabled */
60
		if(typeof GraphValue == 'function') {
61
			GraphValue(graph[0], x);
62
		}
63
}
64

    
65
function updateTemp(x) {
66
	if($("tempmeter")) {
67
		$("tempmeter").value = x + 'C';
68
		$("tempwidtha").style.width = x + 'px';
69
		$("tempwidthb").style.width = (100 - x) + 'px';
70
	}
71
}
72

    
73
function updateDateTime(x) {
74
	if($('datetime')) 
75
		$("datetime").firstChild.data = x;
76
}
77

    
78
function updateUptime(x) {
79
	if($('uptime'))
80
		$("uptime").value = x;
81
}
82

    
83
function updateState(x) {
84
	if($('pfstate'))
85
		$("pfstate").value = x;
86
}
87

    
88
function updateGatewayStats(x){
89
	if (widgetActive("gateways")){
90
		gateways_split = x.split(",");
91
		var counter = 1;
92
		for (var y=0; y<gateways_split.length-1; y++){
93
			if($('gateway' + counter)) {
94
				$('gateway' + counter).update(gateways_split[y]);
95
				counter++;	
96
			}
97
		}
98
	}
99
}
100

    
101
function updateInterfaceStats(x){
102
	if (widgetActive("interface_statistics")){
103
		statistics_split = x.split(",");
104
		var counter = 1;
105
		for (var y=0; y<statistics_split.length-1; y++){
106
			if($('stat' + counter)) {
107
				$('stat' + counter).update(statistics_split[y]);
108
				counter++;	
109
			}
110
		}
111
	}
112
}
113

    
114
function updateInterfaces(x){
115
	if (widgetActive("interfaces")){
116
		interfaces = x.split("~");
117
		interfaces.each(function(iface){
118
			details = iface.split(",");
119
			switch(details[1]) {
120
				case "up":
121
					$(details[0] + '-up').style.display = "inline";
122
					$(details[0] + '-down').style.display = "none";
123
					$(details[0] + '-block').style.display = "none";
124
					$(details[0] + '-ip').update(details[2]);
125
					$(details[0] + '-media').update(details[3]);
126
					break;
127
				case "down":
128
					$(details[0] + '-down').style.display = "inline";
129
					$(details[0] + '-up').style.display = "none";
130
					$(details[0] + '-block').style.display = "none";
131
					$(details[0] + '-ip').update(details[2]);
132
					$(details[0] + '-media').update(details[3]);
133
					break;
134
				case "block":
135
						$(details[0] + '-block').style.display = "inline";
136
						$(details[0] + '-down').style.display = "none";
137
						$(details[0] + '-up').style.display = "none";
138
					break;
139
			}
140
		});
141
	}
142
}
143

    
144
function widgetActive(x) {
145
	var widget = $(x + '-container');
146
	if (widget.style.display != "none")
147
		return true;
148
	else
149
		return false;
150
}
151

    
152
/* start updater */
153
document.observe('dom:loaded', function(){
154
	setTimeout('updateMeters()', update_interval);
155
});
156

    
    (1-1/1)