1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
$(function() {
function setNav(target) {
$('.navbar .nav-item a[data-target="'+target+'"]').parent().addClass('active').siblings().removeClass('active');
$('#'+target).show().siblings().hide();
}
setNav(window.sessionStorage.getItem('nav') || 'status');
$('.navbar .nav-link').on('click', function(e){
var selected = $(this).data('target');
setNav(selected);
window.sessionStorage.setItem('nav',selected);
});
$('a[href="#"]').on('click', function(e) {
e.preventDefault();
});
var valueStr = $.inmon.gauge.prototype.valueStr;
$('.year').html((new Date()).getFullYear());
function updateLicense(data) {
var type = data.license.type;
switch(type) {
case 'production':
$('#about-license').text('Production');
$('#license-type').text('Production');
$('#license-restriction').html('Use in production networks limited to single computer "' + data.license.host + '"');
break;
case 'enterprise':
$('#about-license').text('Enterprise');
$('#license-type').text('Enterprise');
$('#license-resriction').html('Use in production networks limited to single organization "' + data.license.account + '"');
break;
case 'non-production':
default:
$('#about-license').text('Research and Evaluation');
$('#license-type').text('Research and Evaluation');
$('#license-restriction').html('Only use for research purposes and evaluation purposes is permitted. All use in production networks, including production networks in academic; research; and non-profit institutions, is prohibited.');
}
$('#about-hostname').text(data.analyzer.host);
$('#about-sflowrate').text(valueStr(data.analyzer.bps) + ' bps');
$('#license-number').text(data.license.license || '');
$('#license-account').text(data.license.account || '');
if(data.license.host) {
$('#license-host').text(data.license.host);
if(data.license.host_ok) $('#license-host').removeClass('text-danger').addClass('text-success');
else $('#license-host').removeClass('text-success').addClass('text-danger');
} else $('#license-host').text('');
if(data.license.max_bps) {
$('#license-rate').text(valueStr(data.license.max_bps) + ' bps');
if(data.license.max_bps_ok) $('#license-rate').removeClass('text-danger').addClass('text-success');
else $('#license.rate').removeClass('text-success').addClass('text-warn');
} else $('#license-rate').text('');
if(data.license.expires) {
$('#license-expires').text((new Date(data.license.expires)).toDateString());
if(data.license.expires_ok) $('#license-expires').removeClass('text-danger').addClass('text-success');
else $('#license-expires').removeClass('text-success').addClass('text-warn');
} else $('#license-expires').text('');
}
(function pollLicense() {
$.ajax({
url: '../license/json',
dataType: 'json',
success: function(data) {
updateLicense(data);
},
complete: function() {
setTimeout(pollLicense, 5000);
},
timeout: 60000
});
})();
var m_agents = $('#metric-agents').gauge({label:'sFlow Agents', suffix:'', maxValue: 5000, threshold: 4000, logScale: true});
var m_sflow_bps = $('#metric-sflow-bps').gauge({label:'sFlow Bytes', suffix:'bps', maxValue: 1e10, threshold: 1e9, logScale: true, counter: true});
var m_sflow_pps = $('#metric-sflow-pps').gauge({label:'sFlow Packets', suffix: 'pps', maxValue: 50000, threshold: 40000, logScale: true, counter: true});
var m_heap = $('#metric-heap').gauge({label:'Memory', suffix:'%', maxValue: 100, threshold: 90});
var m_process = $('#metric-cpu-process').gauge({label:'CPU Process', suffix:'%', maxValue: 100, threshold: 80});
var m_system = $('#metric-cpu-system').gauge({label:'CPU System', suffix:'%', maxValue: 100, threshold: 80});
var m_script_run = $('#metric-script-run').gauge({label:'Scripts', suffix:'', maxValue: 100, threshold: 80});
var m_script_err = $('#metric-script-err').gauge({label:'Scripts Failed',suffix:'', maxValue: 10, threshold: 1});
var m_app_run = $('#metric-app-run').gauge({label:'Apps',suffix:'', maxValue: 50, threshold: 40});
var m_app_err = $('#metric-app-err').gauge({label:'Apps Failed', suffix:'', maxValue: 10, threshold: 1});
var m_http_conn_cur = $('#metric-http-conn-cur').gauge({label:'HTTP Connections', maxValue: 100, threshold: 80});
var m_http_conn_tot= $('#metric-http-conn-tot').gauge({label:'HTTP Connections', suffix: 'cps', maxValue: 1000, threshold: 800, counter: true});
function updateAnalyzer(data) {
m_sflow_bps.gauge('update', {value: data.sFlowBytesReceived * 8});
m_sflow_pps.gauge('update', {value: data.sFlowDatagramsReceived});
m_process.gauge('update', {value: 100 * data.cpuLoadProcess});
m_system.gauge('update', {value: 100 * data.cpuLoadSystem});
m_heap.gauge('update', {value: 100 * data.heapUsed / data.heapMax});
m_agents.gauge('update',{value: data.sFlowAgents});
m_http_conn_cur.gauge('update',{value: data.httpConnectionsCurrent});
m_http_conn_tot.gauge('update',{value: data.httpConnectionsTotal});
$('#about-version').html(data.updateAvailable ? data.version + ' (<a href="https://sflow-rt.com/download.php">update available</a>)': data.version);
}
(function pollAnalyzer() {
$.ajax({
url: '../analyzer/json',
dataType: 'json',
success: function(data) {
updateAnalyzer(data);
},
error: function() {
$('.gauge').addClass('warn');
},
complete: function() {
setTimeout(pollAnalyzer, 5000);
},
timeout: 60000
});
})();
function updateApps(appInfo) {
var scriptToApp = {};
var apps = Object.keys(appInfo).sort();
for(let i = 0; i < apps.length; i++) {
let rec = appInfo[apps[i]];
let scripts = rec.scripts;
for(let s = 0; s < scripts.length; s++) scriptToApp[scripts[s]] = apps[i];
}
m_app_run.gauge('update', {value: apps.length});
$.get('../scripts/json', function(scriptInfo) {
var failed = 0, running = 0, failedApps = {}, app_failed = 0;
var scripts = Object.keys(scriptInfo);
for(let i = 0; i < scripts.length; i++) {
let metrics = scriptInfo[scripts[i]];
if(metrics.alive) running++;
else if(!metrics.gracefulExit) {
failed++;
let app = scriptToApp[scripts[i]];
if(app) {
let appFailures = failedApps[app];
if(appFailures) failedApps[app]++;
else {
failedApps[app] = 1;
app_failed++;
}
}
}
}
m_script_run.gauge('update', {value: scripts.length});
m_script_err.gauge('update', {value: failed, maxValue: scripts.length });
m_app_err.gauge('update', {value: app_failed, maxValue: apps.length });
$('#app-list').empty();
if(apps.length > 0) {
for(let i = 0; i < apps.length; i++) {
let rec = appInfo[apps[i]];
let uri = rec.entry ? '../app/'+apps[i]+rec.entry : '#';
let status = failedApps[apps[i]] ? 'btn-outline-danger' : 'btn-outline-success';
let disabled = rec.entry ? '' : ' disabled';
$('#app-list').append('<a href="'+uri+'" class="btn m-1 text-truncate ' + status + disabled + '">'+apps[i]+'</a>');
}
} else {
$('#app-list').append('<p class="lead"><em>No applications installed</em></p>');
}
}, 'json');
}
(function pollApps() {
$.ajax({
url: '../apps/json',
dataType: 'json',
success: function(data) {
updateApps(data);
},
error: function() {
$('#app-list a').removeClass('btn-outline-success').addClass('btn-outline-danger');
},
complete: function() {
setTimeout(pollApps, 5000);
},
timeout: 60000
});
})();
});
|