-
-
Save szajbus/fb4b3bf8f56601bd347a06c022d1b3ff to your computer and use it in GitHub Desktop.
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 'optparse' | |
require 'json' | |
require 'net/http' | |
options = {} | |
OptionParser.new do |opts| | |
opts.banner = "Usage: es_bench.rb [options]" | |
opts.on("-c COUNT", "--count=COUNT", "Number of requests") do |count| | |
options[:count] = count | |
end | |
opts.on("-f FILE", "--file=FILE", "Path to JSON file") do |file| | |
options[:file] = file | |
end | |
opts.on("-e ENDPOINT", "--endpoint=ENDPOINT", "Endpoint URL") do |endpoint| | |
options[:endpoint] = endpoint | |
end | |
end.parse! | |
file = File.read(options[:file]) | |
uri = URI.parse(options[:endpoint]) | |
http = Net::HTTP.new(uri.hostname, uri.port) | |
http.use_ssl = uri.scheme == 'https' | |
req = Net::HTTP::Get.new(uri.path) | |
req.basic_auth uri.user, uri.password | |
options[:count].to_i.times do |i| | |
req.body = file | |
resp = http.request(req) | |
response = JSON.parse(resp.body) | |
$stdout.puts response['took'] | |
$stderr.puts "#{response['hits']['total']} hits in #{response['took']}ms" | |
end | |
$stderr.puts '--------------' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment