Skip to main content

Metrics

@eik/service exposes a metrics stream that can give insight on how the server is performing.

Usage

You access the metrics stream on the .metric property of the Eik service. In this example we'll set up an endpoint so Prometheus can periodically fetch the metrics.

tip

The metrics stream isn't tied specifically to Prometheus. See the MetricsJS documentation to learn how to consume these metrics if you don't use Prometheus.

import MetricsConsumer from "@metrics/prometheus-consumer";
import prometheus from "prom-client";
import Service from "@eik/service";
import fastify from "fastify";

const service = new Service();

const metricsConsumer = new MetricsConsumer({
client: prometheus,
});

service.metrics.pipe(metricsConsumer);

const app = fastify();
app.register(service.api());

app.get("/_/metrics", (request, reply) => {
reply.type(metricsConsumer.registry.contentType);
reply.send(metricsConsumer.registry.metrics());
});

const run = async () => {
await service.health();
await app.listen({
port: service.config.get("http.port"),
host: service.config.get("http.address"),
});
};

run();

Available metrics

Each metric provided by the server has a unique name and a type defining what type (counter, histogram, etc) of metric it is.

The server exposes these metrics.

NameTypeDescription
eik_core_auth_post_handlerhistogramTime taken in a login method
eik_core_pkg_get_handlerhistogramTime taken in a public package method
eik_core_pkg_log_handlerhistogramTime taken in a package version overview method
eik_core_pkg_put_handlerhistogramTime taken in a upload package method
eik_core_versions_get_handlerhistogramTime taken in a latest package versions method
eik_core_alias_get_handlerhistogramTime taken in a public alias method
eik_core_alias_put_handlerhistogramTime taken in a create alias method
eik_core_alias_post_handlerhistogramTime taken in a update alias method
eik_core_alias_del_handlerhistogramTime taken in a delete alias method
eik_core_map_get_handlerhistogramTime taken in a public import maps method
eik_core_map_put_handlerhistogramTime taken in a upload import maps method