data-prometheus: Prometheus metrics text format

[ bsd3, library, metrics ] [ Propose Tags ] [ Report a vulnerability ]

Pure Prometheus metrics text data parser and builder


[Skip to Readme]

Flags

Automatic Flags
NameDescriptionDefault
buildexecutable

Build example executable

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Dependencies attoparsec, base (>=4.7 && <5), bytestring, containers, data-prometheus, lens, mtl, text, transformers, wreq [details]
License BSD-3-Clause
Copyright 2024 Sorki
Author Sorki
Maintainer srk@48.io
Category Metrics
Home page https://github.com/sorki/data-prometheus
Source repo head: git clone https://github.com/sorki/data-prometheus
Uploaded by srk at 2025-03-29T15:42:58Z
Distributions LTSHaskell:0.1.0.0, NixOS:0.1.0.0, Stackage:0.1.0.0
Executables data-prometheus-exe
Downloads 24 total (2 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2025-03-29 [all 1 reports]

Readme for data-prometheus-0.1.0.0

[back to package description]

data-prometheus

Pure Prometheus metrics parser and builder.

Usage

Parsing metrics

import qualified Data.Prometheus import qualified Network.Wreq import qualified Data.ByteString.Lazy main :: IO () main = do r <- Network.Wreq.get "http://localhost:9100/metrics" case Data.Prometheus.parseProm (Data.ByteString.Lazy.toStrict $ r ^. responseBody) of Right result -> print result Left err -> putStrLn err 

Generating metrics

In monadic manner

{-# LANGUAGE OverloadedStrings #-} import Data.Prometheus import qualified Data.Text.IO main :: IO () main = do Data.Text.IO.putStrLn $ runMetrics (metric "readme") $ do addMetric "subMetric" (Counter 13) logError "something is not right" addMetric' ( sub "anotherSubMetric" . sub "gauge" . label "key" "val") (Gauge 13) 

or alternatively define ToMetrics instances for your data types.

Above example will output:

# HELP readme_gauge_anotherSubMetric # TYPE readme_gauge_anotherSubMetric gauge readme_gauge_anotherSubMetric{key="val"} 13.0 # HELP readme_subMetric # TYPE readme_subMetric counter readme_subMetric 13.0 # ERROR something is not right