Skip to content
This repository
tree: af14da0f70
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 51 lines (44 sloc) 1.129 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
#!/bin/env ruby
# encoding: utf-8
module Munin
  class RailsDatabaseTime < RailsPlugin
    def config
      puts <<-CONFIG
graph_category #{graph_category}
graph_title Database time
graph_vlabel Seconds
graph_args --base 1000 -l 0
graph_info The minimum, maximum and average database times - railsdoctors.com

min.label min
max.label max
average.label avg
CONFIG
      exit 0
    end

    # Gather information
    def run
      ensure_log_file

      # Initialize values
      max_value = 0
      min_value = 1.0/0.0
      cumulative = 0
      hits = 0
      
      rla = parse_request_log_analyzer_data

      if rla && rla["Database time"]
        rla["Database time"].each do |item|
          max_value = item[1][:max] if item[1][:max] > max_value
          min_value = item[1][:min] if item[1][:min] < min_value
          hits += item[1][:hits]
          cumulative += item[1][:sum]
        end
      else
        hits = 1
        min_value = 0
      end

      # Report in seconds
      puts "max.value #{max_value}"
      puts "min.value #{min_value}"
      puts "average.value #{cumulative / hits.to_f}"
    end

  end
end
Something went wrong with that request. Please try again.