ddtop 0.0.2 → 0.0.3

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/README.md CHANGED
@@ -38,6 +38,16 @@ Swap: 0k total, 0k used, 0k free, 1124444k cached
38
38
 
39
39
  ![datadog-metrics.png](https://bitbucket.org/winebarrel/ddtop/downloads/datadog-metrics.png)
40
40
 
41
+ ### `--emits` option
42
+
43
+ Sending all processes data to Datadog is too heavy.
44
+
45
+ You can specify the process of sending in `--emits` option.
46
+
47
+ ```sh
48
+ ddtop --emits httpd.worker,awk,ruby
49
+ ```
50
+
41
51
  ## Contributing
42
52
 
43
53
  1. Fork it ( http://github.com/<my-github-username>/ddtop/fork )
data/bin/ddtop CHANGED
@@ -5,9 +5,12 @@ require 'ddtop'
5
5
  civis = system('tput civis')
6
6
 
7
7
  trap(:INT) do
8
+ exit
9
+ end
10
+
11
+ at_exit do
8
12
  puts "\e[0m"
9
13
  system('tput cnorm') if civis
10
- exit
11
14
  end
12
15
 
13
16
  Ddtop.run
data/lib/ddtop/ddtop.rb CHANGED
@@ -12,12 +12,14 @@ class Ddtop::Ddtop
12
12
  def run
13
13
  clear_screen
14
14
 
15
+ emits = get_emits(ARGV)
16
+
15
17
  summary, fields = nil
16
18
  values = []
17
19
 
18
20
  head_hook = proc do
19
21
  if summary and not values.empty?
20
- emit_points(summary, fields, values)
22
+ emit_points(summary, fields, values, emits)
21
23
  values.clear
22
24
  end
23
25
  end
@@ -33,6 +35,19 @@ class Ddtop::Ddtop
33
35
 
34
36
  private
35
37
 
38
+ def get_emits(args)
39
+ i = args.index('--emits')
40
+ emits = []
41
+
42
+ if i and args[i + 1] and args[i + 1] !~ /\A-/
43
+ emits = args[i + 1].split(/,/).map {|i| i.strip }.select {|i| not i.empty? }
44
+ args.delete_at(i + 1)
45
+ args.delete_at(i)
46
+ end
47
+
48
+ return emits
49
+ end
50
+
36
51
  def top_each_lien(head_hook)
37
52
  cmd = [TOP_CMD, ARGV].flatten.join(' ')
38
53
 
@@ -47,7 +62,7 @@ class Ddtop::Ddtop
47
62
  line = top.gets
48
63
 
49
64
  if head?(line)
50
- @win_rows = win_rows
65
+ @win_rows, @win_cols = get_winsize
51
66
  @curr_row = 0
52
67
  yield if block_given?
53
68
  reset_cursor
@@ -55,10 +70,16 @@ class Ddtop::Ddtop
55
70
 
56
71
  @curr_row += 1
57
72
 
73
+ if @curr_row <= @win_rows
74
+ line.chomp!
75
+ delta = @win_cols - line.length
76
+ line += ' ' * (@win_cols - line.length) if delta > 0
77
+ end
78
+
58
79
  if @curr_row < @win_rows
59
- print line.sub(/\s+\Z/, "\n")
80
+ puts line[0, @win_cols]
60
81
  elsif @curr_row == @win_rows
61
- print line.sub(/\s+\Z/, '')
82
+ print line[0, @win_cols]
62
83
  end
63
84
 
64
85
  return line.strip
@@ -102,9 +123,9 @@ class Ddtop::Ddtop
102
123
  Hash[*items.flatten]
103
124
  end
104
125
 
105
- def emit_points(summary, names, values)
126
+ def emit_points(summary, names, values, emits)
106
127
  time = summary.delete(:time)
107
- fields = aggregate_fields(names, values)
128
+ fields = aggregate_fields(names, values, emits)
108
129
  emit_points0(time, summary)
109
130
  emit_points0(time, fields)
110
131
  end
@@ -123,7 +144,7 @@ class Ddtop::Ddtop
123
144
  # nothing to do
124
145
  end
125
146
 
126
- def aggregate_fields(names, values)
147
+ def aggregate_fields(names, values, emits)
127
148
  aggregated = {}
128
149
 
129
150
  values.map {|v|
@@ -131,6 +152,8 @@ class Ddtop::Ddtop
131
152
  %w(PID USER PR NI S).each {|k| h.delete(k) }
132
153
  h['TIME+'] = parse_time_plus(h['TIME+'])
133
154
  h
155
+ }.select {|h|
156
+ emits.empty? || emits.include?(h['COMMAND'])
134
157
  }.sort_by {|h|
135
158
  h['COMMAND']
136
159
  }.chunk {|h|
@@ -158,8 +181,10 @@ class Ddtop::Ddtop
158
181
  t[0] * 60 + t[1] + t[2] / 100
159
182
  end
160
183
 
161
- def win_rows
162
- `stty -a`.split("\n").first.split(';')[1].strip.split(/\s+/, 2)[1].to_i
184
+ def get_winsize
185
+ `stty -a`.split("\n").first.split(';').values_at(1, 2).map do |nv|
186
+ nv.strip.split(/\s+/, 2)[1].to_i
187
+ end
163
188
  end
164
189
 
165
190
  def clear_screen
data/lib/ddtop/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ddtop
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddtop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: