Project

General

Profile

Download (4.01 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
}
45

    
46
function updateMemory(x) {
47
	if(jQuery('#memusagemeter'))
48
		jQuery("#memusagemeter").html(x + '%');
49
	if(jQuery('#memwidtha'))
50
		jQuery("#memwidtha").css('width',x + 'px');
51
	if(jQuery('#memwidthb'))
52
		jQuery("#memwidthb").css('width', (100 - x) + 'px');
53
}
54

    
55
function updateCPU(x) {
56
	if(jQuery('#cpumeter'))
57
		jQuery("#cpumeter").html(x + '%');
58
	if(jQuery('#cpuwidtha'))
59
		jQuery("#cpuwidtha").css('width',x + 'px');
60
	if(jQuery('#cpuwidthb'))
61
		jQuery("#cpuwidthb").css('width',(100 - x) + 'px');
62
	/* Load CPU Graph widget if enabled */
63
	if(widgetActive('cpu_graphs')) {
64
		GraphValue(graph[0], x);
65
	}
66
}
67

    
68
function updateTemp(x) {
69
	if(jQuery("#tempmeter"))
70
		jQuery("#tempmeter").html(x + '\u00B0' + 'C');
71
        if(jQuery('#tempwidtha'))
72
		jQuery("#tempwidtha").css('width',x + 'px');
73
        if(jQuery('#tempwidthb'))
74
		jQuery("#tempwidthb").css('width',(100 - x) + 'px');
75
}
76

    
77
function updateDateTime(x) {
78
	if(jQuery('#datetime'))
79
		jQuery("#datetime").html(x);
80
}
81

    
82
function updateUptime(x) {
83
	if(jQuery('#uptime'))
84
		jQuery("#uptime").html(x);
85
}
86

    
87
function updateState(x) {
88
	if(jQuery('#pfstate'))
89
		jQuery("#pfstate").html(x);
90
}
91

    
92
function updateGatewayStats(x){
93
	if (widgetActive("gateways")){
94
		gateways_split = x.split(",");
95
		for (var y=0; y<gateways_split.length; y++){
96
			if(jQuery('#gateway' + (y + 1))) {
97
				jQuery('#gateway' + (y + 1)).html(gateways_split[y]);
98
			}
99
		}
100
	}
101
}
102

    
103
function updateInterfaceStats(x){
104
	if (widgetActive("interface_statistics")){
105
		statistics_split = x.split(",");
106
		var counter = 1;
107
		for (var y=0; y<statistics_split.length-1; y++){
108
			if(jQuery('#stat' + counter)) {
109
				jQuery('#stat' + counter).html(statistics_split[y]);
110
				counter++;	
111
			}
112
		}
113
	}
114
}
115

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

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

    
154
/* start updater */
155
jQuery(document).ready(function(){
156
	setTimer();
157
});
    (1-1/1)