Skip to content

Instantly share code, notes, and snippets.

@brianjolly
Created November 15, 2012 01:39

Revisions

  1. brianjolly created this gist Nov 15, 2012.
    15 changes: 15 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    #!/usr/local/bin/ruby

    log_file = "/var/log/mem_stats"
    date = `date`.rstrip
    mem_stats = `free -k`.split

    output = ""

    if Dir[log_file] == []
    output << "date,\t total memory,\t used memory,\t free memory\n"
    end

    output << "#{date},\t #{mem_stats[7]}kb,\t #{mem_stats[8]}kb,\t #{mem_stats[9]}kb\n"

    File.open(log_file, 'a') {|f| f.write(output) }