Last active
June 19, 2019 06:39
-
-
Save kenzo0107/18f8bc2a056a8e85c1e81c721edcc254 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
| require 'benchmark' | |
| require 'net/http' | |
| require 'uri' | |
| def post_metrics_datadog(metrics, val) | |
| project = "hoge" | |
| api_key = ENV['DATADOG_API_KEY'] | |
| current_time = Time.now.to_i | |
| uri = URI.parse("https://api.datadoghq.com/api/v1/series?api_key=#{api_key}") | |
| request = Net::HTTP::Post.new(uri) | |
| request.content_type = "application/json" | |
| request.body = "{ \"series\" : | |
| [{\"metric\":\"#{metrics}\", | |
| \"points\":[[#{current_time}, #{val}]], | |
| \"type\":\"gauge\", | |
| \"host\":\"#{project}\"}] | |
| }" | |
| req_options = { | |
| use_ssl: uri.scheme == "https", | |
| } | |
| response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http| | |
| http.request(request) | |
| end | |
| end | |
| def profile_app_load_time | |
| Benchmark.measure do | |
| system("./bin/rails r '1;'") or raise "error" | |
| end | |
| end | |
| puts "=== Warming disk cache, ... ===" | |
| puts profile_app_load_time | |
| puts "=== Benchmark of 'rails r' 3 times ! ===" | |
| 3.times do | |
| result = profile_app_load_time | |
| # puts result | |
| puts result.real | |
| post_metrics_datadog('rails.runner.load_time', result.real) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment