Project

General

Profile

Download (4.65 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
			if(jQuery('#gateway' + (y + 1))) {
115
				jQuery('#gateway' + (y + 1)).html(gateways_split[y]);
116
			}
117
		}
118
	}
119
}
120

    
121
function updateCpuFreq(x) {
122
	if(jQuery('#cpufreq'))
123
		jQuery("#cpufreq").html(x);
124
}
125

    
126
function updateLoadAverage(x) {
127
	if(jQuery('#load_average'))
128
		jQuery("#load_average").html(x);
129
}
130

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

    
144
function updateInterfaces(x){
145
	if (widgetActive("interfaces")){
146
		interfaces_split = x.split("~");
147
		interfaces_split.each(function(iface){
148
			details = iface.split(",");
149
			switch(details[1]) {
150
				case "up":
151
					jQuery('#' + details[0] + '-up').css("display","inline");
152
					jQuery('#' + details[0] + '-down').css("display","none");
153
					jQuery('#' + details[0] + '-block').css("display","none");
154
					jQuery('#' + details[0] + '-ip').html(details[2]);
155
					jQuery('#' + details[0] + '-media').html(details[3]);
156
					break;
157
				case "down":
158
					jQuery('#' + details[0] + '-down').css("display","inline");
159
					jQuery('#' + details[0] + '-up').css("display","none");
160
					jQuery('#' + details[0] + '-block').css("display","none");
161
					jQuery('#' + details[0] + '-ip').html(details[2]);
162
					jQuery('#' + details[0] + '-media').html(details[3]);
163
					break;
164
				case "block":
165
						jQuery('#' + details[0] + '-block').css("display","inline");
166
						jQuery('#' + details[0] + '-down').css("display","none");
167
						jQuery('#' + details[0] + '-up').css("display","none");
168
					break;
169
			}
170
		});
171
	}
172
}
173

    
174
function widgetActive(x) {
175
	var widget = jQuery('#' + x + '-container');
176
	if ((widget != null) && (widget.css('display') != null) && (widget.css('display') != "none"))
177
		return true;
178
	else
179
		return false;
180
}
181

    
182
/* start updater */
183
jQuery(document).ready(function(){
184
	setTimer();
185
});
186

    
    (1-1/1)