This repository was archived by the owner on May 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetric.rb
More file actions
78 lines (68 loc) · 2.26 KB
/
metric.rb
File metadata and controls
78 lines (68 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
module Graphdat
require 'socket'
class Metric
@temp = {} # used when begin and end statements are used.
@context_list = []
@start_time = 0
@path
@msg = {}
def initialize
@path = ''
@msg = {}
@temp = {}
@context_list = []
@msg[:source] = 'HTTP'
@msg[:type] = 'Sample'
@msg[:host] = Socket.gethostname
@msg[:route] = 'GET /'
# @msg[:cputime] = 60
@msg[:timestamp] = Time.now.to_f*1000
@start_time = Time.now.to_f
self.begin ''
end
def run
self.end ''
@end_time = Time.now.to_f
responsetime = @end_time - @start_time
ints = responsetime*1000
@msg[:responsetime] = ints
@msg[:context] = @context_list.reverse
Graphdat::Agent.send_package @msg
end
# for adding the metrics to the context list when you have the response time
def measure key,value
@context= {}
@path = "#{key}"
@context[:callcount] = 1
@context[:firsttimestampoffset] = Time.now.to_f*1000 - value
@context[:name] = @path
@context[:responsetime] = value
@context_list << @context
end
# for instrumentation
def begin key
if @path == '/'
@path = @path+"#{key}"
else
@path = @path+"/#{key}"
end
@temp["#{key}:start"] = Time.now.to_f
@temp["#{key}:path"] = @path
@temp
end
def end key
@context= {}
key_start = @temp["#{key}:start"]
path = @temp["#{key}:path"]
firsttimestampoffset = key_start - @start_time
responsetime = Time.now.to_f - key_start
name = key
@context[:callcount] = 1
@context[:cputime] = 49.634
@context[:firsttimestampoffset] = firsttimestampoffset*1000
@context[:name] = path
@context[:responsetime] = responsetime*1000
@context_list << @context
end
end
end