Skip to content

Instantly share code, notes, and snippets.

@palkan
Created August 29, 2022 22:03
Show Gist options
  • Save palkan/4bb4765bbad1b6c7ecc73781036a4c2a to your computer and use it in GitHub Desktop.
Save palkan/4bb4765bbad1b6c7ecc73781036a4c2a to your computer and use it in GitHub Desktop.
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