ddstat 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTBlOWNmNTk5OGMxOTZiOGYxZDY4Y2UxNTQ5ZTcyMzljNzUyZGI4ZA==
5
+ data.tar.gz: !binary |-
6
+ NzdlNjBjOTY4NjI4Zjc2YzllMDE3OWQ5M2I3YjhkMzcyMGE2NTkwMQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ Y2JlMTI1Y2MzN2YzOTA3OGIxMmYzMTNlMDY4YWM1ODFmMWQxY2IxNjQyNGE5
10
+ NGQ1NmQ3MDczYjhmMDRjODI3ZTJmNThkYTI3NzFmNjNjMjA5MWFkYWNkYjEz
11
+ MWZlN2M2ZjA1YTdmNmU3YzNmZjRlZjg4Y2RiMjY2YTMzMmJmOTA=
12
+ data.tar.gz: !binary |-
13
+ ZDRmZDk3OWZmYjBiZGNjZjZiZTUxZGFlOWEwODhjOGY2NWFmOThiMTQ2OTgz
14
+ NzU3MGQxYzBiMjVjYTNmNzRjOTc0ZWQwZWExZTMzOGIyMTk5MTEzODhlNTVk
15
+ MmIyZDBhMGFhZjAxOWVkZDc2OGY3NjRlNTJhYjM5ZWNlYTM0YTY=
data/README.md CHANGED
@@ -22,7 +22,6 @@ Or install it yourself as:
22
22
 
23
23
  ```sh
24
24
  $ export DD_API_KEY=...
25
- $ #export DD_APP_KEY=...
26
25
  $ ddstat -tclmsdrn 5 # The outputted data is transmitted to Datadog.
27
26
  ----system---- ----total-cpu-usage---- ---load-avg--- ------memory-usage----- ----swap--- -dsk/total- --io/total- -net/total-
28
27
  date/time |usr sys idl wai hiq siq| 1m 5m 15m | used buff cach free| used free| read writ| read writ| recv send
data/bin/ddstat CHANGED
@@ -1,4 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
  $: << File.expand_path("#{File.dirname __FILE__}/../lib")
3
3
  require 'ddstat'
4
+
5
+ trap(:INT) do
6
+ print "\e[0m"
7
+ exit
8
+ end
9
+
4
10
  Ddstat.run
data/ddstat.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'dogapi'
21
+ spec.add_dependency 'json'
22
22
  spec.add_development_dependency 'bundler', '~> 1.5'
23
23
  spec.add_development_dependency 'rake'
24
24
  end
data/lib/ddstat.rb CHANGED
@@ -4,9 +4,11 @@ module Ddstat
4
4
  end
5
5
  end
6
6
 
7
- require 'thread'
7
+ require 'json'
8
+ require 'net/http'
9
+ require 'pty'
8
10
  require 'time'
9
11
  require 'socket'
10
- require 'dogapi'
11
12
  require 'ddstat/version'
12
13
  require 'ddstat/ddstat'
14
+ require 'ddstat/ddclient'
data/lib/ddstat/ddstat.rb CHANGED
@@ -4,19 +4,24 @@ class Ddstat::Ddstat
4
4
 
5
5
  def initialize
6
6
  api_key = ENV['DD_API_KEY']
7
- app_key = ENV['DD_APP_KEY']
8
7
  host = %x[hostname -f 2> /dev/null].strip
9
8
  host = Socket.gethostname if host.empty?
10
- @dog = Dogapi::Client.new(api_key, app_key, host)
9
+ @dog = Ddstat::Ddclient.new(api_key, host)
11
10
  end
12
11
 
13
12
  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)
13
+ rows, cols = curr_rows_cols
14
+ cmd = [
15
+ "stty rows #{rows}",
16
+ "stty cols #{cols}",
17
+ "#{DSTAT_PATH} #{ARGV.join(' ')}"
18
+ ].join(';')
19
+
20
+ PTY.spawn(cmd) do |r, w, pid|
21
+ while line = gets_with_print(r)
22
+ line = line.gsub(/\e\[?7l?-/, '-')
23
+ line = line.split("\e8").last
24
+ parse_line(r, line)
20
25
  end
21
26
  end
22
27
  end
@@ -26,13 +31,17 @@ class Ddstat::Ddstat
26
31
  def gets_with_print(dstat)
27
32
  line = dstat.gets
28
33
  print line
29
- return line
34
+ return remove_color(line)
30
35
  end
31
36
 
32
37
  def parse_line(dstat, line)
33
38
  if line =~ /\A-/
34
- categories = parse_category_header(line)
35
- @fields = parse_header(categories, gets_with_print(dstat))
39
+ header = gets_with_print(dstat)
40
+
41
+ unless @fields
42
+ categories = parse_category_header(line)
43
+ @fields = parse_header(categories, header)
44
+ end
36
45
  else
37
46
  field_values = parse_values(line)
38
47
  emit_points(field_values)
@@ -85,17 +94,27 @@ class Ddstat::Ddstat
85
94
  Time.now
86
95
  end
87
96
 
97
+ metrics = {}
98
+
88
99
  field_values.each do |category, fields|
89
100
  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
101
+ metric_name = [PREFIX, category, name].join('.')
102
+ metrics[metric_name] = value.to_f
98
103
  end
99
104
  end
105
+
106
+ @dog.emit_series(date_time, metrics)
107
+ rescue Timeout::Error
108
+ # nothing to do
109
+ end
110
+
111
+ def remove_color(str)
112
+ str.gsub(/\e\[\d{1,2}(?:;\d{1,2})*[mK]/, '')
113
+ end
114
+
115
+ def curr_rows_cols
116
+ `stty -a`.split("\n").first.split(';').values_at(1, 2).map do |nv|
117
+ nv.strip.split(/\s+/, 2)[1]
118
+ end
100
119
  end
101
120
  end
@@ -1,3 +1,3 @@
1
1
  module Ddstat
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddstat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Genki Sugawara
@@ -12,9 +11,8 @@ cert_chain: []
12
11
  date: 2014-02-16 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: dogapi
14
+ name: json
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bundler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
@@ -80,26 +73,25 @@ files:
80
73
  homepage: https://bitbucket.org/winebarrel/ddstat
81
74
  licenses:
82
75
  - MIT
76
+ metadata: {}
83
77
  post_install_message:
84
78
  rdoc_options: []
85
79
  require_paths:
86
80
  - lib
87
81
  required_ruby_version: !ruby/object:Gem::Requirement
88
- none: false
89
82
  requirements:
90
83
  - - ! '>='
91
84
  - !ruby/object:Gem::Version
92
85
  version: '0'
93
86
  required_rubygems_version: !ruby/object:Gem::Requirement
94
- none: false
95
87
  requirements:
96
88
  - - ! '>='
97
89
  - !ruby/object:Gem::Version
98
90
  version: '0'
99
91
  requirements: []
100
92
  rubyforge_project:
101
- rubygems_version: 1.8.23
93
+ rubygems_version: 2.1.11
102
94
  signing_key:
103
- specification_version: 3
95
+ specification_version: 4
104
96
  summary: A tool that send to Datadog the data while execute dstat
105
97
  test_files: []