Permalink
Browse files

add examples for redis stats publisher

  • Loading branch information...
1 parent 92ff44d commit df921bf73815eccfb705b8fdcb825e37b82dc95f @bolgovr committed May 8, 2012
Showing with 34 additions and 0 deletions.
  1. +29 −0 example/redis_transport.js
  2. +5 −0 example/redis_viewer.js
@@ -0,0 +1,29 @@
+var express = require('express');
+var Stats = require('../index.js').statCollector;
+var opts = {'transport': 'redis', 'statServers': ['stats']};
+var st = new Stats(opts);
+var counters = {
+ 'ips': function (req, res) {
+ return req.connection.remoteAddress;
+ },
+ 'urls': function (req, res) {
+ return req.originalUrl;
+ },
+ 'client': function (req, res) {
+ return req.headers['user-agent'] + "::" + req.connection.remoteAddress;
+ }
+};
+var app = express.createServer();
+app.use(st.useCounters(counters)); //use counters as middleware
+st.attach(app); //expose stats object through req.stats
+
+app.get('/', function (req, res) {
+ res.send('/');
+});
+app.get('/ok', function (req, res) {
+ res.send('/ok');
+ req.stats.counter('ppls', Math.random());
+});
+
+app.listen(8080);
+console.log('example app listen on 8080 port, for getting stat subscribe to redis channel \'stats\'');
@@ -0,0 +1,5 @@
+var client = require('redis').createClient();
+client.subscribe('stats');
+client.on('message', function (channel, message) {
+ console.log('got message from ' + channel + ' : ' + message);
+});

0 comments on commit df921bf

Please sign in to comment.