Project

General

Profile

Download (3.56 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(widgetActive('cpu_graphs')) {
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
		for (var y=0; y<gateways_split.length; y++){
92
			if($('gateway' + (y + 1))) {
93
				$('gateway' + (y + 1)).update(gateways_split[y]);
94
			}
95
		}
96
	}
97
}
98

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

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

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

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

    
    (1-1/1)