npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-grafana-prom

v0.1.1

Published

Lightweight Grafana-inspired React charts for Prometheus and Thanos time-series data.

Downloads

257

Readme

react-grafana-prom

Grafana-inspired React time-series charts for Prometheus, Thanos, and monitoring dashboards.

The package is built on Recharts and keeps the data contract simple: your backend or app fetches metrics, normalizes them, and passes time-series data directly to the chart. Units are chosen by your dashboard code, because Prometheus and Thanos query responses usually do not include display units.

Install

npm install react-grafana-prom recharts

Import the CSS once in your app:

import 'react-grafana-prom/styles.css';

Quick Start

'use client';

import { TimeSeriesChart } from 'react-grafana-prom';
import 'react-grafana-prom/styles.css';

const cpuSeries = [
  {
    labels: { pod: 'orderer-0', namespace: 'hlf' },
    unit: 'percentunit',
    points: [
      [1713780000, 0.43],
      [1713780300, 0.51],
      [1713780600, 0.48],
    ],
  },
  {
    labels: { pod: 'orderer-1', namespace: 'hlf' },
    unit: 'percentunit',
    points: [
      [1713780000, 0.36],
      [1713780300, 0.41],
      [1713780600, 0.39],
    ],
  },
];

export function CpuPanel() {
  return (
    <TimeSeriesChart
      title="CPU usage"
      description="Kubernetes pods"
      series={cpuSeries}
      variant="area"
      unit="percentunit"
      theme="auto"
      legend={{ template: '{{pod}}', value: 'last' }}
      tooltip={{ sort: 'desc' }}
    />
  );
}

Data Format

type TimeSeries = {
  id?: string;
  name?: string;
  labels?: Record<string, string | number | boolean | null | undefined>;
  unit?: string;
  color?: string;
  points: Array<[number | string | Date, number | null | undefined]>;
};

Time values can be Unix seconds, Unix milliseconds, ISO strings, or Date objects.

const memory = [
  {
    name: 'peer-0',
    unit: 'bytes',
    points: [
      ['2026-04-26T10:00:00Z', 523986944],
      ['2026-04-26T10:01:00Z', 534773760],
    ],
  },
];

Units and Formatters

Prometheus metric names can hint at units, but the API response normally does not tell the chart how to format values. Prefer storing the unit with your dashboard panel or attaching it when you normalize backend data.

<TimeSeriesChart series={memorySeries} unit="bytes" />
<TimeSeriesChart series={latencySeries} unit="ms" />
<TimeSeriesChart series={cpuRatioSeries} unit="percentunit" />

Common formatter IDs:

| Category | IDs | | --- | --- | | Numbers | none, short, sishort, locale, sci | | Percent | percent, percentunit | | Data | bytes, decbytes, bits, decbits, kbytes, mbytes, gbytes | | Data rate | Bps, binBps, bps, binbps, KBs, MBs, GBs | | Time | ns, us, ms, s, m, h, d, dtdurationms, dtdurations | | Throughput | ops, reqps, rps, wps, iops, eps, mps | | Currency | currencyINR, currencyUSD, currencyEUR, currencyGBP, currencyJPY, currencyBTC | | State | bool, bool_yes_no, bool_on_off |

Custom unit patterns:

<TimeSeriesChart series={blockHeightSeries} unit="suffix:blocks" />
<TimeSeriesChart series={peerSeries} unit="suffix:peers" />
<TimeSeriesChart series={txSeries} unit="count:tx/s" />
<TimeSeriesChart series={hashRateSeries} unit="si:H/s" />
<TimeSeriesChart series={healthSeries} unit="bool:Healthy/Down" />

Register a formatter for your own domain:

import { registerValueFormat } from 'react-grafana-prom';

registerValueFormat('blockHeight', (value) => ({
  text: Math.round(value ?? 0).toLocaleString(),
  suffix: ' blocks',
}));

Layout and Sizing

The chart uses ResizeObserver, waits for a positive render size, and falls back to 300x200 when mounted inside a container that has not measured yet.

<TimeSeriesChart
  title="Transaction rate"
  series={txSeries}
  unit="count:tx/s"
  height={360}
  fallbackSize={{ width: 480, height: 260 }}
/>

Use aspectRatio when the chart should size itself from its container width:

<TimeSeriesChart series={series} aspectRatio={16 / 9} />

Legend

Legends are interactive and work with large result sets.

  • Click a legend item to hide or show that series.
  • Double-click a legend item to isolate it.
  • Ctrl, Cmd, or Alt click also isolates when behavior is toggle-or-isolate.
  • A search box appears automatically when there are many series.
  • Overflowing legends scroll inside the card.
<TimeSeriesChart
  series={podSeries}
  legend={{
    template: '{{namespace}} / {{pod}}',
    value: 'last',
    placement: 'right',
    searchable: true,
    maxHeight: 360,
  }}
/>

Tooltip

The tooltip is custom-built for dense monitoring data. It shows the timestamp and all visible series values, supports scrolling, and can sort values.

<TimeSeriesChart
  series={series}
  tooltip={{
    sort: 'desc',
    maxHeight: 240,
    timestampFormat: {
      dateStyle: 'medium',
      timeStyle: 'long',
    },
  }}
/>

Themes

Use theme="auto" to follow the user's color scheme, or force a mode:

<TimeSeriesChart series={series} theme="dark" />
<TimeSeriesChart series={series} theme="light" />

The component ships with shadcn-inspired card styling, rounded corners, subtle borders, dark mode variables, and Grafana-style chart interactions.

API

type TimeSeriesChartProps = {
  series: TimeSeries[];
  title?: React.ReactNode;
  description?: React.ReactNode;
  actions?: React.ReactNode;
  footer?: React.ReactNode;
  card?: boolean;
  unit?: string;
  variant?: 'line' | 'area';
  theme?: 'auto' | 'light' | 'dark';
  height?: number;
  aspectRatio?: number;
  fallbackSize?: { width: number; height: number };
  decimals?: number;
  colors?: string[];
  legend?: boolean | ChartLegendOptions;
  tooltip?: boolean | ChartTooltipOptions;
  showGrid?: boolean;
  syncId?: string;
  emptyState?: React.ReactNode;
};