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

@nodellmcache/observability

v1.0.0

Published

Metrics, cost estimation, and reporting for NodeLLMCache

Readme

@nodellmcache/observability

Metrics, cost estimation, and reporting for NodeLLMCache. A MetricsCollector that aggregates cache events into hit rates, latency percentiles, tokens/dollars saved, and compression ratios — and a process-wide observability singleton you can drop into any cache.

Every cache manager accepts a metrics sink; MetricsCollector is a MetricsSink, so wiring it up is one line.

Install

npm install @nodellmcache/observability @nodellmcache/core

Quick start

import { observability } from '@nodellmcache/observability'
import { PromptCache } from '@nodellmcache/prompt-cache'
import { MemoryAdapter } from '@nodellmcache/memory'

// Inject the shared collector into any cache.
const cache = new PromptCache({ adapter: new MemoryAdapter(), metrics: observability })

// ... use the cache ...

const stats = await observability.snapshot()
// {
//   hits, misses, hitRate, sets, evictions,
//   tokensSaved, estimatedSavingsUSD, embeddingsReused,
//   avgLatencyMs, p95LatencyMs, p99LatencyMs,
//   compressionRatio,
//   byType: { prompt: { hits, misses, sets, evictions }, embedding: { ... } }
// }

observability.printReport() // pretty console summary

// Subscribe to live events
observability.on('cache.hit', (e) => console.log('HIT', e.cacheType))
const unsubscribe = observability.on('cache.miss', (e) => console.log('MISS', e.cacheType))
unsubscribe()

API

| Member | Description | |--------|-------------| | emit(event, data) | MetricsSink entrypoint — called by cache managers | | snapshot() | Promise<MetricsSnapshot> — point-in-time aggregate | | on(event, fn) / off(event, fn) | Subscribe / unsubscribe; on returns an unsubscribe fn | | recordCompression({ originalSize, compressedSize }) | Feed compression ratios | | compressionStats() | Aggregate ratio / saved bytes | | printReport() | Pretty console output | | reset() | Clear metrics (keeps listeners) |

Cost estimation

estimatedSavingsUSD is derived from tokensSaved and the event's provider/model against a built-in output-token price table (USD per 1M tokens). Override per collector:

import { MetricsCollector } from '@nodellmcache/observability'
const collector = new MetricsCollector({ pricing: { 'openai:gpt-4o': 10, default: 8 } })

If an event already carries estimatedCostUSD, that value is used directly.

Latency percentiles

avg/p95/p99 are computed over recent read latencies (hits + misses) using a bounded ring buffer (maxLatencySamples, default 10,000) so memory stays flat in long-running processes.

Pricing tables here and in @nodellmcache/prompt-cache are intentionally separate for now; they may be unified in a future release.

License

MIT