Skip to content

Commit

Permalink
Merge pull request statsd#50 from nzjess/master
Browse files Browse the repository at this point in the history
Make Graphite connection config variables optional to allow 'dry' server mode.
  • Loading branch information
kastner committed Dec 27, 2011
2 parents f86dbab + 7ac28e9 commit 03f8556
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
9 changes: 8 additions & 1 deletion exampleConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@
Required Variables:
port: StatsD listening port [default: 8125]
Graphite Required Variables:
(Leave these unset to avoid sending stats to Graphite.
Set debug flag and leave these unset to run in 'dry' debug mode -
useful for testing statsd clients without a Graphite server.)
graphiteHost: hostname or IP of Graphite server
graphitePort: port of Graphite server
port: StatsD listening port [default: 8125]
Optional Variables:
Expand Down
30 changes: 16 additions & 14 deletions stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,25 @@ config.configFile(process.argv[2], function (config, oldConfig) {

statString += 'statsd.numStats ' + numStats + ' ' + ts + "\n";

try {
var graphite = net.createConnection(config.graphitePort, config.graphiteHost);
graphite.addListener('error', function(connectionException){
if (config.graphiteHost) {
try {
var graphite = net.createConnection(config.graphitePort, config.graphiteHost);
graphite.addListener('error', function(connectionException){
if (config.debug) {
sys.log(connectionException);
}
});
graphite.on('connect', function() {
this.write(statString);
this.end();
stats['graphite']['last_flush'] = Math.round(new Date().getTime() / 1000);
});
} catch(e){
if (config.debug) {
sys.log(connectionException);
sys.log(e);
}
});
graphite.on('connect', function() {
this.write(statString);
this.end();
stats['graphite']['last_flush'] = Math.round(new Date().getTime() / 1000);
});
} catch(e){
if (config.debug) {
sys.log(e);
stats['graphite']['last_exception'] = Math.round(new Date().getTime() / 1000);
}
stats['graphite']['last_exception'] = Math.round(new Date().getTime() / 1000);
}

}, flushInterval);
Expand Down

0 comments on commit 03f8556

Please sign in to comment.