No release in over 3 years
Low commit activity in last 3 years
Generates & parses prometheus text reporting format
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.11
~> 3.7
~> 0.52
~> 0.15
 Project Readme

Gem Version Build Status Dependency Status Maintainability Status

Prometheus Reporter

prometheus_reporter helps you to generate Prometheus metric reports using its text format. Official client helps you to monitor internal web-server guts, while prometheus_reporter can help you representing any data you want.

Overview

require 'prometheus_reporter'

f = PrometheusReporter::TextFormatter.new
f.entry(:my_metric, value: 144, labels: { source: 'api', module: 'chat' })
f.to_s
# => 'my_metric{souce="api",module="chat"} 144'

Installation

Installation is pretty standard:

$ gem install prometheus_reporter

or using Gemfile:

gem 'prometheus_reporter', '~> 1.1.1'

Configuration

You may want to have metric keys application prefix to distinguish those metrics from metric keys reported by other applications.

By default, prefix isn't used.

PrometheusReporter.configure do |config|
  config.prefix = 'my_web_app'
end

f = PrometheusReporter::TextFormatter.new
f.entry(:emails_count, value: 567)
f.to_s # => "my_web_app_emails_count 567\n"

You can overwrite it passing another prefix to a new TextFormatter instance:

f = PrometheusReporter::TextFormatter.new(prefix: 'facebook_clone')
f.entry(:emails_count, value: 987)
f.to_s # => "facebook_clone_emails_count 987\n"

Usage

DSL

You can also use DSL to define reports:

report =
  PrometheusReporter::TextFormatter.draw(prefix: 'my_application') do
    type  :emails_today, :counter
    entry :emails_today, value: 1337

    type  :registrations_today, :counter
    entry :registrations_today, value: 105

    type  :payments_total, :summary
    entry :payments_total, 29913
  end

Creating text report for Prometheus:

require 'prometheus_reporter'

f = PrometheusReporter::TextFormatter.new
f.help(:emails_today, 'Events created from the beginning of the day')
f.type(:emails_today, :counter)
f.entry(:emails_today,
        value: 10,
        labels: { type: 'notify_for_inactivity' },
        timestamp: Time.now.to_i)
f.entry(:emails_today,
        value: 18,
        labels: { type: 'registration_confirmation' },
        timestamp: Time.now.to_i)
f.to_s

Produces the following output:

# HELP facebook_clone_emails_today Amount of emails sent from the beginning of the day
# TYPE facebook_clone_emails_today counter
facebook_clone_emails_today{type="notify_for_inactivity"} 10 1515681885
facebook_clone_emails_today{type="registration_confirmation"} 18 1515681886

Usefull links