gaugesEngine.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. *
  3. *
  4. */
  5. function MySQLBackendGaugesEngine() {
  6. var self = this;
  7. }
  8. /**
  9. *
  10. *
  11. */
  12. MySQLBackendGaugesEngine.prototype.buildQuerries = function(gauges, time_stamp) {
  13. var querries = [];
  14. // Iterate on each gauge
  15. for(var gaugeName in gauges) {
  16. var gaugeValue = gauges[gaugeName];
  17. if(gaugeValue === 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 `gauges_statistics` values ("+time_stamp+", '"+gaugeName+"', "+gaugeValue+");");
  28. querries.push("insert into `gauges_statistics` select "+time_stamp+", '"+gaugeName+"', "+gaugeValue+" from dual where (select if(max(value),max(value),-678) from `gauges_statistics` where name = '"+gaugeName+"') = -678 OR (select value from `gauges_statistics` where name = '"+gaugeName+"' order by timestamp desc limit 0,1) <> "+gaugeValue+";")
  29. }
  30. }
  31. return querries;
  32. }
  33. /**
  34. *
  35. *
  36. */
  37. exports.init = function() {
  38. var instance = new MySQLBackendGaugesEngine();
  39. return instance;
  40. };