Class: Block
Overview
gl_tail.rb - OpenGL visualization of your server traffic Copyright 2007 Erlend Simonsen <[email protected]>
Licensed under the GNU General Public License v2 (see LICENSE)
Instance Attribute Summary collapse
Instance Method Summary
collapse
#config_rewrite_color, included
Constructor Details
#initialize(config, name) ⇒ Block
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/gl_tail/block.rb', line 22
def initialize(config, name)
@config = config
@name = name
@size = 10
@auto_clean = true
@activity_type = "blobs"
@order = 100
@show = 0
@header = Element.new(self, @name.upcase, [1.0, 1.0, 1.0, 1.0])
@elements = { }
@bottom_position = -@config.screen.top
@max_rate = 1.0/599
@sorted = []
end
|
Instance Attribute Details
#bottom_position ⇒ Object
Returns the value of attribute bottom_position.
10
11
12
|
# File 'lib/gl_tail/block.rb', line 10
def bottom_position
@bottom_position
end
|
#column ⇒ Object
Returns the value of attribute column.
18
19
20
|
# File 'lib/gl_tail/block.rb', line 18
def column
@column
end
|
#config ⇒ Object
Returns the value of attribute config.
19
20
21
|
# File 'lib/gl_tail/block.rb', line 19
def config
@config
end
|
#max_rate ⇒ Object
Returns the value of attribute max_rate.
20
21
22
|
# File 'lib/gl_tail/block.rb', line 20
def max_rate
@max_rate
end
|
#name ⇒ Object
Returns the value of attribute name.
10
11
12
|
# File 'lib/gl_tail/block.rb', line 10
def name
@name
end
|
#show ⇒ Object
Returns the value of attribute show.
52
53
54
|
# File 'lib/gl_tail/block.rb', line 52
def show
@show
end
|
Instance Method Details
#add_activity(options = { }) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/gl_tail/block.rb', line 110
def add_activity(options = { })
return unless options[:name]
x = nil
unless @elements[options[:name]]
x = Element.new(self, options[:name], @color || options[:color] )
@elements[options[:name]] = x
if @sorted.size > @size
@sorted.insert(@size,x)
else
@sorted << x
end
else
x = @elements[options[:name]]
end
x.add_activity(options[:message], @color || options[:color], options[:size] || 0.01, options[:type] || 0, options[:real_size] || options[:size] )
end
|
#add_event(options = { }) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/gl_tail/block.rb', line 127
def add_event(options = { })
return unless options[:name]
x = nil
unless @elements[options[:name]]
x = Element.new(self, options[:name], @color || options[:color] )
@elements[options[:name]] = x
if @sorted.size > @size
@sorted.insert(@size,x)
else
@sorted << x
end
else
x = @elements[options[:name]]
end
x.add_event(options[:message], options[:color] || @color, options[:update_stats] || false)
end
|
#alignment ⇒ Object
66
67
68
|
# File 'lib/gl_tail/block.rb', line 66
def alignment
column.alignment
end
|
#is_right ⇒ Object
62
63
64
|
# File 'lib/gl_tail/block.rb', line 62
def is_right
column.is_right
end
|
#line_size ⇒ Object
58
59
60
|
# File 'lib/gl_tail/block.rb', line 58
def line_size
@config.screen.line_size
end
|
#position ⇒ Object
70
71
72
|
# File 'lib/gl_tail/block.rb', line 70
def position
column.position
end
|
#render(engine, num) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/gl_tail/block.rb', line 78
def render(engine, num)
return num if @elements.size == 0 || @sorted.size == 0
@header.wy = top - (num * line_size)
@header.render(engine)
num += 1
count = 0
@sorted.each do |e|
engine.stats[0] += 1
if count < @size
e.wy = top - (num * line_size)
e.render(engine)
num += 1
@max_rate = e.rate if e.rate > @max_rate
else
e.render_events(engine)
end
if e.activities.size == 0 && (e.rate <= 0.001 || count > 100) && @auto_clean
@elements.delete(e.name)
@sorted.delete(e)
end
count += 1
end
@bottom_position = top - ((@sorted.size > 0 ? (num-1) : num) * line_size)
num + 1
end
|
#top ⇒ Object
54
55
56
|
# File 'lib/gl_tail/block.rb', line 54
def top
@config.screen.top
end
|
#update ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
# File 'lib/gl_tail/block.rb', line 145
def update
return if @sorted.size == 0
@max_rate = @max_rate * 0.9999
startTime = Time.now
i = 1
@sorted[0].update
@ordered = [@sorted[0]]
min_pos = 0
size = @sorted.size
if @show == 0
min = @sorted[0].rate
while i < size
@sorted[i].update
rate = @sorted[i].rate
if rate > min
j = min_pos
while @ordered[j-1].rate < rate && j > 0
j -= 1
end
@ordered.insert(j, @sorted[i])
else
@ordered << @sorted[i]
if i < @size
min = rate
min_pos = i
end
end
i += 1
end
elsif @show == 1
min = @sorted[0].total
while i < size
@sorted[i].update
total = @sorted[i].total
if total > min
j = min_pos
while @ordered[j-1].total < total && j > 0
j -= 1
end
@ordered.insert(j, @sorted[i])
else
@ordered << @sorted[i]
if i < @size
min = total
min_pos = i
end
end
i += 1
end
elsif @show == 2
min = @sorted[0].average
while i < size
@sorted[i].update
average = @sorted[i].average
if average > min
j = min_pos
while @ordered[j-1].average < average && j > 0
j -= 1
end
@ordered.insert(j, @sorted[i])
else
@ordered << @sorted[i]
if i < @size
min = average
min_pos = i
end
end
i += 1
end
end
@sorted = @ordered
end
|
#width ⇒ Object
74
75
76
|
# File 'lib/gl_tail/block.rb', line 74
def width
column.size
end
|