countersEngine.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. *
  3. *
  4. */
  5. function MySQLBackendCountersEngine() {
  6. var self = this;
  7. }
  8. /**
  9. *
  10. *
  11. */
  12. MySQLBackendCountersEngine.prototype.buildQuerries = function(userCounters, time_stamp) {
  13. var querries = [];
  14. // Iterate on each userCounter
  15. for(var userCounterName in userCounters) {
  16. var counterValue = userCounters[userCounterName];
  17. if(counterValue === 0) {
  18. continue;
  19. } else {
  20. /**********************************************************************
  21. * Edit following line to custumize where statsd datas are inserted
  22. *
  23. * Parameters :
  24. * - userCounterName: Counter name
  25. * - counterValue: Counter value
  26. */
  27. querries.push("insert into `counters_statistics` (`timestamp`,`name`,`value`) values(" + time_stamp + ",'" + userCounterName +"'," + counterValue + ") on duplicate key update value = value + " + counterValue + ", timestamp = " + time_stamp);
  28. }
  29. }
  30. return querries;
  31. }
  32. /**
  33. *
  34. *
  35. */
  36. exports.init = function() {
  37. var instance = new MySQLBackendCountersEngine();
  38. return instance;
  39. };