-
Notifications
You must be signed in to change notification settings - Fork 4
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
Metrics for page resources #26
Changes from 1 commit
2aeaf2a
1bee5a0
93f4a71
1178d40
7a86db8
1e32850
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* global window */ | ||
'use strict' | ||
var pageResources = module.exports = {} | ||
|
||
var pageChange = require('./pageChange.js') | ||
var transport = require('./transport.js') | ||
var lastIndex | ||
var timingOffset = 0 | ||
var pageStart = new Date() | ||
|
||
pageChange.onPageChange(function () { | ||
timingOffset = (new Date() - pageStart) | ||
var entries = window.performance.getEntries() | ||
for (; lastIndex++; lastIndex < entries.length) { | ||
pageResources.handleResource(entries[lastIndex]) | ||
} | ||
}) | ||
|
||
pageResources.handleResource = function (entry) { | ||
var metrics = pageResources.findRule(entry) | ||
if (!metrics) return | ||
pageResources.track(entry, metrics) | ||
} | ||
|
||
pageResources.findRule = function (entry) { | ||
var config = window.barometer.resources | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking about this for bandwidthStats:
this will give null or undefined values a default config There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was going with the idea that you don't define it if you don't want it. If you do define it, it should be an array of properties to match on and the metrics we want to capture. The default value should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does seem like one that should be disabled by default, maybe bandwidth as well, not sure? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah sorry, I've just re-read this now I'm fully behind a computer, I think we were talking about different things. I think you're right, bandwidth should be an opt-in, and maybe locked behind an |
||
if (!config) return | ||
|
||
var name = entry.name.replace(/https?:\/\//i, '').split('/') | ||
var domain = name.shift() | ||
var path = name.join('/') | ||
|
||
for (var i = 0; i < config.length; i++) { | ||
var rule = config[i] | ||
if (rule.domain && !domain.match(rule.domain)) continue | ||
if (rule.resourceRegex && !path.match(rule.resourceRegex)) continue | ||
if (rule.type && entry.entryType !== rule.type) continue | ||
return rule.metrics | ||
} | ||
return null | ||
} | ||
|
||
pageResources.track = function (entry, metrics) { | ||
var prefix = entry.name.replace(/https?:\/\//i, '').split('?')[0].replace(/[a-z0-9_]/gi, '_') | ||
|
||
for (var i in metrics) { | ||
var value = entry[i] | ||
if (value === 0) continue | ||
if (i !== 'duration') value = timingOffset - value | ||
transport.gauge(prefix + '.' + i, value) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems inconsistent to list these for pageLoad but not the others