Skip to content

Instantly share code, notes, and snippets.

@mmb
Created February 19, 2009 04:16
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 mmb/66728 to your computer and use it in GitHub Desktop.
Save mmb/66728 to your computer and use it in GitHub Desktop.
sparkline showing the number of lines in a file
#!/usr/bin/ruby
# sparkline showing the number of lines in a file
# run from cron at regular intervals
require 'rubygems'
require 'sparklines'
file_to_count = '/tmp/growing_file'
count_file = "#{file_to_count}.linecount"
graph = '/tmp/growing_file.png'
open(count_file, 'a') do |cf|
open(file_to_count) { |ftc| cf.write("#{ftc.readlines.size}\n") }
end
open(count_file) do |f|
data = f.readlines.map { |li| li.to_i }
Sparklines.plot_to_file(graph, data, :line_color => :red)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment