countersEngine.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. // old strategy
  28. // querries.push("insert into `counters_statistics` select "+time_stamp+", '"+userCounterName+"' , if(max(value),max(value),0) + "+counterValue+" from `counters_statistics` where if(name = '"+userCounterName+"', 1,0) = 1 ;");
  29. // new strategy
  30. querries.push("INSERT INTO `counters_statistics` (`timestamp`, `name`, `value`) VALUES ("+time_stamp+", '"+userCounterName+"', "+counterValue+")");
  31. }
  32. }
  33. return querries;
  34. }
  35. /**
  36. *
  37. *
  38. */
  39. exports.init = function() {
  40. var instance = new MySQLBackendCountersEngine();
  41. return instance;
  42. };