mool 3.0.5 → 3.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3b461e0aedab1998e9c0442875e2099805d2463f
4
- data.tar.gz: c63a8eb327e217acadcbb4bb8b02a4be99790361
5
2
  SHA512:
6
- metadata.gz: 71261616439867bc8d6f45c6f6068576e4e04f6cea3bc15cb3427c052302c829e2eafd34cf4dd072fce3652859f0ac43b60604c839bf4c4a837a741a471c79d4
7
- data.tar.gz: c0edc7c72bbf5c11d1fa02f002dea11c82580cb5b3eb2aa21b3f9f9bf862c7be64e7a3f2f3df44bf5bf5d2635b1e5864501774835dfc3f806a72a21c44869d79
3
+ data.tar.gz: e07dd657246723cdea9f2e264f99a30c9aad65f5c783c855e3400f64ccdae36eb948754f4e432fdee4f52e42f665db983ca371ebe4f71982c8a591ad5c57cbfb
4
+ metadata.gz: 68792e1d1e4f631f2e4058eeb1e2102e45e0b4ed0cf8ebafde94709623260c48e8fc7be610e4d53ea4d6861f989e60d97c67ec208d67c13d210dfd0ca2b6753a
5
+ SHA1:
6
+ data.tar.gz: 471d44dad63f429c3572b0fa516fcb39863fe745
7
+ metadata.gz: 7657dcd7d6041995180a5ce735414dad643a57c1
data/README.md CHANGED
@@ -313,50 +313,23 @@ In this case we have only one messure, but exists especial cases, where the patt
313
313
  @pattern="urxvt">
314
314
  ```
315
315
  ### Disk
316
- It's possible to get disk, partition or virtual device information using dev name **MAJOR:MINOR** ("**8:2**"), device name **sda**, **sda1** or virtual device such as "**lvm-sda2**" or "**md0**".
316
+ It's possible to get disk, partition or virtual device information using dev name **sda**, **sda1** or virtual device such as or "**md-0**". You can check `cat /proc/partitions`.
317
317
  ```ruby
318
- >> Mool::Disk.new("8:0")
319
- #<Mool::Disk:0x7fdc6e283f00 @logical_name="sda",
320
- @total_block=500107862016.0,
321
- @devtype="disk",
322
- @mount_point="/boot",
323
- @swap=false,
324
- @minor="0",
325
- @devname="sda",
326
- @block_free=0.0,
327
- @path="/sys/dev/block/8:0",
328
- @major="8",
329
- @file_system="ext4",
330
- @unity="Bytes",
331
- @block_used=0.0>
332
- >> Mool::Disk.new("sda1")
333
- #<Mool::Disk:0x7fdc6e266a40 @logical_name="sda1",
334
- @total_block=262144000.0,
335
- @devtype="partition",
336
- @mount_point="/boot",
337
- @swap=false,
338
- @minor="1",
339
- @devname="sda1",
340
- @block_free=59062784.0,
341
- @path="/sys/dev/block/8:1",
342
- @major="8",
343
- @file_system="ext4",
344
- @unity="Bytes",
345
- @block_used=57123840.0>
346
- >> Mool::Disk.new("sdblvm-homelvm")
347
- #<Mool::Disk:0x7fdc6e248658 @logical_name="sdblvm-homelvm",
348
- @total_block=445602856960.0,
349
- @devtype="disk",
350
- @mount_point="/boot",
351
- @swap=false,
352
- @minor="3",
353
- @devname="dm-3",
354
- @block_free=187429210112.0,
355
- @path="/sys/dev/block/252:3",
356
- @major="252",
357
- @file_system="btrfs",
358
- @unity="Bytes",
359
- @block_used=34269296640.0>
318
+ >> Mool::Disk.new("sda")
319
+ => #<Mool::Disk:0x000056407745c5a0
320
+ @block_free=0.0,
321
+ @block_used=0.0,
322
+ @devname="sda",
323
+ @devtype="disk",
324
+ @free_size=0.0,
325
+ @logical_name="sda",
326
+ @major="8",
327
+ @minor="0",
328
+ @path="/sys/block/sda",
329
+ @total_block=0.0,
330
+ @total_size=0.0,
331
+ @unity="Bytes",
332
+ @used_size=0.0>
360
333
  ```
361
334
  It's possible get all partition if the object is `@devtype="disk"`, such as:
362
335
  ```ruby
@@ -370,7 +343,7 @@ It's possible get all partition if the object is `@devtype="disk"`, such as:
370
343
  @minor="1",
371
344
  @devname="sda1",
372
345
  @block_free=59062784.0,
373
- @path="/sys/dev/block/8:1",
346
+ @path="/sys/block/sda/sda1",
374
347
  @major="8",
375
348
  @file_system="ext4",
376
349
  @unity="Bytes",
@@ -382,7 +355,7 @@ It's possible get all partition if the object is `@devtype="disk"`, such as:
382
355
  @minor="2",
383
356
  @devname="sda2",
384
357
  @block_free=0.0,
385
- @path="/sys/dev/block/8:2",
358
+ @path="/sys/block/sda/sda2",
386
359
  @major="8",
387
360
  @file_system="cgroup",
388
361
  @unity="Bytes",
@@ -394,7 +367,7 @@ It's possible get all partition if the object is `@devtype="disk"`, such as:
394
367
  @minor="3",
395
368
  @devname="sda3",
396
369
  @block_free=0.0,
397
- @path="/sys/dev/block/8:3",
370
+ @path="/sys/block/sda/sda3",
398
371
  @major="8",
399
372
  @file_system=nil,
400
373
  @unity="Bytes",
@@ -413,7 +386,7 @@ Otherwise it's possible too get the slaves. The slaves are virtual devices for e
413
386
  @minor="0",
414
387
  @devname="dm-0",
415
388
  @block_free=9739984896.0,
416
- @path="/sys/dev/block/252:0",
389
+ @path="/sys/block/sda/sda3/holders/dm-0",
417
390
  @major="252",
418
391
  @file_system="ext4",
419
392
  @unity="Bytes",
@@ -426,7 +399,7 @@ Otherwise it's possible too get the slaves. The slaves are virtual devices for e
426
399
  @minor="1",
427
400
  @devname="dm-1",
428
401
  @block_free=1926668288.0,
429
- @path="/sys/dev/block/252:1",
402
+ @path="/sys/block/sda/sda3/holders/dm-1",
430
403
  @major="252",
431
404
  @file_system="ext4",
432
405
  @unity="Bytes",
@@ -439,7 +412,7 @@ Otherwise it's possible too get the slaves. The slaves are virtual devices for e
439
412
  @minor="2",
440
413
  @devname="dm-2",
441
414
  @block_free=5497151488.0,
442
- @path="/sys/dev/block/252:2",
415
+ @path="/sys/block/sda/sda3/holders/dm-2",
443
416
  @major="252",
444
417
  @file_system="ext4",
445
418
  @unity="Bytes",
@@ -452,7 +425,7 @@ Otherwise it's possible too get the slaves. The slaves are virtual devices for e
452
425
  @minor="3",
453
426
  @devname="dm-3",
454
427
  @block_free=187430152192.0,
455
- @path="/sys/dev/block/252:3",
428
+ @path="/sys/block/sda/sda3/holders/dm-3",
456
429
  @major="252",
457
430
  @file_system="btrfs",
458
431
  @unity="Bytes",
@@ -461,131 +434,15 @@ Otherwise it's possible too get the slaves. The slaves are virtual devices for e
461
434
  ```
462
435
 
463
436
  Other way is get all disk with yours parititons and slaves.
437
+
464
438
  ```ruby
465
439
  >> Mool::Disk.all
466
- - !ruby/object:MoolDisk
467
- block_free: 0.0
468
- block_used: 0.0
469
- devname: sda
470
- evtype: disk
471
- file_system: ext4
472
- logical_name: sda
473
- major: "8"
474
- minor: "0"
475
- mount_point: /boot
476
- swap: false
477
- total_block: 500107862016.0
478
- unity: Bytes
479
- partitions:
480
- - !ruby/object:MoolDisk
481
- block_free: 59062784.0
482
- block_used: 57123840.0
483
- devname: sda1
484
- devtype: partition
485
- file_system: ext4
486
- logical_name: sda1
487
- major: "8"
488
- minor: "1"
489
- mount_point: /boot
490
- partitions: []
491
- path: /sys/dev/block/8:1
492
- slaves: []
493
- swap: false
494
- total_block: 262144000.0
495
- unity: Bytes
496
- - !ruby/object:MoolDisk
497
- block_free: 0.0
498
- block_used: 0.0
499
- devname: sda2
500
- devtype: partition
501
- file_system: cgroup
502
- logical_name: sda2
503
- major: "8"
504
- minor: "2"
505
- partitions: []
506
- path: /sys/dev/block/8:2
507
- slaves: []
508
- swap: true
509
- total_block: 1073741824.0
510
- unity: Bytes
511
- - !ruby/object:MoolDisk
512
- block_free: 0.0
513
- block_used: 0.0
514
- devname: sda3
515
- devtype: partition
516
- file_system:
517
- logical_name: sda3
518
- major: "8"
519
- minor: "3"
520
- partitions: []
521
- path: /sys/dev/block/8:3
522
- slaves:
523
- - !ruby/object:MoolDisk
524
- block_free: 9739984896.0
525
- block_used: 5232629760.0
526
- devname: dm-0
527
- devtype: disk
528
- file_system: ext4
529
- logical_name: sdblvm-rootlvm
530
- major: "252"
531
- minor: "0"
532
- path: /sys/dev/block/252:0
533
- swap: false
534
- total_block: 32212254720.0
535
- unity: Bytes
536
- - !ruby/object:MoolDisk
537
- block_free: 1926668288.0
538
- block_used: 4227072.0
539
- devname: dm-1
540
- devtype: disk
541
- file_system: ext4
542
- logical_name: sdblvm-tmplvm
543
- major: "252"
544
- minor: "1"
545
- mount_point: /boot
546
- path: /sys/dev/block/252:1
547
- swap: false
548
- total_block: 4294967296.0
549
- unity: Bytes
550
- - !ruby/object:MoolDisk
551
- block_free: 5497149440.0
552
- block_used: 1951401984.0
553
- devname: dm-2
554
- devtype: disk
555
- file_system: ext4
556
- logical_name: sdblvm-varlvm
557
- major: "252"
558
- minor: "2"
559
- mount_point: /boot
560
- path: /sys/dev/block/252:2
561
- swap: false
562
- total_block: 16106127360.0
563
- unity: Bytes
564
- - !ruby/object:MoolDisk
565
- block_free: 187430135808.0
566
- block_used: 34268346368.0
567
- devname: dm-3
568
- devtype: disk
569
- file_system: btrfs
570
- logical_name: sdblvm-homelvm
571
- major: "252"
572
- minor: "3"
573
- mount_point: /boot
574
- path: /sys/dev/block/252:3
575
- swap: false
576
- total_block: 445602856960.0
577
- unity: Bytes
578
- swap: false
579
- total_block: 498770927616.0
580
- unity: Bytes
581
- path: /sys/dev/block/8:0
582
- slaves: []
583
440
  ```
584
441
 
585
442
  Swap partition:
586
443
 
587
444
  ```ruby
588
- >> MoolDisk.swap
445
+ >> Mool::Disk.swap
589
446
  #<Mool::Disk:0x7f711644d890 @file_system="cgroup",
590
447
  @unity="Bytes",
591
448
  @block_used=0.0,
@@ -593,7 +450,7 @@ Swap partition:
593
450
  @total_block=1073741824.0,
594
451
  @minor="2",
595
452
  @devtype="partition",
596
- @path="/sys/dev/block/8:2",
453
+ @path="/sys/block/sda/sda2",
597
454
  @swap=true,
598
455
  @major="8",
599
456
  @ devname="sda2",
data/lib/mool/command.rb CHANGED
@@ -1,90 +1,88 @@
1
1
  module Mool
2
2
  module Command
3
3
 
4
- def self.cpuinfo_command
4
+ # CPU COMMANDS
5
+ def self.cpuinfo
5
6
  File.read('/proc/cpuinfo')
6
7
  end
7
8
 
8
- def self.mpstat_command
9
+ def self.mpstat
9
10
  File.read('|mpstat -P ALL 1 1')
10
11
  end
11
12
 
12
- def self.df_command
13
- `POSIXLY_CORRECT=512 df`
14
- end
15
-
16
- def self.dev_name_command(dev_entry)
17
- File.read("#{dev_entry}/dev")
13
+ # DISK COMMANDS
14
+ def self.logical_name(path)
15
+ File.read("#{path}/dm/name") rescue nil
18
16
  end
19
17
 
20
- def self.mount_command
18
+ def self.mount
21
19
  File.read('/proc/mounts')
22
20
  end
23
21
 
24
- def self.file_system_command
22
+ def self.file_system
25
23
  Dir.glob('/sys/fs/**/*')
26
24
  end
27
25
 
28
- def self.logical_name_command(path)
29
- File.exist?("#{path}/dm/name") ? File.read("#{path}/dm/name").chomp : nil
30
- end
31
-
32
- def self.uevent_command(path)
26
+ def self.uevent(path)
33
27
  File.read("#{path}/uevent")
34
28
  end
35
29
 
36
- def self.swap_command(lname = nil)
30
+ def self.swap(lname = nil)
37
31
  result = File.read('/proc/swaps')
38
32
  lname.present? ? result[/#{lname} /] : result
39
33
  end
40
34
 
41
- def self.capacity_partition_command(path)
42
- File.read("#{path}/size")
35
+ def self.df
36
+ `POSIXLY_CORRECT=512 df`
43
37
  end
44
38
 
45
- def self.partitions_command(path, devname)
46
- Dir.glob("#{path}/#{devname}*")
39
+ def self.partitions(devname)
40
+ Dir.glob("/sys/block/#{devname}/#{devname}*")
47
41
  end
48
42
 
49
- def self.dev_block_command
50
- Dir.glob('/sys/dev/block/*')
43
+ def self.holders(path)
44
+ Dir.glob("#{path}/holders/*").uniq
51
45
  end
52
46
 
53
- def self.real_path_block_command(entry)
54
- `readlink -f #{entry}`.chomp
47
+ def self.all_partitions
48
+ File.read('/proc/partitions')
55
49
  end
56
50
 
57
- def self.real_path_command_exist?(real_path)
58
- File.exist?("#{real_path}/partition")
51
+ def self.root_block_device?(devname)
52
+ File.exist?("/sys/block/#{devname}") &&
53
+ !Dir.glob("/sys/block/#{devname}/slaves/*").present?
59
54
  end
60
55
 
61
- def self.slaves_command(real_path)
62
- Dir.glob("#{real_path}/slaves/*")
63
- end
56
+ # def self.capacity_partition_command(path)
57
+ # File.read("#{path}/size")
58
+ # end
64
59
 
65
- def self.meminfo_command
60
+ # MEMORY COMMANDS
61
+ def self.meminfo
66
62
  File.read('/proc/meminfo')
67
63
  end
68
64
 
69
- def self.ps_command
65
+ # PROCESS COMMANDS
66
+ def self.ps
70
67
  # `ps --no-headers -o pid,user,pcpu,pmem,rss,priority,time,stat,nice,args -A`
71
68
  `ps --no-headers -o ruser,user,rgroup,group,pid,ppid,pgid,pcpu,vsz,nice,etime,time,tty,comm,args=HEADER -A`
72
69
  end
73
70
 
74
- def self.top_command
71
+ def self.top
75
72
  `top -c -b -n1`
76
73
  end
77
74
 
78
- def self.uname_command
75
+ # SYSTEM COMMANDS
76
+ def self.uname
79
77
  `uname -r`.chomp
80
78
  end
81
79
 
82
- def self.uptime_command
83
- `cat /proc/uptime`.chomp
80
+ def self.loadavg
81
+ File.read('/proc/loadavg').chomp
84
82
  end
85
83
 
86
- def self.loadavg_command
87
- File.read('/proc/loadavg').chomp
84
+ def self.uptime
85
+ `cat /proc/uptime`.chomp
88
86
  end
89
87
  end
90
88
  end
data/lib/mool/cpu.rb CHANGED
@@ -52,7 +52,7 @@ module Mool
52
52
  def self.cpuinfo
53
53
  cpu_info = {}
54
54
 
55
- mpstat = Mool::Command.mpstat_command.split("\n\n")[2].split("\n").map do |i|
55
+ mpstat = Mool::Command.mpstat.split("\n\n")[2].split("\n").map do |i|
56
56
  i.gsub(/^\S+:/, '').strip.split(/\s+/)
57
57
  end
58
58
 
@@ -66,8 +66,8 @@ module Mool
66
66
  cpu_info.merge!(core_name => res)
67
67
  end
68
68
 
69
- Mool::Command.cpuinfo_command.gsub(/([^\n])\n([^\n])/,
70
- '\1 \2').scan(/processor\t*: (\d+).*model name\t*: (.*) stepping.*cpu cores\t*: (\d+)/).each do |v|
69
+ Mool::Command.cpuinfo.gsub(/([^\n])\n([^\n])/,
70
+ '\1 \2').scan(/processor\t*: (\d+).*model name\t*: (.*) stepping.*cpu cores\t*: (\d+)/).each do |v|
71
71
  cpu_info[v[0]]['model_name'] = v[1]
72
72
  cpu_info[v[0]]['cpu_cores'] = v[2]
73
73
  end
@@ -76,7 +76,7 @@ module Mool
76
76
  end
77
77
 
78
78
  def self.processors
79
- Mool::Command.cpuinfo_command.scan(/processor\t*: (\d+)/).flatten + ['all']
79
+ Mool::Command.cpuinfo.scan(/processor\t*: (\d+)/).flatten + ['all']
80
80
  end
81
81
 
82
82
  def self.all
data/lib/mool/disk.rb CHANGED
@@ -16,42 +16,38 @@ module Mool
16
16
  :total_block,
17
17
  :block_used,
18
18
  :block_free,
19
+ :logical_name,
19
20
  :partitions,
20
21
  :slaves,
21
22
  :unity
22
23
 
23
- def initialize(dev_name)
24
- @path = nil
24
+ def initialize(devname, path = nil)
25
+ @unity = Mool::BYTES
26
+ @devname = devname
25
27
 
26
- Mool::Command.dev_block_command.each do |entry|
27
- logical_name = Mool::Command.logical_name_command(entry)
28
- next unless Mool::Command.dev_name_command(entry).include?(dev_name) ||
29
- Mool::Command.uevent_command(entry).include?(dev_name) ||
30
- (logical_name.present? && logical_name.include?(dev_name))
31
- @path = entry
32
- break
33
- end
28
+ @path = if path.nil?
29
+ Mool::Disk.proc_partitions_hash(@devname)[:path]
30
+ else
31
+ path
32
+ end
34
33
 
35
- raise "Does't exist #{dev_name}!" if @path.nil?
34
+ raise "Does't exist #{devname} on #{@path}" if @path.nil? || @devname.nil?
35
+ lname = Mool::Command.logical_name(@path)
36
+ @logical_name = lname.blank? ? @devname : lname
36
37
  read_uevent
37
- logical_name
38
- swap
39
38
  capacity
40
- @unity = Mool::BYTES
41
- mounting_point
42
- file_system
43
39
  end
44
40
 
45
41
  def mounting_point
46
42
  @mount_point = nil
47
- Mool::Command.mount_command.include?(@logical_name) &&
48
- @mount_point ||= Mool::Command.mount_command.scan(
49
- /#{@logical_name} (\S+)/
43
+ Mool::Command.mount.include?(@devname) &&
44
+ @mount_point ||= Mool::Command.mount.scan(
45
+ /#{@devname} (\S+)/
50
46
  ).flatten.first
51
47
  end
52
48
 
53
49
  def file_system
54
- files = Mool::Command.file_system_command.select do |a|
50
+ files = Mool::Command.file_system.select do |a|
55
51
  a.include?(@devname)
56
52
  end
57
53
 
@@ -59,45 +55,38 @@ module Mool
59
55
  @file_system ||= files.first.split('/')[3]
60
56
  end
61
57
 
62
- def logical_name
63
- lname = Mool::Command.logical_name_command(@path)
64
- @logical_name = lname.present? ? lname : @devname
65
- end
66
-
67
58
  def read_uevent
68
59
  @major,
69
60
  @minor,
70
61
  @devname,
71
62
  @devtype =
72
- Mool::Command.uevent_command(@path).split("\n").map do |result|
63
+ Mool::Command.uevent(@path).split("\n").map do |result|
73
64
  result.split('=').last
74
65
  end
75
- # Mool::Command.uevent_command(@path).scan(
76
- # /.*=(\d+)\n.*=(\d+)\n.*=(\S+)\n.*=(\w+)\n/
77
- # ).flatten
78
66
  end
79
67
 
80
68
  def dev
81
69
  @major + @minor
82
70
  end
83
71
 
84
- def is_disk?
72
+ def disk?
85
73
  @devtype == 'disk'
86
74
  end
87
75
 
88
- def is_partition?
76
+ def partition?
89
77
  @devtype == 'partition'
90
78
  end
91
79
 
92
80
  def swap
93
- @swap ||= Mool::Command.swap_command(@logical_name).present?
81
+ @swap ||= Mool::Command.swap(@devname).present?
94
82
  end
95
83
 
96
84
  def capacity
97
85
  return if defined?(@total_block) && defined?(@block_used) && defined?(@block_free)
98
- result = Mool::Command.df_command.scan(
86
+ result = Mool::Command.df.scan(
99
87
  /(#{@logical_name}|#{@devname})\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)/
100
88
  ).flatten
89
+
101
90
  # @total_block = Mool::Command.capacity_partition_command(@path).chomp.to_f
102
91
  @total_block = result[1].to_f
103
92
  @total_size = result[1].to_f * Mool::BLOCK_SIZE
@@ -110,26 +99,23 @@ module Mool
110
99
  end
111
100
 
112
101
  def partitions
113
- return @partitions if defined? @partitions
114
- return [] unless is_disk?
115
-
116
- @partitions = Mool::Command.partitions_command(
117
- @path,
118
- @devname
119
- ).map do |part|
120
- Mool::Disk.new(part.split('/').last)
102
+ return @cache_partitions if defined? @cache_partitions
103
+ return [] unless disk?
104
+
105
+ paths = Mool::Command.partitions(@devname)
106
+
107
+ @cache_partitions = paths.map do |path|
108
+ Mool::Disk.new(path.split('/').last, path)
121
109
  end
122
110
  end
123
111
 
124
112
  def slaves
125
- return @slaves if defined? @slaves
113
+ return @cache_slaves if defined? @cache_slaves
126
114
 
127
- blocks = Mool::Command.dev_block_command.select do |entry|
128
- File.directory?("#{entry}/slaves/#{@devname}")
129
- end
115
+ slaves = Mool::Command.holders(@path)
130
116
 
131
- @slaves = blocks.map do |slave|
132
- Mool::Disk.new(slave.split('/').last)
117
+ @cache_slaves = slaves.map do |slave_devname|
118
+ Mool::Disk.new(slave_devname, @path + "/holders/#{slave_devname}")
133
119
  end
134
120
  end
135
121
 
@@ -173,21 +159,116 @@ module Mool
173
159
  Mool::GBYTES)
174
160
  end
175
161
 
162
+ def self.swap
163
+ result = Mool::Command.swap.scan(%r{/.*\n\/dev\/(\S+)/}).flatten.first
164
+ Mool::Disk.new(result) unless result.nil?
165
+ end
166
+
167
+ def self.find_slaves(path, all_partitions)
168
+ slaves = Mool::Command.holders(path)
169
+
170
+ result = {}
171
+
172
+ slaves.each do |slave|
173
+ all_partitions.each do |partition|
174
+ devname = partition[3]
175
+ next unless slave.include?(devname)
176
+ all_partitions.delete(partition)
177
+ result[devname] = { path: path + "/holders/#{slave}" }
178
+ end
179
+ end
180
+
181
+ result
182
+ end
183
+
184
+ def self.find_partitions(disk, all_partitions)
185
+ parts = Mool::Command.partitions(disk)
186
+
187
+ result = {}
188
+
189
+ parts.each do |part|
190
+ all_partitions.each do |partition|
191
+ devname = partition[3]
192
+ next unless part.include?(devname)
193
+ all_partitions.delete(partition)
194
+ result[devname] = {
195
+ path: part,
196
+ slaves: find_slaves(part, all_partitions)
197
+ }
198
+ end
199
+ end
200
+
201
+ result
202
+ end
203
+
204
+ def self.find_especific_devname(obj, key)
205
+ if obj.respond_to?(:key?) && obj.key?(key)
206
+ obj[key]
207
+ elsif obj.respond_to?(:each)
208
+ r = nil
209
+ obj.find { |*a| r = find_especific_devname(a.last, key) }
210
+ r
211
+ end
212
+ end
213
+
214
+ def self.proc_partitions_hash(especific_devname = nil)
215
+ all_partitions = Mool::Command.all_partitions.scan(/(\d+)\s+(\d+)\s+(\d+)\s+(\S+)/)
216
+ hash_disks = {}
217
+
218
+ all_partitions.each do |partition|
219
+ if partition[3].include?('ram') || partition[3].include?('sr')
220
+ all_partitions.delete(partition)
221
+ next
222
+ end
223
+ devname = partition[3]
224
+ path = "/sys/block/#{devname}"
225
+ next unless Mool::Command.root_block_device?(devname)
226
+ all_partitions.delete(partition)
227
+ hash_disks[devname] = {
228
+ path: path,
229
+ partitions: find_partitions(devname, all_partitions),
230
+ slaves: find_slaves(path, all_partitions)
231
+ }
232
+ end
233
+
234
+ return hash_disks if especific_devname.nil?
235
+ find_especific_devname(hash_disks, especific_devname)
236
+ end
237
+
176
238
  def self.all
177
239
  disks = []
178
240
 
179
- Mool::Command.dev_block_command.each do |entry|
180
- real_path = Mool::Command.real_path_block_command(entry)
181
- next unless !real_path.include?('virtual') &&
182
- !real_path.include?('/sr') &&
183
- !Mool::Command.real_path_command_exist?(real_path) &&
184
- Mool::Command.slaves_command(real_path).empty?
241
+ proc_partitions_hash.each do |disk_name, disk_opts|
242
+ all_partitions = []
243
+ disk = Mool::Disk.new(disk_name, disk_opts[:path])
185
244
 
186
- disks << Mool::Disk.new(entry.split('/').last)
187
- end
245
+ disk_opts[:partitions].map do |partition_name, partition_opts|
246
+ partition = Mool::Disk.new(
247
+ partition_name,
248
+ partition_opts[:path]
249
+ )
250
+
251
+ all_partitions << partition
252
+
253
+ partition.slaves = partition_opts[:slaves].map do |slave_name, slave_opts|
254
+ Mool::Disk.new(
255
+ slave_name,
256
+ slave_opts[:path]
257
+ )
258
+ end
259
+ end
188
260
 
189
- disks.each { |disk| disk.partitions.each { |part| part.partitions && part.slaves }}
190
- disks.each { |disk| disk.slaves.each { |part| part.partitions && part.slaves }}
261
+ disk.partitions = all_partitions
262
+
263
+ disk.slaves = disk_opts[:slaves].map do |slave_name, slave_opts|
264
+ Mool::Disk.new(
265
+ slave_name,
266
+ slave_opts[:path]
267
+ )
268
+ end
269
+
270
+ disks << disk
271
+ end
191
272
 
192
273
  disks.each do |disk|
193
274
  disk.partitions.each do |partition|
@@ -210,20 +291,5 @@ module Mool
210
291
 
211
292
  disks
212
293
  end
213
-
214
- def self.swap
215
- result = Mool::Command.swap_command.scan(%r{/.*\n\/dev\/(\S+)/}).flatten.first
216
- Mool::Disk.new(result) unless result.nil?
217
- end
218
-
219
- def self.all_usable
220
- result = Mool::Disk.all
221
- result.each do |disk|
222
- result += (disk.partitions +
223
- disk.slaves +
224
- (disk.partitions + disk.slaves).collect { |p| p.partitions + p.slaves }.flatten)
225
- end
226
- result.reject(&:blank?).select { |d| (d.partitions + d.slaves).blank? }
227
- end
228
294
  end
229
295
  end
data/lib/mool/memory.rb CHANGED
@@ -4,7 +4,7 @@ module Mool
4
4
  attr_accessor :unity, :mem_used
5
5
 
6
6
  def initialize
7
- Mool::Command.meminfo_command.scan(/(\S+):\s+(\d+)/).each do |meminfo|
7
+ Mool::Command.meminfo.scan(/(\S+):\s+(\d+)/).each do |meminfo|
8
8
  var = meminfo[0].tr('(', '_').tr(')', '').underscore
9
9
  instance_variable_set(
10
10
  "@#{var}",
data/lib/mool/process.rb CHANGED
@@ -76,8 +76,8 @@ module Mool
76
76
  end
77
77
 
78
78
  def self.services_status(services)
79
- command_ps = Mool::Command.ps_command
80
- command_top = Mool::Command.top_command
79
+ command_ps = Mool::Command.ps
80
+ command_top = Mool::Command.top
81
81
 
82
82
  result = {}
83
83
 
data/lib/mool/system.rb CHANGED
@@ -13,8 +13,8 @@ module Mool
13
13
  :uptime_second
14
14
 
15
15
  def initialize
16
- @kernel = Mool::Command.uname_command
17
- load_avg = Mool::Command.loadavg_command.split(' ')
16
+ @kernel = Mool::Command.uname
17
+ load_avg = Mool::Command.loadavg.split(' ')
18
18
  @current_loadavg = load_avg[0].to_f
19
19
  @last_5min_loadavg = load_avg[1].to_f
20
20
  @last_15min_loadavg = load_avg[2].to_f
@@ -23,7 +23,7 @@ module Mool
23
23
  # Number of kernel scheduling entities that currently exist on the system
24
24
  @total_thread_entities = load_avg[3].split('/').last.to_i
25
25
  @last_pid_process_created = load_avg[4].to_i
26
- time = Mool::Command.uptime_command.split(' ').first.to_f
26
+ time = Mool::Command.uptime.split(' ').first.to_f
27
27
  mm, ss = time.divmod(60)
28
28
  hh, mm = mm.divmod(60)
29
29
  dd, hh = hh.divmod(24)
data/lib/mool/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mool
2
- VERSION = "3.0.5"
2
+ VERSION = "3.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mool
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.5
4
+ version: 3.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - g.edera
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
11
 
12
- date: 2018-04-04 00:00:00 Z
12
+ date: 2018-04-10 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler