Skip to content

Instantly share code, notes, and snippets.

@theflow
Created September 11, 2009 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theflow/185198 to your computer and use it in GitHub Desktop.
Save theflow/185198 to your computer and use it in GitHub Desktop.
LOGFILE = "/var/log/#{PROJECT}/#{now.strftime('%Y-%m')}/#{now.strftime('%Y-%m-%d')}.production.log"
STATEFILE = "/var/lib/munin/plugin-state/rails_response_time_#{TITLE}_#{PROJECT}#{FILTER}.state"
# get the state
statefile = File.new(STATEFILE, "r")
statefile.each do |line|
amount = line.to_i
end
statefile.close
# parse the logfile
logfile = File.new(LOGFILE, "r")
amount = 0 if logfile.stat.size < amount
logfile.seek(amount, IO::SEEK_SET)
logfile.each_line do |line|
# do your work
end
amount = logfile.pos
logfile.close
statefile = File.new(STATEFILE, "w")
statefile.puts(amount)
statefile.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment