Skip to content

Commit

Permalink
Add Report and Server documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
larzconwell committed Oct 10, 2013
1 parent 94c0df5 commit 5ec9902
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
40 changes: 40 additions & 0 deletions support/reference/Report.md
@@ -0,0 +1,40 @@
Report tracks multiple metric instruments in a structured way with namespaces.

Report implements: [`addMetric()`](#Report.addMetric), [`getMetric()`](#Report.getMetric), [`summary()`](#Report.summary)

### Instantiate
`Report` is an exported constructor in `metrics`.

```
var metrics = require('metrics'),
report = new metrics.Report();
report.addMetric('namespace.name', new metrics.Counter());
report.addMetric('counter', new metrics.Counter());
report.summary(); // {...}
```

Metrics can be structured by using namespaces, to put an instrument behind a namespace include the namespace before the metrics name followed by a period(e.g. `namespace.name`).

You can also include metrics already being tracked when instantiating the report. To do this, when you create an instance give it an object in the format
```
{
namespace: { name: new metrics.Counter() },
'': {counter: new metrics.Counter()} // Items without a namespace
}
```

### .addMetric
`Report.addMetric(eventName, metric)`

Add a new metric instrument to the given event name.

### .getMetric
`Report.getMetric(eventName)`

Retrieve the metric for the given event name.

### .summary
`Report.summary()`

Get a summary of the metric instruments being tracked in a readable format.
25 changes: 25 additions & 0 deletions support/reference/Server.md
@@ -0,0 +1,25 @@
Server is an HTTP server that prints summaries for a `Report`.

Report implements: [`addMetric()`](#Server.addMetric)

### Instantiate
`Server` is an exported constructor in `metrics`.

```
var metrics = require('metrics'),
server = new metrics.Server(3000);
server.addMetric('namespace.name', new metrics.Counter());
server.addMetric('counter', new metrics.Counter());
```

The server takes a port argument, and optionally a object of metrics to track, for this format please check the `Report` instantiation documentation.

The server responds with the report summary in JSON format at the endpoint `/metrics`.

For more advanced usage of reporting, you can use the `Report` constructor and create an HTTP server that responds however you'd like.

### .addMetric
`Report.addMetric(eventName, metric)`

Delegated to the servers Report instance.

0 comments on commit 5ec9902

Please sign in to comment.