forked from The-McGrail-Foundation/MIMEDefang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch-multiple-mimedefangs.tcl
executable file
·1593 lines (1444 loc) · 48.8 KB
/
watch-multiple-mimedefangs.tcl
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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
# -*-Mode: TCL;-*-
#
# Copyright (C) 2007 Roaring Penguin Software Inc. This file may be
# distributed under the terms of the GNU General Public License, Version 2,
# or (at your option) any later version.
# Next line restarts using wish \
exec wish "$0" -- "$@" ; clear; echo "*****"; echo "Cannot find 'wish' -- you need Tcl/Tk installed to run this program"; exit 1
# Main update interval (ms)
set MainUpdateInterval 1500
# Busy worker update interval (ms)
set BusyWorkerUpdateInterval 3000
# Trace command - pid is appended
set TraceCommand "strace -s 100 -t -p"
# Command to run SSH
set SSHCommand "ssh"
# Command to run md-mx-ctrl
set MD_MX_CTRL "md-mx-ctrl -i"
# Archive readings?
set DoArchive 0
# Have we done a redraw since the last update?
# Start out set to yes to kick things off!
set DoneARedrawSinceLastUpdate 1
# Use new-style "rawload1" command?
set NewStyle 0
set NewStyleShowScans 0
set NewStyleShowRelayoks 0
set NewStyleShowSenderoks 0
set NewStyleShowRecipoks 0
# Time scale for graph y-axes (seconds)
set NewStyleTimeInterval 1
set MachinesAwaitingReply {}
if {[info exists env(MD_MX_CTRL)]} {
set x $env(MD_MX_CTRL)
if {"$x" != ""} {
set MD_MX_CTRL $x
}
}
proc strip_zeros { num } {
return [regsub {\.0+$} $num ""]
}
# Don't edit anything below here!
set Machines {}
set ctr 0
set after_token {}
proc find_machine { mach } {
global Machines
set index 0
foreach m $Machines {
if {"[lindex $m 0]" == "$mach"} {
return $index
}
incr index
}
return -1
}
proc add_machine { mach } {
if {[find_machine $mach] >= 0} {
return
}
global Machines
if {[catch {
set fp [open_connection $mach]
lappend Machines [list $mach $fp]
} err]} {
puts stderr $err
}
}
proc host_plus_user { mach } {
if { [string match "*@*" $mach] } {
return $mach
}
return "root@$mach"
}
proc del_machine { mach } {
global Machines
global Data
set mnew {}
set index 0
set did_something 0
foreach m $Machines {
if { "[lindex $m 0]" == "$mach"} {
catch {
close [lindex $m 1]
}
catch { unset Data($mach,busy) }
catch { unset Data($mach,time) }
catch { unset Data($mach,persec) }
catch { unset Data($mach,busy_snap) }
catch { unset Data($mach,persec_snap) }
catch { unset Data($mach,time_snap) }
catch { unset Data($mach,qsize) }
catch { unset Data($mach,busyworkerwin) }
catch { unset Data($mach,busyworkerafter) }
catch { unset Data($mach,error) }
set did_something 1
continue
}
lappend mnew $m
}
set Machines $mnew
if {$did_something} {
reconfigure
}
}
proc open_connection { mach } {
global SSHCommand
global MD_MX_CTRL
set hmach [host_plus_user $mach]
set fp [open "| $SSHCommand $hmach $MD_MX_CTRL" "r+"]
fconfigure $fp -blocking 0
#fconfigure $fp -translation binary
fileevent $fp readable [list connection_readable $mach $fp]
return $fp
}
proc connection_readable { mach fp } {
global DoArchive
global MachinesAwaitingReply
global after_token
# Delete from MachinesAwaitingReply
set index [lsearch -exact $MachinesAwaitingReply $mach]
if {$index >= 0} {
set MachinesAwaitingReply [lreplace $MachinesAwaitingReply $index $index]
}
gets $fp line
if {"$line" == ""} {
if {[eof $fp]} {
catch { close $fp }
del_machine $mach
}
} else {
set index [find_machine $mach]
if {$index >= 0} {
if {[catch { update_machine $line $index $mach } err]} {
mach_set_status_error $mach $index $err
}
if {$DoArchive} {
if {[catch { log_stats $mach $line } err]} {
puts stderr $err
}
}
}
}
# If all machines have replied, redraw
if {[llength $MachinesAwaitingReply] == 0} {
if {"$after_token" != ""} {
after cancel $after_token
set after_token {}
}
redraw
}
}
proc log_stats { mach line } {
set dir "~/.watch-multiple-mimedefangs/$mach"
if {![file isdirectory $dir]} {
file mkdir $dir
}
set fp [open "$dir/data" "a"]
puts $fp "[clock seconds] $line"
close $fp
}
proc get_machine_windows { } {
set kids [winfo children .top]
set result {}
set hi 0
foreach k $kids {
if {[regexp {^\.top\.name([0-9]+)$} $k dummy index]} {
if {$index > $hi} {
set hi $index
}
}
}
foreach k $kids {
if {[regexp {^\.top\.[^0-9]+([0-9]+)$} $k dummy index]} {
if {$index <= $hi} {
lappend result $k
}
}
}
return $result
}
proc mach_set_status_error { mach index err } {
global Data
set Data($mach,error) 1
.top.name$index configure -foreground red
.top.c$index itemconfigure statusText -text $err
.top.c$index delete withtag data1
.top.c$index delete withtag data2
.top.c$index delete withtag data3
}
proc mach_set_status_normal { mach index status } {
global Data
set Data($mach,error) 0
.top.name$index configure -foreground black
.top.c$index itemconfigure statusText -text $status
}
proc mach_populate_data { mach index line } {
global Data
global NewStyle
if {$NewStyle} {
mach_populate_data_new_style $mach $index $line
return
}
foreach { msg0 msg1 msg5 msg10 busy0 busy1 busy5 busy10 ms0 ms1 ms5 ms10 a0 a1 a5 a10 r0 r1 r5 r10 busy idle stopped killed msgs activations qsize qnum uptime} $line { break }
set total_workers [expr $busy + $idle + $stopped + $killed]
set ms0 [format "%.0f" $ms0]
set msg0 [format "%.2f" [expr $msg0 / 10.0]]
lappend Data($mach,busy) $busy0
lappend Data($mach,time) $ms0
lappend Data($mach,persec) $msg0
set Data($mach,total_workers) $total_workers
set Data($mach,busy_snap) $busy
set Data($mach,persec_snap) $msg0
set Data($mach,time_snap) $ms0
set Data($mach,qsize) $qsize
schedule_redraw
}
proc mach_populate_data_new_style { mach index line } {
global Data
foreach { scans avgbusyscans scantime relayoks avgbusyrelayoks relayoktime senderoks avgbusysenderoks senderoktime recipoks avgbusyrecipoks recipoktime busyworkers idleworkers stoppedworkers killedworkers msgs activations qsize numqueued uptime back } $line { break }
set scantime [format "%.0f" $scantime]
set relayoktime [format "%.0f" $relayoktime]
set senderoktime [format "%.0f" $senderoktime]
set recipoktime [format "%.0f" $recipoktime]
set total_workers [expr $busyworkers + $idleworkers + $stoppedworkers + $killedworkers]
set back [expr 1.0 * $back]
set scanspersec [expr (1.0 * $scans) / $back ]
set relayokspersec [expr (1.0 * $relayoks) / $back ]
set senderokspersec [expr (1.0 * $senderoks) / $back ]
set recipokspersec [expr (1.0 * $recipoks) / $back ]
set scanspersec [format "%.2f" $scanspersec]
set relayokspersec [format "%.2f" $relayokspersec]
set senderokspersec [format "%.2f" $senderokspersec]
set recipokspersec [format "%.2f" $recipokspersec]
lappend Data($mach,busy) $busyworkers
lappend Data($mach,scantime) $scantime
lappend Data($mach,scanspersec) $scanspersec
lappend Data($mach,relayoktime) $relayoktime
lappend Data($mach,relayokspersec) $relayokspersec
lappend Data($mach,senderoktime) $senderoktime
lappend Data($mach,senderokspersec) $senderokspersec
lappend Data($mach,recipoktime) $recipoktime
lappend Data($mach,recipokspersec) $recipokspersec
set Data($mach,total_workers) $total_workers
set Data($mach,busy_snap) $busyworkers
set Data($mach,scanspersec_snap) $scanspersec
set Data($mach,relayokspersec_snap) $relayokspersec
set Data($mach,senderokspersec_snap) $senderokspersec
set Data($mach,recipokspersec_snap) $recipokspersec
set Data($mach,scantime_snap) $scantime
set Data($mach,relayoktime_snap) $relayoktime
set Data($mach,senderoktime_snap) $senderoktime
set Data($mach,recipoktime_snap) $recipoktime
set Data($mach,qsize) $qsize
set Data($mach,numqueued) $numqueued
schedule_redraw
}
proc schedule_redraw {} {
global MainUpdateInterval
global after_token
if {"$after_token" == ""} {
set after_token [after $MainUpdateInterval redraw]
}
}
proc redraw_new_style {} {
global Machines
global after_token
global Data
global TotalData
global NewStyleShowScans NewStyleShowRelayoks NewStyleShowSenderoks NewStyleShowRecipoks
set after_token ""
set index 0
set scanspersec_total 0
set relayokspersec_total 0
set senderokspersec_total 0
set recipokspersec_total 0
set scantime_total 0
set relayoktime_total 0
set senderoktime_total 0
set recipoktime_total 0
set busyworkers_total 0
set totalworkers_total 0
set busyworkers_active 0
set totalworkers_active 0
set num_machines 0
set num_graphs 1
if {$NewStyleShowScans} {
incr num_graphs 2
}
if {$NewStyleShowRelayoks} {
incr num_graphs 2
}
if {$NewStyleShowSenderoks} {
incr num_graphs 2
}
if {$NewStyleShowRecipoks} {
incr num_graphs 2
}
set wid [winfo width .top.clabels]
.top.clabels delete all
set spacing [expr $wid / (1.0 * $num_graphs)]
set x [expr $spacing / 2.0]
.top.clabels create text $x 2 -anchor n -fill "#A00000" -text "Busy Workers"
if {$NewStyleShowScans} {
set x [expr $x + $spacing]
.top.clabels create text $x 2 -anchor n -fill "#00A000" -text "Scans/d"
set x [expr $x + $spacing]
.top.clabels create text $x 2 -anchor n -fill "#0000A0" -text "ms/scan"
}
if {$NewStyleShowRelayoks} {
set x [expr $x + $spacing]
.top.clabels create text $x 2 -anchor n -fill "#808000" -text "Relays/d"
set x [expr $x + $spacing]
.top.clabels create text $x 2 -anchor n -fill "#008080" -text "ms/relay"
}
if {$NewStyleShowSenderoks} {
set x [expr $x + $spacing]
.top.clabels create text $x 2 -anchor n -fill "#808080" -text "Senders/d"
set x [expr $x + $spacing]
.top.clabels create text $x 2 -anchor n -fill "#800080" -text "ms/sender"
}
if {$NewStyleShowRecipoks} {
set x [expr $x + $spacing]
.top.clabels create text $x 2 -anchor n -fill "#008000" -text "Recips/d"
set x [expr $x + $spacing]
.top.clabels create text $x 2 -anchor n -fill "#000000" -text "ms/recip"
}
foreach m $Machines {
set mach [lindex $m 0]
if {![info exists Data($mach,busy)]} {
incr index
continue
}
if {$Data($mach,error)} {
incr index
continue
}
# Update totals
set busy $Data($mach,busy_snap)
set totalworkers $Data($mach,total_workers)
# Only update worker counts for machines that are actually doing something
if {$Data($mach,scanspersec_snap) > 0 || $Data($mach,relayokspersec_snap) > 0 || $Data($mach,senderokspersec_snap) > 0 || $Data($mach,recipokspersec_snap) > 0} {
set totalworkers_active [expr $totalworkers_active + $totalworkers]
set busyworkers_active [expr $busyworkers_active + 1.0*$busy]
}
set totalworkers_total [expr $totalworkers_total + $totalworkers]
set busyworkers_total [expr $busyworkers_total + 1.0*$busy]
set scanspersec_total [expr $scanspersec_total + 1.0*$Data($mach,scanspersec_snap)]
set scantime_total [expr $scantime_total + (1.0*$Data($mach,scanspersec_snap) * $Data($mach,scantime_snap))]
set relayokspersec_total [expr $relayokspersec_total + 1.0*$Data($mach,relayokspersec_snap)]
set relayoktime_total [expr $relayoktime_total + (1.0*$Data($mach,relayokspersec_snap) * $Data($mach,relayoktime_snap))]
set senderokspersec_total [expr $senderokspersec_total + 1.0*$Data($mach,senderokspersec_snap)]
set senderoktime_total [expr $senderoktime_total + (1.0*$Data($mach,senderokspersec_snap) * $Data($mach,senderoktime_snap))]
set recipokspersec_total [expr $recipokspersec_total + 1.0*$Data($mach,recipokspersec_snap)]
set recipoktime_total [expr $recipoktime_total + (1.0*$Data($mach,recipokspersec_snap) * $Data($mach,recipoktime_snap))]
set graph 0
set Data($mach,busy) [graph [expr $graph / (1.0 * $num_graphs)] [expr ($graph + 1.0) / (1.0 * $num_graphs)] 0 $Data($mach,total_workers) $Data($mach,busy) $index "Busy" $graph "#A00000" 1]
if {$totalworkers > 0} {
set pctbusy [expr int((1.0*$busy) / (1.0*$totalworkers) * 100)]
} else {
set pctbusy 100
}
if {$pctbusy < 80} {
.top.busy$index configure -background #D9D9D9 -foreground "#A00000"
} elseif {$pctbusy < 90} {
.top.busy$index configure -background #C0C000 -foreground "#A00000"
} else {
.top.busy$index configure -background #C00000 -foreground "#000000"
}
.top.busy$index configure -text "$busy/$totalworkers\n$pctbusy%"
incr graph
if {$NewStyleShowScans} {
set Data($mach,scanspersec) [graph [expr $graph / (1.0 * $num_graphs)] [expr ($graph + 1.0) / (1.0 * $num_graphs)] 0 auto $Data($mach,scanspersec) $index "Scans/s" $graph "#00A000" 1]
incr graph
set Data($mach,scantime) [graph [expr $graph / (1.0 * $num_graphs)] [expr ($graph + 1.0) / (1.0 * $num_graphs)] 0 auto $Data($mach,scantime) $index "ms/scan" $graph "#0000A0" 1]
incr graph
set s $Data($mach,scanspersec_snap)
set h [human_number [expr $s * 3600]]
set d [human_number [expr $s * 86400]]
if {$s == 0} {
.top.scanspersec$index configure -text "-"
.top.scantime$index configure -text "-"
} else {
.top.scanspersec$index configure -text [format "%.2f\n%s/h\n%s/d" $s $h $d]
.top.scantime$index configure -text $Data($mach,scantime_snap)
}
} else {
set Data($mach,scanspersec) {}
set Data($mach,scantime) {}
}
if {$NewStyleShowRelayoks} {
set Data($mach,relayokspersec) [graph [expr $graph / (1.0 * $num_graphs)] [expr ($graph + 1.0) / (1.0 * $num_graphs)] 0 auto $Data($mach,relayokspersec) $index "Relayoks/s" $graph "#808000" 1]
incr graph
set Data($mach,relayoktime) [graph [expr $graph / (1.0 * $num_graphs)] [expr ($graph + 1.0) / (1.0 * $num_graphs)] 0 auto $Data($mach,relayoktime) $index "ms/relayok" $graph "#008080" 1]
incr graph
set s $Data($mach,relayokspersec_snap)
set h [human_number [expr $s * 3600]]
set d [human_number [expr $s * 86400]]
if {$s == 0} {
.top.relayspersec$index configure -text "-"
.top.relaytime$index configure -text "-"
} else {
.top.relayspersec$index configure -text [format "%.2f\n%s/h\n%s/d" $s $h $d]
.top.relaytime$index configure -text $Data($mach,relayoktime_snap)
}
} else {
set Data($mach,relayokspersec) {}
set Data($mach,relayoktime) {}
}
if {$NewStyleShowSenderoks} {
set Data($mach,senderokspersec) [graph [expr $graph / (1.0 * $num_graphs)] [expr ($graph + 1.0) / (1.0 * $num_graphs)] 0 auto $Data($mach,senderokspersec) $index "Senderoks/s" $graph "#808080" 1]
incr graph
set Data($mach,senderoktime) [graph [expr $graph / (1.0 * $num_graphs)] [expr ($graph + 1.0) / (1.0 * $num_graphs)] 0 auto $Data($mach,senderoktime) $index "ms/senderok" $graph "#800080" 1]
incr graph
set s $Data($mach,senderokspersec_snap)
set h [human_number [expr $s * 3600]]
set d [human_number [expr $s * 86400]]
if {$s == 0} {
.top.senderspersec$index configure -text "-"
.top.sendertime$index configure -text "-"
} else {
.top.senderspersec$index configure -text [format "%.2f\n%s/h\n%s/d" $s $h $d]
.top.sendertime$index configure -text $Data($mach,senderoktime_snap)
}
} else {
set Data($mach,senderokspersec) {}
set Data($mach,senderoktime) {}
}
if {$NewStyleShowRecipoks} {
set Data($mach,recipokspersec) [graph [expr $graph / (1.0 * $num_graphs)] [expr ($graph + 1.0) / (1.0 * $num_graphs)] 0 auto $Data($mach,recipokspersec) $index "Recipoks/s" $graph "#008000" 1]
incr graph
set Data($mach,recipoktime) [graph [expr $graph / (1.0 * $num_graphs)] [expr ($graph + 1.0) / (1.0 * $num_graphs)] 0 auto $Data($mach,recipoktime) $index "ms/recipok" $graph "#000000" 1]
incr graph
set s $Data($mach,recipokspersec_snap)
set h [human_number [expr $s * 3600]]
set d [human_number [expr $s * 86400]]
if {$s == 0} {
.top.recipspersec$index configure -text "-"
.top.reciptime$index configure -text "-"
} else {
.top.recipspersec$index configure -text [format "%.2f\n%s/h\n%s/d" $s $h $d]
.top.reciptime$index configure -text $Data($mach,recipoktime_snap)
}
} else {
set Data($mach,recipokspersec) {}
set Data($mach,recipoktime) {}
}
incr index
}
lappend TotalData(busy) $busyworkers_total
lappend TotalData(total) $totalworkers_total
lappend TotalData(scanspersec) $scanspersec_total
set scantime_avg [expr $scantime_total / ($scanspersec_total + 0.000000001)]
set relayoktime_avg [expr $relayoktime_total / ($relayokspersec_total + 0.000000001)]
set senderoktime_avg [expr $senderoktime_total / ($senderokspersec_total + 0.000000001)]
set recipoktime_avg [expr $recipoktime_total / ($recipokspersec_total + 0.000000001)]
lappend TotalData(scantime) $scantime_avg
lappend TotalData(relayokspersec) $relayokspersec_total
lappend TotalData(relayoktime) $relayoktime_avg
lappend TotalData(senderokspersec) $senderokspersec_total
lappend TotalData(senderoktime) $senderoktime_avg
lappend TotalData(recipokspersec) $recipokspersec_total
lappend TotalData(recipoktime) $recipoktime_avg
set graph 0
set TotalData(busy) [graph [expr $graph / (1.0 * $num_graphs)] [expr ($graph + 1.0) / (1.0 * $num_graphs)] 0 $totalworkers_total $TotalData(busy) $index "Busy" $graph "#A00000" 1]
if {$totalworkers_total > 0} {
set busyworkers_total [expr int($busyworkers_total)]
set pctbusy [expr int((1.0 * $busyworkers_total) / (1.0 * $totalworkers_total) * 100)]
} else {
set pctbusy 100
}
if {$totalworkers_active > 0} {
set busyworkers_active [expr int($busyworkers_active)]
set apct [expr int((1.0 * $busyworkers_active) / (1.0 * $totalworkers_active) * 100)]
} else {
set apct 100
}
.top.busytotal configure -text "$busyworkers_total/$totalworkers_total\n$pctbusy%\n$busyworkers_active/$totalworkers_active\n$apct%"
incr graph
if {$NewStyleShowScans} {
set TotalData(scanspersec) [graph [expr $graph / (1.0 * $num_graphs)] [expr ($graph + 1.0) / (1.0 * $num_graphs)] 0 auto $TotalData(scanspersec) $index "Scans/s" $graph "#00A000" 1]
incr graph
set TotalData(scantime) [graph [expr $graph / (1.0 * $num_graphs)] [expr ($graph + 1.0) / (1.0 * $num_graphs)] 0 auto $TotalData(scantime) $index "ms/scan" $graph "#0000A0" 1]
incr graph
set h [human_number [expr $scanspersec_total * 3600]]
set d [human_number [expr $scanspersec_total * 86400]]
.top.scanspersectotal configure -text [format "%.2f\n%s/h\n%s/d" $scanspersec_total $h $d]
.top.avgscantime configure -text [format "%.0f" $scantime_avg]
} else {
set TotalData(scanspersec) {}
set TotalData(scantime) {}
}
if {$NewStyleShowRelayoks} {
set TotalData(relayokspersec) [graph [expr $graph / (1.0 * $num_graphs)] [expr ($graph + 1.0) / (1.0 * $num_graphs)] 0 auto $TotalData(relayokspersec) $index "Relayoks/s" $graph "#808000" 1]
incr graph
set TotalData(relayoktime) [graph [expr $graph / (1.0 * $num_graphs)] [expr ($graph + 1.0) / (1.0 * $num_graphs)] 0 auto $TotalData(relayoktime) $index "ms/relayok" $graph "#008080" 1]
incr graph
set h [human_number [expr $relayokspersec_total * 3600]]
set d [human_number [expr $relayokspersec_total * 86400]]
.top.relayspersectotal configure -text [format "%.2f\n%s/h\n%s/d" $relayokspersec_total $h $d]
.top.avgrelaytime configure -text [format "%.0f" $relayoktime_avg]
} else {
set TotalData(relayokspersec) {}
set TotalData(relayoktime) {}
}
if {$NewStyleShowSenderoks} {
set TotalData(senderokspersec) [graph [expr $graph / (1.0 * $num_graphs)] [expr ($graph + 1.0) / (1.0 * $num_graphs)] 0 auto $TotalData(senderokspersec) $index "Senderoks/s" $graph "#808080" 1]
incr graph
set TotalData(senderoktime) [graph [expr $graph / (1.0 * $num_graphs)] [expr ($graph + 1.0) / (1.0 * $num_graphs)] 0 auto $TotalData(senderoktime) $index "ms/senderok" $graph "#800080" 1]
incr graph
set h [human_number [expr $senderokspersec_total * 3600]]
set d [human_number [expr $senderokspersec_total * 86400]]
.top.senderspersectotal configure -text [format "%.2f\n%s/h\n%s/d" $senderokspersec_total $h $d]
.top.avgsendertime configure -text [format "%.0f" $senderoktime_avg]
set s [human_number $senderokspersec_total]
} else {
set TotalData(senderokspersec) {}
set TotalData(senderoktime) {}
}
if {$NewStyleShowRecipoks} {
set TotalData(recipokspersec) [graph [expr $graph / (1.0 * $num_graphs)] [expr ($graph + 1.0) / (1.0 * $num_graphs)] 0 auto $TotalData(recipokspersec) $index "Recipoks/s" $graph "#008000" 1]
incr graph
set TotalData(recipoktime) [graph [expr $graph / (1.0 * $num_graphs)] [expr ($graph + 1.0) / (1.0 * $num_graphs)] 0 auto $TotalData(recipoktime) $index "ms/recipok" $graph "#000000" 1]
incr graph
set h [human_number [expr $recipokspersec_total * 3600]]
set d [human_number [expr $recipokspersec_total * 86400]]
.top.recipspersectotal configure -text [format "%.2f\n%s/h\n%s/d" $recipokspersec_total $h $d]
.top.avgreciptime configure -text [format "%.0f" $recipoktime_avg]
} else {
set TotalData(recipokspersec) {}
set TotalData(recipoktime) {}
}
update
}
proc redraw {} {
global Machines
global NewStyle
global after_token
global Data
global TotalData
global DoneARedrawSinceLastUpdate
set DoneARedrawSinceLastUpdate 1
if {$NewStyle} {
redraw_new_style
return
}
set after_token ""
set index 0
set persec_total 0
set busy_workers_total 0
set avail_workers_total 0
set msgs_per_sec_total 0
set ms_per_scan_total 0
set num_machines 0
foreach m $Machines {
set mach [lindex $m 0]
if {![info exists Data($mach,busy)]} {
incr index
continue
}
if {$Data($mach,error)} {
incr index
continue
}
set busy $Data($mach,busy_snap)
set total_workers $Data($mach,total_workers)
set msg0 $Data($mach,persec_snap)
set ms0 $Data($mach,time_snap)
set persec_total [expr $persec_total + $msg0]
# Format $busy to have as many characters as $total_workers
set l [string length $total_workers]
set busy [format "%${l}d" $busy]
.top.busy$index configure -text "$busy/$total_workers"
.top.persec$index configure -text $msg0
.top.time$index configure -text $ms0
if {$busy == $total_workers} {
.top.name$index configure -background "#CCCC00"
} else {
.top.name$index configure -background "#D9D9D9"
}
set Data($mach,busy) [graph 0 [expr 1.0/3] 0 $Data($mach,total_workers) $Data($mach,busy) $index "Busy" 1 red 1]
set Data($mach,persec) [graph [expr 1.0/3] [expr 2.0/3] 0 auto $Data($mach,persec) $index "Msgs/Sec" 2 green 1]
set Data($mach,time) [graph [expr 2.0/3] 1 0 auto $Data($mach,time) $index "ms/scan" 3 blue 1]
incr index
if {$ms0 > 0 || $Data($mach,busy_snap) > 0 || $msg0 > 0} {
incr num_machines
incr busy_workers_total $Data($mach,busy_snap)
incr avail_workers_total $Data($mach,total_workers);
incr ms_per_scan_total $ms0
}
}
lappend TotalData(busy) $busy_workers_total
if {$num_machines > 0} {
lappend TotalData(time) [expr 1.0 * $ms_per_scan_total / (1.0 * $num_machines)]
} else {
lappend TotalData(time) 0
}
lappend TotalData(persec) $persec_total
incr index
set TotalData(busy) [graph 0 [expr 1.0/3] 0 $avail_workers_total $TotalData(busy) $index "Busy" 1 red 1]
set TotalData(persec) [graph [expr 1.0/3] [expr 2.0/3] 0 auto $TotalData(persec) $index "Msgs/Sec" 2 green 1]
set TotalData(time) [graph [expr 2.0/3] 1 0 auto $TotalData(time) $index "ms/scan" 3 blue 1]
set msgs_per_sec_total $persec_total
set hour [human_number [expr $persec_total * 3600.0]]
set day [human_number [expr $persec_total * 86400.0]]
set persec_total [strip_zeros [format "%.1f" $persec_total]]
.top.c configure -text "Total throughput $persec_total/s = $hour/hour = $day/day"
set l [string length $avail_workers_total]
set busy_workers_total [format "%${l}d" $busy_workers_total]
.top.busytotal configure -text "$busy_workers_total/$avail_workers_total"
.top.persectotal configure -text [strip_zeros [format "%.1f" $msgs_per_sec_total]]
if {$num_machines > 0} {
.top.avgtime configure -text [strip_zeros [format "%.0f" [expr 1.0 * $ms_per_scan_total / (1.0 * $num_machines)]]]
} else {
.top.avgtime configure -text "--"
}
update
}
proc graph { start_frac end_frac min max data index label tag fill_color line_width} {
global NewStyleTimeInterval
set tag "data$tag"
set c .top.c$index
set h [winfo height $c]
set w [winfo width $c]
set x0 [expr int($start_frac * $w)]
set x1 [expr int($end_frac * $w)]
set x0 [expr $x0 + 40]
set x1 [expr $x1 - 5]
set diff [expr $x1 - $x0]
set gridline_spacing 15
if {[llength $data] > $diff} {
set toChop [expr [llength $data] - $diff]
set data [lrange $data $toChop end]
}
set multiplier 1
if {"$label" == "Scans/s"} {
if {$NewStyleTimeInterval == 3600} {
set label "Scans/h"
set multiplier 3600
} elseif {$NewStyleTimeInterval == 86400} {
set label "Scans/d"
set multiplier 86400
}
}
if {"$label" == "Senderoks/s"} {
if {$NewStyleTimeInterval == 3600} {
set label "Senderoks/h"
set multiplier 3600
} elseif {$NewStyleTimeInterval == 86400} {
set label "Senderoks/d"
set multiplier 86400
}
}
if {"$label" == "Relayoks/s"} {
if {$NewStyleTimeInterval == 3600} {
set label "Relayoks/h"
set multiplier 3600
} elseif {$NewStyleTimeInterval == 86400} {
set label "Relayoks/d"
set multiplier 86400
}
}
if {"$label" == "Recipoks/s"} {
if {$NewStyleTimeInterval == 3600} {
set label "Recipoks/h"
set multiplier 3600
} elseif {$NewStyleTimeInterval == 86400} {
set label "Recipoks/d"
set multiplier 86400
}
}
if {"$min" == "auto"} {
set min [lindex $data 0]
foreach thing $data {
if {$thing < $min} {set min $thing}
}
set min [expr $multiplier * $min]
set min [nicenum $min 1]
}
if {"$max" == "auto"} {
set max [lindex $data 0]
foreach thing $data {
if {$thing > $max} {set max $thing}
}
set max [expr $multiplier * $max]
set max [nicenum $max 0]
}
set x $x0
$c delete withtag $tag
set coords {}
if {$max == $min} {
set max [expr $max + 1.0]
}
set diff [expr 1.0 * ($max - $min)]
set num_gridlines [expr int((1.0 * $h) / (1.0 * $gridline_spacing))]
if {$num_gridlines > 10} {
set num_gridlines 10
}
if {$num_gridlines < 1} {
set num_gridlines 1
}
set delta [nicenum [expr $diff / $num_gridlines] 1]
foreach point $data {
set y [expr $point * $multiplier - $min]
set y [expr (1.0 * $y * $h) / (1.0 * $diff)]
set y [expr $h - $y]
if {$y < 1} {
set y 1
}
if {$y >= $h} {
set y [expr $h - 1]
}
lappend coords $x $y
incr x
}
if {$delta > 0.0} {
set last_phys_y 99999
for {set y $min} {$y <= $max} {set y [expr $y + $delta]} {
set cy [expr (1.0 * ($y-$min) * $h) / (1.0 * $diff)]
set cy [expr $h - $cy]
if {$cy <= 0} {
continue
}
if {$cy > [expr $h-1]} {
set cy [expr $h-1]
}
if {($last_phys_y - $cy) >= (2 * $gridline_spacing)} {
set last_phys_y $cy
set anc w
if {$cy < $gridline_spacing} {
set anc nw
}
if {$cy >= ($h - $gridline_spacing)} {
set anc sw
}
$c create line [expr $x0 - 10] $cy $x1 $cy -fill "#A0A0A0" -tags $tag
$c create text [expr $x0 - 37] $cy -text [human_number $y] -tag $tag -anchor $anc
} else {
$c create line $x0 $cy $x1 $cy -fill "#DDDDDD" -tags $tag
}
}
} else {
$c create text [expr $x0 - 37] 0 -anchor nw -text [human_number $max] -tag $tag
$c create text [expr $x0 - 37] $h -anchor sw -text [human_number $min] -tag $tag
}
if {[llength $coords] >= 4} {
$c create line $coords -fill $fill_color -width $line_width -tags $tag
}
return $data
}
proc update_machine { line index mach } {
if {[string match "ERROR *" $line]} {
mach_set_status_error $mach $index $line
return
}
mach_set_status_normal $mach $index ""
mach_populate_data $mach $index $line
}
proc interactive_add_machine {} {
set mach [.top.new get]
if {"$mach" != ""} {
add_machine $mach
reconfigure
}
}
proc reconfigure_new_style {} {
global Machines
global NewStyleShowScans NewStyleShowRelayoks NewStyleShowSenderoks NewStyleShowRecipoks
catch { destroy .top.name }
catch { destroy .top.busy }
catch { destroy .top.scanspersec }
catch { destroy .top.scantime }
catch { destroy .top.relayspersec }
catch { destroy .top.relaytime }
catch { destroy .top.senderspersec }
catch { destroy .top.sendertime }
catch { destroy .top.recipspersec }
catch { destroy .top.reciptime }
catch { destroy .top.c }
set col 2
set canv_width 200
label .top.name -text "Machine Name"
label .top.busy -text "Busy Workers " -foreground "#A00000"
grid .top.name -row 0 -column 0 -sticky new
grid .top.busy -row 0 -column 1 -sticky new
catch { destroy .top.clabels}
canvas .top.clabels -width $canv_width -height 10 -takefocus 0 -borderwidth 0 -background #ffffff -highlightthickness 0
if {$NewStyleShowScans} {
incr canv_width 200
label .top.scanspersec -text "Scans/s " -foreground "#00A000"
grid .top.scanspersec -row 0 -column $col -sticky new
incr col
label .top.scantime -text "ms/scan " -foreground "#0000A0"
grid .top.scantime -row 0 -column $col -sticky new
incr col
}
if {$NewStyleShowRelayoks} {
incr canv_width 200
label .top.relayspersec -text "Relays/s " -foreground "#808000"
grid .top.relayspersec -row 0 -column $col -sticky new
incr col
label .top.relaytime -text "ms/relay " -foreground "#008080"
grid .top.relaytime -row 0 -column $col -sticky new
incr col
}
if {$NewStyleShowSenderoks} {
incr canv_width 200
label .top.senderspersec -text "Senders/s " -foreground "#808080"
grid .top.senderspersec -row 0 -column $col -sticky new
incr col
label .top.sendertime -text "ms/sender " -foreground "#800080"
grid .top.sendertime -row 0 -column $col -sticky new
incr col
}
if {$NewStyleShowRecipoks} {
incr canv_width 200
label .top.recipspersec -text "Recips/s " -foreground "#008000"
grid .top.recipspersec -row 0 -column $col -sticky new
incr col
label .top.reciptime -text "ms/recip " -foreground "#000000"
grid .top.reciptime -row 0 -column $col -sticky new
incr col
}
grid .top.clabels -row 0 -column $col -sticky nsew
grid rowconfigure .top 0 -weight 0
set index 0
foreach m $Machines {
grid_machine_new_style $m $index
incr index
}
# If a machine has been deleted, destroy its windows
catch { destroy .top.name$index }
catch { destroy .top.busy$index }
catch { destroy .top.scanspersec$index }
catch { destroy .top.scantime$index }
catch { destroy .top.relayspersec$index }
catch { destroy .top.relaytime$index }
catch { destroy .top.senderspersec$index }
catch { destroy .top.sendertime$index }
catch { destroy .top.recipspersec$index }
catch { destroy .top.reciptime$index }
catch { destroy .top.c$index }
# Bottom row of labels
catch { destroy .top.totalrow }
catch { destroy .top.busytotal }
catch { destroy .top.scanspersectotal }
catch { destroy .top.avgscantime }
catch { destroy .top.relayspersectotal }
catch { destroy .top.avgrelaytime }
catch { destroy .top.senderspersectotal }
catch { destroy .top.avgsendertime }
catch { destroy .top.recipspersectotal }
catch { destroy .top.avgreciptime }
# Mop up total window if a machine has been deleted
set row [expr $index + 1]
catch { destroy .top.c$row }
set col 2
label .top.totalrow -text "Totals:"
label .top.busytotal -foreground "#A00000"
grid .top.totalrow -row $row -column 0 -sticky new
grid .top.busytotal -row $row -column 1 -sticky new
if {$NewStyleShowScans} {
label .top.scanspersectotal -foreground "#00A000"
grid .top.scanspersectotal -row $row -column $col -sticky new
incr col
label .top.avgscantime -foreground "#0000A0"
grid .top.avgscantime -row $row -column $col -sticky new
incr col
}
if {$NewStyleShowRelayoks} {
label .top.relayspersectotal -foreground "#808000"
grid .top.relayspersectotal -row $row -column $col -sticky new
incr col
label .top.avgrelaytime -foreground "#008080"
grid .top.avgrelaytime -row $row -column $col -sticky new
incr col
}
if {$NewStyleShowSenderoks} {
label .top.senderspersectotal -foreground "#808080"
grid .top.senderspersectotal -row $row -column $col -sticky new
incr col
label .top.avgsendertime -foreground "#800080"
grid .top.avgsendertime -row $row -column $col -sticky new
incr col
}
if {$NewStyleShowRecipoks} {
label .top.recipspersectotal -foreground "#008000"
grid .top.recipspersectotal -row $row -column $col -sticky new
incr col
label .top.avgreciptime -foreground "#000000"
grid .top.avgreciptime -row $row -column $col -sticky new
incr col
}
set num_items [expr $col-1]
canvas .top.c$index -width $canv_width -height 60 -takefocus 0 -borderwidth 0 -background #FFFFEE -highlightthickness 0
grid .top.c$index -row $row -column $col -sticky nsew -pady 1
grid rowconfigure .top $row -weight 3
for {set i 0} {$i < $col} {incr i} {
grid columnconfigure .top $i -weight 0
}
grid columnconfigure .top $col -weight 1
incr index
incr row
# Now a spot for adding a new machine...
catch { destroy .top.newlab }
catch { destroy .top.new }
catch { destroy .top.all }
label .top.newlab -text "Add Machine: "
entry .top.new -width 20
grid .top.newlab -row $row -column 0
grid .top.new -row $row -column 1 -columnspan [expr $col - 1] -sticky ew