# prometheus-browser

> prometheus client library for browser to interact with push gateway

Latest version **0.2.3** (published 2022-12-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install prometheus-browser
pnpm add prometheus-browser
yarn add prometheus-browser
bun add prometheus-browser
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.3 |
| Published | 2022-12-03 |
| First published | 2020-12-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 252.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Yulong Ruan |
| Maintainers | ruanyu1 |
| Keywords | typescript |

## Links

- npm: https://www.npmjs.com/package/prometheus-browser
- Repository: https://github.com/ruanyl/boilerplate-ts
- Issues: https://github.com/ruanyl/boilerplate-ts/issues
- npm.io page: https://npm.io/package/prometheus-browser

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.2.3 (latest) — 2022-12-03
- 0.2.2 — 2022-11-26
- 0.2.1 — 2020-12-03
- 0.1.0 — 2020-12-02

## README

# prometheus-browser ![workflow](https://github.com/ruanyl/prometheus-browser/workflows/Build%20&%20Test/badge.svg)

Prometheus client implementation for browser to interact with push gateway

## Metrics

#### Counter
```typescript
import {Counter} from 'prometheus-browser'

const counter = new Counter({
  name: 'http_request_counter',
  help: 'A counter of the total number of requests',
  labels: ['status']
})
// increase by 1
counter.inc()

// increase by value
counter.inc(2)

// with label
counter.inc(2, {status: '200'})
```

#### Gauge
```typescript
import {Gauge} from 'prometheus-browser'

const gauge = new Gauge({
  name: 'memory_usage',
  help: 'A gauge of the memory usage',
  labels: ['foo']
})
// increase by 1
gauge.inc()

// increase by value
gauge.inc(2)

// decrease by 1
gauge.dec()

// decrease by value
gauge.dec(2)

// set a value
gauge.set(0)

// with label
gauge.inc(2, {foo: 'bar'})
```

#### Histogram
```typescript
import {Histogram} from 'prometheus-browser'

const histogram = new Histogram({
  name: 'http_request_duration',
  help: 'HTTP request duration',
  labels: ['foo']
})
// observe value
histogram.observe(0.5)
histogram.observe(2)

// with custom buckets
const histogram = new Histogram({
  name: 'http_request_duration',
  help: 'HTTP request duration',
  labels: ['foo'],
  buckets: [0.5, 1, 2, 5, 10]
})

// use a timer
const timer = histogram.startTimer()
// observe a timer
timer.observeDuration()
```

#### Default labels
```typescript
import {defaultRegistry} from 'prometheus-browser'

// set default labels to a registry
// default labels will be merged with metric labels when exposing metrics from the registry
defaultRegistry.setDefaultLabels({environment: 'production'})
```

## With Push Gateway
```typescript
import {PushGateway} from 'prometheus-browser'

const gateway = new PushGateway({url: 'http://localhost:8080/metrics'})
// push metrics
// by default metrics are sent with "POST" request: https://github.com/prometheus/pushgateway#post-method
await gateway.push({job: 'pushgateway'})

// push to a group, the group is arrya of tuple: [string, string]
await gateway.push({job: 'pushgateway', group: [['client', 'foo']]})

// if you need "PUT" method: https://github.com/prometheus/pushgateway#put-method
await gateway.push({job: 'pushgateway', group: [['client', 'foo']], fetchOptions: {method: 'PUT'}})

// init gateway with fetch options, if you need apply a method or other options to every push
const gateway2 = new PushGateway({url: 'http://localhost:8080/metrics', fetchOptions: {method: 'PUT'}})
await gateway2.push({job: 'pushgateway', group: [['client', 'foo']]})
```

---
_Source: https://npm.io/package/prometheus-browser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
