Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Report and Server documentation.
- Loading branch information
1 parent
94c0df5
commit 5ec9902
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |