Move to Apache License
[amazing.git] / lib / amazing / widgets / file_system.rb
blob9ca2b6a9927ae4092f122e73990dcee04c0b3d04
1 # Copyright 2008 Dag Odenhall <dag.odenhall@gmail.com>
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 #    http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 require 'amazing/widget'
17 module Amazing
18   module Widgets
19     class FileSystem < Widget
20       description "Various filesystem information"
21       option :mountpoint, "Mountpoint for default format", "/"
22       field :size, "Total size of volume in MB", {}
23       field :used, "Size of used data in MB", {}
24       field :free, "Size of free data in MB", {}
25       field :percentage, "Percentage of used space", {}
26       field :device, "Device name of mount point", {}
27       default { @percentage[@mountpoint] }
29       init do
30         IO.popen("df") do |io|
31           io.readlines[1..-1].map {|l| l.split }.each do |fs|
32             @device[fs[5]] = fs[0].to_s
33             @size[fs[5]] = fs[1].to_f / 1024
34             @used[fs[5]] = fs[2].to_f / 1024
35             @free[fs[5]] = fs[3].to_f / 1024
36             @percentage[fs[5]] = fs[4].to_i
37           end
38         end
39       end
40     end
41   end
42 end