countersEngine.js 1.1 KB

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