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:

    1. /** Creates a new FirstCollection
    2. *
    3. * Creates a new FirstCollection-Item. The information has to be in the
    4. * requestBody.
    5. */
    6. controller.post('/firstCollection', function (req, res) {
    7. var firstCollection = req.params('firstCollection');
    8. firstCollection.attributes.Date = Date.now();
    9. res.json(FirstCollection_repo.save(firstCollection).forClient());
    10. }).bodyParam('firstCollection', {
    11. description: 'The FirstCollection you want to create',
    12. type: FirstCollection
    13. });

    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.

    1. /**
    2. * we use a group-by construct to get the values:
    3. */
    4. var db = require('org/arangodb').db;
    5. var searchQuery = 'FOR x IN @@collection FILTER x.Date >= @until collect value=x.value with count into counter RETURN {[[CONCAT("choice", value)] : counter }';
    6. res.json(
    7. db._query(searchQuery, {
    8. '@collection': FirstCollection_repo.collection.name(),
    9. 'until': until
    10. }).toArray()
    11. );
    12. }).pathParam('nSeconds', {
    13. description: 'look up to n Seconds into the past',
    14. type: joi.string().required()
    15. });

    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:

    1. # Load the plug-in:
    2. LoadPlugin curl_json
    3. # we need to use our own types to generate individual names for our gauges:
    4. TypesDB "/etc/collectd/collectd.conf.d/foxx_simple_types.db"
    5. <Plugin curl_json>
    6. # Adjust the URL so collectd can reach your arangod:
    7. <URL "http://localhost:8529/_db/_system/collectable_foxx/data/firstCollection/firstCollection/lastSeconds/10">
    8. # Set your authentication to Aardvark here:
    9. # User "foo"
    10. Type "the_values"
    11. </Key>
    12. <Key "choice1">
    13. Type "first_values"
    14. </Key>
    15. <Key "choice2">
    16. Type "second_values"
    17. </Key>
    18. <Key "choice3">
    19. Type "third_values"
    20. </Key>
    21. <Key "choice4">
    22. Type "fourth_values"
    23. </Key>
    24. <Key "choice5">
    25. Type "fifth_values"
    26. </Key>
    27. </URL>
    28. </Plugin>