Skip to content

Commit

Permalink
Rename to yabeda-puma-plugin, because yabeda-puma has already taken
Browse files Browse the repository at this point in the history
  • Loading branch information
dsalahutdinov committed Apr 1, 2019
1 parent 8da09c9 commit ca0eaf4
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 106 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
alt="Sponsored by Amplifr" src="https://amplifr-direct.s3-eu-west-1.amazonaws.com/social_images/image/37b580d9-3668-4005-8d5a-137de3a3e77c.png" />
</a>

# Yabeda::Puma
# Yabeda::Puma::Plugin

Built-in metrics for [Puma](https://github.com/puma/puma) web server monitoring out of the box! Part of the [yabeda](https://github.com/yabeda-rb/yabeda) suite.

Expand Down
12 changes: 6 additions & 6 deletions lib/puma/plugin/yabeda.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'yabeda/puma.rb'
require 'yabeda/puma/plugin.rb'

Puma::Plugin.create do
def start(launcher)
Expand All @@ -7,7 +7,7 @@ def start(launcher)
control_url = launcher.options[:control_url]
raise StandardError, "Puma control app is not activated" if control_url == nil

Yabeda::Puma.tap do |puma|
Yabeda::Puma::Plugin.tap do |puma|
puma.control_url = control_url
puma.control_auth_token = launcher.options[:control_auth_token]
end
Expand All @@ -27,10 +27,10 @@ def start(launcher)
end

collect do
require 'yabeda/puma/statistics/fetcher'
stats = Yabeda::Puma::Statistics::Fetcher.call
require 'yabeda/puma/statistics/parser'
Yabeda::Puma::Statistics::Parser.new(clustered: clustered, data: stats).call.each do |item|
require 'yabeda/puma/plugin/statistics/fetcher'
stats = Yabeda::Puma::Plugin::Statistics::Fetcher.call
require 'yabeda/puma/plugin/statistics/parser'
Yabeda::Puma::Plugin::Statistics::Parser.new(clustered: clustered, data: stats).call.each do |item|
send("puma_#{item[:name]}").set(item[:labels], item[:value])
end
end
Expand Down
10 changes: 0 additions & 10 deletions lib/yabeda/puma.rb

This file was deleted.

12 changes: 12 additions & 0 deletions lib/yabeda/puma/plugin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require "yabeda/puma/plugin/version"
require 'yabeda'

module Yabeda
module Puma
module Plugin
class << self
attr_accessor :control_url, :control_auth_token
end
end
end
end
10 changes: 10 additions & 0 deletions lib/yabeda/puma/plugin/statistics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Yabeda
module Puma
module Plugin
module Statistics
METRICS = [:backlog, :running, :pool_capacity, :max_threads, :workers]
CLUSTERED_METRICS = [:booted_workers, :old_workers]
end
end
end
end
21 changes: 21 additions & 0 deletions lib/yabeda/puma/plugin/statistics/fetcher.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'yabeda/puma/plugin/statistics'
require 'json'

module Yabeda
module Puma
module Plugin
module Statistics
class Fetcher
def self.call
body = Socket.unix(Yabeda::Puma::Plugin.control_url.gsub("unix://", '')) do |socket|
socket << "GET /stats?token=#{Yabeda::Puma::Plugin.control_auth_token} HTTP/1.0\r\n\r\n"
socket.read
end

JSON.parse(body.split("\n").last)
end
end
end
end
end
end
36 changes: 36 additions & 0 deletions lib/yabeda/puma/plugin/statistics/parser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'yabeda/puma/plugin/statistics'

module Yabeda
module Puma
module Plugin
module Statistics
class Parser
attr_reader :clustered, :data

def initialize(clustered:, data:)
@clustered = clustered
@data = data
end

def call
Array.new.tap { |result| parse(data, result) }
end

private

def parse(stats, labels = {}, result)
stats.each do |key, value|
value.each { |s| parse(s, labels.merge(index: s['index']), result) } if key == 'worker_status'
parse(value, labels, result) if key == 'last_status'
result << {name: key, value: value, labels: labels} if metric?(key)
end
end

def metric?(name)
Statistics::METRICS.include?(name.to_sym) || (Statistics::CLUSTERED_METRICS.include?(name.to_sym) && clustered)
end
end
end
end
end
end
7 changes: 7 additions & 0 deletions lib/yabeda/puma/plugin/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Yabeda
module Puma
module Plugin
VERSION = "0.1.0"
end
end
end
8 changes: 0 additions & 8 deletions lib/yabeda/puma/statistics.rb

This file was deleted.

19 changes: 0 additions & 19 deletions lib/yabeda/puma/statistics/fetcher.rb

This file was deleted.

34 changes: 0 additions & 34 deletions lib/yabeda/puma/statistics/parser.rb

This file was deleted.

5 changes: 0 additions & 5 deletions lib/yabeda/puma/version.rb

This file was deleted.

7 changes: 1 addition & 6 deletions spec/integration/clustered_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@
require "puma/detect"
require "puma/cli"
require 'rack'
require 'byebug'

RSpec.describe Yabeda::Puma do
# it "has a version number" do
# expect(Yabeda::Puma::VERSION).not_to be nil
# end
#
RSpec.describe Yabeda::Puma::Plugin do
def next_port(incr = 1)
@next_port = 9000 if @next_port == nil
@next_port += incr
Expand Down
3 changes: 1 addition & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require "bundler/setup"
require "yabeda/puma"
require 'byebug'
require "yabeda/puma/plugin"

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'
require 'yabeda/puma/statistics/parser'
require 'yabeda/puma/plugin/statistics/parser'

RSpec.describe Yabeda::Puma::Statistics::Parser do
RSpec.describe Yabeda::Puma::Plugin::Statistics::Parser do

describe '#parse' do
subject(:statistics) { described_class.new(clustered: clustered, data: data).call }
Expand Down
7 changes: 7 additions & 0 deletions spec/yabeda/puma/plugin_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'spec_helper'

RSpec.describe Yabeda::Puma::Plugin do
it "has a version number" do
expect(Yabeda::Puma::Plugin::VERSION).not_to be nil
end
end
7 changes: 0 additions & 7 deletions spec/yabeda/puma/puma_spec.rb

This file was deleted.

11 changes: 5 additions & 6 deletions yabeda-puma.gemspec → yabeda-puma-plugin.gemspec
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@

lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "yabeda/puma/version"
require "yabeda/puma/plugin/version"

Gem::Specification.new do |spec|
spec.name = "yabeda-puma"
spec.version = Yabeda::Puma::VERSION
spec.name = "yabeda-puma-plugin"
spec.version = Yabeda::Puma::Plugin::VERSION
spec.authors = ["Salahutdinov Dmitry"]
spec.email = ["[email protected]"]

spec.summary = %q{Collecting metrics of the puma web server.}
spec.summary = %q{Puma web server plugin for collecting puma metrics with Yabeda framework.}
spec.description = %q{Extends Yabeda metrics with puma web server values by using puma plugin}
spec.homepage = "http://github.com/yabeda-rb/yabeda-puma"
spec.homepage = "http://github.com/yabeda-rb/yabeda-puma-plugin"
spec.license = "MIT"

spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
Expand All @@ -28,6 +28,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "bundler"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "byebug"
spec.add_development_dependency "rack"
end

0 comments on commit ca0eaf4

Please sign in to comment.