-
-
Save paulbellamy/2577931 to your computer and use it in GitHub Desktop.
Quick bucketing of PG logs
This file contains 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 | |
module Enumerable | |
# sum of an array of numbers | |
def sum | |
return self.inject(0){|acc,i|acc +i} | |
end | |
# average of an array of numbers | |
def average | |
return self.sum/self.length.to_f | |
end | |
def sample_variance | |
avg=self.average | |
sum=self.inject(0){|acc,i|acc +(i-avg)**2} | |
return(1/self.length.to_f*sum) | |
end | |
# standard deviation of an array of numbers | |
def standard_deviation | |
return Math.sqrt(self.sample_variance) | |
end | |
end | |
outputs = {} | |
STDIN.each_line do |line| | |
data = line.gsub(';', '').split(' ') | |
outputs[data[1].to_i] = [] unless outputs[data[1].to_i] | |
outputs[data[1].to_i] << data[0].to_f | |
end | |
outputs.keys.sort.each do |k| | |
v = outputs[k] | |
puts k | |
puts " Min: #{v.min}" | |
puts " Avg: #{v.average}" | |
puts " Max: #{v.max}" | |
puts " SDV: #{v.standard_deviation} | |
end |
This file contains 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
cat pglog_oldskool | grep "SELECT \* " | cut -d " " -f 7,30 | ./bucket.rb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
DS ID Mod 10
cosm@dbfun1:~$ cat pglog_dsidmod | grep "SELECT * " | cut -d " " -f 7,30 | ./bucket.rb
1
Min: 6.513
Avg: 610.452147472204
Max: 3522.191
SDV: 693.578756776515
3
Min: 6.299
Avg: 476.082501403585
Max: 2003.337
SDV: 492.663970770051
7
Min: 6.316
Avg: 1080.75604513889
Max: 2990.404
SDV: 808.373659920346
10
Min: 6.446
Avg: 181.532417197452
Max: 554.524
SDV: 119.950128016387