$ fluentd_buffer_stats.rb --help
Usage: fluentd_buffer_stats [options]
-p, --port PORT Port
--plugin-id ID Plugin ID
--chunk-limit CHUNK_LIMIT Default buffer chunk limit (bytes)
--queue-limit QUEUE_LIMIT Default buffer queue limit
--retry-limit Default retry limit
Last active
March 29, 2016 08:24
-
-
Save tkuchiki/570221effb7cd75048d1 to your computer and use it in GitHub Desktop.
fluentd の plugin ごとの buffer_total_queued_size と buffer 使用率を出力する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "net/http" | |
require "uri" | |
require "json" | |
require "optparse" | |
@args = {} | |
OptionParser.new do |opt| | |
opt.on("-p PORT", "--port PORT", "Port"){|v| @args[:port] = v } | |
opt.on("--plugin-id ID", "Plugin ID"){|v| @args[:plugin_id] = v } | |
opt.on("--chunk-limit CHUNK_LIMIT", "Default buffer chunk limit (bytes)"){|v| @args[:chunk_limit] = v } | |
opt.on("--queue-limit QUEUE_LIMIT", "Default buffer queue limit"){|v| @args[:queue_limit] = v } | |
opt.on("--retry-limit", "Default retry limit"){|v| @args[:retry_limit] = v } | |
opt.parse!(ARGV) | |
end | |
if @args[:plugin_id].nil? | |
puts "--plugin-id is required" | |
exit 1 | |
end | |
@args[:port] ||= 24220 | |
@args[:chunk_limit] ||= 8 * (1024 ** 2) | |
@args[:queue_limit] ||= 256 | |
@args[:retry_limit] ||= 17 | |
def chunk_limit(bytes_str) | |
return @args[:chunk_limit] if bytes_str.nil? | |
case | |
when bytes_str.include?("k") | |
bytes_str.delete("k").to_i * 1024 | |
when bytes_str.include?("m") | |
bytes_str.delete("m").to_i * (1024 ** 2) | |
when bytes_str.include?("g") | |
bytes_str.delete("g").to_i * (1024 ** 3) | |
end | |
end | |
uri = URI.parse("http://localhost:#{@args[:port]}/api/plugins.json") | |
body = Net::HTTP.get(uri) | |
plugins = JSON.parse(body) | |
plugins["plugins"].each do |plugin| | |
next unless plugin["plugin_category"] == "output" | |
next unless plugin["config"]["@id"] == @args[:plugin_id] | |
queued_size = plugin["buffer_total_queued_size"].to_i | |
chunk_limit = chunk_limit(plugin["config"]["buffer_chunk_limit"]) | |
queue_limit = plugin["config"]["buffer_queue_limit"].to_i || @args[:queue_limit] | |
retry_limit = plugin["config"]["retry_limit"].to_i || @args[:retry_limit] | |
retry_count = plugin["retry_count"].to_i | |
puts "#{queued_size} #{(queued_size / (chunk_limit * queue_limit)) * 100} #{(retry_count / retry_limit) * 100}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment