dstat 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e4cf88b13a58735fcc04844a1511ef91a6354cf1
4
+ data.tar.gz: a21026e28964163cb1feaf3a59fe18dc505d8d18
5
+ SHA512:
6
+ metadata.gz: 65233a90ae1a866e91d011ca1d53c8ccd6b537cee84d70f519c1b49a27eb6ebb9b1e250ffe9426106fd3147ef8d22306def6c1b1cf0596c66b2a63dfac862858
7
+ data.tar.gz: b48f1e0d4339b6d7058dbd523a58ef2cdd33a843294c78470b63072c84d0461518d0932ed3aa59c918885af46feae0ca62237a005eada0b8ade4033e6f22e3bb
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dstat.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ryan Larson
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,96 @@
1
+ # dstat
2
+
3
+ dstat is a ruby gem that provides utilites for working with dstat data
4
+
5
+ Given a dstat csv file, this will import the data, columnwise, into a Hash.
6
+
7
+ dstat CSV files are often of the form:
8
+
9
+ ```
10
+ top_level_header_1,top_level_header_2,,,
11
+ child_header_1,child_header_2,child_header3,child_header4
12
+ ```
13
+
14
+ or a more concrete example:
15
+
16
+ ```
17
+ epoch,memory usage,,,
18
+ epoch,used,buff,cach,free
19
+ 1121245,12456,12856,20059,2999095
20
+ 1121246,12457,12855,20068,2996885
21
+ ```
22
+
23
+ Where `used`, `buff`, `cache`, and `free` all correspond to memory usage. An index is created
24
+ for each (parent header -> child header), unless parent header == child header.
25
+
26
+ Using the concrete example above, the hash returned from this method would be indexed
27
+ like so:
28
+
29
+ ```
30
+ hash[:epoch] => [1121245, 1121246]
31
+ hash[:memory_usage] => {:used => [12456, 12457],
32
+ :buff => [12856, 12855],
33
+ :cach => [20059, 20068],
34
+ :free => [2999095, 2996885]
35
+ }
36
+ ```
37
+
38
+ Written another way:
39
+
40
+
41
+ ```
42
+ puts hash[:memory_usage][:used]
43
+ => "[12456, 12457]"
44
+ ```
45
+
46
+ The hash also has aliases for the keys, so you can access the values multiple ways:
47
+
48
+ ```
49
+ puts hash[:memory_usage][:used]
50
+ => "[12456, 12457]"
51
+
52
+ puts hash["memory_usage"]["used"]
53
+ => "[12456, 12457]"
54
+
55
+ puts hash["memory_usage_used"]
56
+ => "[12456, 12457]"
57
+ ```
58
+
59
+ ## Installation
60
+
61
+ Add this line to your application's Gemfile:
62
+
63
+ gem 'dstat'
64
+
65
+ And then execute:
66
+
67
+ $ bundle
68
+
69
+ Or install it yourself as:
70
+
71
+ $ gem install dstat
72
+
73
+ ## Usage
74
+
75
+ Dstat is a module, and you can include it to mix in it's functionality.
76
+
77
+ ```
78
+ require 'dstat'
79
+ include Dstat
80
+ ```
81
+
82
+ Once you do this, you have access to all of the Dstat methods. The most useful of which is:
83
+
84
+ ```
85
+ import_dstat_csv(file)
86
+ ```
87
+
88
+ You can pass this a File or a String representing a path to a file, and it will return a colmnwise hash of keys to values
89
+
90
+ ## Contributing
91
+
92
+ 1. Fork it ( http://github.com/<my-github-username>/dstat/fork )
93
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
94
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
95
+ 4. Push to the branch (`git push origin my-new-feature`)
96
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ # require "bundler/gem_tasks"
2
+
3
+ require 'rubygems/tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new('spec')
7
+
8
+ #This gives us build, install, and release
9
+ Gem::Tasks.new(:console => false, :sign => false)
data/dstat.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dstat/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dstat"
8
+ spec.version = Dstat::VERSION
9
+ spec.authors = ["Ryan Larson"]
10
+ spec.email = ["rlarson@tripwire.com"]
11
+ spec.summary = "Utilities for parsing dstat data from dstat csv files."
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.5"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "rubygems-tasks"
24
+ end
data/lib/dstat.rb ADDED
@@ -0,0 +1,105 @@
1
+ require 'csv'
2
+
3
+ module Dstat
4
+ def flatten_headers(csv)
5
+ headers = csv[0]
6
+ csv[0] = []
7
+
8
+ good = headers[0]
9
+ headers.each do |header|
10
+ good = header unless header.nil?
11
+ csv[0] << good
12
+ end
13
+
14
+ csv[1] = csv[1].map do |child_header|
15
+ parent_header = csv[0][csv[1].index(child_header)]
16
+ parent_header != child_header ? "#{parent_header} #{child_header}" : parent_header
17
+ end
18
+ csv[1..-1]
19
+ end
20
+
21
+ def normalize_top_level_header(csv)
22
+ headers = csv[0]
23
+ csv[0] = []
24
+
25
+ good = headers[0]
26
+ headers.each do |header|
27
+ good = header unless header.nil?
28
+ csv[0] << good
29
+ end
30
+ csv
31
+ end
32
+
33
+ def parse_from_file(file)
34
+ file = File.new(file) unless file.is_a? File
35
+ # Split on the double newlines that separate the dstat header from the csv data
36
+ file = file.read.split("\n\n")
37
+ file = file[1].nil? ? file[0] : file[1]
38
+ CSV.parse(file)
39
+ end
40
+
41
+ #
42
+ # Given a dstat csv file, this will import the data, columnwise, into a Hash.
43
+ # dstat CSV files are often of the form:
44
+ #
45
+ # top_level_header_1,top_level_header_2,,,
46
+ # child_header_1,child_header_2,child_header3,child_header4
47
+ #
48
+ # or a more concrete example:
49
+ #
50
+ # epoch,memory usage,,,
51
+ # epoch,used,buff,cach,free
52
+ # 1121245,12456,12856,20059,2999095
53
+ # 1121246,12457,12855,20068,2996885
54
+ #
55
+ # Where used, buff, cache, and free all correspond to memory usage. An index is created
56
+ # for each (parent header -> child header), unless parent header == child header.
57
+ #
58
+ # Using the concrete example above, the hash returned from this method would be indexed
59
+ # like so:
60
+ #
61
+ # hash[:epoch] => [1121245, 1121246]
62
+ # hash[:memory_usage] => {:used => [12456, 12457],
63
+ # :buff => [12856, 12855],
64
+ # :cach => [20059, 20068],
65
+ # :free => [2999095, 2996885]
66
+ # }
67
+ #
68
+ # Written another way:
69
+ #
70
+ # puts hash[:memory_usage][:used]
71
+ # => "[12456, 12457]"
72
+ #
73
+ # The hash also has aliases for the keys, so you can access the values multiple ways:
74
+ #
75
+ # puts hash[:memory_usage][:used]
76
+ # => "[12456, 12457]"
77
+ #
78
+ # puts hash["memory_usage"]["used"]
79
+ # => "[12456, 12457]"
80
+ #
81
+ # puts hash["memory_usage_used"]
82
+ # => "[12456, 12457]"
83
+ #
84
+ def import_dstat_csv(file)
85
+ csv = parse_from_file(file)
86
+ csv = normalize_top_level_header(csv)
87
+ csv = csv.transpose
88
+ csv_hash = Hash.new
89
+ csv.each do |column|
90
+ parent_header = column[0].gsub(/\s+/, "_").strip.to_sym
91
+ child_header = column[1].gsub(/\s+/, "_").strip.to_sym
92
+ if (parent_header != child_header)
93
+ csv_hash[parent_header] = Hash.new if csv_hash[parent_header].nil?
94
+ csv_hash[parent_header.to_s] = Hash.new if csv_hash[parent_header.to_s].nil?
95
+ csv_hash[parent_header][child_header] = column[2..-1]
96
+ csv_hash[parent_header.to_s][child_header.to_s] = column[2..-1]
97
+ csv_hash["#{parent_header}_#{child_header}"] = column[2..-1]
98
+ else
99
+ csv_hash[parent_header] = column[2..-1]
100
+ csv_hash[parent_header.to_s] = column[2..-1]
101
+ end
102
+ end
103
+ csv_hash
104
+ end
105
+ end
@@ -0,0 +1,3 @@
1
+ module Dstat
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ "epoch","total cpu usage",,,,,,"dsk/total",,"load avg",,,"memory usage",,,,"net/total",,"procs",,,"filesystem",,"sockets",,,,,"interrupts",,,"system",,"sysv ipc",,,"file locks",,,
2
+ "epoch","usr","sys","idl","wai","hiq","siq","read","writ","1m","5m","15m","used","buff","cach","free","recv","send","run","blk","new","files","inodes","tot","tcp","udp","raw","frg","33","34","35","int","csw","msg","sem","shm","pos","lck","rea","wri"
3
+ 1412803673.026,2.092,0.337,91.968,5.596,0.000,0.007,877736.191,203248.643,0.220,0.050,0.020,2316075008.0,196341760.0,3298529280.0,2308231168.0,0.0,0.0,0.0,0.0,0.696,6464.0,266398.0,736.0,22.0,16.0,0.0,0.0,72.613,0.007,90.803,577.711,760.541,0.0,2.0,23.0,5.0,5.0,0.0,10.0
4
+ 1412803674.027,20.698,1.496,77.805,0.0,0.0,0.0,0.0,8192.0,0.220,0.050,0.020,2319179776.0,196341760.0,3298578432.0,2305077248.0,167.0,0.0,1.0,0.0,13.0,6464.0,266408.0,735.0,22.0,15.0,0.0,0.0,2.0,0.0,1.0,1061.0,240.0,0.0,2.0,23.0,5.0,5.0,0.0,10.0
5
+ 1412803675.027,11.750,0.750,87.500,0.0,0.0,0.0,0.0,16384.0,0.220,0.050,0.020,2322378752.0,196362240.0,3298578432.0,2301857792.0,60.0,0.0,0.0,0.0,21.0,6528.0,266424.0,735.0,22.0,15.0,0.0,0.0,4.0,0.0,2.0,710.0,340.0,0.0,2.0,23.0,5.0,5.0,0.0,10.0
6
+ 1412803676.027,0.0,0.0,100.0,0.0,0.0,0.0,0.0,0.0,0.220,0.050,0.020,2322513920.0,196362240.0,3298594816.0,2301706240.0,0.0,0.0,0.0,0.0,1.0,6528.0,266424.0,735.0,22.0,15.0,0.0,0.0,0.0,0.0,0.0,64.0,97.0,0.0,2.0,23.0,5.0,5.0,0.0,10.0
7
+ 1412803677.027,0.0,0.0,100.0,0.0,0.0,0.0,0.0,0.0,0.220,0.050,0.020,2322513920.0,196362240.0,3298594816.0,2301706240.0,60.0,0.0,0.0,0.0,0.0,6528.0,266424.0,735.0,22.0,15.0,0.0,0.0,0.0,0.0,2.0,39.0,54.0,0.0,2.0,23.0,5.0,5.0,0.0,10.0
@@ -0,0 +1,37 @@
1
+ require 'rspec'
2
+ require 'dstat'
3
+
4
+ describe Dstat do
5
+ include Dstat
6
+ it "creates multiple indexes for dstat output" do
7
+ dstat = import_dstat_csv('spec/dstat-test.csv')
8
+
9
+ expect(dstat[:epoch]).to eq(dstat["epoch"])
10
+
11
+ [:usr, :sys, :idl, :wai, :hiq, :siq].each do |usage|
12
+ expect(dstat[:total_cpu_usage][usage]).to eq(dstat["total_cpu_usage"][usage.to_s])
13
+ end
14
+
15
+ [:read, :writ].each do |dsk|
16
+ expect(dstat[:"dsk/total"][dsk]).to eq(dstat["dsk/total"][dsk.to_s])
17
+ end
18
+
19
+ [:"1m", :"5m", :"15m"].each do |avg|
20
+ expect(dstat[:load_avg][avg]).to eq(dstat["load_avg"][avg.to_s])
21
+ end
22
+
23
+ [:used, :buff, :cach, :free].each do |usage|
24
+ expect(dstat[:memory_usage][usage]).to eq(dstat["memory_usage"][usage.to_s])
25
+ end
26
+
27
+ [:recv, :send].each do |net|
28
+ expect(dstat[:"net/total"][net]).to eq(dstat["net/total"][net.to_s])
29
+ end
30
+
31
+ # TODO, write the rest of the assertions
32
+ end
33
+
34
+ it "correctly parses the data" do
35
+ # TODO write parser validation
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dstat
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Larson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-09 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubygems-tasks
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - rlarson@tripwire.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - dstat.gemspec
82
+ - lib/dstat.rb
83
+ - lib/dstat/version.rb
84
+ - spec/dstat-test.csv
85
+ - spec/dstat_spec.rb
86
+ homepage: ''
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.2.2
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Utilities for parsing dstat data from dstat csv files.
110
+ test_files:
111
+ - spec/dstat-test.csv
112
+ - spec/dstat_spec.rb