Dysnomia 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +17 -0
- data/Dysnomia.gemspec +26 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/lib/Dysnomia/linux.rb +155 -0
- data/lib/Dysnomia/version.rb +3 -0
- data/lib/Dysnomia.rb +11 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ac2a20f81e40576da5c5e45143a469c12108bc69
|
4
|
+
data.tar.gz: b9163b29cc01daae093b1188908195fa17ab4bbb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e2e7692a6632adb3eb5081679b7b4d3a635f50060634614ecc5c9e99b3be80884ebb88c2b19a8f76a93ad1b5553c483be7caf066bff33820954bfe2c72d66fd2
|
7
|
+
data.tar.gz: 49c6e14844dedb701aad736d432ff8b33a9e844c7f289e73c88815c90f3453f56fcf2a0994c2509ecaf950b7d77da748eb0a81b26ee3e0cf94c39d00c5d05dca
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/Dysnomia.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'Dysnomia/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "Dysnomia"
|
9
|
+
spec.version = Dysnomia::VERSION
|
10
|
+
spec.authors = ["Sedat ÇİFTÇİ"]
|
11
|
+
spec.email = ["me@sedat.us"]
|
12
|
+
spec.description = %q{Mac and linux statistics gem}
|
13
|
+
spec.summary = %q{Dysnomia supported is only mac and linux platforms !}
|
14
|
+
spec.homepage = "http://sedat.us/Dysnomia"
|
15
|
+
spec.license = "MIT"
|
16
|
+
spec.rdoc_options << '--main' << 'README'
|
17
|
+
|
18
|
+
spec.files = `git ls-files`.split($/)
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.post_install_message = "Thanks for installing!"
|
26
|
+
end
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Sedat ÇİFTÇİ
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Dysnomia
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
gem 'Dysnomia'
|
8
|
+
|
9
|
+
And then execute:
|
10
|
+
|
11
|
+
$ bundle
|
12
|
+
|
13
|
+
Or install it yourself as:
|
14
|
+
|
15
|
+
$ gem install Dysnomia
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
<pre>
|
20
|
+
require 'Dysnomia'
|
21
|
+
|
22
|
+
dys = Dysnomia
|
23
|
+
|
24
|
+
dys.top_memory_processes # Top ten memory processes
|
25
|
+
dys.top_cpu_processes # Top ten cpu processes
|
26
|
+
|
27
|
+
</pre>
|
28
|
+
|
29
|
+
## Warning
|
30
|
+
|
31
|
+
Dysnomia supported is only mac and linux platforms !
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,155 @@
|
|
1
|
+
module Dysnomia
|
2
|
+
class << self
|
3
|
+
@@ipv4_file = "/proc/net/sockstat"
|
4
|
+
@@ipv6_file = "/proc/net/sockstat6"
|
5
|
+
|
6
|
+
def disk_usage
|
7
|
+
|
8
|
+
# return gib
|
9
|
+
|
10
|
+
# execute command
|
11
|
+
$command = `df`
|
12
|
+
|
13
|
+
# split command all spaces
|
14
|
+
$explode = $command.split(" ").map { |s| s.to_i }
|
15
|
+
|
16
|
+
$total = 0
|
17
|
+
for i in (9..$explode.size - 1).step(6) do
|
18
|
+
$total += $explode[i]
|
19
|
+
end
|
20
|
+
|
21
|
+
$total = $total.round(2)
|
22
|
+
|
23
|
+
(($total/1024) / 1024).round(2)
|
24
|
+
end
|
25
|
+
|
26
|
+
def disk_usage_percent
|
27
|
+
|
28
|
+
# return percent
|
29
|
+
|
30
|
+
@command = `df --total`
|
31
|
+
|
32
|
+
@command.split(" ").last.to_f.round(2)
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def cpu_used
|
37
|
+
|
38
|
+
# percentage cpu used
|
39
|
+
|
40
|
+
# read proc stats and grep cpu
|
41
|
+
$p1 = File.readlines('/proc/stat').grep('/^cpu /').first.split(' ')
|
42
|
+
|
43
|
+
# sleep one moment
|
44
|
+
sleep 1
|
45
|
+
|
46
|
+
# read proc stats and grep cpu again
|
47
|
+
$p2 = File.readlines('/proc/stat').grep('/^cpu /').first.split(' ')
|
48
|
+
|
49
|
+
|
50
|
+
# Sum proc 1 usage
|
51
|
+
$proc1usage = $p1[1].to_i + $p1[2].to_i + $p1[3].to_i
|
52
|
+
|
53
|
+
# Sum proc 2 usage
|
54
|
+
$proc2usage = $p2[1].to_i + $p2[2].to_i + $p2[3].to_i
|
55
|
+
|
56
|
+
# Proc usage
|
57
|
+
$procusageend = $proc2usage - $proc1usage
|
58
|
+
|
59
|
+
|
60
|
+
$p1total = 0
|
61
|
+
$p2total = 0
|
62
|
+
|
63
|
+
# proc1 total
|
64
|
+
for i in (1..4) do
|
65
|
+
$p1total += $p1[i].to_i
|
66
|
+
end
|
67
|
+
|
68
|
+
# proc2 total
|
69
|
+
for i in (1..4) do
|
70
|
+
$p2total += $p2[i].to_i
|
71
|
+
end
|
72
|
+
|
73
|
+
# difference procs
|
74
|
+
$total_usage = $p2total - $p1total
|
75
|
+
|
76
|
+
# total cpu usage
|
77
|
+
$total_cpu_usage = $procusageend.to_f / $total_usage
|
78
|
+
|
79
|
+
# total cpu usage percentage
|
80
|
+
$total_cpu_usage = (100 * $total_cpu_usage).to_f.round(2)
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def top_cpu_processes
|
86
|
+
# top 10 cpu processes
|
87
|
+
|
88
|
+
$command = `ps aux | awk '{print $11, $3}' | sort -k2nr | head -n 10`
|
89
|
+
$return_array = []
|
90
|
+
|
91
|
+
# each to line
|
92
|
+
|
93
|
+
$command.each_line do |pro|
|
94
|
+
# split line is space
|
95
|
+
$l = pro.chomp.split(' ')
|
96
|
+
$return_array << $l.first + "," + $l.last
|
97
|
+
end
|
98
|
+
|
99
|
+
$return_array
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
def top_memory_processes
|
105
|
+
# top 10 mem processes
|
106
|
+
|
107
|
+
$command = `ps aux | awk '{print $11, $4}' | sort -k2nr | head -n 10`
|
108
|
+
$return_array = []
|
109
|
+
|
110
|
+
# each to line
|
111
|
+
|
112
|
+
$command.each_line do |pro|
|
113
|
+
# split line is space
|
114
|
+
$l = pro.chomp.split(' ')
|
115
|
+
$return_array << $l.first + "," + $l.last
|
116
|
+
end
|
117
|
+
|
118
|
+
$return_array
|
119
|
+
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
def tcp
|
124
|
+
|
125
|
+
$sockstat4 = 0
|
126
|
+
$sockstat6 = 0
|
127
|
+
|
128
|
+
# Get ipv4 stat
|
129
|
+
|
130
|
+
if File.exist?(@@ipv4_file)
|
131
|
+
File.open(@@ipv4_file, "r") do |i4|
|
132
|
+
$sockstat4 = i4.read
|
133
|
+
end
|
134
|
+
$t4_data = $sockstat4.split
|
135
|
+
$t4_count = $t4_data[5]
|
136
|
+
end
|
137
|
+
|
138
|
+
if File.exist?(@@ipv6_file)
|
139
|
+
File.open(@@ipv6_file, "r") do |i6|
|
140
|
+
$sockstat6 = i6.read
|
141
|
+
end
|
142
|
+
|
143
|
+
$t6_data = $sockstat6.split
|
144
|
+
$t6_count = $t6_data[2]
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
$total = $t4_count.to_i - $t6_count.to_i
|
149
|
+
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
|
data/lib/Dysnomia.rb
ADDED
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Dysnomia
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sedat ÇİFTÇİ
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Mac and linux statistics gem
|
42
|
+
email:
|
43
|
+
- me@sedat.us
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .DS_Store
|
49
|
+
- .gitignore
|
50
|
+
- Dysnomia.gemspec
|
51
|
+
- Gemfile
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- lib/Dysnomia.rb
|
56
|
+
- lib/Dysnomia/linux.rb
|
57
|
+
- lib/Dysnomia/version.rb
|
58
|
+
homepage: http://sedat.us/Dysnomia
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message: Thanks for installing!
|
63
|
+
rdoc_options:
|
64
|
+
- --main
|
65
|
+
- README
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.2.0
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Dysnomia supported is only mac and linux platforms !
|
84
|
+
test_files: []
|