Ori.livneh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/90076
Change subject: webperf: count number of CSS rules, log to Ganglia
......................................................................
webperf: count number of CSS rules, log to Ganglia
* Count the total number of CSS rules that are declared by all stylesheets on
the current page and log it to Ganglia.
* Count requests / bytes for all resources that are not JS, CSS or image
requests as 'other'; log to Ganglia.
* Simplify the asset-check.js's output JSON object format, so that it consists
of resource type keys that map to nested objects with metric keys and integer
values. This makes the object easier to decode iteratively from Python.
Change-Id: I14c9801d46003c4cdce42e0ca27c51b3640e0cbc
---
M manifests/misc/monitoring.pp
M modules/webperf/files/asset-check.js
M modules/webperf/files/asset-check.py
3 files changed, 42 insertions(+), 11 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/operations/puppet
refs/changes/76/90076/1
diff --git a/manifests/misc/monitoring.pp b/manifests/misc/monitoring.pp
index 86aca7f..2808fd7 100644
--- a/manifests/misc/monitoring.pp
+++ b/manifests/misc/monitoring.pp
@@ -371,6 +371,11 @@
metric_regex => '^assets_css_requests_*',
},
{
+ title => 'Main page CSS rules',
+ host_regex => 'client-side',
+ metric_regex => '^assets_css_rules_*',
+ },
+ {
title => 'Main page image byte payload',
host_regex => 'client-side',
metric_regex => '^assets_image_bytes_*',
@@ -380,6 +385,21 @@
host_regex => 'client-side',
metric_regex => '^assets_image_requests_*',
},
+ {
+ title => 'Main page misc. byte payload',
+ host_regex => 'client-side',
+ metric_regex => '^assets_other_bytes_*',
+ },
+ {
+ title => 'Main page misc. requests',
+ host_regex => 'client-side',
+ metric_regex => '^assets_other_requests_*',
+ },
+ {
+ title => 'Main page cookies set',
+ host_regex => 'client-side',
+ metric_regex => '^assets_cookies_set_*',
+ },
],
}
}
diff --git a/modules/webperf/files/asset-check.js
b/modules/webperf/files/asset-check.js
index e6dc4ad..0859934 100644
--- a/modules/webperf/files/asset-check.js
+++ b/modules/webperf/files/asset-check.js
@@ -40,11 +40,20 @@
phantom.exit( 1 );
}
+function countCssRules() {
+ return Array.prototype.reduce.call( document.styleSheets, function (
total, styleSheet ) {
+ return styleSheet.cssRules ? total + styleSheet.cssRules.length :
total;
+ }, 0 );
+}
+
function checkAssets( url ) {
var payload = {
- cookies : 0,
- requests : { image : 0, javascript : 0, css : 0, html : 0 },
- bytes : { image : 0, javascript : 0, css : 0, html : 0 }
+ javascript : { requests : 0, bytes : 0 },
+ html : { requests : 0, bytes : 0 },
+ css : { requests : 0, bytes : 0, rules : 0 },
+ image : { requests : 0, bytes : 0 },
+ other : { requests : 0, bytes : 0 },
+ cookies : { set: 0 },
};
var page = webpage.create();
@@ -55,16 +64,18 @@
// Analyze incoming resource
page.onResourceReceived = function ( res ) {
- var type = /image|javascript|css|html/i.exec( res.contentType );
- if ( type && res.bodySize && !/^data:/.test( res.url ) ) {
- payload.requests[type]++;
- payload.bytes[type] += res.bodySize;
+ var type = /image|javascript|css|html/i.exec( res.contentType ) ||
'other',
+ resource = payload[type];
+ if ( res.bodySize && !/^data:/.test( res.url ) ) {
+ resource.requests++;
+ resource.bytes += res.bodySize;
}
};
// Print network report
page.onLoadFinished = function () {
- payload.cookies = page.cookies.length;
+ payload.cookies.set = page.cookies.length;
+ payload.css.rules = page.evaluate( countCssRules );
console.log( JSON.stringify( payload ) );
phantom.exit( 0 );
};
diff --git a/modules/webperf/files/asset-check.py
b/modules/webperf/files/asset-check.py
index 3a72cff..2c44f10 100644
--- a/modules/webperf/files/asset-check.py
+++ b/modules/webperf/files/asset-check.py
@@ -41,12 +41,12 @@
def dispatch_stats(name, stats):
"""Send metrics to Ganglia by shelling out to gmetric."""
- for type in ('image', 'javascript', 'css'):
- for measure in ('bytes', 'requests'):
+ for type, data in stats.items():
+ for measure, value in data.items():
metric = defaults.copy()
metric.update({
'name': 'assets_%s_%s_%s' % (type, measure, name),
- 'value': stats[measure][type],
+ 'value': value,
'units': measure,
})
command = ['gmetric']
--
To view, visit https://gerrit.wikimedia.org/r/90076
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I14c9801d46003c4cdce42e0ca27c51b3640e0cbc
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Ori.livneh <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits