DatabaseProcApplicationCreatedLinks
sybsystemprocssp_sysmon_repagent  31 Aug 14Defects Dependencies

1     
2     /*
3     ** ===========================================================================
4     ** Generated by spgenmsgs.pl on Sun Jan 29 13:21:05 2006 
5     ** 
6     ** raiserror Messages for sysmon_repagent [Total 0]
7     ** 
8     ** sp_getmessage Messages for sysmon_repagent [Total 0]
9     ** 
10    ** End spgenmsgs.pl output.
11    */
12    create procedure sp_sysmon_repagent
13    as
14        declare @dbid int /* dbid of the database 	 */
15        declare @dbname varchar(255) /* Database name 		 */
16        declare @group_name varchar(255) /* Counter group name		 */
17        declare @rptline varchar(305) /* Formatted info for print stmt */
18        declare @rptline1 varchar(305) /* Formatted info for print stmt */
19        declare @rptline2 varchar(305) /* Formatted info for print stmt */
20        declare @section char(80) /* String to delimit sections    */
21        declare @blankline char(1) /* To print blank line 		 */
22        declare @tmp_int int
23        declare @tmp_total int /* Used to calculate average     */
24        declare @tmp_cnt int /* Used to calculate average     */
25        declare @na_str char(3) /* 'n/a' for 'not applicable'    */
26        declare @tmp_avg varchar(10) /* Used to stored average 	 */
27        declare @tmp_size varchar(12) /* Used to calculate pool size   */
28        declare @runval_multithread varchar(5) /* Used for multithread property */
29        declare @packets_sent int /* Used to calculate avg packets sent */
30        declare @spid int /* Sender spid			*/
31        declare @SleepsOnEmptyQueue int /* Number of sender sleeps on empty queue */
32        declare @NumberOfQueueFlushes int /* Number of times queue is flushed */
33        declare @SleepTimeOnEmptyQueue int /* Total sleep time on empty queue */
34        declare @LongestSleepTimeOnEmptyQueue int
35        /* Longest sleep time on empty queue */
36        declare @MaxQueueSize int /* Max. queue size reached */
37    
38        set nocount on
39    
40        /* Check if ASE is configured to use Replication Agent threads */
41        if is_rep_agent_enabled() = 0
42        begin
43            /* There is nothing to print if Replication Agent is not enable */
44            return (0)
45        end
46    
47        select @blankline = " "
48        select @na_str = "n/a"
49        select @rptline = space(34) + "per sec      per xact       count  %% of total"
50        select @rptline1 = space(29) + "------------  ------------  ----------  ----------"
51    
52        print "==============================================================================="
53        print @blankline
54        print "Replication Agent"
55        print "-----------------"
56        print @blankline
57    
58        /*
59        ** Create a temp table of all databases.  Do not include databases that do
60        ** not support RepAgent Thread (i.e. 'tempdb' (2), 'model' (3),
61        ** 'sybsystemdb' (31513), 'sybsystemprocs' (31514)), local system tempdbs
62        ** (status3 & 536870912), and local user tempdbs (status3 & 256)
63        */
64        select dbid,
65            name,
66            "repagent_" + convert(char(3), dbid) as group_name
67        into #tempdatabases
68        from master.dbo.sysdatabases
69        where name not in ('tempdb', 'model', 'sybsystemdb', 'sybsystemprocs')
70            and (((status3 & 256) = 0)
71                and ((status3 & 536870912) = 0))
72            and is_rep_agent_enabled(dbid) = 1
73    
74        /* Start processing for each database stored in tempdatabases */
75        declare db_info cursor
76        for select dbid, name, group_name from #tempdatabases
77    
78        open db_info
79        fetch db_info into @dbid, @dbname, @group_name
80        while (@@sqlstatus = 0)
81        begin
82            /* make sure temp variables are initialized to 0 */
83            select @tmp_cnt = 0
84            select @tmp_int = 0
85            select @tmp_total = 0
86    
87            select @rptline2 = "Replication Agent:  " + @dbname
88            print @rptline2
89    
90            select @rptline2 = "Replication Server: " +
91                rep_agent_config(@dbid, "config", "rs servername")
92            print @rptline2
93            print @blankline
94            print @rptline
95            print @rptline1
96            print "Log Scan Summary"
97    
98            select @tmp_int = value
99            from #tempmonitors
100           where group_name = @group_name
101               and field_name = "ra_log_records_scanned"
102   
103           select @rptline2 = "    Log Records Scanned"
104           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
105               @na_str + space(11) + @na_str + space(2) +
106               str(@tmp_int, 10) + space(7) + @na_str
107           print @rptline2
108   
109           select @tmp_int = value
110           from #tempmonitors
111           where group_name = @group_name
112               and field_name = "ra_log_records_processed"
113   
114           select @rptline2 = "    Log Records Processed"
115           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
116               @na_str + space(11) + @na_str + space(2) +
117               str(@tmp_int, 10) + space(7) + @na_str
118           print @rptline2
119   
120           select @tmp_int = value
121           from #tempmonitors
122           where group_name = @group_name
123               and field_name = "ra_log_scans"
124   
125           select @rptline2 = "    Number of Log Scans"
126           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
127               @na_str + space(11) + @na_str + space(2) +
128               str(@tmp_int, 10) + space(7) + @na_str
129           print @rptline2
130           select @tmp_cnt = @tmp_int
131   
132           select @tmp_int = value
133           from #tempmonitors
134           where group_name = @group_name
135               and field_name = "ra_sum_log_scan"
136           select @rptline2 = "    Amount of Time for Log Scans (ms)"
137           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
138               @na_str + space(11) + @na_str + space(2) +
139               str(@tmp_int, 10) + space(7) + @na_str
140           print @rptline2
141           select @tmp_total = @tmp_int
142   
143           select @tmp_int = value
144           from #tempmonitors
145           where group_name = @group_name
146               and field_name = "ra_longest_log_scan"
147           select @rptline2 = "    Longest Time for Log Scan (ms)"
148           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
149               @na_str + space(11) + @na_str + space(2) +
150               str(@tmp_int, 10) + space(7) + @na_str
151           print @rptline2
152   
153           select @rptline2 = "    Average Time per Log Scan (ms)"
154           if (@tmp_cnt > 0)
155           begin
156               select @tmp_avg = str(1.0 * @tmp_total / @tmp_cnt, 10, 1)
157           end
158           else select @tmp_avg = str(1.0 * 0, 10, 1)
159           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
160               @na_str + space(11) + @na_str + space(2) + @tmp_avg +
161               space(7) + @na_str
162           print @rptline2
163   
164           print @blankline
165           print "Log Scan Activity"
166   
167           select @tmp_int = value
168           from #tempmonitors
169           where group_name = @group_name and field_name = "ra_xupdate_processed"
170   
171           select @rptline2 = "    Updates"
172           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
173               @na_str + space(11) + @na_str + space(2) +
174               str(@tmp_int, 10) + space(7) + @na_str
175           print @rptline2
176   
177           select @tmp_int = value
178           from #tempmonitors
179           where group_name = @group_name and field_name = "ra_xinsert_processed"
180           select @rptline2 = "    Inserts"
181           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
182               @na_str + space(11) + @na_str + space(2) +
183               str(@tmp_int, 10) + space(7) + @na_str
184           print @rptline2
185   
186           select @tmp_int = value
187           from #tempmonitors
188           where group_name = @group_name and field_name = "ra_xdelete_processed"
189           select @rptline2 = "    Deletes"
190           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
191               @na_str + space(11) + @na_str + space(2) +
192               str(@tmp_int, 10) + space(7) + @na_str
193           print @rptline2
194   
195           select @tmp_int = value
196           from #tempmonitors
197           where group_name = @group_name and field_name = "ra_xexec_processed"
198           select @rptline2 = "    Store Procedures"
199           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
200               @na_str + space(11) + @na_str + space(2) +
201               str(@tmp_int, 10) + space(7) + @na_str
202           print @rptline2
203   
204           select @tmp_int = value
205           from #tempmonitors
206           where group_name = @group_name and field_name = "ra_xcmdtext_processed"
207           select @rptline2 = "    DDL Log Records"
208           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
209               @na_str + space(11) + @na_str + space(2) +
210               str(@tmp_int, 10) + space(7) + @na_str
211           print @rptline2
212   
213           select @tmp_int = value
214           from #tempmonitors
215           where group_name = @group_name and field_name = "ra_xwrtext_processed"
216           select @rptline2 = "    Writetext Log Records"
217           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
218               @na_str + space(11) + @na_str + space(2) +
219               str(@tmp_int, 10) + space(7) + @na_str
220           print @rptline2
221   
222           select @tmp_int = value
223           from #tempmonitors
224           where group_name = @group_name and field_name = "ra_xrowimage_processed"
225           select @rptline2 = "    Text/Image Log Records"
226           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
227               @na_str + space(11) + @na_str + space(2) +
228               str(@tmp_int, 10) + space(7) + @na_str
229           print @rptline2
230   
231           select @tmp_int = value
232           from #tempmonitors
233           where group_name = @group_name and field_name = "ra_xclr_processed"
234           select @rptline2 = "    CLRs"
235           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
236               @na_str + space(11) + @na_str + space(2) +
237               str(@tmp_int, 10) + space(7) + @na_str
238           print @rptline2
239   
240           select @tmp_int = value
241           from #tempmonitors
242           where group_name = @group_name and field_name = "ra_xckpt_processed"
243           select @rptline2 = "    Checkpoints Processed"
244           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
245               @na_str + space(11) + @na_str + space(2) +
246               str(@tmp_int, 10) + space(7) + @na_str
247           print @rptline2
248   
249           select @tmp_int = value
250           from #tempmonitors
251           where group_name = @group_name and field_name = "ra_sqldml_processed"
252           select @rptline2 = "    SQL Statements Processed"
253           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
254               @na_str + space(11) + @na_str + space(2) +
255               str(@tmp_int, 10) + space(7) + @na_str
256           print @rptline2
257   
258   
259           print @blankline
260           print "Transaction Activity"
261   
262           select @tmp_int = value
263           from #tempmonitors
264           where group_name = @group_name and field_name = "ra_open_xact"
265           select @rptline2 = "    Opened"
266           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
267               @na_str + space(11) + @na_str + space(2) +
268               str(@tmp_int, 10) + space(7) + @na_str
269           print @rptline2
270   
271           select @tmp_int = value
272           from #tempmonitors
273           where group_name = @group_name and field_name = "ra_commit_xact"
274           select @rptline2 = "    Commited"
275           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
276               @na_str + space(11) + @na_str + space(2) +
277               str(@tmp_int, 10) + space(7) + @na_str
278           print @rptline2
279   
280           select @tmp_int = value
281           from #tempmonitors
282           where group_name = @group_name and field_name = "ra_abort_xact"
283           select @rptline2 = "    Aborted"
284           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
285               @na_str + space(11) + @na_str + space(2) +
286               str(@tmp_int, 10) + space(7) + @na_str
287           print @rptline2
288   
289           select @tmp_int = value
290           from #tempmonitors
291           where group_name = @group_name and field_name = "ra_prepared_xact"
292           select @rptline2 = "    Prepared"
293           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
294               @na_str + space(11) + @na_str + space(2) +
295               str(@tmp_int, 10) + space(7) + @na_str
296           print @rptline2
297   
298           select @rptline2 = "    Delayed Commit"
299           select @tmp_int = value
300           from #tempmonitors
301           where group_name = @group_name and field_name = "ra_delayed_commit_xact"
302           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
303               @na_str + space(11) + @na_str + space(2) +
304               str(@tmp_int, 10) + space(7) + @na_str
305           print @rptline2
306   
307           select @tmp_int = value
308           from #tempmonitors
309           where group_name = @group_name and field_name = "ra_maintuser_xact"
310           select @rptline2 = "    Maintenance User"
311           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
312               @na_str + space(11) + @na_str + space(2) +
313               str(@tmp_int, 10) + space(7) + @na_str
314           print @rptline2
315           print @blankline
316   
317           print "Log Extension Wait"
318           select @tmp_int = value
319           from #tempmonitors
320           where group_name = @group_name and field_name = "ra_log_waits"
321           select @rptline2 = "    Count"
322           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
323               @na_str + space(11) + @na_str + space(2) +
324               str(@tmp_int, 10) + space(7) + @na_str
325           print @rptline2
326           select @tmp_cnt = @tmp_int
327   
328           select @tmp_int = value
329           from #tempmonitors
330           where group_name = @group_name and field_name = "ra_sum_log_wait"
331           select @rptline2 = "    Amount of time (ms)"
332           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
333               @na_str + space(11) + @na_str + space(2) +
334               str(@tmp_int, 10) + space(7) + @na_str
335           print @rptline2
336           select @tmp_total = @tmp_int
337   
338           select @tmp_int = value
339           from #tempmonitors
340           where group_name = @group_name and field_name = "ra_longest_log_wait"
341           select @rptline2 = "    Longest Wait (ms)"
342           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
343               @na_str + space(11) + @na_str + space(2) +
344               str(@tmp_int, 10) + space(7) + @na_str
345           print @rptline2
346   
347           select @rptline2 = "    Average Time (ms)"
348           if (@tmp_cnt > 0)
349           begin
350               select @tmp_avg = str(1.0 * @tmp_total / @tmp_cnt, 10, 1)
351           end
352           else select @tmp_avg = str(1.0 * 0, 10, 1)
353           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
354               @na_str + space(11) + @na_str + space(2) + @tmp_avg +
355               space(7) + @na_str
356   
357           print @rptline2
358           print @blankline
359   
360           print "Schema Cache"
361           print " Usage"
362           select @rptline2 = "    Max Ever Used"
363           select @tmp_int = convert(int,
364               rep_agent_config(@dbid,
365                   "schema cache",
366                   "max"))
367           select @rptline2 = @rptline2 +
368               space(38 - datalength(@rptline2)) +
369               @na_str + space(11) + @na_str + space(2) +
370               str(@tmp_int, 10) + space(7) + @na_str
371           print @rptline2
372   
373           select @tmp_int = value
374           from #tempmonitors
375           where group_name = @group_name and field_name = "ra_schema_reuse"
376           select @rptline2 = "    Schemas reused"
377           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
378               @na_str + space(11) + @na_str + space(2) +
379               str(@tmp_int, 10) + space(7) + @na_str
380           print @rptline2
381   
382           print " Forward Schema Lookups"
383           select @tmp_int = value
384           from #tempmonitors
385           where group_name = @group_name and field_name = "ra_forward_schema"
386           select @rptline2 = "    Count"
387           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
388               @na_str + space(11) + @na_str + space(2) +
389               str(@tmp_int, 10) + space(7) + @na_str
390           print @rptline2
391           select @tmp_cnt = @tmp_int
392   
393           select @tmp_int = value
394           from #tempmonitors
395           where group_name = @group_name and field_name = "ra_sum_forward_wait"
396           select @rptline2 = "    Total Wait (ms)"
397           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
398               @na_str + space(11) + @na_str + space(2) +
399               str(@tmp_int, 10) + space(7) + @na_str
400           print @rptline2
401           select @tmp_total = @tmp_int
402   
403           select @tmp_int = value
404           from #tempmonitors
405           where group_name = @group_name and field_name = "ra_longest_forward_wait"
406           select @rptline2 = "    Longest Wait (ms)"
407           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
408               @na_str + space(11) + @na_str + space(2) +
409               str(@tmp_int, 10) + space(7) + @na_str
410           print @rptline2
411   
412           select @rptline2 = "    Average Time (ms)"
413           if (@tmp_cnt > 0)
414           begin
415               select @tmp_avg = str(1.0 * @tmp_total / @tmp_cnt, 10, 1)
416           end
417           else select @tmp_avg = str(1.0 * 0, 10, 1)
418           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
419               @na_str + space(11) + @na_str + space(2) + @tmp_avg +
420               space(7) + @na_str
421           print @rptline2
422           print " Backward Schema Lookups"
423           select @tmp_int = value
424           from #tempmonitors
425           where group_name = @group_name and field_name = "ra_backward_schema"
426           select @rptline2 = "    Count"
427           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
428               @na_str + space(11) + @na_str + space(2) +
429               str(@tmp_int, 10) + space(7) + @na_str
430           print @rptline2
431           select @tmp_cnt = @tmp_int
432   
433           select @tmp_int = value
434           from #tempmonitors
435           where group_name = @group_name and field_name = "ra_sum_bckward_wait"
436           select @rptline2 = "    Total Wait (ms)"
437           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
438               @na_str + space(11) + @na_str + space(2) +
439               str(@tmp_int, 10) + space(7) + @na_str
440           print @rptline2
441           select @tmp_total = @tmp_int
442   
443           select @tmp_int = value
444           from #tempmonitors
445           where group_name = @group_name and field_name = "ra_longest_bckward_wait
446   "
447           select @rptline2 = "    Longest Wait (ms)"
448           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
449               @na_str + space(11) + @na_str + space(2) +
450               str(@tmp_int, 10) + space(7) + @na_str
451           print @rptline2
452   
453           select @rptline2 = "    Average Time (ms)"
454           if (@tmp_cnt > 0)
455           begin
456               select @tmp_avg = str(1.0 * @tmp_total / @tmp_cnt, 10, 1)
457           end
458           else select @tmp_avg = str(1.0 * 0, 10, 1)
459           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
460               @na_str + space(11) + @na_str + space(2) + @tmp_avg +
461               space(7) + @na_str
462           print @rptline2
463           print @blankline
464           print "Truncation Point Movement"
465   
466           select @tmp_int = value
467           from #tempmonitors
468           where group_name = @group_name and field_name = "ra_truncpt_moved"
469           select @rptline2 = "    Moved"
470           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
471               @na_str + space(11) + @na_str + space(2) +
472               str(@tmp_int, 10) + space(7) + @na_str
473           print @rptline2
474   
475           select @tmp_int = value
476           from #tempmonitors
477           where group_name = @group_name and field_name = "ra_truncpt_gotten"
478           select @rptline2 = "    Gotten from RS"
479           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
480               @na_str + space(11) + @na_str + space(2) +
481               str(@tmp_int, 10) + space(7) + @na_str
482           print @rptline2
483           print @blankline
484           print "Connections to Replication Server"
485   
486           select @tmp_int = value
487           from #tempmonitors
488           where group_name = @group_name and field_name = "ra_rs_connect"
489           select @rptline2 = "    Success"
490           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
491               @na_str + space(11) + @na_str + space(2) +
492               str(@tmp_int, 10) + space(7) + @na_str
493           print @rptline2
494   
495           select @tmp_int = value
496           from #tempmonitors
497           where group_name = @group_name and field_name = "ra_fail_rs_connect"
498           select @rptline2 = "    Failed"
499           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
500               @na_str + space(11) + @na_str + space(2) +
501               str(@tmp_int, 10) + space(7) + @na_str
502           print @rptline2
503           print @blankline
504           print "Network Packet Information"
505   
506           select @tmp_int = value
507           from #tempmonitors
508           where group_name = @group_name and field_name = "ra_packets_sent"
509           select @rptline2 = "    Packets Sent"
510           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
511               @na_str + space(11) + @na_str + space(2) +
512               str(@tmp_int, 10) + space(7) + @na_str
513           print @rptline2
514           select @tmp_cnt = @tmp_int
515           select @packets_sent = @tmp_int
516   
517           select @tmp_int = value
518           from #tempmonitors
519           where group_name = @group_name and field_name = "ra_full_packets_sent"
520           select @rptline2 = "    Full Packets Sent"
521           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
522               @na_str + space(11) + @na_str + space(2) +
523               str(@tmp_int, 10) + space(7) + @na_str
524           print @rptline2
525   
526           select @tmp_int = value
527           from #tempmonitors
528           where group_name = @group_name and field_name = "ra_largest_packet"
529           select @rptline2 = "    Largest Packet"
530           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
531               @na_str + space(11) + @na_str + space(2) +
532               str(@tmp_int, 10) + space(7) + @na_str
533           print @rptline2
534   
535           select @tmp_int = value
536           from #tempmonitors
537           where group_name = @group_name and field_name = "ra_sum_packet"
538           select @rptline2 = "    Amount of Bytes Sent"
539           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
540               @na_str + space(11) + @na_str + space(2) +
541               str(@tmp_int, 10) + space(7) + @na_str
542           print @rptline2
543           select @tmp_total = @tmp_int
544   
545           select @rptline2 = "    Average Packet"
546           if (@tmp_cnt > 0)
547           begin
548               select @tmp_avg = str(1.0 * @tmp_total / @tmp_cnt, 10, 1)
549           end
550           else select @tmp_avg = str(1.0 * 0, 10, 1)
551           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
552               @na_str + space(11) + @na_str + space(2) + @tmp_avg +
553               space(7) + @na_str
554           print @rptline2
555           print @blankline
556           print "I/O Wait from RS"
557   
558           select @tmp_int = sum(value)
559           from #tempmonitors
560           where group_name = @group_name
561               and (field_name = "ra_io_send" or field_name = "ra_io_recv")
562           select @rptline2 = "    Count"
563           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
564               @na_str + space(11) + @na_str + space(2) +
565               str(@tmp_int, 10) + space(7) + @na_str
566           print @rptline2
567           select @tmp_cnt = @tmp_int
568   
569           select @tmp_int = sum(value)
570           from #tempmonitors
571           where group_name = @group_name
572               and (field_name = "ra_sum_io_send_wait"
573                   or field_name = "ra_sum_io_recv_wait")
574           select @rptline2 = "    Amount of Time (ms)"
575           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
576               @na_str + space(11) + @na_str + space(2) +
577               str(@tmp_int, 10) + space(7) + @na_str
578           print @rptline2
579           select @tmp_total = @tmp_int
580   
581           select @tmp_int = max(value)
582           from #tempmonitors
583           where group_name = @group_name
584               and (field_name = "ra_longest_io_send_wait"
585                   or field_name = "ra_longest_io_recv_wait")
586           select @rptline2 = "    Longest Wait (ms)"
587           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
588               @na_str + space(11) + @na_str + space(2) +
589               str(@tmp_int, 10) + space(7) + @na_str
590           print @rptline2
591   
592           select @rptline2 = "    Average Wait (ms)"
593           if (@tmp_cnt > 0)
594           begin
595               select @tmp_avg = str(1.0 * @tmp_total / @tmp_cnt, 10, 1)
596           end
597           else select @tmp_avg = str(1.0 * 0, 10, 1)
598           select @rptline2 = @rptline2 + space(38 - datalength(@rptline2)) +
599               @na_str + space(11) + @na_str + space(2) + @tmp_avg +
600               space(7) + @na_str
601           print @rptline2
602           print @blankline
603   
604           select @rptline2 = replicate('-', 80)
605           print @rptline2
606   
607           print @rptline2
608   
609           fetch db_info into @dbid, @dbname, @group_name
610   
611       end
612       close db_info
613       deallocate cursor db_info
614   
615       return 0
616   


exec sp_procxmode 'sp_sysmon_repagent', 'AnyMode'
go

Grant Execute on sp_sysmon_repagent to public
go
DEFECTS
 CUNU 3 Cursor not updated: cursor should contain 'for read only' clause db_info 76
 MGTP 3 Grant to public master..sysdatabases  
 MGTP 3 Grant to public sybsystemprocs..sp_sysmon_repagent  
 MLCH 3 Char type with length>30 char(80) 20
 MNER 3 No Error Check should check @@error after select into 64
 MUCO 3 Useless Code Useless Brackets 44
 MUCO 3 Useless Code Useless Brackets 80
 MUCO 3 Useless Code Useless Brackets 154
 MUCO 3 Useless Code Useless Brackets 348
 MUCO 3 Useless Code Useless Brackets 413
 MUCO 3 Useless Code Useless Brackets 454
 MUCO 3 Useless Code Useless Brackets 546
 MUCO 3 Useless Code Useless Brackets 593
 QAFM 3 Var Assignment from potentially many rows 98
 QAFM 3 Var Assignment from potentially many rows 109
 QAFM 3 Var Assignment from potentially many rows 120
 QAFM 3 Var Assignment from potentially many rows 132
 QAFM 3 Var Assignment from potentially many rows 143
 QAFM 3 Var Assignment from potentially many rows 167
 QAFM 3 Var Assignment from potentially many rows 177
 QAFM 3 Var Assignment from potentially many rows 186
 QAFM 3 Var Assignment from potentially many rows 195
 QAFM 3 Var Assignment from potentially many rows 204
 QAFM 3 Var Assignment from potentially many rows 213
 QAFM 3 Var Assignment from potentially many rows 222
 QAFM 3 Var Assignment from potentially many rows 231
 QAFM 3 Var Assignment from potentially many rows 240
 QAFM 3 Var Assignment from potentially many rows 249
 QAFM 3 Var Assignment from potentially many rows 262
 QAFM 3 Var Assignment from potentially many rows 271
 QAFM 3 Var Assignment from potentially many rows 280
 QAFM 3 Var Assignment from potentially many rows 289
 QAFM 3 Var Assignment from potentially many rows 299
 QAFM 3 Var Assignment from potentially many rows 307
 QAFM 3 Var Assignment from potentially many rows 318
 QAFM 3 Var Assignment from potentially many rows 328
 QAFM 3 Var Assignment from potentially many rows 338
 QAFM 3 Var Assignment from potentially many rows 373
 QAFM 3 Var Assignment from potentially many rows 383
 QAFM 3 Var Assignment from potentially many rows 393
 QAFM 3 Var Assignment from potentially many rows 403
 QAFM 3 Var Assignment from potentially many rows 423
 QAFM 3 Var Assignment from potentially many rows 433
 QAFM 3 Var Assignment from potentially many rows 443
 QAFM 3 Var Assignment from potentially many rows 466
 QAFM 3 Var Assignment from potentially many rows 475
 QAFM 3 Var Assignment from potentially many rows 486
 QAFM 3 Var Assignment from potentially many rows 495
 QAFM 3 Var Assignment from potentially many rows 506
 QAFM 3 Var Assignment from potentially many rows 517
 QAFM 3 Var Assignment from potentially many rows 526
 QAFM 3 Var Assignment from potentially many rows 535
 VUNU 3 Variable is not used @section 20
 VUNU 3 Variable is not used @tmp_size 27
 VUNU 3 Variable is not used @runval_multithread 28
 VUNU 3 Variable is not used @spid 30
 VUNU 3 Variable is not used @SleepsOnEmptyQueue 31
 VUNU 3 Variable is not used @NumberOfQueueFlushes 32
 VUNU 3 Variable is not used @SleepTimeOnEmptyQueue 33
 VUNU 3 Variable is not used @LongestSleepTimeOnEmptyQueue 34
 VUNU 3 Variable is not used @MaxQueueSize 36
 CUPD 2 Updatable Cursor Marker (updatable by default) 76
 MTR1 2 Metrics: Comments Ratio Comments: 6% 12
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 56 = 56dec - 2exi + 2 12
 MTR3 2 Metrics: Query Complexity Complexity: 443 12

DEPENDENCIES
PROCS AND TABLES USED
reads table master..sysdatabases (1)  
read_writes table tempdb..#tempdatabases (1) 
reads table tempdb..#tempmonitors (1) 

CALLERS
called by proc sybsystemprocs..sp_sysmon_analyze  
   called by proc sybsystemprocs..sp_sysmon