Project

General

Profile

Download (3.77 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
	jQuery.ajax(url, {
12
		type: 'get',
13
		success: function(data) {
14
			response = data || "";
15
			if (response != "")
16
				stats(data);
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(jQuery('#memusagemeter'))
45
		jQuery("#memusagemeter").val(x + '%');
46
	if(jQuery('#memwidtha'))
47
		jQuery("#memwidtha").css('width',x + 'px');
48
	if(jQuery('#memwidthb'))
49
		jQuery("#memwidthb").css('width', (100 - x) + 'px');
50
}
51

    
52
function updateCPU(x) {
53
	if(jQuery('#cpumeter'))
54
		jQuery("#cpumeter").val(x + '%');
55
	if(jQuery('#cpuwidtha'))
56
		jQuery("#cpuwidtha").css('width',x + 'px');
57
	if(jQuery('#cpuwidthb'))
58
		jQuery("#cpuwidthb").css('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(jQuery("#tempmeter")) {
67
		jQuery("#tempmeter").val(x + 'C');
68
		jQuery("#tempwidtha").css('width',x + 'px');
69
		jQuery("#tempwidthb").css('width',(100 - x) + 'px');
70
	}
71
}
72

    
73
function updateDateTime(x) {
74
	if(jQuery('#datetime'))
75
		jQuery("#datetime").html(x);
76
}
77

    
78
function updateUptime(x) {
79
	if(jQuery('#uptime'))
80
		jQuery("#uptime").val(x);
81
}
82

    
83
function updateState(x) {
84
	if(jQuery('#pfstate'))
85
		jQuery("#pfstate").val(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(jQuery('#gateway' + (y + 1))) {
93
				jQuery('#gateway' + (y + 1)).html(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(jQuery('#stat' + counter)) {
105
				jQuery('#stat' + counter).html(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
					jQuery('#' + details[0] + '-up').css("display","inline");
120
					jQuery('#' + details[0] + '-down').css("display","none");
121
					jQuery('#' + details[0] + '-block').css("display","none");
122
					jQuery('#' + details[0] + '-ip').html(details[2]);
123
					jQuery('#' + details[0] + '-media').html(details[3]);
124
					break;
125
				case "down":
126
					jQuery('#' + details[0] + '-down').css("display","inline");
127
					jQuery('#' + details[0] + '-up').css("display","none");
128
					jQuery('#' + details[0] + '-block').css("display","none");
129
					jQuery('#' + details[0] + '-ip').html(details[2]);
130
					jQuery('#' + details[0] + '-media').html(details[3]);
131
					break;
132
				case "block":
133
						jQuery('#' + details[0] + '-block').css("display","inline");
134
						jQuery('#' + details[0] + '-down').css("display","none");
135
						jQuery('#' + details[0] + '-up').css("display","none");
136
					break;
137
			}
138
		});
139
	}
140
}
141

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

    
150
/* start updater */
151
jQuery(document).ready(function(){
152
	setTimeout('updateMeters()', update_interval);
153
});
154

    
    (1-1/1)