Skip to content
Browse files

added Endpoint.stats function that returns request related statistics

  • Loading branch information...
1 parent df1eadc commit 51fa583db496161a3b16cf799baae47f6a4f5f47 @dannycoates committed Nov 26, 2012
Showing with 26 additions and 23 deletions.
  1. +23 −1 lib/endpoint.js
  2. +3 −22 lib/pool.js
View
24 lib/endpoint.js
@@ -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
25 lib/pool.js
@@ -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
}

0 comments on commit 51fa583

Please sign in to comment.
Something went wrong with that request. Please try again.