mysql-backend.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ///////////////////////////////////////////////////////////////////////////////////
  2. // NodeJS Statsd MySQL Backend 1.0
  3. // ------------------------------------------------------------------------------
  4. //
  5. // Authors: Nicolas FRADIN, Damien PACAUD
  6. // Date: 31/10/2012
  7. //
  8. ///////////////////////////////////////////////////////////////////////////////////
  9. var _mysql = require('mysql'),
  10. _mysql_config = { pool_size: 5 }
  11. _options = {}
  12. /**
  13. * Backend Constructor
  14. *
  15. * @param startupTime
  16. * @param config
  17. * @param emmiter
  18. */
  19. function StatdMySQLBackend(startupTime, config, emitter) {
  20. var self = this;
  21. // Attach events
  22. emitter.on('flush', self.onFlush );
  23. emitter.on('status', self.onStatus );
  24. }
  25. /**
  26. *
  27. * @param time_stamp
  28. * @param metrics
  29. */
  30. StatdMySQLBackend.prototype.onFlush = function(time_stamp, metrics) {
  31. }
  32. /**
  33. *
  34. * @param error
  35. * @param backend_name
  36. * @param stat_name
  37. * @param stat_value
  38. */
  39. StatdMySQLBackend.prototype.onStatus = function(error, backend_name, stat_name, stat_value) {
  40. }
  41. exports.init = function(startupTime, config, events) {
  42. var instance = new StatdMySQLBackend(startupTime, config, events);
  43. return true;
  44. };
  45. /*
  46. * Backend example : repeater.js
  47. *
  48. var util = require('util'),
  49. dgram = require('dgram');
  50. function RepeaterBackend(startupTime, config, emitter){
  51. var self = this;
  52. this.config = config.repeater || [];
  53. this.sock = dgram.createSocket('udp6');
  54. // attach
  55. emitter.on('packet', function(packet, rinfo) { self.process(packet, rinfo); });
  56. };
  57. RepeaterBackend.prototype.process = function(packet, rinfo) {
  58. var self = this;
  59. hosts = self.config;
  60. for(var i=0; i<hosts.length; i++) {
  61. self.sock.send(packet,0,packet.length,hosts[i].port,hosts[i].host,
  62. function(err,bytes) {
  63. if (err) {
  64. console.log(err);
  65. }
  66. });
  67. }
  68. };
  69. exports.init = function(startupTime, config, events) {
  70. var instance = new RepeaterBackend(startupTime, config, events);
  71. return true;
  72. };
  73. */