ddstat 0.0.1
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +1 -0
- data/bin/ddstat +4 -0
- data/ddstat.gemspec +24 -0
- data/lib/ddstat.rb +12 -0
- data/lib/ddstat/ddstat.rb +101 -0
- data/lib/ddstat/version.rb +3 -0
- metadata +105 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Genki Sugawara
|
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,43 @@
|
|
1
|
+
# Ddstat
|
2
|
+
|
3
|
+
A tool that send to Datadog the data while execute dstat.
|
4
|
+
|
5
|
+
[](http://badge.fury.io/rb/ddstat)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'ddstat'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ddstat
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```sh
|
24
|
+
$ export DD_API_KEY=...
|
25
|
+
$ #export DD_APP_KEY=...
|
26
|
+
$ ddstat -tclmsdrn 5 # The outputted data is transmitted to Datadog.
|
27
|
+
----system---- ----total-cpu-usage---- ---load-avg--- ------memory-usage----- ----swap--- -dsk/total- --io/total- -net/total-
|
28
|
+
date/time |usr sys idl wai hiq siq| 1m 5m 15m | used buff cach free| used free| read writ| read writ| recv send
|
29
|
+
16-02 07:51:06| 1 1 98 0 0 0| 0 0.06 0.22| 235M 44.7M 1156M 13.2G| 0 0 |9792B 69k|0.79 0.81 | 0 0
|
30
|
+
16-02 07:51:11| 0 0 100 0 0 0| 0 0.06 0.22| 236M 44.7M 1156M 13.2G| 0 0 | 0 27k| 0 3.20 | 48B 127B
|
31
|
+
16-02 07:51:16| 0 0 100 0 0 0| 0 0.06 0.22| 236M 44.7M 1156M 13.2G| 0 0 | 0 0 | 0 0 | 10B 46B
|
32
|
+
...
|
33
|
+
```
|
34
|
+
|
35
|
+

|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it ( http://github.com/<my-github-username>/ddstat/fork )
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/ddstat
ADDED
data/ddstat.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 'ddstat/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'ddstat'
|
8
|
+
spec.version = Ddstat::VERSION
|
9
|
+
spec.authors = ['Genki Sugawara']
|
10
|
+
spec.email = ['sgwr_dts@yahoo.co.jp']
|
11
|
+
spec.summary = %q{A tool that send to Datadog the data while execute dstat}
|
12
|
+
spec.description = %q{A tool that send to Datadog the data while execute dstat}
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'dogapi'
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
end
|
data/lib/ddstat.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
class Ddstat::Ddstat
|
2
|
+
DSTAT_PATH = 'dstat'
|
3
|
+
PREFIX = 'ddstat'
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
api_key = ENV['DD_API_KEY']
|
7
|
+
app_key = ENV['DD_APP_KEY']
|
8
|
+
host = %x[hostname -f 2> /dev/null].strip
|
9
|
+
host = Socket.gethostname if host.empty?
|
10
|
+
@dog = Dogapi::Client.new(api_key, app_key, host)
|
11
|
+
end
|
12
|
+
|
13
|
+
def run
|
14
|
+
cmd = "#{DSTAT_PATH} #{ARGV.join(' ')}"
|
15
|
+
|
16
|
+
IO.popen(cmd) do |dstat|
|
17
|
+
while line = gets_with_print(dstat)
|
18
|
+
line = line.gsub("\e[7l-", '-')
|
19
|
+
parse_line(dstat, line)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def gets_with_print(dstat)
|
27
|
+
line = dstat.gets
|
28
|
+
print line
|
29
|
+
return line
|
30
|
+
end
|
31
|
+
|
32
|
+
def parse_line(dstat, line)
|
33
|
+
if line =~ /\A-/
|
34
|
+
categories = parse_category_header(line)
|
35
|
+
@fields = parse_header(categories, gets_with_print(dstat))
|
36
|
+
else
|
37
|
+
field_values = parse_values(line)
|
38
|
+
emit_points(field_values)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def parse_category_header(category_header)
|
43
|
+
categories = {}
|
44
|
+
items = category_header.split('- -')
|
45
|
+
|
46
|
+
items.each_with_index do |category, i|
|
47
|
+
n = (i.zero? or i == items.length - 1) ? 2 : 3
|
48
|
+
len = category.length + n
|
49
|
+
category = category.strip.sub(/\A-+\s*/, '').sub(/\s*-+\Z/, '')
|
50
|
+
category.gsub!(%r|[-/\s]+|, '_')
|
51
|
+
categories[category] = len
|
52
|
+
end
|
53
|
+
|
54
|
+
return categories
|
55
|
+
end
|
56
|
+
|
57
|
+
def parse_header(categories, header)
|
58
|
+
fields = []
|
59
|
+
|
60
|
+
categories.each do |category, len|
|
61
|
+
names = header.slice!(0, len).split(/[\|\s]+/).select {|i| not i.empty? }.map {|i| i.gsub(%r|[-/\s]+|, '_') }
|
62
|
+
fields << [category, names]
|
63
|
+
end
|
64
|
+
|
65
|
+
return fields
|
66
|
+
end
|
67
|
+
|
68
|
+
def parse_values(line)
|
69
|
+
categorized_values = line.split(/\|/)
|
70
|
+
field_values = {}
|
71
|
+
|
72
|
+
@fields.each_with_index do |category_names, i|
|
73
|
+
category, names = category_names
|
74
|
+
values = categorized_values[i].strip.split(/\s+/, names.length)
|
75
|
+
field_values[category] = Hash[*names.zip(values).flatten]
|
76
|
+
end
|
77
|
+
|
78
|
+
return field_values
|
79
|
+
end
|
80
|
+
|
81
|
+
def emit_points(field_values)
|
82
|
+
date_time = if field_values['system'] and field_values['system']['date_time']
|
83
|
+
Time.parse(field_values['system'].delete('date_time'))
|
84
|
+
else
|
85
|
+
Time.now
|
86
|
+
end
|
87
|
+
|
88
|
+
field_values.each do |category, fields|
|
89
|
+
fields.each do |name, value|
|
90
|
+
Thread.start do
|
91
|
+
begin
|
92
|
+
metric_name = [PREFIX, category, name].join('.')
|
93
|
+
@dog.emit_point(metric_name, value.to_f)
|
94
|
+
rescue Timeout::Error
|
95
|
+
# nothing to do
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ddstat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Genki Sugawara
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-02-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: dogapi
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.5'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.5'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: A tool that send to Datadog the data while execute dstat
|
63
|
+
email:
|
64
|
+
- sgwr_dts@yahoo.co.jp
|
65
|
+
executables:
|
66
|
+
- ddstat
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- bin/ddstat
|
76
|
+
- ddstat.gemspec
|
77
|
+
- lib/ddstat.rb
|
78
|
+
- lib/ddstat/ddstat.rb
|
79
|
+
- lib/ddstat/version.rb
|
80
|
+
homepage: ''
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.8.23
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: A tool that send to Datadog the data while execute dstat
|
105
|
+
test_files: []
|