77import sys
88import instana .agent_const as a
99
10+
1011class Snapshot (object ):
1112 name = None
1213 version = None
13- rlimit_core = (0 , 0 )
14- rlimit_cpu = (0 , 0 )
15- rlimit_fsize = (0 , 0 )
16- rlimit_data = (0 , 0 )
17- rlimit_stack = (0 , 0 )
18- rlimit_rss = (0 , 0 )
19- rlimit_nproc = (0 , 0 )
20- rlimit_nofile = (0 , 0 )
21- rlimit_memlock = (0 , 0 )
22- rlimit_as = (0 , 0 )
14+ rlimit_core = (0 , 0 )
15+ rlimit_cpu = (0 , 0 )
16+ rlimit_fsize = (0 , 0 )
17+ rlimit_data = (0 , 0 )
18+ rlimit_stack = (0 , 0 )
19+ rlimit_rss = (0 , 0 )
20+ rlimit_nproc = (0 , 0 )
21+ rlimit_nofile = (0 , 0 )
22+ rlimit_memlock = (0 , 0 )
23+ rlimit_as = (0 , 0 )
2324 versions = None
2425
2526 def __init__ (self , ** kwds ):
2627 self .__dict__ .update (kwds )
2728
29+
2830class GC (object ):
2931 collect0 = 0
3032 collect1 = 0
@@ -36,6 +38,7 @@ class GC(object):
3638 def __init__ (self , ** kwds ):
3739 self .__dict__ .update (kwds )
3840
41+
3942class Metrics (object ):
4043 ru_utime = .0
4144 ru_stime = .0
@@ -50,7 +53,7 @@ class Metrics(object):
5053 ru_oublock = 0
5154 ru_msgsnd = 0
5255 ru_msgrcv = 0
53- ru_nsignals = 0
56+ ru_nsignals = 0
5457 ru_nvcs = 0
5558 ru_nivcsw = 0
5659 dead_threads = 0
@@ -61,6 +64,7 @@ class Metrics(object):
6164 def __init__ (self , ** kwds ):
6265 self .__dict__ .update (kwds )
6366
67+
6468class EntityData (object ):
6569 pid = 0
6670 snapshot = None
@@ -69,6 +73,7 @@ class EntityData(object):
6973 def __init__ (self , ** kwds ):
7074 self .__dict__ .update (kwds )
7175
76+
7277class Meter (object ):
7378 SNAPSHOT_PERIOD = 600
7479 snapshot_countdown = 1
@@ -105,13 +110,18 @@ def collect_snapshot(self):
105110 version = sys .version ,
106111 rlimit_core = resource .getrlimit (resource .RLIMIT_CORE ),
107112 rlimit_cpu = resource .getrlimit (resource .RLIMIT_CPU ),
108- rlimit_fsize = resource .getrlimit (resource .RLIMIT_FSIZE ),
113+ rlimit_fsize = resource .getrlimit (
114+ resource .RLIMIT_FSIZE ),
109115 rlimit_data = resource .getrlimit (resource .RLIMIT_DATA ),
110- rlimit_stack = resource .getrlimit (resource .RLIMIT_STACK ),
116+ rlimit_stack = resource .getrlimit (
117+ resource .RLIMIT_STACK ),
111118 rlimit_rss = resource .getrlimit (resource .RLIMIT_RSS ),
112- rlimit_nproc = resource .getrlimit (resource .RLIMIT_NPROC ),
113- rlimit_nofile = resource .getrlimit (resource .RLIMIT_NOFILE ),
114- rlimit_memlock = resource .getrlimit (resource .RLIMIT_MEMLOCK ),
119+ rlimit_nproc = resource .getrlimit (
120+ resource .RLIMIT_NPROC ),
121+ rlimit_nofile = resource .getrlimit (
122+ resource .RLIMIT_NOFILE ),
123+ rlimit_memlock = resource .getrlimit (
124+ resource .RLIMIT_MEMLOCK ),
115125 rlimit_as = resource .getrlimit (resource .RLIMIT_AS ),
116126 versions = self .collect_modules ())
117127
@@ -147,33 +157,47 @@ def collect_metrics(self):
147157 c = list (gc .get_count ())
148158 th = list (gc .get_threshold ())
149159 g = GC (collect0 = c [0 ] if not self .last_collect else c [0 ] - self .last_collect [0 ],
150- collect1 = c [1 ] if not self .last_collect else c [1 ] - self .last_collect [1 ],
151- collect2 = c [2 ] if not self .last_collect else c [2 ] - self .last_collect [2 ],
160+ collect1 = c [1 ] if not self .last_collect else c [
161+ 1 ] - self .last_collect [1 ],
162+ collect2 = c [2 ] if not self .last_collect else c [
163+ 2 ] - self .last_collect [2 ],
152164 threshold0 = th [0 ],
153165 threshold1 = th [1 ],
154166 threshold2 = th [2 ])
155167
156168 thr = t .enumerate ()
157169 daemon_threads = len (map (lambda tr : tr .daemon and tr .is_alive (), thr ))
158- alive_threads = len (map (lambda tr : not tr .daemon and tr .is_alive (), thr ))
170+ alive_threads = len (
171+ map (lambda tr : not tr .daemon and tr .is_alive (), thr ))
159172 dead_threads = len (map (lambda tr : not tr .is_alive (), thr ))
160173
161174 m = Metrics (ru_utime = u [0 ] if not self .last_usage else u [0 ] - self .last_usage [0 ],
162- ru_stime = u [1 ] if not self .last_usage else u [1 ] - self .last_usage [1 ],
175+ ru_stime = u [1 ] if not self .last_usage else u [
176+ 1 ] - self .last_usage [1 ],
163177 ru_maxrss = u [2 ],
164178 ru_ixrss = u [3 ],
165179 ru_idrss = u [4 ],
166180 ru_isrss = u [5 ],
167- ru_minflt = u [6 ] if not self .last_usage else u [6 ] - self .last_usage [6 ],
168- ru_majflt = u [7 ] if not self .last_usage else u [7 ] - self .last_usage [7 ],
169- ru_nswap = u [8 ] if not self .last_usage else u [8 ] - self .last_usage [8 ],
170- ru_inblock = u [9 ] if not self .last_usage else u [9 ] - self .last_usage [9 ],
171- ru_oublock = u [10 ] if not self .last_usage else u [10 ] - self .last_usage [10 ],
172- ru_msgsnd = u [11 ] if not self .last_usage else u [11 ] - self .last_usage [11 ],
173- ru_msgrcv = u [12 ] if not self .last_usage else u [12 ] - self .last_usage [12 ],
174- ru_nsignals = u [13 ] if not self .last_usage else u [13 ] - self .last_usage [13 ],
175- ru_nvcs = u [14 ] if not self .last_usage else u [14 ] - self .last_usage [14 ],
176- ru_nivcsw = u [15 ] if not self .last_usage else u [15 ] - self .last_usage [15 ],
181+ ru_minflt = u [6 ] if not self .last_usage else u [
182+ 6 ] - self .last_usage [6 ],
183+ ru_majflt = u [7 ] if not self .last_usage else u [
184+ 7 ] - self .last_usage [7 ],
185+ ru_nswap = u [8 ] if not self .last_usage else u [
186+ 8 ] - self .last_usage [8 ],
187+ ru_inblock = u [9 ] if not self .last_usage else u [
188+ 9 ] - self .last_usage [9 ],
189+ ru_oublock = u [10 ] if not self .last_usage else u [
190+ 10 ] - self .last_usage [10 ],
191+ ru_msgsnd = u [11 ] if not self .last_usage else u [
192+ 11 ] - self .last_usage [11 ],
193+ ru_msgrcv = u [12 ] if not self .last_usage else u [
194+ 12 ] - self .last_usage [12 ],
195+ ru_nsignals = u [13 ] if not self .last_usage else u [
196+ 13 ] - self .last_usage [13 ],
197+ ru_nvcs = u [14 ] if not self .last_usage else u [
198+ 14 ] - self .last_usage [14 ],
199+ ru_nivcsw = u [15 ] if not self .last_usage else u [
200+ 15 ] - self .last_usage [15 ],
177201 alive_threads = alive_threads ,
178202 dead_threads = dead_threads ,
179203 daemon_threads = daemon_threads ,
0 commit comments