onering-report-plugins 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,174 @@
1
+ if Facter::Util::Resolution.which("zpool")
2
+ def sz_to_bytes(sz)
3
+ case sz[-1].chr
4
+ when 'K'
5
+ rv = sz[0..-2].to_f * (1024)
6
+ when 'M'
7
+ rv = sz[0..-2].to_f * (1024 ** 2)
8
+ when 'G'
9
+ rv = sz[0..-2].to_f * (1024 ** 3)
10
+ when 'T'
11
+ rv = sz[0..-2].to_f * (1024 ** 4)
12
+ when 'P'
13
+ rv = sz[0..-2].to_f * (1024 ** 5)
14
+ when 'E'
15
+ rv = sz[0..-2].to_f * (1024 ** 6)
16
+ when 'Z'
17
+ rv = sz[0..-2].to_f * (1024 ** 7)
18
+ when 'Y'
19
+ rv = sz[0..-2].to_f * (1024 ** 8)
20
+ else
21
+ rv = sz[0..-2].to_f
22
+ end
23
+
24
+ rv.to_i
25
+ end
26
+
27
+ zfs = {
28
+ :filesystems => [],
29
+ :pools => [],
30
+ :snapshots => []
31
+ }
32
+
33
+
34
+ # =============================================================================
35
+ # POOLS
36
+ Facter::Util::Resolution.exec("zpool list -H").to_s.lines.each do |line|
37
+ pool, size, allocated, free, used_perc, dedup, health, altroot = line.strip.split(/\s+/)
38
+ zfs_pool = {
39
+ :name => pool,
40
+ :status => health.downcase,
41
+ :size => {
42
+ :total => sz_to_bytes(size),
43
+ :allocated => sz_to_bytes(allocated),
44
+ :free => sz_to_bytes(free),
45
+ :used => (sz_to_bytes(size) - sz_to_bytes(free)),
46
+ :percent_used => used_perc.delete('%').to_f
47
+ },
48
+ :deduplication_factor => dedup.delete('x').to_f,
49
+ :virtual_devices => {}
50
+ }
51
+
52
+ zfs_pool[:mountpoint] = altroot if altroot != '-'
53
+ vdevs = {}
54
+ current_vdev = nil
55
+
56
+ # get vdevs/devices
57
+ Facter::Util::Resolution.exec("zpool status -v #{pool}").to_s.lines.each do |line|
58
+ if line =~ /^\s*([a-z]+):\s+(.*)$/
59
+ case $1
60
+ when 'scan'
61
+ # scrub output
62
+ if $2 =~ /scrub repaired ([0-9]+) in ((?:[0-9]+d)?(?:[0-9]+h)?(?:[0-9]+m)) with ([0-9]+) errors on (.*)$/
63
+ zfs_pool[:scrub] ||= {}
64
+ zfs_pool[:scrub][:repaired] = $1.to_i
65
+ zfs_pool[:scrub][:errors] = $3.to_i
66
+ zfs_pool[:scrub][:completed_at] = DateTime.parse($4).strftime("%Y-%m-%d %H:%M:%S %z")
67
+ end
68
+ end
69
+
70
+ # vdev line
71
+ elsif line =~ /^\t ([a-z0-9]+)(?:-([0-9]+))\s+([A-Z]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s*$/
72
+ current_vdev = "#{$1}-#{$2}"
73
+ vdevs[current_vdev] = {
74
+ :name => "#{$1}-#{$2}",
75
+ :type => $1.to_sym,
76
+ :number => $2.to_i,
77
+ :status => $3.downcase,
78
+ :errors => {
79
+ :read => $4.to_i,
80
+ :write => $5.to_i,
81
+ :checksum => $6.to_i
82
+ },
83
+ :devices => []
84
+ }
85
+
86
+ # device line
87
+ elsif line =~ /^\t ([a-zA-Z0-9\-\_]+)\s+([A-Z]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s*$/
88
+ if File.symlink?("/dev/disk/by-id/#{$1}")
89
+ dev = File.expand_path(File.readlink("/dev/disk/by-id/#{$1}"), "/dev/disk/by-id")
90
+ elsif File.exists?("/dev/#{$1}")
91
+ dev = "/dev/#{$1}"
92
+ end
93
+
94
+ vdevs[current_vdev][:devices] << {
95
+ :name => $1,
96
+ :device => dev,
97
+ :errors => {
98
+ :read => $2.to_i,
99
+ :write => $3.to_i,
100
+ :checksum => $4.to_i
101
+ }
102
+ }
103
+ end
104
+ end
105
+
106
+ vdevs.each do |name, devs|
107
+ zfs_pool[:virtual_devices][name.split('-').first.to_sym] ||= []
108
+ zfs_pool[:virtual_devices][name.split('-').first.to_sym] << devs
109
+ end
110
+
111
+ zfs[:pools] << zfs_pool
112
+ end
113
+
114
+
115
+
116
+
117
+ # =============================================================================
118
+ # FILESYSTEMS
119
+ Facter::Util::Resolution.exec("zfs list -H").to_s.lines.each do |line|
120
+ filesystem, used, available, referenced, mountpoint = line.strip.split(/\s+/)
121
+
122
+ zfs_filesystem = {
123
+ :name => filesystem,
124
+ :mountpoint => mountpoint,
125
+ :properties => {},
126
+ :snapshots => [],
127
+ :size => {
128
+ :used => sz_to_bytes(used),
129
+ :free => sz_to_bytes(available)
130
+ }
131
+ }
132
+
133
+ # get properties
134
+ Facter::Util::Resolution.exec("zfs get all -H #{filesystem}").to_s.lines.each do |line|
135
+ fs, property, value, source = line.strip.split(/\t/)
136
+
137
+ value = case value
138
+ when 'off' then false
139
+ when 'on' then true
140
+ when 'none' then nil
141
+ when /^[0-9]+(?:\.[0-9]+)?[KMGTPEZY]$/ then sz_to_bytes(value)
142
+ when /^[0-9]+$/ then value.to_i
143
+ when /^[0-9]+\.[0-9]+$/ then value.to_f
144
+ when /^[0-9]+\.[0-9]+x$/ then value.delete('x').to_f
145
+ else value
146
+ end
147
+
148
+ zfs_filesystem[:properties][property.to_sym] = value
149
+ end
150
+
151
+ zfs[:filesystems] << zfs_filesystem
152
+ end
153
+
154
+
155
+ # =============================================================================
156
+ # SNAPSHOTS
157
+ Facter::Util::Resolution.exec("zfs list -H -t snapshot").to_s.lines.each do |line|
158
+ name, used, available, referenced, mountpoint = line.strip.split(/\s+/)
159
+ mountpoint = nil if mountpoint == '-'
160
+
161
+ zfs[:snapshots] << {
162
+ :name => name,
163
+ :used => sz_to_bytes(used),
164
+ :available => sz_to_bytes(available),
165
+ :referenced => sz_to_bytes(referenced),
166
+ :mountpoint => mountpoint
167
+ }
168
+ end
169
+
170
+
171
+ Facter.add("zfs") do
172
+ setcode{ zfs }
173
+ end
174
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onering-report-plugins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: onering-client
16
- requirement: &12312960 !ruby/object:Gem::Requirement
16
+ requirement: &22262760 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *12312960
24
+ version_requirements: *22262760
25
25
  description: Base plugins for providing system information via the Onering client
26
26
  utility
27
27
  email: ghetzel@outbrain.com
@@ -37,6 +37,7 @@ files:
37
37
  - lib/facter/onering_properties_physical.rb
38
38
  - lib/facter/onering_properties_system.rb
39
39
  - lib/facter/onering_properties_id.rb
40
+ - lib/facter/onering_properties_zfs.rb
40
41
  - lib/facter/onering_properties_xen.rb
41
42
  - lib/reporter/default/properties_physical.rb
42
43
  - lib/reporter/default/properties_facter.rb