Skip to content

on-ramp/prometheus-port

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

prometheus-port CircleCI

This library is yet another prometheus client implementation, with prometheus being a bulky mess of imports and prometheus-client breaking referential transparency (it's still probably a better choice for smaller-sized projects).

Library usage

The interface defined in this package is an exact copy of that defined in prometheus-client, except:

  • Collection operations are all defined in typeclasses (e.g. Counters and Gauges use increment instead of their respective incCounter and incGauge),
  • and metrics can be registered and exported in bulk if defined inside of a matching Generic datatype.

Using metrics as usual

-- Create metrics
cntr   <- register . counter   $ Info "counter"   "counter_help"
gg     <- register . gauge     $ Info "gauge"     "gauge_help"
hstgrm <- register . histogram ( Info "histogram" "histogram_help" ) defBuckets
smmr   <- register . summary   ( Info "summary"   "summary_help"   ) defQuantiles

-- Collect some data with the metrics
increment cntr
plus 5 cntr

increment gg
plus 5 gg
decrement gg
minus 5 gg
set 5 gg

observe 2.5 hstgrm

observe 2.5 smmr

-- Extract and export metrics
cntrCurrentValue <- extract cntr
ggExported <- export gg


-- In case of vectors everything is the same, but with additional functions
vcntr <- register . vector "label" . counter $ Info "counter"   "counter_help"

withLabel "this" vcntr increment
withlabel "this" vcntr $ plus 5

vcntrExported <- export vcntr

Packing metrics into datatypes

{-# LANGUAGE DeriveGeneric #-}

-- Define a datatype that looks something like
data These f = These
                 { this :: NoIdentity f Counter
                 , that :: NoIdentity f (Vector1 Summary)
                 } deriving Generic

-- Initialize the said datatype
these :: These Metric -- You might need this if compiler cannot infer it
these = These
          (counter $ Info "this" "helpful comment")
          (vector "some" $ summary (Info "that" "helpful comment #2") def)

-- Register the metrics
registeredThese <- genericRegister these

-- Perform operations over the fields as usual
increment $ this registeredThese
withLabel "test" (that registeredThese) $ observe 6.9

-- Export metrics
bytestr <- genericExport registeredThese

About

It's like prometheus-client, except wrapped in too many types

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •