boomcatch
Standalone,
node.js-based
beacon server for boomerang.
Read more.
- boomcatch version: 1.0.0
- node.js versions: 0.8, 0.10, 0.11
Installation
At the system level
First you must
install node.
You can then
install boomcatch via npm:
npm install -g boomcatch
Local to a node.js project
Add boomcatch
to the dependencies
in your project's package.json
,
then run:
npm install
Usage
From the command line
To see
the list of command line options
run:
boomcatch --help
Available options are:
-
--host <name>
:
Host name to accept HTTP connections on.
The default is 0.0.0.0 (INADDR_ANY).
-
--port <port>
:
Port to accept HTTP connections on.
The default is 80.
-
--path <path>
:
URL path to accept requests to.
The default is /beacon.
-
--referer <regex>
:
HTTP referers to accept requests from.
The default is .*
.
-
--origin <origin>
:
Comma-separated list of URL(s)
for the Access-Control-Allow-Origin header.
The default is * (any origin),
specify 'null' to force same origin.
-
--limit <milliseconds>
:
Minimum elapsed time to allow
between requests from the same IP adderss.
The default is 0.
-
--maxSize <bytes>
:
Maximum body size to allow for POST requests.
The default is -1 (unlimited).
-
--silent
:
Prevent the command
from logging output
to the console.
-
--validator <path>
:
Validator used to accept or reject request data.
The default is permissive
(always accept requests).
-
--mapper <path>
:
Data mapper used to transform data before forwarding,
loaded with require.
The default is statsd.
-
--prefix <prefix>
:
Prefix for mapped metric names.
The default is the empty string
(no prefix).
-
--forwarder <path>
:
Forwarder used to send data,
loaded with require.
The default is udp.
-
--fwdHost <name>
:
Host name to forward mapped data to.
The default is 127.0.0.1.
This option is only effective
with the UDP forwarder.
-
--fwdPort <port>
:
Port to forward mapped data on.
The default is 8125.
This option is only effective
with the UDP forwarder.
-
--fwdUrl <url>
:
URL to forward mapped data to.
This option is only effective
with the HTTP forwarder.
-
--fwdMethod <method>
:
Method to forward mapped data with.
The default is GET.
This option is only effective
with the HTTP forwarder.
From a node.js project
var path = require('path'),
boomcatch = require('boomcatch');
boomcatch.listen({
host: 'rum.example.com',
port: 8080,
path: '/perf',
referer: /^\w+\.example\.com$/,
origin: [
'http://foo.example.com',
'http://bar.example.com'
],
limit: 100,
maxSize: 1048576,
log: console.log,
validator: path.resolve('./myvalidator'),
mapper: path.resolve('./mymapper'),
prefix: 'mystats.rum.',
forwarder: 'http',
fwdUrl: 'https://stats.example.com/',
fwdMethod: 'POST'
});
Data mappers
Mappers are used
to transform data
into appropriate formats
for back-end stats consumers.
Currently, one mapper is available out-of-the-box,
which formats the metrics
as statsd timers.
Defining a custom data mapper
is straightforward.
The source code for the statsd mapper
should be easy to follow,
but the basic pattern
is to export an interface
that looks like this:
{
initialise: function (options) {
}
}
The initialise
function
should return a function
that is passed a data object
and a referring URL
as parameters,
and returns the mapped data
as its result.
If you then specify
the path to your new mapper
with the mapper
option,
a first attempt to load it
is made relative
to this project's src/mappers
directory.
When that call to require
fails,
a second attempt will be made
using the path that you specified verbatim.
Data forwarders
Forwarders are used
to send mapped data
to back-end stats consumers.
At the moment, two forwarders are implemented,
dispatching the data over UDP or HTTP.
Defining a custom forwarder
takes broadly the same form
as defining a custom mapper
and can be seen
in the source code for the udp forwarder.
Again, the module should export
an interface that looks like this:
{
initialise: function (options) {
}
}
In this case,
the initialise
function
should return a function
that is passed
the mapped data
and a callback function
as its two parameters.
When the forwarding process has completed,
the callback function should be invoked,
following the node.js convention
of the first argument containing any error,
or a falsey value if things went okay.
The second argument should contain
the number of bytes that were sent.
Once your custom forwarder is ready,
you can specify the path to it
using the forwarder
option.
Request validators
Validators are used
to test whether each request
should be accepted or rejected.
Typically, they check
for the presence
of a valid nonce
in the query string,
as a preventative measure
against denial-of-service attacks.
One validator is available out-of-the-box,
which simply accepts all requests.
As with mappers and forwarders,
defining your own validator is easy
and the basic interface
looks the same:
{
initialise: function (options) {
}
}
Here,
the initialise
function
should return a function
that receives an object
representing the parsed query string
and returns either true
or false
,
signifying that the request
is valid or invalid respectively.
Requests that are identified as invalid
will fail with an HTTP 400 status.
Development
Before sumitting any pull requests,
please ensure that you have
adhered to the contribution guidelines.
To clone the repository:
git clone git@github.com:nature/boomcatch.git
To set up the development environment:
npm install
To lint the code:
npm run lint
To run the unit tests:
npm test
Change log
History
License
GPL 3
Copyright © 2014 Nature Publishing Group