Skip to content

Instantly share code, notes, and snippets.

@pglombardo
Created October 28, 2013 23:19
Show Gist options
  • Save pglombardo/7206557 to your computer and use it in GitHub Desktop.
Save pglombardo/7206557 to your computer and use it in GitHub Desktop.
Using the TraceView Data API to Export Performance Data into Instrumental App
#!/usr/bin/env ruby
require 'rubygems'
require 'instrumental_agent'
require "net/https"
require "uri"
require 'json'
require 'debugger'
INSTRUMENTAL_API_KEY='<insert_your_key>'
TRACEVIEW_API_KEY='<insert_your_key>'
I = Instrumental::Agent.new(INSTRUMENTAL_API_KEY, :enabled => true)
I.synchronous = true # every command sends immediately
http = Net::HTTP.new("api.tracelytics.com", 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
# Retrieve TraceView Server Latency and Report to Instrumental
response = http.request(Net::HTTP::Get.new("/api-v1/latency/Gameface/server/series?key=#{TRACEVIEW_API_KEY}"))
hash = JSON.parse response.body
I.notice("backfill'ing 1 hour of TraceView Server latency data")
hash["data"].each do |s|
next if s[2].nil? # Skip if no traces for this time slice
latency = s[2]
timestamp = s[0]
I.gauge('gameface.app_latency', latency, timestamp)
end
# Retrieve TraceView RUM Latency and Report to Instrumental
response = http.request(Net::HTTP::Get.new("/api-v1/latency/Gameface/client/series?key=#{TRACEVIEW_API_KEY}"))
hash = JSON.parse response.body
I.notice("backfill'ing 1 hour of TraceView RUM latency data")
hash["data"].each do |s|
next if s[2].nil? # Skip if no traces for this time slice
latency = s[2]
timestamp = s[0]
I.gauge('gameface.rum_latency', latency, timestamp)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment