prometheus-sdk
v3.12.0
Published
Fully typed SDK for Prometheus. Compatible with vanilla Fetch, React Query, and SWR.
Maintainers
Readme
Prometheus JS
Fully typed SDK for the Prometheus HTTP API
Built on top of prometheus-openapi · Works with Vanilla Fetch · React Query · SWR
Install
npm install prometheus-sdkVanilla
import createClient from 'prometheus-sdk'
const client = createClient({ baseUrl: 'http://localhost:9090/api/v1' })
// Instant query
const { data: result } = await client.GET('/query', {
params: { query: { query: 'up' } },
})
console.log(result)
// Get all label names
const { data: labels } = await client.GET('/labels')
console.log(labels)Tanstack/React Query
import createQueryClient from 'prometheus-sdk/query'
const prom = createQueryClient({ baseUrl: 'http://localhost:9090/api/v1' })
function Labels() {
const { data, isLoading, error } = prom.useQuery('get', '/labels')
if (isLoading) return <div>Loading...</div>
if (error) return <div>Error: {error.message}</div>
return (
<ul>
{data?.data?.map(label => (
<li key={label}>{label}</li>
))}
</ul>
)
}SWR
import createSWR from 'prometheus-sdk/swr'
const prom = createSWR({ baseUrl: 'http://localhost:9090/api/v1' })
function Labels() {
const { data, error, isLoading } = prom.useQuery('get', '/labels')
if (isLoading) return <div>Loading...</div>
if (error) return <div>Error: {error.message}</div>
return (
<ul>
{data?.data?.map(label => (
<li key={label}>{label}</li>
))}
</ul>
)
}Types
If you need the raw OpenAPI types, they're re-exported as paths:
import { type paths } from 'prometheus-sdk'Contributing
Contributions welcome! If the change is about the OpenAPI spec itself, check if it's a better fit for the prometheus-openapi repo.
