Permalink
Browse files

Merge pull request #8 from dannycoates/stats

Endpoint Stats
  • Loading branch information...
2 parents df1eadc + 4af17d3 commit fe25f755992877fa7c8f665d3827321bd2bf1cba @dannycoates committed Nov 27, 2012
Showing with 27 additions and 24 deletions.
  1. +23 −1 lib/endpoint.js
  2. +3 −22 lib/pool.js
  3. +1 −1 package.json
View
@@ -3,7 +3,7 @@ var http = require('http')
var KeepAlive = require('agentkeepalive')
module.exports = function (inherits, EventEmitter) {
- var MAX_COUNT = Math.pow(2, 31) // largest smi value
+ var MAX_COUNT = Math.pow(2, 52)
var clock = Date.now()
var clockInterval = null
function noop() { return false }
@@ -64,6 +64,28 @@ module.exports = function (inherits, EventEmitter) {
}
inherits(Endpoint, EventEmitter)
+ Endpoint.prototype.stats = function () {
+ var socketNames = Object.keys(this.agent.sockets)
+ var requestCounts = []
+ for (var i = 0; i < socketNames.length; i++) {
+ var name = socketNames[i]
+ var s = this.agent.sockets[name] || []
+ for (var j = 0; j < s.length; j++) {
+ requestCounts.push(s[j]._requestCount || 1)
+ }
+ }
+ return {
+ name: this.name,
+ requestCount: this.requestCount,
+ requestRate: this.requestRate,
+ pending: this.pending,
+ successes: this.successes,
+ failures: this.failures,
+ healthy: this.healthy,
+ socketRequestCounts: requestCounts
+ }
+ }
+
Endpoint.prototype.checkTimeouts = function () {
var keys = Object.keys(this.requests)
for (var i = 0; i < keys.length; i++) {
View
@@ -157,32 +157,13 @@ module.exports = function (inherits, EventEmitter, Endpoint, RequestSet) {
return this.request(options, callback)
}
- Pool.prototype.get_stats = function () {
- var stats = {
- percent_healthy: 0,
- max_busyness: 0,
- min_busyness: Number.MAX_VALUE,
- avg_busyness: 0,
- }
- var h = 0
- var sum = 0
+ Pool.prototype.stats = function () {
+ var stats = []
var len = this.nodes.length
for (var i = 0; i < len; i++) {
var node = this.nodes[i]
- if (node.healthy) {
- h++
- var b = node.busyness()
- if (b > stats.max_busyness) {
- stats.max_busyness = b
- }
- if (b < stats.min_busyness) {
- stats.min_busyness = b
- }
- sum += b
- }
+ stats.push(node.stats())
}
- stats.percent_healthy = h / len
- stats.avg_busyness = sum / h
return stats
}
View
@@ -1,6 +1,6 @@
{
"name": "poolee",
- "version": "0.3.0",
+ "version": "0.4.0",
"description": "HTTP pool and load balancer",
"homepage": "http://github.com/dannycoates/poolee",
"author": "Danny Coates <dannycoates@gmail.com>",

0 comments on commit fe25f75

Please sign in to comment.