Last active
March 27, 2018 03:30
-
-
Save luk3thomas/7cfe7370a27e555610e9 to your computer and use it in GitHub Desktop.
Revisions
-
luk3thomas revised this gist
Mar 18, 2016 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,8 @@ // 1. Go to chrome://memory-redirect/ // 2. Paste this script into the developer console (function(){ var SERVER = 'http://localhost:4567/', // Post metrics to any server STRINGS = 'chrome://memory-redirect/strings.js', INTERVAL = 10e3, RE_INCLUDE = /./; // only include certain results, if you want. -
luk3thomas revised this gist
Mar 18, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ var SERVER = 'http://localhost:4567/', STRINGS = 'chrome://memory-redirect/strings.js', INTERVAL = 10e3, RE_INCLUDE = /./; // only include certain results, if you want. function getMemoryStats() { console.log('Getting stats.') -
luk3thomas revised this gist
Mar 18, 2016 . 2 changed files with 0 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +0,0 @@ File renamed without changes. -
luk3thomas revised this gist
Mar 18, 2016 . 1 changed file with 9 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,17 @@ (function(){ var SERVER = 'http://localhost:4567/', STRINGS = 'chrome://memory-redirect/strings.js', INTERVAL = 10e3, RE_INCLUDE = /librato/i; function getMemoryStats() { console.log('Getting stats.') xhr({ method: 'GET', url: STRINGS, callback: sendMemoryStats }) } function sendMemoryStats(req){ eval(req.responseText.replace(/loadTimeData./, '')) xhr({ method: 'POST', url: SERVER, data: formatData(data) }) } function xhr(opts){ @@ -39,7 +44,7 @@ return memory; }) .filter(function(item){ return RE_INCLUDE.test(item.source) }) }); } @@ -63,5 +68,5 @@ console.info('Start collecting memory stats...') getMemoryStats() setInterval(getMemoryStats, INTERVAL) })() -
luk3thomas revised this gist
Mar 18, 2016 . 2 changed files with 82 additions and 48 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,50 +1,67 @@ (function(){ function getMemoryStats() { console.log('Getting stats.') xhr({ method: 'GET', url: 'chrome://memory-redirect/strings.js', callback: sendMemoryStats }) } function sendMemoryStats(req){ eval(req.responseText.replace(/loadTimeData./, '')) xhr({ method: 'POST', url: 'http://localhost:4567/', data: formatData(data) }) } function xhr(opts){ var req, type, url, callback; method = opts.method; url = opts.url; callback = opts.callback || function(){}; data = opts.data; req = new XMLHttpRequest() req.open(method, url, true) req.onreadystatechange = function(){ if (req.readyState === 4 && req.status === 200) { callback(req) } } req.send(data) } function formatData(data){ return JSON.stringify({ browsers: data.jstemplateData.browsers.map(function(browser){ memory = getMemory(browser); memory.source = formatSource(browser.name); return memory; }), processes: data.jstemplateData.child_data .map(function(item){ memory = getMemory(item); memory.source = formatSource(item.child_name, item.titles.slice(-1)[0]); return memory; }) .filter(function(item){ return /librato/i.test(item.source) }) }); } function getMemory(measurement) { return { virtual: measurement.comm_priv * 1000, private: measurement.ws_priv * 1000 }; } function formatSource() { var args = [].slice.call(arguments); return args.join(" ") .toLowerCase() .replace(/[^a-z\- ]/g, ' ') .replace(/ [ ]*/g, ' ') .replace(/ /g, '.') .replace(/\.$/g, '') } console.info('Start collecting memory stats...') getMemoryStats() setInterval(getMemoryStats, 10e3) })() 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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,6 @@ require 'librato/metrics' Librato::Metrics.authenticate ENV['email'], ENV['token'] post '/' do queue = Librato::Metrics::Queue.new @@ -12,12 +11,30 @@ "Access-Control-Allow-Headers" => "*", "Access-Control-Allow-Methods" => "*", "Access-Control-Allow-Origin" => "*" req = JSON.parse(request.body.read) req['processes'].each do |item| queue.add 'chrome.process.memory.private' => { value: item['private'], source: item['source'] } queue.add 'chrome.process.memory.virtual' => { value: item['virtual'], source: item['source'] } end req['browsers'].each do |item| queue.add 'chrome.memory.private' => { value: item['private'], source: item['source'] } queue.add 'chrome.memory.virtual' => { value: item['virtual'], source: item['source'] } end queue.submit end -
luk3thomas revised this gist
Mar 17, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -29,7 +29,7 @@ formatted = data.jstemplateData.child_data.map(function(item){ return { value: item.ws_priv * 1000, source: formatSource(item.child_name, item.titles.slice(-1)[0]) } }) -
luk3thomas created this gist
Mar 17, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ source 'https://rubygems.org' gem 'sinatra' gem 'librato-metrics' 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ (function(){ function getMemoryStats() { makeXHR({ method: 'GET', url: 'chrome://memory-redirect/strings.js', callback: sendMemoryStats }) } function sendMemoryStats(xhr){ eval(xhr.responseText.replace(/loadTimeData./, '')) makeXHR({ method: 'POST', url: 'http://localhost:4567/', data: formatData(data) }) } function makeXHR(opts){ var xhr, type, url, callback; method = opts.method; url = opts.url; callback = opts.callback || function(){}; data = opts.data; xhr = new XMLHttpRequest() xhr.open(method, url, true) xhr.onreadystatechange = function(){ if (xhr.readyState === 4 && xhr.status === 200) { callback(xhr) } } xhr.send(data) } function formatData(data){ var formatted; formatted = data.jstemplateData.child_data.map(function(item){ return { value: item.ws_priv, source: formatSource(item.child_name, item.titles.slice(-1)[0]) } }) return JSON.stringify(formatted); } function formatSource() { var args = [].slice.call(arguments); return args.join(" ") .toLowerCase() .replace(/[^a-z\- ]/g, '') .replace(/ [ ]*/g, ' ') .replace(/ /g, '.') .replace(/\.$/g, '') } setInterval(getMemoryStats, 5e3) })() 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ require 'sinatra' require 'json' require 'librato/metrics' Librato::Metrics.authenticate ENV['email'], ENV['token'] Librato::Metrics.api_endpoint = ENV['api'] post '/' do queue = Librato::Metrics::Queue.new headers \ "Access-Control-Allow-Credentials" => "true", "Access-Control-Allow-Headers" => "*", "Access-Control-Allow-Methods" => "*", "Access-Control-Allow-Origin" => "*" measurements = JSON.parse(request.body.read) measurements.each do |measurement| queue.add 'browser.memory.private' => { value: measurement['value'], source: measurement['source'] } end queue.submit end