# @atlassian/metrics-interface

This module just exports an interface that provides better interoperability for TypeScript services that use any kind of
metrics.

## Usage

```typescript
// Import each type as required by your use-case.
import { Metrics, Counter, Gauge, Tags, Timing } from '@atlassian/metrics-interface';

export class MyMetricsClass implements Metrics {
    // Returns a Metrics instance to be used as child.
    child(name: string, tags?: Tags): Metrics {
        /* ... */
    }

    // Create a counter metric:
    //  const counter = myMetrics.counter('page_visits');
    //  counter.incr(); // <-- increase the count
    //  counter.decr(); // <-- decrease the count
    counter(name: string, tags?: Tags): Counter {
        /* ... */
    }

    // Create a simple gauge metric:
    //  const gauge = myMetrics.gauge('cpu_percentage');
    //  gauge.set(75);
    gauge(name: string, tags?: Tags): Gauge {
        /* ... */
    }

    // Create a timer metric:
    //  const initMetric = myMetrics.timing('initialisation');
    //  const timer = initMetric.measure();
    //  ...
    //  timer.stop();
    timing(name: string, tags?: Tags): Timing {
        /* ... */
    }

    // Create a histogram metric:
    //  const initMetric = myMetrics.histogram('latency', [10, 100, 500]);
    //  const timer = initMetric.measure();
    //  ...
    //  timer.stop();
    histogram(name: string, buckets: number[], tags?: Tags): Timing {
        /* ... */
    }

    // Emit a custom event for your metrics:
    //  myMetrics.event('something_happened', 'foo bar baz quix...');
    event(title: string, description?: string): void {
        /* ... */
    }
}
```

## Implementations

For great implementations of this interface, see the following:

-   [statsd-metrics](/platform/node/platform/packages/statsd-metrics-collector/)
