0.3.2 • Published 9 years ago

grunt-metrics v0.3.2

Weekly downloads
1
License
-
Repository
github
Last release
9 years ago

grunt-metrics Build Status

A metrics collection and reporting plugin for Grunt.

Installation

npm install --save-dev grunt-metrics

Quick Usage

  1. Install the plugin
  2. Add grunt.loadNpmTasks("grunt-metrics") to your Gruntfile.
  3. Add metrics as your last task: grunt.registerTask("default", [ ..., "metrics" ]);

Configuration

grunt-metrics can be configured by adding a metrics property to your Grunt config.

Collectors

Collectors gather information at Grunt run time. The current collectors and their options are:

  • build: task duration recording

    no options

  • npm: package information

    optionrequireddescription
    pathfalsepath to package.json
  • git: git information

    no options

  • travis: travis-ci environment variables

    no options

A collector has the following signature:

function collectorName (config) { }

parameterdescription
configconfiguration for this collector

returns an object with the following schema:

{
    series : String,
    data   : Object
}

Configuration for a collector is looked up in metrics config using its name.

Reporters

Reporters do something with the final metrics gathered by all collectors. Reporters need to be enabled individually. The current reporters and their options are:

  • console: write fancy bar chart to console

    optiondefaultrequireddescription
    enablefalsefalseenable this reporter
    verbosefalsefalseoutput everything
    threshold0.001falseminimum duration to report
    columns80falsenumber of columns the output should use
  • json: write metrics to a json file

    optionrequireddescription
    pathfalsepath to write the json file to
  • influx: write metrics to an InfluxDB database

    optiondefaultrequireddescription
    enablefalsefalseenable this reporter
    usernamen/atruedatabase user
    passwordn/atruedatabase user's password
    databasen/atruedatabase to write series to
    hostlocalhostfalsehostname of the database
    port8086falseport InfluxDB is listening on

A reporter has the following signature:

function reporterName (config, metrics) { }

parameterdescription
configconfiguration for this reporter
metricsmetrics to report

returns a promise that is resolved when reporting is done Configuration for a reporter is looked up in metrics config using its name.

Example Gruntfile

"use strict";

module.exports = function (grunt) {

    grunt.initConfig({
        metrics : {
            collectors : {

            },
            reporters  : {
                console : {
                    verbose : true
                }
            }
        }
    });

    // Load plugins
    grunt.loadNpmTasks("grunt-metrics");

    grunt.registerTask("test", "Do some tests", function () {
        // testing here
    });

    // Register tasks
    grunt.registerTask("default", [ "test", "metrics" ]);

};

Flow

  • When the plugin is loaded, it hooks the grunt.log.header method.
    • time between calls to these methods are recorded
  • When the task is invoked:
    • All collectors are run at the same time, before reporting.
    • Results from collectors are aggregated in a metrics object like so:
      {
          result.series : result.data
      }
    • The aggregate metrics object is passed to all reporters, at the same time.

Contributing

Create a PR.

0.3.2

9 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago