Skip to content

Instantly share code, notes, and snippets.

@palkan
Created Aug 29, 2022
Embed
What would you like to do?
Yabeda stdout adapter
# frozen_string_literal: true
require "yabeda/base_adapter"
module Yabeda
module STDOUT
class Adapter < BaseAdapter
def register_counter!(_metric)
end
def perform_counter_increment!(counter, tags, increment)
$stdout.puts "[METRICS] #{counter.name}#{build_tags(tags)} #{increment}"
end
def register_gauge!(_metric)
end
def perform_gauge_set!(metric, tags, value)
$stdout.puts "[METRICS] #{metric.name}#{build_tags(tags)} #{value}"
end
def register_histogram!(_metric)
end
def perform_histogram_measure!(metric, tags, value)
$stdout.puts "[METRICS] #{metric.name}#{build_tags(tags)} #{value}"
end
private
def build_tags(tags)
return if tags.nil? || tags.empty?
tags.map { |k, v| "#{k}=#{v}" }.join(",").then { "{#{_1}}" }
end
Yabeda.register_adapter(:stdout, new)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment