-
Notifications
You must be signed in to change notification settings - Fork 1
/
wowza-stats.js
executable file
·80 lines (71 loc) · 2.56 KB
/
wowza-stats.js
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
#!/usr/bin/env node
// Requires.
// request, jsdom, optimist, all of which can be install with npm.
// NOTE: -----------------------------------------------------------------------
// Uses jsdom 0.2.13, 0.2.14 has a bug
// https://github.com/tmpvar/jsdom/issues/436
// Install w/ npm via `npm install [email protected]`
// -----------------------------------------------------------------------------
// Require modules.
var request = require('request'),
jsdom = require('jsdom'),
argv = require('optimist').argv;
// Make sure that at least the --uri argument was passed.
if (argv.uri.length == 0) {
console.log('URI Required! Script should be called with one argument which is the URI of the connectioncounts HTTP provider to query.');
return;
}
/**
*
*/
var Collector = {
stats: {},
get_stats: function(uri, callback) {
request({ uri: uri }, function (error, response, body) {
if (error && response.statusCode !== 200) {
console.log('Error when contacting ' + uri);
}
jsdom.env({
html: body,
scripts: [
// TODO:
// Does this end up making a network call for every time this code
// gets fired or does jsdom load it once and use it over and over?
'http://code.jquery.com/jquery.min.js'
]
}, function (err, window) {
// User jQuery to Gather some stats from the connectioncounts HTTP
// provider.
var $ = window.jQuery;
Collector.stats['connections_current'] = parseInt($('ConnectionsCurrent').html());
Collector.stats['connections_total'] = parseInt($('ConnectionsTotal').html());
Collector.stats['bytes_in'] = parseFloat($('MessagesInBytesRate').html());
Collector.stats['bytes_out'] = parseFloat($('MessagesOutBytesRate').html());
callback(window);
});
});
},
}
/**
* Wrap Collector.get_stats call in a closure it works better with setInterval.
*/
var callDelay = function() {
Collector.get_stats(argv.uri, function(response) {
// Print out collected stats.
console.log(Collector.stats);
// Show the names of all streams being viewed.
//response.jQuery('ApplicationInstance Stream Name').each(function(index, value) {
// console.log(response.jQuery(value).html().replace('%2F', '/'));
//});
});
}
// Get stats once right away.
callDelay();
// Allo repeating at specified interval if --repeat is set.
if (argv.repeat != undefined) {
// Default to every 30 seconds if no delay is specified.
if (argv.delay == undefined) {
argv.delay = 30000;
}
setInterval(callDelay, argv.delay);
}