2.0.9 • Published 13 days ago

@shopify/koa-metrics v2.0.9

Weekly downloads
1,543
License
MIT
Repository
github
Last release
13 days ago

@shopify/koa-metrics

Build Status Build Status License: MIT npm version

Opinionated performance metric tracking for Koa, implemented with DogStatsD.

Installation

yarn add @shopify/koa-metrics

Usage

import Koa from 'koa';
import metrics from '@shopify/koa-metrics';

const app = new Koa();

app.use(
  metrics({
    prefix: 'AppName',
    host: 'some-statsd-host.com:8125',
  }),
);

Options

The passed in options object adheres to the following API:

prefix (required)

The global StatsD metric name prefix; should be provided in PascalCase.

host (required)

The url for the StatsD host; should be provided in the format: hostname:port.

API

An instance of the Metrics object will be available on ctx.metrics further down in the middleware stack.

Metrics

.distribution(name: string, value: number, sampleRate?: number, tags?: Tags)

Sends a distribution command with the specified value in milliseconds.

.initTimer(): Timer

Returns a new Timer started at the current process.hrtime()

Timer

.stop(): number

Returns the time, in milliseconds, since the Timer was created.

Tags

tags are an object keyed by the name of the corresponding tag. For example:

{
  name: value,
  name2: value2
}

Intelligent Defaults

The global metric name prefix is provided through the options object.

This package automatically provides performance metrics for HTTP requests.

Standard tags

  • path
  • request_method
  • response_code
  • response_type (eg. 2xx, 3xx, ...)

Default Metrics

request_time

Time to complete a request, from the application perspective.

request_queuing_time

Time before a request actually started being processed.

This metric is emitted when the application start processing a request. It relies on the presence of a header X-Request-Start set by the first HTTP hop.

request_content_length

This metric is based on the response header Content-Length. Some responses don't provide this header (chunked encoding); in those cases, this will not be reported.

2.0.9

13 days ago

2.0.8

1 month ago

2.0.5

1 year ago

2.0.7

1 year ago

2.0.6

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.4

1 year ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.5

2 years ago

1.1.0

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.9

2 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.5.6

3 years ago

0.5.4

3 years ago

0.5.3

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.5.0

3 years ago

0.4.4

4 years ago

0.4.3

4 years ago

0.4.2

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.12

4 years ago

0.3.11

4 years ago

0.3.10

4 years ago

0.3.9

4 years ago

0.3.8

4 years ago

0.3.7

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.9

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.14

5 years ago

0.1.13

5 years ago

0.1.12

5 years ago

0.1.10

5 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago