Socket
Book a DemoInstallSign in
Socket

@nokkel/monitoring

Package Overview
Dependencies
Maintainers
6
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nokkel/monitoring

A monitoring library for integrating monitoring and observability platforms and generating logs for monitoring

latest
npmnpm
Version
1.0.1
Version published
Maintainers
6
Created
Source

Nokkel Monitoring Library

A monitoring library for integrating monitoring and observability platforms and generating logs for monitoring.

How to use the library

To install this library follow the steps below:

npm add @nokkel/monitoring

Once installed you can use the library to do the following:

logger.ts

import { createLogger } from '@nokkel/monitoring';

export const logger = createLogger({
  name: process.env.HOSTNAME,
  logLevel: process.env.LOG_LEVEL,

  // Can optionally configure the logger for the browser
  // isBrowser: true,
});

Enjoy!

Grafana Stack (Loki, Prometheus, Tempo)

Loki logging

logger.loki.ts

import { createLokiLogger } from '@nokkel/monitoring/grafana';

export const logger = createLokiLogger({
  name: process.env.SERVICE_NAME || 'my-service',
  logLevel: (process.env.LOG_LEVEL as any) || 'info',
  loki: {
    host: process.env.LOKI_URL || 'http://localhost:3100',
    labels: { service: 'my-service', env: process.env.NODE_ENV || 'dev' },
  },
});

logger.info({ msg: 'hello loki' });

Alternatively, compose your own pino with a Loki destination:

import { createLogger } from '@nokkel/monitoring';
import { createLokiDestination } from '@nokkel/monitoring/grafana';

const destination = createLokiDestination({ host: 'http://localhost:3100' });
export const logger = createLogger({ name: 'svc', logLevel: 'info', destination });

Prometheus metrics

Expose a /metrics endpoint Prometheus/Grafana Agent can scrape.

import { initMetrics, startMetricsServer, promClient } from '@nokkel/monitoring/metrics';

// set default labels and collect Node process metrics
initMetrics({ defaultLabels: { service: 'my-service' } });

// define custom metrics
export const requests = new promClient.Counter({ name: 'http_requests_total', help: 'Total HTTP requests' });

// start a metrics server on :9464/metrics
startMetricsServer({ port: 9464 });

OpenTelemetry tracing (Tempo)

Send traces via OTLP HTTP to Grafana Agent or Tempo.

import { initTracing } from '@nokkel/monitoring/tracing';

await initTracing({
  serviceName: 'my-service',
  serviceVersion: '1.0.0',
  environment: process.env.NODE_ENV || 'dev',
  otlpUrl: process.env.OTLP_TRACES_URL || 'http://localhost:4318/v1/traces',
});

// Your app code; auto-instrumentations cover http/express/etc.

Notes:

  • Loki logging uses pino-loki. Ensure Grafana Loki accepts pushes at LOKI_URL.
  • Metrics use prom-client and are scrape-based (no Pushgateway assumed).
  • Traces use OpenTelemetry OTLP/HTTP; point OTLP_TRACES_URL to Grafana Agent/Tempo.

Keywords

app

FAQs

Package last updated on 15 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts