# grunt-metrics

> Grunt metrics collection.

Latest version **0.3.2** (published 2014-11-20) · 0 weekly downloads

## Install

```sh
npm install grunt-metrics
pnpm add grunt-metrics
yarn add grunt-metrics
bun add grunt-metrics
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2014-11-20 |
| First published | 2014-10-31 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Known vulnerabilities | 0 (+7 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Tyler Cross |
| Maintainers | wtcross |
| Keywords | gruntplugin, metrics |

## Links

- npm: https://www.npmjs.com/package/grunt-metrics
- Repository: git@github.com:wtcross/grunt-metrics
- Homepage: https://github.com/wtcross/grunt-metrics
- Issues: https://github.com/wtcross/grunt-metrics/issues
- npm.io page: https://npm.io/package/grunt-metrics

## Dependencies (9)

- [q](https://npm.io/package/q.md) ^1.0.1
- [chalk](https://npm.io/package/chalk.md) ^0.5.1
- [hooker](https://npm.io/package/hooker.md) ^0.2.3
- [influx](https://npm.io/package/influx.md) ^3.0.0
- [lodash](https://npm.io/package/lodash.md) ^2.4.1
- [moment](https://npm.io/package/moment.md) ^2.8.3
- [figures](https://npm.io/package/figures.md) ^1.3.3
- [shelljs](https://npm.io/package/shelljs.md) ^0.3.0
- [text-table](https://npm.io/package/text-table.md) ^0.2.0

## Recent versions

- 0.3.2 (latest) — 2014-11-20
- 0.3.1 — 2014-11-11
- 0.3.0 — 2014-11-03
- 0.2.1 — 2014-11-01
- 0.2.0 — 2014-10-31

## README

grunt-metrics [![Build Status](https://travis-ci.org/wtcross/grunt-metrics.svg)](https://travis-ci.org/wtcross/grunt-metrics)
=========

> 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

    | option | required | description            |
    |--------|----------|------------------------|
    | path   | false    | path to `package.json` |

- *git*: git information

    *no options*

- *travis*: travis-ci environment variables

    *no options*

A collector has the following signature:

#### function collectorName (config) { }

| parameter | description                        |
|-----------|------------------------------------|
| config    | configuration 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

    | option    | default  | required | description                             |
    |-----------|----------|----------|-----------------------------------------|
    | enable    | false    | false    | enable this reporter                    |
    | verbose   | false    | false    | output everything                       |
    | threshold | 0.001    | false    | minimum duration to report              |
    | columns   | 80       | false    | number of columns the output should use |

- *json*: write metrics to a json file

    | option  | required | description                    |
    |---------|----------|--------------------------------|
    | path    | false    | path to write the json file to |

- *influx*: write metrics to an InfluxDB database

    | option    | default   | required | description                             |
    |-----------|-----------|----------|-----------------------------------------|
    | enable    | false     | false    | enable this reporter                    |
    | username  |   n/a     | true     | database user                           |
    | password  |   n/a     | true     | database user's password                |
    | database  |   n/a     | true     | database to write series to             |
    | host      | localhost | false    | hostname of the database                |
    | port      | 8086      | false    | port InfluxDB is listening on           |

A reporter has the following signature:

#### function reporterName (config, metrics) { }

| parameter | description                        |
|-----------|------------------------------------|
| config    | configuration for this reporter    |
| metrics   | metrics 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.

---
_Source: https://npm.io/package/grunt-metrics · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
