Project

General

Profile

Download (4.98 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('#memwidtha'))
55
		jQuery("#memwidtha").css('width',x + 'px');
56
	if(jQuery('#memwidthb'))
57
		jQuery("#memwidthb").css('width', (100 - x) + 'px');
58
}
59

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

    
65
function updateMbufMeter(x) {
66
	if(jQuery('#mbufusagemeter'))
67
		jQuery("#mbufusagemeter").html(x + '%');
68
	if(jQuery('#mbufwidtha'))
69
		jQuery("#mbufwidtha").css('width',x + 'px');
70
	if(jQuery('#mbufwidthb'))
71
		jQuery("#mbufwidthb").css('width', (100 - x) + 'px');
72
}
73

    
74
function updateCPU(x) {
75
	if(jQuery('#cpumeter'))
76
		jQuery("#cpumeter").html(x + '%');
77
	if(jQuery('#cpuwidtha'))
78
		jQuery("#cpuwidtha").css('width',x + 'px');
79
	if(jQuery('#cpuwidthb'))
80
		jQuery("#cpuwidthb").css('width',(100 - x) + 'px');
81
	/* Load CPU Graph widget if enabled */
82
	if(widgetActive('cpu_graphs')) {
83
		GraphValue(graph[0], x);
84
	}
85
}
86

    
87
function updateTemp(x) {
88
	if(jQuery("#tempmeter"))
89
		jQuery("#tempmeter").html(x + '\u00B0' + 'C');
90
        if(jQuery('#tempwidtha'))
91
		jQuery("#tempwidtha").css('width',x + 'px');
92
        if(jQuery('#tempwidthb'))
93
		jQuery("#tempwidthb").css('width',(100 - x) + 'px');
94
}
95

    
96
function updateDateTime(x) {
97
	if(jQuery('#datetime'))
98
		jQuery("#datetime").html(x);
99
}
100

    
101
function updateUptime(x) {
102
	if(jQuery('#uptime'))
103
		jQuery("#uptime").html(x);
104
}
105

    
106
function updateState(x) {
107
	if(jQuery('#pfstate'))
108
		jQuery("#pfstate").html(x);
109
}
110

    
111
function updateStateMeter(x) {
112
	if(jQuery('#pfstateusagemeter'))
113
		jQuery("#pfstateusagemeter").html(x + '%');
114
	if(jQuery('#pfstatewidtha'))
115
		jQuery("#pfstatewidtha").css('width',x + 'px');
116
	if(jQuery('#pfstatewidthb'))
117
		jQuery("#pfstatewidthb").css('width',(100 - x) + 'px');
118
}
119

    
120
function updateGatewayStats(x){
121
	if (widgetActive("gateways")){
122
		gateways_split = x.split(",");
123
		for (var y=0; y<gateways_split.length; y++){
124
			if(jQuery('#gateway' + (y + 1))) {
125
				jQuery('#gateway' + (y + 1)).html(gateways_split[y]);
126
			}
127
		}
128
	}
129
}
130

    
131
function updateCpuFreq(x) {
132
	if(jQuery('#cpufreq'))
133
		jQuery("#cpufreq").html(x);
134
}
135

    
136
function updateLoadAverage(x) {
137
	if(jQuery('#load_average'))
138
		jQuery("#load_average").html(x);
139
}
140

    
141
function updateInterfaceStats(x){
142
	if (widgetActive("interface_statistics")){
143
		statistics_split = x.split(",");
144
		var counter = 1;
145
		for (var y=0; y<statistics_split.length-1; y++){
146
			if(jQuery('#stat' + counter)) {
147
				jQuery('#stat' + counter).html(statistics_split[y]);
148
				counter++;	
149
			}
150
		}
151
	}
152
}
153

    
154
function updateInterfaces(x){
155
	if (widgetActive("interfaces")){
156
		interfaces_split = x.split("~");
157
		interfaces_split.each(function(iface){
158
			details = iface.split(",");
159
			switch(details[1]) {
160
				case "up":
161
					jQuery('#' + details[0] + '-up').css("display","inline");
162
					jQuery('#' + details[0] + '-down').css("display","none");
163
					jQuery('#' + details[0] + '-block').css("display","none");
164
					jQuery('#' + details[0] + '-ip').html(details[2]);
165
					jQuery('#' + details[0] + '-media').html(details[3]);
166
					break;
167
				case "down":
168
					jQuery('#' + details[0] + '-down').css("display","inline");
169
					jQuery('#' + details[0] + '-up').css("display","none");
170
					jQuery('#' + details[0] + '-block').css("display","none");
171
					jQuery('#' + details[0] + '-ip').html(details[2]);
172
					jQuery('#' + details[0] + '-media').html(details[3]);
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') != "none"))
187
		return true;
188
	else
189
		return false;
190
}
191

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