UNPKG

rest-api-starter

Version:
40 lines (33 loc) 1.17 kB
/** * Created by svinci on 3/16/17. */ 'use strict'; const logger = require('./logger')('graphite'); const graphite = require('graphite-tcp'); const configuration = require('config'); const Promise = require('bluebird'); module.exports = { 'sendData': (data) => new Promise((resolve) => { let client = null; logger.debug('Opening graphite client.'); const graphiteConfiguration = { 'host': configuration.get('app.graphite.host'), 'port': configuration.get('app.graphite.port'), 'type': 'udp4', 'prefix': configuration.get('app.graphite.prefix'), 'callback': function(error) { if (error) { logger.warning(`Could not send data to graphite. Cause: ${error}`); } if (client) { logger.debug('Closing graphite client.'); client.close(); client = null; } } }; client = graphite.createClient(graphiteConfiguration); data.forEach((item) => client.put(item.key, item.value)); resolve(); }) };