Sha256: ab569b61bfa4aaad0c21a6e82e05a1b2e9c2fc9cc4f4172d5e33a11a7b14986f
Contents?: true
Size: 1.55 KB
Versions: 1
Compression:
Stored size: 1.55 KB
Contents
#! /usr/bin/env ruby require 'optparse' require 'prometheus/client/rack/exporter' require 'rack' require 'yaml' require_relative '../lib/twemproxy_exporter' config = { 'interval' => 30, 'timeout' => 5.0, 'port' => 9222, 'bind' => '0.0.0.0' } OptionParser.new do |args| args.banner = "Usage: #{File.basename($0)} [flags] host[:port] ...\nOptions:" args.on('-i', '--interval <seconds>', "Default: #{config['interval']}") do |seconds| config['interval'] = seconds.to_i end args.on('-t', '--timeout <seconds>', "Default: #{config['timeout']}") do |seconds| config['timeout'] = seconds.to_f end args.on('-f', '--config <file>') do |file| config = YAML.load_file(file) end args.on('-p', '--port <number>', "Default: #{config['port']}") do |port| config['port'] = port.to_i end args.on('-b', '--bind <address>', "Default: #{config['bind']}") do |bind| config['bind'] = bind end args.on_tail('-v', '--version') do puts ::TwemproxyExporter::VERSION exit(0) end end.parse! config['proxies'] = Array(config['proxies']) + ARGV exporter = TwemproxyExporter::Exporter.new(config) Thread.new {exporter.run!} app = Rack::Builder.app do use Rack::CommonLogger use Prometheus::Client::Rack::Exporter use Rack::Deflater, if: ->(_, _, _, body) { body.any? && body[0].length > 512 } map '/' do run ->(env) {[200, {'Content-Type' => 'text/plain'}, ['OK']]} end end Rack::Server.start({ app: app, AccessLog: [], # Shut up, WEBrick. Host: config['bind'] || '0.0.0.0', Port: config['port'] || 9222 })
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
twemproxy_exporter-0.1.1 | bin/twemproxy_exporter |