Progressive web metrics at your fingertipz. đź’…
CLI tool and lib to gather performance metrics via Lighthouse. IN BETA.
Documentation on these metrics in the works. If you hit bugs in the metrics collection, report at Lighthouse issues.
$ npm install --global pwmetrics
# or
$ npm install --save pwmetrics
# --runs=n Does n runs (eg. 3, 5), and reports the median run's numbers.
# Median run selected by run with the median TTI.
pwmetrics http://example.com/ --runs=3
# --submit Submits results to a google spreadsheet (requires some setup)
pwmetrics http://goat.com --submit
# --json Reports json details to stdout.
pwmetrics --json http://example.com/
# returns...
# {runs: [{
# "timings": [
# {
# "name": "First Contentful Paint",
# "value": 289.642
# },
# {
# "name": "First Meaningful Paint",
# "value": 289.6
# },
# ...
# --config Provide configuration. See _Defining config_ below.
pwmetrics --config=your-own-file.js
pwmetrics --config
##
## CLI options useful for CI
##
# --expectations Assert metrics results against provides values. See _Defining expectations_ below.
pwmetrics --expectations --config=your-own-file.js
pwmetrics --expectations
##
## CLI options useful for submittiing data to services
##
# --submit Submit results to Google Sheets. See _Defining submit_ below.
pwmetrics --submit --config=your-own-file.js
pwmetrics --submit
# run pwmetrics with config in package.json
pwmetrics --config
package.json
...
"pwmetrics": {
"url": "http://example.com/",
"sheets": {
// sheets configurations
},
"expectations": {
// expectations configurations
}
}
...
# run pwmetrics with config in your-own-file.js
pwmetrics --config=your-own-file.js
your-own-file.js
module.exports = {
"url": "http://example.com/",
"flags": {
// submit: true, // submit metrics
// expectations: true // assert against the provided metric thresholds
},
"sheets": {
// sheets configuration
},
"expectations": {
// expectations configuration
}
}
# run pwmetrics with config in package.json
pwmetrics --expectations
package.json
...
"pwmetrics": {
"url": "http://example.com/",
"expectations": {
"ttfmp": {
"warn": ">=3000",
"error": ">=5000"
},
"psi": {
"warn": ">=1500",
"error": ">=3200"
}
}
}
...
# run pwmetrics with config in your-own-file.js
pwmetrics --expectations --config=your-own-file.js
your-own-file.js
module.exports = {
url: 'http://example.com/',
expectations: {
ttfmp: {
warn: '>=3000',
error: '>=5000'
},
psi: {
warn: '>=1500',
error: '>=3200'
}
}
}
Instructions:
- Copy this spreadsheet.
- Copy the ID of the spreadsheet into the config as value of
sheets.options.spreadsheetId
property. - Setup Google Developer project and get credentials. (everything in step 1 here)
- Take a
client_secret
and put it into the config as value ofsheets.options.clientSecret
property.
# run pwmetrics with config in package.json
pwmetrics --submit
package.json
...
"pwmetrics": {
"url": 'http://example.com/',
"sheets": {
"type": 'GOOGLE_SHEETS', // sheets service type. Available types: GOOGLE_SHEETS
"options": {
"spreadsheetId": "sheet_id",
"tableName": "data",
"clientSecret": {
// Data object. Can be get by (using everything in step 1 here)[https://developers.google.com/sheets/api/quickstart/nodejs#step_1_turn_on_the_api_name]
}
}
}
}
...
# run pwmetrics with config in your-own-file.js
pwmetrics --submit --config=your-own-file.js
your-own-file.js
module.exports = {
url: 'http://example.com/',
sheets: {
type: 'GOOGLE_SHEETS', // sheets service type. Available types: GOOGLE_SHEETS
options: {
spreadsheetId: 'sheet_id',
tableName: 'data',
clientSecret: {
// Follow step 1 of https://developers.google.com/sheets/api/quickstart/nodejs#step_1_turn_on_the_api_name
// Then paste resulting JSON payload as this clientSecret value
}
}
}
}
ttfcp
- First Contentful Paintttfmp
- First Meaningful Paintpsi
- Perceptual Speed Indexfv
- First Visual Changevc
- Visually Complete 100%tti
- Time to Interactivevc85
- Visually Complete 85%
disableCpuThrottling
is setfalse
by default. It means that CPU throttling5x
is enabled. To turn it off, runpwmetrcis http:example.com --disableCpuThrottling
const PWMetrics = require('pwmetrics');
const pwMetrics = new PWMetrics('http://example.com/', opts);
pwMetrics.start(); // returns Promise
flags [Object]
Feature flags. These are equal to CLI options. For example, if you want to get result in json format.
const PWMetrics = require('pwmetrics');
const pwMetrics = new PWMetrics('http://example.com/', { flags: { json: true } });
pwMetrics.start();
Default: { disableCpuThrottling: false }
expectations [Object]
Example:
const PWMetrics = require('pwmetrics');
const pwMetrics = new PWMetrics('http://example.com/', {
expectations: {
// expecations data
}
});
pwMetrics.start();
See Defining expectations above.
Default: {}
sheets [Object]
Example:
const PWMetrics = require('pwmetrics');
const pwMetrics = new PWMetrics('http://example.com/', {
sheets: {
// sheets data
}
});
pwMetrics.start();
See Defining submit above.
Default: {}
Apache 2.0. Google Inc.