storage_visualizer 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/storage_visualizer.rb +73 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b04a7461544880c9306687b865389509da70a78
|
4
|
+
data.tar.gz: 0bb34bc3b809e78e5c65ba36268c8ce5350083f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71be27304b23dcda4983799579ece5a71a8c8ecf8a7d4a088baaedd9090924c1082023f1cc57621ba183d2bbeddbc0d859d6c091b4d4785e6d5675a65fcb8fe3
|
7
|
+
data.tar.gz: 0c9a246a63c73fde9c094749dea7065f13496032574dfd69691f6c97204299cdd1ea43a4313148a79d61350e2ed9e99eaaf2567ee6818c7045128af7396c66a3
|
data/lib/storage_visualizer.rb
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
# @author Terry Case <terrylcase@gmail.com>
|
4
|
+
|
5
|
+
# Copyright 2015 Terry Case
|
6
|
+
#
|
7
|
+
# Licensed under the Creative Commons, Version 3.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# https://creativecommons.org/licenses/by/3.0/us/
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
|
19
|
+
|
3
20
|
require 'pp'
|
4
21
|
require 'yaml'
|
5
22
|
require 'date'
|
@@ -20,10 +37,12 @@ class StorageVisualizer
|
|
20
37
|
end
|
21
38
|
|
22
39
|
# To do:
|
23
|
-
#
|
40
|
+
# x Make it work on linux
|
41
|
+
# x Specify blocksize and do not assume 512 bytes (use the -k flag, which reports blocks as KB)
|
42
|
+
# - Enable for filesystems not mounted at the root '/'
|
24
43
|
# - Allow the threshold to be specified (default is 5%)
|
25
44
|
# - Allow output filename to be specified
|
26
|
-
#
|
45
|
+
# Maybe:
|
27
46
|
# - Prevent paths on the graph from crossing
|
28
47
|
# - See if it would be cleaner to use the googlecharts gem (gem install googlecharts)
|
29
48
|
# - Create an installer that sets up cron scheduling and add polling to the webpage
|
@@ -177,8 +196,31 @@ class StorageVisualizer
|
|
177
196
|
|
178
197
|
def get_basic_disk_info
|
179
198
|
# df -l gets info about locally-mounted filesystems
|
180
|
-
output = `df -
|
181
|
-
|
199
|
+
output = `df -lk`
|
200
|
+
|
201
|
+
# OSX
|
202
|
+
# Filesystem 1024-blocks Used Available Capacity iused ifree %iused Mounted on
|
203
|
+
# /dev/disk1 975912960 349150592 626506368 36% 87351646 156626592 36% /
|
204
|
+
# localhost:/QwnJE6UBvlR1EvqouX6gMM 975912960 975912960 0 100% 0 0 100% /Volumes/MobileBackups
|
205
|
+
|
206
|
+
# CentOS:
|
207
|
+
# Filesystem 1K-blocks Used Available Use% Mounted on
|
208
|
+
# /dev/xvda1 82436764 3447996 78888520 5% /
|
209
|
+
# devtmpfs 15434608 56 15434552 1% /dev
|
210
|
+
# tmpfs 15443804 0 15443804 0% /dev/shm
|
211
|
+
|
212
|
+
# Ubuntu:
|
213
|
+
# Filesystem 1K-blocks Used Available Use% Mounted on
|
214
|
+
# /dev/xvda1 30832636 797568 28676532 3% /
|
215
|
+
# none 4 0 4 0% /sys/fs/cgroup
|
216
|
+
# udev 3835900 12 3835888 1% /dev
|
217
|
+
# tmpfs 769376 188 769188 1% /run
|
218
|
+
# none 5120 0 5120 0% /run/lock
|
219
|
+
# none 3846876 0 3846876 0% /run/shm
|
220
|
+
# none 102400 0 102400 0% /run/user
|
221
|
+
# /dev/xvdb 30824956 45124 29207352 1% /mnt
|
222
|
+
|
223
|
+
# Populate disk info into a hash of hashes
|
182
224
|
# {"/"=>
|
183
225
|
# {"capacity"=>498876809216, "used"=>434777001984, "available"=>63837663232},
|
184
226
|
# "/Volumes/MobileBackups"=>
|
@@ -190,14 +232,26 @@ class StorageVisualizer
|
|
190
232
|
next
|
191
233
|
end
|
192
234
|
cols = line.split
|
193
|
-
# ["Filesystem", "
|
235
|
+
# ["Filesystem", "1024-blocks", "Used", "Available", "Capacity", "iused", "ifree", "%iused", "Mounted", "on"]
|
194
236
|
# line: ["/dev/disk1", "974368768", "849157528", "124699240", "88%", "106208689", "15587405", "87%", "/"]
|
195
237
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
238
|
+
if cols.length == 9
|
239
|
+
# OSX
|
240
|
+
self.diskhash[cols[8]] = {
|
241
|
+
'capacity' => (cols[1].to_i ).to_i,
|
242
|
+
'used' => (cols[2].to_i ).to_i,
|
243
|
+
'available' => (cols[3].to_i ).to_i
|
244
|
+
}
|
245
|
+
elsif cols.length == 6
|
246
|
+
# Ubuntu & CentOS
|
247
|
+
self.diskhash[cols[5]] = {
|
248
|
+
'capacity' => (cols[1].to_i ).to_i,
|
249
|
+
'used' => (cols[2].to_i ).to_i,
|
250
|
+
'available' => (cols[3].to_i ).to_i
|
251
|
+
}
|
252
|
+
else
|
253
|
+
raise "Reported disk utilization not understood"
|
254
|
+
end
|
201
255
|
end
|
202
256
|
|
203
257
|
# puts "Disk mount info:"
|
@@ -209,13 +263,13 @@ class StorageVisualizer
|
|
209
263
|
|
210
264
|
|
211
265
|
free_space = (self.available).to_i
|
212
|
-
free_space_gb = "#{'%.0f' % (free_space / 1024 / 1024
|
266
|
+
free_space_gb = "#{'%.0f' % (free_space / 1024 / 1024)}"
|
213
267
|
free_space_array = ['/', 'Free Space', free_space_gb]
|
214
268
|
self.tree.push(free_space_array)
|
215
269
|
|
216
|
-
self.capacity_gb = "#{'%.0f' % (self.capacity.to_i / 1024 / 1024
|
217
|
-
self.used_gb = "#{'%.0f' % (self.used.to_i / 1024 / 1024
|
218
|
-
self.available_gb = "#{'%.0f' % (self.available.to_i / 1024 / 1024
|
270
|
+
self.capacity_gb = "#{'%.0f' % (self.capacity.to_i / 1024 / 1024)}"
|
271
|
+
self.used_gb = "#{'%.0f' % (self.used.to_i / 1024 / 1024)}"
|
272
|
+
self.available_gb = "#{'%.0f' % (self.available.to_i / 1024 / 1024)}"
|
219
273
|
|
220
274
|
|
221
275
|
|
@@ -240,19 +294,19 @@ class StorageVisualizer
|
|
240
294
|
end
|
241
295
|
|
242
296
|
|
243
|
-
cmd = "du -
|
297
|
+
cmd = "du -sxk \"#{dir_to_analyze}\""
|
244
298
|
puts "\trunning #{cmd}"
|
245
299
|
output = `#{cmd}`.strip().split("\t")
|
246
300
|
# puts "Du output:"
|
247
301
|
# pp output
|
248
|
-
size = output[0].to_i
|
249
|
-
size_gb = "#{'%.0f' % (size.to_f / 1024 / 1024
|
302
|
+
size = output[0].to_i
|
303
|
+
size_gb = "#{'%.0f' % (size.to_f / 1024 / 1024)}"
|
250
304
|
# puts "Size: #{size}\nCapacity: #{self.diskhash['/']['capacity']}"
|
251
305
|
|
252
306
|
occupancy = (size.to_f / self.capacity.to_f)
|
253
307
|
occupancy_pct = "#{'%.0f' % (occupancy * 100)}"
|
254
308
|
|
255
|
-
capacity_gb = "#{'%.0f' % (self.capacity.to_f / 1024 / 1024
|
309
|
+
capacity_gb = "#{'%.0f' % (self.capacity.to_f / 1024 / 1024)}"
|
256
310
|
|
257
311
|
# if this dir contains more than 5% of disk space, add it to the tree
|
258
312
|
|
@@ -264,7 +318,7 @@ class StorageVisualizer
|
|
264
318
|
if (dir_to_analyze == self.target_dir)
|
265
319
|
|
266
320
|
other_space = self.used - size
|
267
|
-
other_space_gb = "#{'%.0f' % (other_space / 1024 / 1024
|
321
|
+
other_space_gb = "#{'%.0f' % (other_space / 1024 / 1024)}"
|
268
322
|
other_space_array = ['/', 'Other', other_space_gb]
|
269
323
|
|
270
324
|
short_target_dir = self.target_dir.split('/').reverse[0]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: storage_visualizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Terry Case
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This tool helps visualize which directories are occupying the most storage.
|
14
14
|
Any directory that occupies more than 5% of disk space is added to a visual hierarchichal
|