# prom2json-stream

> Parse Prometheus exporter metrics to JSON

Latest version **1.0.12** (published 2019-06-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install prom2json-stream
pnpm add prom2json-stream
yarn add prom2json-stream
bun add prom2json-stream
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.12 |
| Published | 2019-06-07 |
| First published | 2019-06-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=8.9 |
| Dependencies | 3 |
| Unpacked size | 17.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | anasceym |

## Links

- npm: https://www.npmjs.com/package/prom2json-stream
- Repository: https://github.com/anasceym/prom2json-stream
- Homepage: https://github.com/anasceym/prom2json-stream#readme
- Issues: https://github.com/anasceym/prom2json-stream/issues
- npm.io page: https://npm.io/package/prom2json-stream

## Dependencies (3)

- [sha.js](https://npm.io/package/sha.js.md) ^2.4.11
- [through2](https://npm.io/package/through2.md) ^3.0.1
- [binary-split](https://npm.io/package/binary-split.md) ^1.0.5

## Recent versions

- 1.0.12 (latest) — 2019-06-07
- 1.0.11 — 2019-06-02
- 1.0.10 — 2019-06-02
- 1.0.2 — 2019-06-01

## README

# prom2json-stream  [![Build Status][travis-badge]][travis-url] [![codecov][codecov-badge]][codecov-url] [![npm][npm-badge]][npm-url]

`prom2json-stream` is a NodeJS stream transformer to parse Prometheus exporters' metrics into JSON

#### Example

```
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 2.787184e+06
# HELP promhttp_metric_handler_requests_total Total number of scrapes by HTTP status code.
# TYPE promhttp_metric_handler_requests_total counter
promhttp_metric_handler_requests_total{code="200"} 139170
promhttp_metric_handler_requests_total{code="500"} 0
promhttp_metric_handler_requests_total{code="503"} 0
```
transformed into

```json
[  
  {  
    "help":"Number of bytes allocated and still in use.",
    "name":"go_memstats_alloc_bytes",
    "type":"gauge",
    "value":2787184
  },
  {  
    "help":"Total number of scrapes by HTTP status code.",
    "name":"promhttp_metric_handler_requests_total",
    "type":"counter",
    "value":139170,
    "labels":{  
      "code":"200"
    }
  },
  {  
    "help":"Total number of scrapes by HTTP status code.",
    "name":"promhttp_metric_handler_requests_total",
    "type":"counter",
    "value":0,
    "labels":{  
      "code":"500"
    }
  },
  {  
    "help":"Total number of scrapes by HTTP status code.",
    "name":"promhttp_metric_handler_requests_total",
    "type":"counter",
    "value":0,
    "labels":{  
      "code":"503"
    }
  }
]
```

## Installation

Using NPM
```bash
npm install prom2json-stream
```

## Usage

From a readable stream

```javascript
var Prom2Json = require('prom2json-stream')
var split = require('binary-split')

var buffer = `
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 2.787184e+06
`
var stream = new Readable()
stream.push(buffer)
stream.push(null)

stream
  .pipe(split())
  .pipe(Prom2Json())
  .on('data', function (data) {
    console.log(data)
  })
// {
//    "help": "Number of bytes allocated and still in use.",
//    "name": "go_memstats_alloc_bytes",
//    "type": "gauge",
//    "value": 2787184
//  }
```

## Caveats

This library only accepting string/buffer that has been splitted by newline. Please consider using any working splitter (eg: [binary-split](https://github.com/maxogden/binary-split)


[travis-badge]:https://travis-ci.org/anasceym/prom2json-stream.svg?branch=master
[travis-url]:https://travis-ci.org/anasceym/prom2json-stream
[codecov-badge]:https://codecov.io/gh/anasceym/prom2json-stream/branch/master/graph/badge.svg
[codecov-url]:https://codecov.io/gh/anasceym/prom2json-stream
[npm-badge]:https://img.shields.io/npm/v/prom2json-stream.svg
[npm-url]:https://www.npmjs.com/package/prom2json-stream

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