Project

General

Profile

Download (5.04 KB) Statistics
| Branch: | Tag: | Revision:
1
/*   Most widgets update their backend data every 10 seconds.  11 seconds
2
 *   will ensure that we update the GUI right after the stats are updated.
3
 *   Seconds * 1000 = value
4
 */
5
var Seconds = 11;
6
var update_interval = (Math.abs(Math.ceil(Seconds))-1)*1000 + 990;
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
        setTimer();
20
}
21

    
22
function setTimer() { 
23
         timeout = window.setTimeout('updateMeters()', update_interval); 
24
}
25

    
26
function stats(x) {
27
	var values = x.split("|");
28
	if (jQuery.each(values,function(key,value){
29
		if (value == 'undefined' || value == null)
30
			return true;
31
		else
32
			return false;
33
	}))
34

    
35
        updateUptime(values[2]);
36
        updateDateTime(values[5]);
37
        updateCPU(values[0]);
38
        updateMemory(values[1]);
39
        updateState(values[3]);
40
        updateTemp(values[4]);
41
        updateInterfaceStats(values[6]);
42
        updateInterfaces(values[7]);
43
        updateGatewayStats(values[8]);
44
        updateCpuFreq(values[9]);
45
        updateLoadAverage(values[10]);
46
        updateMbuf(values[11]);
47
        updateMbufMeter(values[12]);
48
        updateStateMeter(values[13]);
49
}
50

    
51
function updateMemory(x) {
52
	if(jQuery('#memusagemeter'))
53
		jQuery("#memusagemeter").html(x + '%');
54
	if(jQuery('#memUsagePB'))
55
		jQuery('#memUsagePB').progressbar( { value: parseInt(x) } );
56
}
57

    
58
function updateMbuf(x) {
59
	if(jQuery('#mbuf'))
60
		jQuery("#mbuf").html(x);
61
}
62

    
63
function updateMbufMeter(x) {
64
	if(jQuery('#mbufusagemeter'))
65
		jQuery("#mbufusagemeter").html(x + '%');
66
	if(jQuery('#mbufPB'))
67
		jQuery('#mbufPB').progressbar( { value: parseInt(x) } );
68
}
69

    
70
function updateCPU(x) {
71
	if(jQuery('#cpumeter'))
72
		jQuery("#cpumeter").html(x + '%');
73
	if(jQuery('#cpuPB'))
74
		jQuery('#cpuPB').progressbar( { value: parseInt(x) } );
75
	/* Load CPU Graph widget if enabled */
76
	if(widgetActive('cpu_graphs')) {
77
		GraphValue(graph[0], x);
78
	}
79
}
80

    
81
function updateTemp(x) {
82
	if(jQuery("#tempmeter"))
83
		jQuery("#tempmeter").html(x + '\u00B0' + 'C');
84
        if(jQuery('#tempPB'))
85
		jQuery("#tempPB").progressbar( { value: parseInt(x) } );
86
}
87

    
88
function updateDateTime(x) {
89
	if(jQuery('#datetime'))
90
		jQuery("#datetime").html(x);
91
}
92

    
93
function updateUptime(x) {
94
	if(jQuery('#uptime'))
95
		jQuery("#uptime").html(x);
96
}
97

    
98
function updateState(x) {
99
	if(jQuery('#pfstate'))
100
		jQuery("#pfstate").html(x);
101
}
102

    
103
function updateStateMeter(x) {
104
	if(jQuery('#pfstateusagemeter'))
105
		jQuery("#pfstateusagemeter").html(x + '%');
106
	if(jQuery('#statePB'))
107
		jQuery('#statePB').progressbar( { value: parseInt(x) } );
108
}
109

    
110
function updateGatewayStats(x){
111
	if (widgetActive("gateways")){
112
		gateways_split = x.split(",");
113
		for (var y=0; y<gateways_split.length; y++){
114
			gateways_field_split = gateways_split[y].split("^");
115
			if(jQuery('#gateway' + (y + 1))) {
116
				jQuery('#gateway' + (y + 1)).html(gateways_field_split[0]);
117
				if(gateways_field_split[1]) {
118
					jQuery('#gateway' + (y + 1)).css('background-color',gateways_field_split[1]);
119
				}
120
			}
121
		}
122
	}
123
}
124

    
125
function updateCpuFreq(x) {
126
	if(jQuery('#cpufreq'))
127
		jQuery("#cpufreq").html(x);
128
}
129

    
130
function updateLoadAverage(x) {
131
	if(jQuery('#load_average'))
132
		jQuery("#load_average").html(x);
133
}
134

    
135
function updateInterfaceStats(x){
136
	if (widgetActive("interface_statistics")){
137
		statistics_split = x.split(",");
138
		var counter = 1;
139
		for (var y=0; y<statistics_split.length-1; y++){
140
			if(jQuery('#stat' + counter)) {
141
				jQuery('#stat' + counter).html(statistics_split[y]);
142
				counter++;	
143
			}
144
		}
145
	}
146
}
147

    
148
function updateInterfaces(x){
149
	if (widgetActive("interfaces")){
150
		interfaces_split = x.split("~");
151
		interfaces_split.each(function(iface){
152
			details = iface.split(",");
153
			if (details[2] == '')
154
				ipv4_details = '';
155
			else
156
				ipv4_details = details[2] + '<br />';
157
			switch(details[1]) {
158
				case "up":
159
					jQuery('#' + details[0] + '-up').css("display","inline");
160
					jQuery('#' + details[0] + '-down').css("display","none");
161
					jQuery('#' + details[0] + '-block').css("display","none");
162
					jQuery('#' + details[0] + '-ip').html(ipv4_details);
163
					jQuery('#' + details[0] + '-ipv6').html(details[3]);
164
					jQuery('#' + details[0] + '-media').html(details[4]);
165
					break;
166
				case "down":
167
					jQuery('#' + details[0] + '-down').css("display","inline");
168
					jQuery('#' + details[0] + '-up').css("display","none");
169
					jQuery('#' + details[0] + '-block').css("display","none");
170
					jQuery('#' + details[0] + '-ip').html(ipv4_details);
171
					jQuery('#' + details[0] + '-ipv6').html(details[3]);
172
					jQuery('#' + details[0] + '-media').html(details[4]);
173
					break;
174
				case "block":
175
					jQuery('#' + details[0] + '-block').css("display","inline");
176
					jQuery('#' + details[0] + '-down').css("display","none");
177
					jQuery('#' + details[0] + '-up').css("display","none");
178
					break;
179
			}
180
		});
181
	}
182
}
183

    
184
function widgetActive(x) {
185
	var widget = jQuery('#' + x + '-container');
186
	if ((widget != null) && (widget.css('display') != null) && (widget.css('display') != "none"))
187
		return true;
188
	else
189
		return false;
190
}
191

    
192
/* start updater */
193
jQuery(document).ready(function(){
194
	setTimer();
195
});
196

    
    (1-1/1)