Monitoring your Foxx applications
How to integrate a Foxx application into a monitoring system using the plugin.
Solution
Since Foxx native tongue is JSON, integrating it with the should be an easy exercise. We have a Foxx-Application which can receive Data and write it into a collection. We specify an easy input Model:
/** Creates a new FirstCollection
*
* Creates a new FirstCollection-Item. The information has to be in the
* requestBody.
*/
controller.post('/firstCollection', function (req, res) {
var firstCollection = req.params('firstCollection');
firstCollection.attributes.Date = Date.now();
res.json(FirstCollection_repo.save(firstCollection).forClient());
}).bodyParam('firstCollection', {
description: 'The FirstCollection you want to create',
type: FirstCollection
});
Which we may do using cURL
:
We’d expect the value to be in the range of 1 to 5. Maybe the source of this data is a web-poll or something similar.
/**
* we use a group-by construct to get the values:
*/
var db = require('org/arangodb').db;
var searchQuery = 'FOR x IN @@collection FILTER x.Date >= @until collect value=x.value with count into counter RETURN {[[CONCAT("choice", value)] : counter }';
res.json(
db._query(searchQuery, {
'@collection': FirstCollection_repo.collection.name(),
'until': until
}).toArray()
);
}).pathParam('nSeconds', {
description: 'look up to n Seconds into the past',
type: joi.string().required()
});
We inspect the return document using curl and jq for nice formatting:
We have to design the return values in a way that collectd’s config syntax can simply grab it. This Route returns an object with flat key values where keys may range from 0 to 5. We create a simple collectd configuration in /etc/collectd/collectd.conf.d/foxx_simple.conf
that matches our API:
# Load the plug-in:
LoadPlugin curl_json
# we need to use our own types to generate individual names for our gauges:
TypesDB "/etc/collectd/collectd.conf.d/foxx_simple_types.db"
<Plugin curl_json>
# Adjust the URL so collectd can reach your arangod:
<URL "http://localhost:8529/_db/_system/collectable_foxx/data/firstCollection/firstCollection/lastSeconds/10">
# Set your authentication to Aardvark here:
# User "foo"
Type "the_values"
</Key>
<Key "choice1">
Type "first_values"
</Key>
<Key "choice2">
Type "second_values"
</Key>
<Key "choice3">
Type "third_values"
</Key>
<Key "choice4">
Type "fourth_values"
</Key>
<Key "choice5">
Type "fifth_values"
</Key>
</URL>
</Plugin>