Browse Source

ajout du support des timers

dpacaud 12 years ago
parent
commit
480c77c398
3 changed files with 16 additions and 15 deletions
  1. 2 2
      README.md
  2. 13 12
      mysql-backend.js
  3. 1 1
      tables/counters_statistics.sql

+ 2 - 2
README.md

@@ -39,14 +39,14 @@ Example :
 
 Required parameters :
 
-* `host`: MySQL instance host.
-* `port`: MySQL instance port. 
+* `host`: MySQL instance host. 
 * `user`: MySQL user.
 * `password`: MySQL password.
 * `database`: Default database where statsd table are stored.
 
 Optional parameters :
 
+* `port`: MySQL instance port.
 * `tables`: List of tables names used (see 'Customize MySQL Bakend Database' section for more details).
 * `engines`: List of MySQL Backend engines (see 'Customize MySQL Bakend Engines' section for more details).
 

+ 13 - 12
mysql-backend.js

@@ -45,8 +45,8 @@ function StatdMySQLBackend(startupTime, config, emitter) {
   };
 
   // Verifying that the config file contains enough information for this backend to work  
-  if(!this.config.host || !this.config.database || !this.config.user) {
-    console.log("You need to specify at least host, port, database and user for this mysql backend");
+  if(!this.config.host || !this.config.database || !this.config.user || !this.config.password) {
+    console.log("You need to specify at least host, port, database, user and password for this mysql backend");
     process.exit(-1);
   }
 
@@ -65,7 +65,7 @@ function StatdMySQLBackend(startupTime, config, emitter) {
 
   //Default tables
   if(!this.config.tables) {
-    this.config.tables = {counters: ["counters_statistics"], gauges: ["gauges_statistics"]};
+    this.config.tables = {counters: ["counters_statistics"], gauges: ["gauges_statistics"], timers:["timers_statistics"]};
   }
 
   // Default engines
@@ -73,7 +73,7 @@ function StatdMySQLBackend(startupTime, config, emitter) {
     self.config.engines = {
       counters: ["engines/countersEngine.js"],
       gauges: ["engines/gaugesEngine.js"],
-      timers: [],
+      timers: ["engines/timersEngine.js"],
       sets: []
     };
   }
@@ -354,6 +354,9 @@ StatdMySQLBackend.prototype.onFlush = function(time_stamp, metrics) {
   // Handle statsd gauges
   self.handleGauges(gauges,time_stamp);
   
+  // Handle statsd timers
+  self.handleTimers(timers,time_stamp);
+
 }
 
 
@@ -442,7 +445,6 @@ StatdMySQLBackend.prototype.handleGauges = function(_gauges, time_stamp) {
     // Open MySQL connection
     var canExecuteQuerries = self.openMySqlConnection();
     if(canExecuteQuerries) {
-      console.log("ok");
         //////////////////////////////////////////////////////////////////////
         // Call buildQuerries method on each counterEngine
         for(var gaugesEngineIndex in self.engines.gauges) {
@@ -493,21 +495,20 @@ StatdMySQLBackend.prototype.handleTimers = function(_timers, time_stamp) {
   // If timers received
   if(timersSize > 0) {
     console.log("Timers received !");
-    console.log("Timers = " + util.inspect(_gauges));
+    console.log("Timers = " + util.inspect(_timers));
     var querries = [];
 
     // Open MySQL connection
     var canExecuteQuerries = self.openMySqlConnection();
     if(canExecuteQuerries) {
-      console.log("ok");
         //////////////////////////////////////////////////////////////////////
         // Call buildQuerries method on each counterEngine
-        for(var gaugesEngineIndex in self.engines.gauges) {
-          console.log("gaugesEngineIndex = " + gaugesEngineIndex);
-          var gaugesEngine = self.engines.gauges[gaugesEngineIndex];
+        for(var timersEngineIndex in self.engines.timers) {
+          console.log("timersEngineIndex = " + timersEngineIndex);
+          var timersEngine = self.engines.timers[timersEngineIndex];
 
           // Add current engine querries to querries list
-          var engineQuerries = gaugesEngine.buildQuerries(_gauges, time_stamp);
+          var engineQuerries = timersEngine.buildQuerries(_timers, time_stamp);
           querries = querries.concat(engineQuerries);
 
           // Insert data into database every 100 query
@@ -550,7 +551,7 @@ StatdMySQLBackend.prototype.executeQuerries = function(sqlQuerries) {
       }
       else {
         //TODO : add better error handling code
-        console.log(" -> Query [ERROR]"); 
+        console.log(" -> Query [ERROR]" + err.code); 
       }
     });  
   }

+ 1 - 1
tables/counters_statistics.sql

@@ -1,7 +1,7 @@
 -- Stadard DELIMITER is $$
 
 -- Counters statistics table
-CREATE  TABLE `counters_statistics` (
+CREATE  TABLE `timers_statistics` (
     `timestamp` BIGINT NOT NULL ,
     `name` VARCHAR(255) NOT NULL ,
     `value` INT(11) NOT NULL ,