Skip to content

Loading…

configurable caching in console.js #278

Closed
wants to merge 5 commits into from

3 participants

@vireshas

in console.js the caching that is used for counters and timers sometimes creates a confusion during the development. I also faced an issue where the timers occupied a lot of memory and statsd eventually crashed. This commit now has a configurable caching in console.js. By default caching for counters in enabled while I disable timers caching.

@mrtazz mrtazz commented on an outdated diff
backends/console.js
@@ -5,7 +5,7 @@ function ConsoleBackend(startupTime, config, emitter){
this.lastFlush = startupTime;
this.lastException = startupTime;
this.config = config.console || {};
-
+ console.log(this.config)
@mrtazz Etsy, Inc. member
mrtazz added a note

this looks like a development debug statement, can you remove it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mrtazz mrtazz commented on an outdated diff
config.js
((7 lines not shown))
, port: 8125
-, backends: [ "./backends/graphite" ]
+, backends: [ "./backends/graphite", "./backends/console" ]
@mrtazz Etsy, Inc. member
mrtazz added a note

can you add those changes to the stock exampleConfig.js file please? Also please only add it to the example comments and not to the actual configuration. We want to keep this part as simple as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@draco2003

Hey @vireshas we decided to pull caching from the backend all together so no need to configure it any longer.

Also for the http (socket-io) backend there already exists one : https://github.com/Chatham/statsd-socket.io
I have personally had a few people ask me for an example on how to use it. Can i suggest that you submit the html file and any related updates to that repo so that other people can benefit from the example html interface.

Or if its different enough from the current socket.io backend, feel free to create your own backend, and we'll add it to the supported backends list in the docs.

Thanks!

@draco2003 draco2003 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 22, 2013
  1. @vireshas
Commits on Mar 23, 2013
  1. @vireshas
Commits on Mar 25, 2013
  1. @vireshas
  2. @vireshas
  3. @vireshas
Showing with 85 additions and 8 deletions.
  1. +2 −3 backends/console.js
  2. +38 −0 backends/http.js
  3. +33 −0 backends/index.html
  4. +9 −4 exampleConfig.js
  5. +3 −1 package.json
View
5 backends/console.js
@@ -5,7 +5,6 @@ function ConsoleBackend(startupTime, config, emitter){
this.lastFlush = startupTime;
this.lastException = startupTime;
this.config = config.console || {};
-
this.statsCache = {
counters: {},
timers: {}
@@ -31,8 +30,8 @@ ConsoleBackend.prototype.flush = function(timestamp, metrics) {
});
var out = {
- counters: this.statsCache.counters,
- timers: this.statsCache.timers,
+ counters: this.config.useCounterCache === true ? this.statsCache.counters : metrics.counters,
+ timers: this.config.useTimerCache === true ? this.statsCache.timers : metrics.timers,
gauges: metrics.gauges,
timer_data: metrics.timer_data,
counter_rates: metrics.counter_rates,
View
38 backends/http.js
@@ -0,0 +1,38 @@
+/** This backend pushes the metrics to browser.
+ * Uses socket.io and the stats are pushed to browser every 10s.
+ */
+
+var util = require('util')
+var app = require('express')();
+var server = require('http').createServer(app);
+var socketIO = require('socket.io').listen(server);
+
+server.listen(8000);
+
+app.get('/', function(req, res) {
+ res.sendfile(__dirname + '/index.html');
+});
+
+function HttpBackend(startUpTime, config, emitter){
+ console.log("configuring httpbackend");
+ var self = this;
+ this.lastFlush = startUpTime;
+ this.lastException = startUpTime;
+ this.config = config.http || {};
+}
+
+push_stats = function(timestamp, metrics){
+ socketIO.sockets.emit("counters", metrics);
+}
+
+HttpBackend.prototype.status = function(write) {
+ ['lastFlush', 'lastException'].forEach(function(key) {
+ write(null, 'console', key, this[key]);
+ }, this);
+};
+
+exports.init = function(startupTime, config, events) {
+ var instance = new HttpBackend(startupTime, config, events);
+ events.on("flush", push_stats);
+ return true;
+};
View
33 backends/index.html
@@ -0,0 +1,33 @@
+<html>
+ <head>
+ <style type="text/css">
+ #counters{
+ width: 700px;
+ height: 600px;
+ overflow: scroll;
+ margin-left: 300px;
+ background-color: #d6d6c2;
+ text-shadow:1px -1px 1px #333333;
+ box-shadow:2px 2px 2px 2px #333333;
+ }
+ </style>
+ <script src="/socket.io/socket.io.js"></script>
+ <script type="text/javascript">
+ var socket = io.connect('http://localhost:8000');
+ socket.on("counters", function(metrics){
+ document.getElementById("counters").innerHTML = "<h1>Stats</h1>";
+ for(metric in metrics){
+ document.getElementById("counters").innerHTML += "<b><h3>" + metric + "</h3></b>";
+ for(key in metrics[metric]){
+ document.getElementById("counters").innerHTML += " " + key + " : " + metrics[metric][key] + "</br>";
+ }
+ }
+ });
+ </script>
+ </head>
+ <body>
+ <div id="counters">
+ <h1>Stats</h1>
+ </div>
+ </body>
+</html>
View
13 exampleConfig.js
@@ -45,8 +45,12 @@ Optional Variables:
applies to both legacy and new namespacing
console:
- prettyprint: whether to prettyprint the console backend
- output [true or false, default: true]
+ prettyprint: whether to prettyprint the console backend
+ output [true or false, default: true]
+ useCounterCache: whether to use cache for console.js counters or not
+ values [true or false]
+ useTimerCache: whether to use cache for console.js timers or not
+ values [true or false]
log: log settings [object, default: undefined]
backend: where to log: stdout or syslog [string, default: stdout]
@@ -88,7 +92,8 @@ Optional Variables:
*/
{
graphitePort: 2003
-, graphiteHost: "graphite.example.com"
+, console: { useCounterCache : true, useTimerCache : false}
+, graphiteHost: "localhost"
, port: 8125
-, backends: [ "./backends/graphite" ]
+, backends: [ "./backends/graphite", "./backends/console", "./backends/http" ]
}
View
4 package.json
@@ -18,7 +18,9 @@
"devDependencies": {
"nodeunit": "0.7.x",
"underscore": "1.4.x",
- "temp": "0.4.x"
+ "temp": "0.4.x",
+ "express": "3.0.0",
+ "socket.io": "0.9.x"
},
"optionalDependencies": {
"node-syslog":"1.1.7",
Something went wrong with that request. Please try again.