Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: domain handling #11

Merged
merged 6 commits into from
Mar 8, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: make sure we clean setInterval
  • Loading branch information
AVVS committed Mar 8, 2017
commit 4faffe52d639ddfb1cd7692530c8bf7c44ff21ca
13 changes: 10 additions & 3 deletions lib/httpServerAgent.js
Original file line number Diff line number Diff line change
@@ -30,7 +30,6 @@ module.exports = function httpServerAgent () {
var config = SpmAgent.Config
var logger = SpmAgent.Logger
var Measured = require('measured')
var stats = Measured.createCollection()
var histogram = new Measured.Histogram()
var timer = new Measured.Timer()

@@ -39,9 +38,9 @@ module.exports = function httpServerAgent () {
reqSize: 0,
resSize: 0,
timer: timer,
stats: stats,
logger: logger,
histogram: histogram
histogram: histogram,
stats: Measured.createCollection()
}

// bind monitorHttp safely
@@ -75,11 +74,17 @@ module.exports = function httpServerAgent () {
agent.addMetrics({ ts: now, name: 'http', value: metricValue })
}

// cleanup aggregate stats
stats.end()

// create & reset new metrics
ctx.stats = Measured.createCollection()
histogram.reset()
timer.reset()
ctx.reqSize = 0
ctx.resSize = 0

// track if this is the main process
if (cluster.isMaster || process.env.NODE_APP_INSTANCE === 0 || process.env.SPM_MASTER_MODE === '1' || process.env.STARTUP === 'true') {
agent.addMetrics({
ts: now,
@@ -88,6 +93,8 @@ module.exports = function httpServerAgent () {
})
}
}, config.collectionInterval)

// unref so we can gracefully exit
if (timerId.unref) {
timerId.unref()
}