-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrivedb.lib.awk
1821 lines (1601 loc) · 72 KB
/
drivedb.lib.awk
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
#ADD_ON_VERSION 1.4 - contributed by bjp999
#ADD_ON_VERSION 1.42 - changed spinup method
#ADD_ON_VERSION 1.5 - changes for myMain 12-1-10 release
#ADD_ON_VERSION 1.51 - changes for myMain 12-1-10 release, contributed by bjp999 - minor update 1
#ADD_ON_VERSION 1.52 - changes for myMain 12-1-10 release, contributed by bjp999 - minor update 2
#ADD_ON_VERSION 1.53 - changes for myMain 3-10-11 release, contributed by bjp999 - 5.0b6 support
#ADD_ON_VERSION 1.54 - changes for myMain 4-10-11 release, contributed by bjp999 - preclear support
#UNMENU_RELEASE $Revision$ $Date$
# (c) Copyright bjp999, 2009-2011. All rights reserved.
# This program carries no warranty or guarantee of any kind. It is used strictly at the users risk.
# http://chart.apis.google.com/chart?chxl=1:|%25label1%25|%25label2%25|%25label3%25|%25lable4%25|%25label5%25&chxr=0,0,150|1,0,150&chxt=y,x&chbh=a&chs=300x225&cht=bvg&chco=A2C180&chds=0,150&chd=t:90,130,112,75,98&chtt=%25MyChart%25
#-----------------------------------------------------------------------
# This function begins the creation of the drivedb[] associative array.
# ... assumes an array called "ColorHtml" exists.
#-----------------------------------------------------------------------
function LoadDriveDb(i, k, nextslot, unit, num) {
GetArrayStatus(); #call JoeL.'s function to do the heavy lifting
nextslot=numdisks
#-----------------------------------------
# Loop though all the disks in the array.
#-----------------------------------------
i=0;
for(k=0; k<numdisks; k++) {
#-------------------------------------------------------------
# Do not show "not present" drives, except parity (see below)
#-------------------------------------------------------------
if(disk_status[k] == "DISK_NP")
continue;
if(disk_status[k] == "DISK_NEW") {
drivedb[i, "rowextra"] = drivedb[i, "rowextra"] ";font-weight:bold"
disk_name[k] = "md" k
}
if(rdisk_lastIO[k] == "0")
drivedb[i, "spinind"] = 0;
else
drivedb[i, "spinind"] = 1;
drivedb[i, "num"] = k
#p("ds=" disk_status[k])
#drivedb[i, "name"] = disk_name[k];
if((disk_name[k] == "") && (k == 0)) {
drivedb[i, "md"] = "parity"
drivedb[i, "role"] = "parity"
}
else {
drivedb[i, "md"] = disk_name[k];
drivedb[i, "role"] = "array disk"
}
drivedb[i, "disk"] = drivedb[i, "md"]
gsub("md", "disk", drivedb[i, "disk"])
#--------------------------------
# Deal with missing parity drive
#--------------------------------
if((disk_status[k] == "DISK_DSBL_NP") && (drivedb[i, "num"] == 0)) { #no parity present
drivedb[i, "fullid"] = \
drivedb[i, "serial"] = \
drivedb[i, "disk_size"] = \
drivedb[i, "modelnum"] = \
drivedb[i, "reads"] = \
drivedb[i, "writes"] = \
drivedb[i, "errors"] = \
drivedb[i, "dev"] = "";
drivedb[i, "manu"] = "NOT PROTECTED";
drivedb[i, "rowextra"] = drivedb[i, "rowextra"] ";font-weight:bold"
drivedb[i, "disk_size_raw"] = \
drivedb[i, "reads_raw"] = \
drivedb[i, "writes_raw"] = 0;
drivedb[i, "status"] = "N/A";
} else {
#if(disk_status[k] == "DISK_DSBL")
# drivedb[i, "rowextra"] = drivedb[ix, "rowextra"] ColorHtml[color="orange"];
drivedb[i, "fullid"] = disk_id[k];
gsub(/ /, "", rdisk_serial[k]);
drivedb[i, "serial"] = rdisk_serial[k];
drivedb[i, "autoid"] = lastchars( drivedb[i, "serial"], constant["IdLen"] )
drivedb[i, "autoid4"] = lastchars( drivedb[i, "serial"], 4 )
drivedb[i, "disk_size_raw"] = rdisk_size[k]*1.024;
#p("disk_size_raw=" drivedb[i, "disk_size_raw"] )
#p("disk_size_raw=" sprintf("%.1f", drivedb[i, "disk_size_raw"]/1000/1000/1000 ))
#drivedb[i, "disk_size_1000c"] = CommaFormat(sprintf("%d", drivedb[i, "disk_size_raw"]/1000));
#drivedb[i, "disk_size_1024c"] = CommaFormat(sprintf("%d", disk_size[i]));
drivedb[i, "disk_size"] = human_readable_number(drivedb[i, "disk_size_raw"], 0, 0, 0, 1);
#p("disk_size_raw=" drivedb[i, "disk_size"] )
#if(drivedb[i, "disk_size"] ~ "[0-9]+.0")
# drivedb[i, "disk_size"]= human_readable_number(drivedb[i, "disk_size_raw"], 0, 0, 0, 0);
if(drivedb[i, "md"] != "parity") {
unit=substr(drivedb[i, "disk_size"], length(drivedb[i, "disk_size"]), 1)
num =substr(drivedb[i, "disk_size"], 1, length(drivedb[i, "disk_size"])-1)+0;
if(unit == "M")
num=num*1000;
else if(unit == "G")
num=num*1000*1000;
else if(unit == "T")
num=num*1000*1000*1000;
drivedb["total", "disk_size_raw"] += num;
}
drivedb[i, "modelnum"] = rdisk_model[k];
GetDriveManufacturer(i)
drivedb[i, "reads_raw"] = disk_reads[k];
drivedb[i, "writes_raw"] = disk_writes[k];
drivedb[i, "reads"] = CommaFormat(disk_reads[k]);
drivedb[i, "writes"] = CommaFormat(disk_writes[k]);
drivedb[i, "errors"] = disk_errors[k];
drivedb[i, "status_raw"] = disk_status[k];
drivedb[i, "status"] = disk_status[k];
gsub("DISK_", "", drivedb[i, "status"]);
# Test all of the icons
if(1==0) {
ic[z=0] = "OK";
ic[++z] = "OK";
ic[++z] = "OK";
ic[++z] = "OK";
ic[++z] = "NP";
ic[++z] = "NP_MISSING";
ic[++z] = "INVALID";
ic[++z] = "DSBL";
ic[++z] = "DSBL_NP";
ic[++z] = "DSBL_NEW";
ic[++z] = "WRONG";
ic[++z] = "NEW";
ic[++z] = "RAW";
ic[++z] = "OK";
ic[++z] = "OK";
ic[++z] = "OK";
ic[++z] = "OK";
ic[++z] = "OK";
ic[++z] = "OK";
drivedb[i, "status"] = ic[i];
#perr("i=" i " drivedb[i, num]=" drivedb[i, "num"] " icon=" ic[drivedb[i, "num"]])
}
drivedb[i, "staticon"] = constant["ICON_" drivedb[i, "status"]];
if(drivedb[i, "staticon"] == "")
drivedb[i, "staticon"] = "<p>x" drivedb[i, "status"] "</p>";
drivedb[i, "dev"] = disk_device[k];
}
if(disk_status[k] == "DISK_DSBL_NEW")
drivedb[i, "rowextra"] = drivedb[ix, "rowextra"] ColorHtml[color="blue"];
else if((disk_status[k] != "DISK_OK") && (disk_status[k] != "DISK_NEW"))
drivedb[i, "rowextra"] = drivedb[ix, "rowextra"] ColorHtml[color="orange"];
else if(drivedb[i, "dev"] == highlightdev)
drivedb[i, "rowextra"] = drivedb[i, "rowextra"] ";background: " highlightcolor;
drivedb[rdisk_serial[k]] = i; #allows indexed access to drive by serial number
drivedb[drivedb[i, "autoid"]] = i; #allows indexed access to a drive by autoid
drivedb[drivedb[i, "autoid4"]] = i;
drivedb[drivedb[i, "md"]] = i; #allows indexed access to a drive by "md"
drivedb[drivedb[i, "dev"]] = i; #allows indexed access to a drive by "device"
i++;
}
drivedb["count"] = i;
nextslot=i
GetOtherDisks(); #Load the non-array disks into the drivedb[]
return(nextslot);
}
#-----------------------------------------------------------------------
# This function tries to figure out the drive manufacturer based on the
# drive model number.
#-----------------------------------------------------------------------
function GetDriveManufacturer(ix, dm2, dm3)
{
#--------------------------------------------------------------
# Try to figure out the drive manufacturer based on the model.
#--------------------------------------------------------------
#perr("GetDriveManu modelnum=" drivedb[ix, "modelnum"] ", ix=" ix);
dm2 = tolower(substr(drivedb[ix, "modelnum"],1,2))
dm3 = tolower(substr(drivedb[ix, "modelnum"],1,3))
if((dm2=="st") || (dm3=="sea"))
drivedb[ix, "manu"] = "Seagate";
else if((dm2=="wd") || (dm3=="wes")) {
drivedb[ix, "manu"] = "WD"
drivedb[ix, "smart_nospinup"] = "1"
}
else if((dm3=="hds") || (dm3=="hit"))
drivedb[ix, "manu"] = "Hitachi"
else if((dm2=="hd") || (dm3=="sam"))
drivedb[ix, "manu"] = "Samsung"
else if(dm3=="max")
drivedb[ix, "manu"] = "Maxtor"
else {
#perr("unknown modelnum=" drivedb[ix, "modelnum"] ", ix=" ix);
drivedb[ix, "manu"] = "Unknown"
}
#-------------------------------------------------------------
# Remember that you can explicity define the manufacturer for
# your drive in the myMain_local.conf file
#-------------------------------------------------------------
}
#----------------------------------------------
# Set a few values not set by other functions.
#----------------------------------------------
function LoadOtherInfo(i)
{
drivedb["total", "disk_size"] = human_readable_number(drivedb["total", "disk_size_raw"], 0, 0, 0, 2);
drivedb["total", "disk"] = "Total";
drivedb["total", "rowextra"] = drivedb["total", "rowextra"] ";" TotalColorHtml;
for(i=0; i<drivedb["count"]; i++) {
drivedb[i, "disk_size_1000c"] = CommaFormat(sprintf("%d", drivedb[i, "disk_size_raw"]));
drivedb[i, "disk_size_1024c"] = CommaFormat(sprintf("%d", drivedb[i, "disk_size_raw"]/1.024));
drivedb[i, "disk_free_1000c"] = CommaFormat(sprintf("%d", drivedb[i, "disk_free_raw"]));
drivedb[i, "disk_free_1024c"] = CommaFormat(sprintf("%d", drivedb[i, "disk_free_raw"]/1.024));
drivedb[i, "disk_used_1000c"] = CommaFormat(sprintf("%d", drivedb[i, "disk_used_raw"]));
drivedb[i, "disk_used_1024c"] = CommaFormat(sprintf("%d", drivedb[i, "disk_used_raw"]/1.024));
if(constant[toupper(drivedb[i, "manu"])] == "")
drivedb[i, "manulogo"] = drivedb[i, "manu"];
else
drivedb[i, "manulogo"] = constant[toupper(drivedb[i, "manu"])];
#perr(drivedb[i, "dev"]"="drivedb[i, "manu"]", "drivedb[i, "manulogo"])
}
drivedb["total", "disk_size_1000c"] = CommaFormat(sprintf("%d", drivedb["total", "disk_size_raw"]));
drivedb["total", "disk_size_1024c"] = CommaFormat(sprintf("%d", drivedb["total", "disk_size_raw"]/1.024));
drivedb["total", "disk_free_1000c"] = CommaFormat(sprintf("%d", drivedb["total", "disk_free_raw"]));
drivedb["total", "disk_free_1024c"] = CommaFormat(sprintf("%d", drivedb["total", "disk_free_raw"]/1.024));
drivedb["total", "disk_used_1000c"] = CommaFormat(sprintf("%d", drivedb["total", "disk_used_raw"]));
drivedb["total", "disk_used_1024c"] = CommaFormat(sprintf("%d", drivedb["total", "disk_used_raw"]/1.024));
}
#-------------------------------------------------------------------------
# This function calls the "bwm-ng" command twice - once to get disk I/O
# activity, and once to get network activity. I found some bugs with the
# "-oplain" option. "-ocsv" works much better.
#-------------------------------------------------------------------------
function GetPerformanceData(RxHtml, TxHtml, cmd, cmd1, cmd2, i, a, li, dev, Tx, Rx, RxTx)
{
RS="\n"
#cmd="bwm-ng -t1000 -Tavg -idisk -oplain -c 1 -d|grep -v 'iface\\|-\\|=\\|bwm\\|md'"
#----------------------------
# Gets disk performance data
#----------------------------
#------------------------------------------------------------------------
# I want these runs to occur simultaneously so that the same interval is
# measured (it also speeds up response time). To accomplish this, I kick
# off the network monitoring in the background (via nohup). It pipes
# its output to a file. I then process the disk monitoring normally.
# When it is done the other one should be done also, but I add a short
# pause just to be sure.
#------------------------------------------------------------------------
cmd1="bwm-ng -idisk -ocsv -c 1 |grep -v 'md'"
cmd2="nohup bwm-ng -ocsv -c 1 -d 2>/dev/null |grep 'eth0' >/tmp/perf.txt 2>/dev/null&"
system(cmd2)
while ((cmd1 | getline a) > 0 ) {
li["count"] = split(a, li, ";")
#print "<p>"a"</p><p>"
#for(i=1; i <= li["count"]; i++)
# print "li[" i "]=" li[i] ", "
#print "</p>"
dev = li[2]
#print "<p>dev=" dev "</p>"
if(dev=="total")
#i = "total"
continue;
else {
i = drivedb[dev]
}
Tx = li[3]+0;
Rx = li[4]+0;
RxTx = li[5]+0;
if(i != "") {
if(Rx != 0) {
drivedb[i, "RxSpeed"] = HumanReadablePerSec(Rx);
drivedb[i, "RxSpeed_raw"] = Rx;
drivedb[i, "rowextra"] = drivedb[i, "rowextra"] ";font-weight:bold" #bold rows that have I/O activity
} else {
drivedb[i, "RxSpeed"] = "--";
drivedb[i, "RxSpeed_raw"] = 0;
}
if(Tx != 0) {
drivedb[i, "TxSpeed"] = HumanReadablePerSec(Tx);
drivedb[i, "TxSpeed_raw"] = Tx;
drivedb[i, "rowextra"] = drivedb[i, "rowextra"] ";font-weight:bold" #bold rows that have I/O activity
} else {
drivedb[i, "TxSpeed"] = "--";
drivedb[i, "TxSpeed_raw"] = 0;
}
if(RxTx != 0) {
drivedb[i, "RxTxSpeed"] = HumanReadablePerSec(RxTx);
drivedb[i, "RxTxSpeed_raw"] = RxTx;
} else {
drivedb[i, "RxTxSpeed"] = "--";
drivedb[i, "RxTxSpeed_raw"] = 0;
}
}
}
close(cmd1);
system("sleep 0.5") #Make sure nohup'ed command is complete
#-------------------------------
# Get network performance data.
#-------------------------------
cmd="cat /tmp/perf.txt"
cmd | getline a #only one line of output
delete li
li["count"] = split(a, li, ";");
Tx = li[3]+0;
Rx = li[4]+0;
#p("Rx="Rx "-" HumanReadablePerSec(Rx) ", Tx="Tx "-" HumanReadablePerSec(Tx));
if(Rx > 500)
drivedb["total", "RxSpeed"] = RxHtml HumanReadablePerSec(Rx);
else
drivedb["total", "RxSpeed"] = RxHtml "--";
if(Tx > 500)
drivedb["total", "TxSpeed"] = TxHtml HumanReadablePerSec(Tx);
else
drivedb["total", "TxSpeed"] = TxHtml "--";
close(cmd);
}
#------------------------------------------------------------
# This function loads the smart data into the drivedb array.
# ... uses red_temp, orange_temp, yellow_temp, blue_temp, co[], constant[]
#------------------------------------------------------------
function GetSmartData(cmd, a, ix, ix2, lst, t, d, mode, i, color, v, found, cmd2, b, dl, desc, cmd3, c, dt, tm, mn)
{
rawsmart = (GETARG["rawsmart"]+0 == 1)
#-------------------------------------------------------------------------
# This logic will add add'l rows to the drivedb[] array (and hence to the
# output HTML table) based on locally collect smart reports.
#-------------------------------------------------------------------------
#if((t=constant["smartwsfolder"]) != "") {
# cmd = "find " t " -maxdepth 1 -type d -ls"
#
# #-------------------------------------------------
# # Process each line, they will look like this ...
# # /mnt/cache/Smart
# # /mnt/cache/Smart/host1
# # /mnt/cache/Smart/host1/sn1
# # /mnt/cache/Smart/host1/sn2
# # ...
# # /mnt/cache/Smart/host2
# # /mnt/cache/Smart/host2/sn3
# # ...
# #-------------------------------------------------
# while ((cmd | getline a) > 0 ) {
# gsub(".*" t, "", a);
# delete d;
# d["count"] = split(a,d,"/")
# if(d["count"] == 2) {
# cmd3="ls -l " t a
# perr("cmd3="cmd3)
# cmd3 | getline c #skip first line: "total: "
# while((cmd3 | getline c) > 0) {
# gsub(".*:[0-9][0-9] ", "", c)
# #perr("c=" c);
#
# cmd2 = "fromdos<" t a "/" c "/driveinfo.txt"
# #perr("cmd2="cmd2);
#
# cmd2 | getline b;
# cmd2 | getline dl;
# cmd2 | getline desc;
# close(cmd2);
# cmd2 = "ls -lt " t a "/" c "/smart_*.txt";
# cmd2 | getline b;
# gsub("^[^/]*", "", b); #b is the filename (/directory/smart_yyyymmdd_hhmn.txt)
# #perr(b);
# close(cmd2);
# perr(b);
#
# i=drivedb["count"]++;
# drivedb[i, "num"] = i;
# drivedb[i, "dev"] = dl;
# drivedb[i, "md"] = "";
# drivedb[i, "role"] = "file";
# #drivedb[i, "disk"] = d[2] " " DateTimeStringFromFileName(b);
# drivedb[i, "disk"] = d[2];
# drivedb[i, "filedate"] = DateTimeStringFromFileName(b);
# drivedb[i, "fullid"] = d[2];
# drivedb[i, "status"] = "WS"
# drivedb[i, "file"] = b;
# drivedb[i, "spinind"] = 2;
# drivedb[i, "rowextra"] = drivedb[i, "rowextra"] ";font-style:italic;color: blue"
# }
# close(cmd3)
# }
# }
# close(cmd);
#}
#-------------------------------------------------------------------------
# This logic will add add'l rows to the drivedb[] array (and hence to the
# output HTML table) based on the *.txt files in a configurable folder.
# This loads some known bad smart reports so you can see what they will
# look like when loaded in the myMain smart view.
#-------------------------------------------------------------------------
#if((t=constant["smartlogfolder"]) == "")
# t="/smartlog"
#cmd = "ls " t "/*.txt 2>/dev/null" #cmd to get the list of files
#-------------------------------
# For each file, add a new row.
#-------------------------------
#while ((cmd | getline a) > 0 ) {
# i=drivedb["count"]++;
# drivedb[i, "num"] = i;
# drivedb[i, "dev"] = "file";
# drivedb[i, "md"] = "";
# drivedb[i, "role"] = "file";
# delete d;
# d["count"] = split(a,d,"/")
# drivedb[i, "disk"] = d[d["count"]];
# drivedb[i, "fullid"] = a;
# drivedb[i, "status"] = "FL"
# drivedb[i, "file"] = a;
# drivedb[i, "spinind"] = 2;
# drivedb[i, "rowextra"] = drivedb[i, "rowextra"] ";font-style:italic;color: blue"
# #perr("FILE:" drivedb[i, "file"])
#}
#close(cmd);
#------------------------------------------------------------------------
# Now loop through all the rows in the drivedb array (including those we
# just added.
#------------------------------------------------------------------------
for(ix=0; ix<drivedb["count"]; ix++) {
lst=lst " " "/dev/" drivedb[ix, "dev"];
#----------------------------------------
# Don't run smart report on flash drive.
#----------------------------------------
if(drivedb[ix, "disk"] == "flash") {
drivedb[ix, "smart_family"] = "Flashdrive"
continue;
}
#perr("drivedb[" ix ", autoid]='" drivedb[ix, "autoid"])
#-------------------------------------------------------------------
# Don't run a smart report on drives that are spun down / can't run
# smart while spun down
#-------------------------------------------------------------------
if((drivedb[ix, "spinind"] == 0) && (drivedb[ix, "smart_nospinup"] == 0)) {
#Find latest smartctl file for this drive
#perr("DSN=" drivedb[ix, "serial"])
if((t=constant["smarturfolder"]) == "") {
drivedb[ix, "smart_family"] = "zzz ..."
drivedb[ix, "smart_fail_lst"] = "zzz ..."
continue;
}
cmd = "find " t " -iname " drivedb[ix, "serial"] " -ls"
cmd | getline a
close(cmd);
if(a == "") { #not found
drivedb[ix, "smart_family"] = "zzz ..."
drivedb[ix, "smart_fail_lst"] = "zzz ..."
continue;
}
gsub(".*:[0-9][0-9] ", "", a);
cmd = "ls -lcr " a "/smart_*"
#perr("cmd="cmd)
#perr("a="a)
cmd | getline a
close(cmd)
if(a == "") { #not found
drivedb[ix, "smart_family"] = "zzz ..."
drivedb[ix, "smart_fail_lst"] = "zzz ..."
continue;
}
gsub(".*:[0-9][0-9] ", "", a);
#perr(a);
drivedb[ix, "file"] = a;
#drivedb[ix, "disk"] = drivedb[ix, "disk"] " " DateTimeStringFromFileName(a)
drivedb[ix, "disk"] = drivedb[ix, "disk"];
drivedb[ix, "filedate"] = DateTimeStringFromFileName(a)
drivedb[ix, "rowextra"] = drivedb[i, "rowextra"] ";color: blue"
}
#--------------------------------------------------------------------
# If it is a file, load the smartctl from the file. Otherwise, load
# it from the smartctl command.
#--------------------------------------------------------------------
if(drivedb[ix, "file"] == "") {
smartopt="-d ata"
if(drivedb[ix, "smartopt"] != "")
smartopt = drivedb[ix, "smartopt"];
if(index(smartopt, "/dev/") <= 0)
smartopt = smartopt " /dev/" drivedb[ix, "dev"];
cmd = "smartctl -a " PERMISSIVE_OPTION " " smartopt;
#perr("1 smartctl " drivedb[ix, "dev"]);
}
else
cmd = "fromdos<\"" drivedb[ix, "file"] "\""
#p("cmd='" cmd "'")
#----------------------------
# Process the smartctl file
#--------------------------*/
while ((cmd | getline a) > 0 ) {
#perr(a);
color="";
if(a ~ "Model Family") {
delete d
split(a, d, ":")
gsub("^ +", "", d[2])
drivedb[ix, "smart_family"] = d[2];
#p("smart_family=" drivedb[ix, "smart_family"]);
}
else if (a ~ "Not in smartctl database") {
drivedb[ix, "smart_family"] = drivedb[ix, "manu"] " (unknown family)";
}
else if(a ~ "Device Model") {
delete d
split(a, d, ":")
gsub("^ +", "", d[2])
drivedb[ix, "smart_model"] = d[2];
#p("smart_model=" drivedb[ix, "smart_model"]);
}
else if(a ~ "Firmware Version") {
delete d
split(a, d, ":")
gsub("^ +", "", d[2])
drivedb[ix, "smart_firmware"] = d[2];
#p("smart_firmware=" drivedb[ix, "smart_firmware"]);
}
else if(a ~ "ATA Version is") {
delete d
split(a, d, ":")
gsub("^ +", "", d[2])
drivedb[ix, "smart_ata_ver"] = d[2]+0;
#p("smart_ata_ver=" drivedb[ix, "smart_ata_ver"]);
}
else if(a ~ "SMART overall-health") {
delete d
split(a, d, ":")
gsub("^ +", "", d[2])
if(d[2] == "PASSED")
d[2] = constant["PassedHtml"];
else if (d[2] == "FAILED!") {
d[2] = constant["FailedHtml"];
drivedb[ix, "smart_overallextra"] = drivedb[ix, "smart_overallextra"] ColorHtml["red"];
}
drivedb[ix, "smart_overall"] = d[2];
#p("smart_overall=" drivedb[ix, "smart_overall"]);
}
else if(a ~ "ID#")
mode="ATTR"
else if(a ~ "No Errors Logged")
drivedb[ix, "errors_logged"] = "0";
else if(a ~ "^ATA Error Count") {
delete d
split(a, d, " ")
t=d[4]+0;
ix2="ata_error_count";
#p(ix2 "=" t);
drivedb[ix, ix2] = t;
if((drivedb[ix, ix2]>0) && (d[4]<=drivedb[ix, ix2 "_ok"]) && !rawsmart)
drivedb[ix, ix2 "extra"] = drivedb[ix, ix2 "extra"] ColorHtml[color="override"];
else if(t>0)
drivedb[ix, ix2 "extra"] = drivedb[ix, ix2 "extra"] ColorHtml[color="red"];
}
else if ((a ~ "^ *[1-9]+") && (mode == "ATTR")) {
delete d
#perr("Attr line: '" a "'")
split(a, d)
drivedb[ix, "smart_attr_" d[1] "_name"] = tolower(d[2]);
drivedb[ix, "smart_attr_" d[1] "_flag"] = d[3];
drivedb[ix, "smart_attr_" d[1] "_value"] = d[4];
drivedb[ix, "smart_attr_" d[1] "_worst"] = d[5];
drivedb[ix, "smart_attr_" d[1] "_thresh"] = d[6];
drivedb[ix, "smart_attr_" d[1] "_type"] = d[7];
drivedb[ix, "smart_attr_" d[1] "_updated"] = d[8];
drivedb[ix, "smart_attr_" d[1] "_when_failed"] = d[9];
t = d[10] " " d[11] " " d[12] " " d[13] " " d[14] " " d[15] " " d[16] " " d[17] " " d[18]
t = t " "
t = gensub("[ \\t]+$", "", 1, t)
#------------------------------------------
# Make the value numeric if it is a number
#------------------------------------------
if(t ~ "^[0-9]+$")
t=t+0;
drivedb[ix, "smart_attr_" d[1] "_raw"] = t;
ix2 = tolower(d[2])
if(ix2 == "unknown_attribute")
ix2="attribute_" d[1];
if(d[9] != "-") {
t = d[9];
if(t ~ "FAILING_NOW") {
t = "Failing";
color="red"
}
else if (t ~ "past") {
t = "Past Failure"
color="orange"
}
else { #don't know of any other values, but just in case
gsub("_", " ", t);
color="red"
}
drivedb[ix, ix2 "extra"] = drivedb[ix, ix2 "extra"] ColorHtml[color];
#p(color " = " drivedb[ix, ix2 "extra"])
drivedb[ix, ix2] = drivedb[ix, "smart_" d[1]] = drivedb[ix, "smart_attr_" d[1] "_raw"] " (" t ")"
color="" #@@@ why?
#perr("drivedb[" ix ", " ix2 "]='" drivedb[ix, ix2])
if(drivedb[ix, "smart_fail_lst"] != "")
t = ""
else
t = ""
#drivedb[ix, "smart_fail_lst"] = drivedb[ix, "smart_fail_lst"] t "<div style=\"background-color:" color ";\">" bullet drivedb[ix, "smart_attr_" d[1] "_name"] "</div>"
}
else {
drivedb[ix, ix2] = drivedb[ix, "smart_" d[1]] = drivedb[ix, "smart_attr_" d[1] "_raw"];
#perr("drivedb[" ix ", " ix2 "]='" drivedb[ix, ix2] "'")
}
#---------------------
# Special color rules
#---------------------
t=drivedb[ix, "smart_attr_" d[1] "_raw"]
if(ix2 ~ "temperature") {
split(t, v)
if(drivedb[ix, ix2 "_delta"] != "") {
v[1] = v[1] + drivedb[ix, ix2 "_delta"]
drivedb[ix, ix2 "extra"] = drivedb[ix, ix2 "extra"] ColorHtml["override"];
drivedb[ix, ix2] = drivedb[ix, "smart_" d[1]] = v[1] " adj [" drivedb[ix, "smart_attr_" d[1] "_raw"] ")";
drivedb[ix, ix2] = drivedb[ix, "smart_" d[1]] = v[1] " adj [" drivedb[ix, "smart_attr_" d[1] "_raw"] ")";
}
else
drivedb[ix, ix2] = drivedb[ix, "smart_" d[1]] = gensub("Lifetime Min/Max ", "", 1, drivedb[ix, ix2]);
if(v[1] >= red_temp)
drivedb[ix, ix2 "extra"] = drivedb[ix, ix2 "extra"] ColorHtml[color="red"];
else if(v[1] >= orange_temp)
drivedb[ix, ix2 "extra"] = drivedb[ix, ix2 "extra"] ColorHtml[color="orange"];
else if(v[1] >= yellow_temp)
drivedb[ix, ix2 "extra"] = drivedb[ix, ix2 "extra"] ColorHtml[color="yellow"];
else if(v[1] <= blue_temp)
drivedb[ix, ix2 "extra"] = drivedb[ix, ix2 "extra"] ColorHtml[color="blue"];
}
else if(ix2 == "reallocated_sector_ct") {
if((drivedb[ix, ix2 "_ok"]>0) && (t<=drivedb[ix, ix2 "_ok"]) && !rawsmart)
drivedb[ix, ix2 "extra"] = drivedb[ix, ix2 "extra"] ColorHtml[color="override"];
else if(t>10)
drivedb[ix, ix2 "extra"] = drivedb[ix, ix2 "extra"] ColorHtml[color="red"];
else if(t>0)
drivedb[ix, ix2 "extra"] = drivedb[ix, ix2 "extra"] ColorHtml[color="orange"];
}
else if(ix2 == "current_pending_sector") {
if(t>0)
if((drivedb[ix, ix2 "_ok"]>0) && (t<=drivedb[ix, ix2 "_ok"]) && !rawsmart)
drivedb[ix, ix2 "extra"] = drivedb[ix, ix2 "extra"] ColorHtml[color="override"];
else
drivedb[ix, ix2 "extra"] = drivedb[ix, ix2 "extra"] ColorHtml[color="red"];
}
#else if ("reported_uncorrect high_fly_writes offline_uncorrectable udma_crc_error_count calibration_retry_count spin_retry_count" ~ d[1]) {
else if((",227,221,220,205,204,203,202,201,200,199,198,197,196,189,187,184,183,174,172,171,13,11,10,5," ~ "," d[1] ",") || ((d[1] == 193) && (t>1000) && (t>drivedb[ix, "smart_attr_9_raw"]))) {
#co1lor="yellow";
if((drivedb[ix, ix2 "_ok"]>0) && (t<=drivedb[ix, ix2 "_ok"]) && !rawsmart)
drivedb[ix, ix2 "extra"] = drivedb[ix, ix2 "extra"] ColorHtml[color="override"];
else if(t>0)
drivedb[ix, ix2 "extra"] = drivedb[ix, ix2 "extra"] ColorHtml[color="yellow"];
}
}
else if(a ~ "SMART Error Log Version") {
mode="LOG"
}
if((color == "yellow") || (color == "red") || (color == "orange")) {
found=0;
for(k=1; k<=co["count"]; k++) {
if(co[k] == ix2) {
found=1;
break;
}
}
if(found == 0)
if(index(constant["SmartIgnoreList"], ix2) == 0) {
#drivedb[ix, "smart_fail_lst"] = drivedb[ix, "smart_fail_lst"] "<div style='" ColorHtml[color] ";'>" bullet ix2 "=" t "</div>"
hlink="<a href=\"myConfig?mode=drive"amp"serial=" drivedb[ix,"serial"] amp "newattr=" ix2 amp "newvalue=" t "\" target='_blank'><span title='Click to override'>"
if(qqi==1) perr("HERE2!!")
drivedb[ix, "smart_fail_lst"] = drivedb[ix, "smart_fail_lst"] hlink "<div style='" ColorHtml[color] ";'>" bullet ix2 "=" t "</div></a>"
}
}
#p("smart_overall=" drivedb[ix, "smart_overall"]);
}
#if(drivedb[ix, "smart_fail_lst"] != "")
# drivedb[ix, "smart_fail_lst"] = drivedb[ix, "smart_fail_lst"] "</span>"
close(cmd)
}
}
#----------------------------------------------------------------------------
# This function calls JoeL.'s GetDiskData() function and then reformats the
# data into the drivedb[] array structure.
#----------------------------------------------------------------------------
function GetOtherDisks(bootdrive, cachedrive, a, i, modela, k, m, ms, outstr) {
GetDiskData(); #Another of JoeL.'s functions that do the heavy lifting on non-array disks
bootdrive = ""
cachedrive = ""
unassigned_drive = ""
for( a = 1; a <= num_partitions; a++ ) {
#if(assigned[a] != "in-array")
# perr("#" a " device=" device[a] " assigned='" assigned[a] "' mounted='" mounted[a] "'")
if ( mounted[a] == "/mnt/cache" ) {
i=drivedb["count"]-1;
drivedb[i, "num"] = i;
drivedb[i, "dev"] = substr(device[a], 1, 3);
if(drivedb[i, "dev"] == highlightdev)
drivedb[i, "rowextra"] = drivedb[i, "rowextra"] ";background: " highlightcolor ";" ;
#drivedb[i, "name"] = "cache";
drivedb[i, "md"] = device[a];
drivedb[i, "role"] = "cache";
drivedb[i, "disk"] = "cache";
drivedb[i, "fullid"] = model_serial[a];
delete ms
k=split(model_serial[a], ms, "_");
modela=""
for(m=1; m<k; m++)
modela=modela " " ms[m]
drivedb[i, "disk_size"] = human_readable_number(drivedb[i, "disk_size_raw"], 0, 0, 0, 1);
drivedb[i, "serial"] = ms[k];
drivedb[i, "autoid"] = lastchars(drivedb[i, "serial"], constant["IdLen"])
drivedb[i, "autoid4"] = lastchars(drivedb[i, "serial"], 4)
drivedb[i, "modelnum"] = substr(modela,2);
GetDriveManufacturer(i)
drivedb[i, "size"] = -1; # need this?
drivedb[i, "reads_raw"] = other_reads[a];
drivedb[i, "writes_raw"] = other_writes[a];
drivedb[i, "reads"] = CommaFormat(other_reads[a]);
drivedb[i, "writes"] = CommaFormat(other_writes[a]);
drivedb[i, "status_raw"] = "DISK_MT"
drivedb[i, "status"] = "MT"
drivedb[i, "staticon"] = constant["ICON_CACHE"];
drivedb[drivedb[i, "serial"]] = i; #allows indexed access to drive by serial number
drivedb[drivedb[i, "autoid"]] = i; #allows indexed access to drive by auto id (e.g., last 3 digits of S/N)
drivedb[drivedb[i, "autoid4"]] = i;
drivedb[drivedb[i, "dev"]] = i; #allows indexed access to a drive by disk name
drivedb[drivedb[i, "dev"]"1"] = i; #allows indexed access to a drive by disk name
#} else if ( mounted[a] == "/boot" ) {
} else if ( device[a] == boot_device ) {
i=drivedb["count"]++;
#perr("boot drive=" i);
if(view[activeview, "smartdata"] > 0)
drivedb[i, "suppress"] = 1
drivedb[i, "num"] = i;
drivedb[i, "dev"] = substr(device[a], 1, 3);
#if(drivedb[i, "dev"] == highlightdev)
# drivedb[i, "rowextra"] = drivedb[i, "rowextra"] ";background: " highlightcolor;
#drivedb[i, "name"] = "boot";
drivedb[i, "md"] = device[a];
drivedb[i, "role"] = "boot";
drivedb[i, "disk"] = "flash";
if(substr(model_serial[a], 1, 4) == "usb-")
model_serial[a] = substr(model_serial[a], 5);
if(substr(model_serial[a], length(model_serial[a])-3) == "-0:0")
model_serial[a] = substr(model_serial[a], 1, length(model_serial[a])-4)
drivedb[i, "fullid"] = model_serial[a];
#drivedb[i, "serial"] = model_serial[a];
#drivedb[i, "modelnum"] = model_serial[a];
delete ms
k=split(model_serial[a], ms, "_");
modela=""
for(m=1; m<k; m++)
modela=modela " " ms[m]
drivedb[i, "serial"] = ms[k];
drivedb[i, "autoid"] = lastchars(drivedb[i, "serial"], constant["IdLen"])
drivedb[i, "autoid4"] = lastchars(drivedb[i, "serial"], 4)
drivedb[i, "modelnum"] = substr(modela,2);
GetDriveManufacturer(i)
drivedb[i, "size"] = -1; # need this?
drivedb[i, "reads_raw"] = other_reads[a];
drivedb[i, "writes_raw"] = other_writes[a];
drivedb[i, "reads"] = CommaFormat(other_reads[a]);
drivedb[i, "writes"] = CommaFormat(other_writes[a]);
drivedb[i, "status_raw"] = "DISK_BT"
drivedb[i, "status"] = "BT"
drivedb[i, "staticon"] = constant["ICON_BT"];
drivedb[drivedb[i, "serial"]] = i; #allows indexed access to drive by serial number
drivedb[drivedb[i, "autoid"]] = i; #allows indexed access to drive by auto id (e.g., last 3 digits of S/N)
drivedb[drivedb[i, "autoid4"]] = i;
drivedb[drivedb[i, "dev"]] = i; #allows indexed access to a drive by disk name
drivedb[drivedb[i, "dev"]"1"] = i; #allows indexed access to a drive by disk name
} else if ( (substr(device[a],1,2) != "md") && (assigned[a] == "") && (device[a] ~ "[a-z]+1" )) {
i=drivedb["count"]-1; # should have already hit this device (without the 1)
#perr("i=" i " (array disk)")
#p("part " device[a] " " i)
#drivedb[i, "num"] = i;
#drivedb[i, "dev"] = substr(device[a],1,3);
#if(drivedb[i, "dev"] == highlightdev)
# drivedb[i, "rowextra"] = drivedb[i, "rowextra"] "background: " highlightcolor;
#drivedb[i, "name"] = "staging";
drivedb[i, "md"] = device[a] "1";
drivedb[i, "role"] = "non-array";
drivedb[i, "fullid"] = model_serial[a];
#drivedb[i, "serial"] = model_serial[a];
#drivedb[i, "modelnum"] = model_serial[a];
delete ms
k=split(model_serial[a], ms, "_");
modela=""
for(m=1; m<k; m++)
modela=modela " " ms[m]
drivedb[i, "serial"] = ms[k];
drivedb[i, "autoid"] = lastchars(drivedb[i, "serial"], constant["IdLen"])
drivedb[i, "autoid4"] = lastchars(drivedb[i, "serial"], 4)
drivedb[i, "modelnum"] = substr(modela,2);
GetDriveManufacturer(i)
drivedb[i, "size"] = -1; # need this?
drivedb[i, "reads_raw"] = other_reads[a];
drivedb[i, "writes_raw"] = other_writes[a];
drivedb[i, "reads"] = CommaFormat(other_reads[a]);
drivedb[i, "writes"] = CommaFormat(other_writes[a]);
if(mounted[a] == "") {
drivedb[i, "status_raw"] = "DISK_UN"
drivedb[i, "status"] = "UN"
drivedb[i, "disk"] = "--";
drivedb[i, "staticon"] = constant["ICON_UN"];
}
else {
drivedb[i, "status_raw"] = "DISK_MT"
drivedb[i, "status"] = "MT"
drivedb[i, "disk"] = substr(mounted[a], 6)
drivedb[i, "staticon"] = constant["ICON_MT"];
}
drivedb[drivedb[i, "serial"]] = i; #allows indexed access to drive by serial number
drivedb[drivedb[i, "autoid"]] = i; #allows indexed access to drive by auto id (e.g., last 3 digits of S/N)
drivedb[drivedb[i, "autoid4"]] = i;
drivedb[drivedb[i, "dev"]] = i; #allows indexed access to a drive by disk name
drivedb[drivedb[i, "dev"]"1"] = i; #allows indexed access to a drive by disk name
} else if ( (substr(device[a],1,2) != "md") && (assigned[a] == "") && (device[a] ~ "[a-z]+$" ) && (device[a] != boot_device)) {
i=drivedb["count"]++;
#perr("i=" i " (new disk)")
#p("drive=" i);
#p("raw " device[a] " " i)
drivedb[i, "num"] = i;
drivedb[i, "dev"] = substr(device[a],1,3);
if(drivedb[i, "dev"] == highlightdev)
drivedb[i, "rowextra"] = drivedb[i, "rowextra"] "background: " highlightcolor;
#drivedb[i, "name"] = "staging";
drivedb[i, "md"] = device[a];
drivedb[i, "role"] = "non-array";
drivedb[i, "fullid"] = model_serial[a];
#drivedb[i, "serial"] = model_serial[a];
#drivedb[i, "modelnum"] = model_serial[a];
delete ms
k=split(model_serial[a], ms, "_");
modela=""
for(m=1; m<k; m++)
modela=modela " " ms[m]
drivedb[i, "serial"] = ms[k];
drivedb[i, "autoid"] = lastchars(drivedb[i, "serial"], constant["IdLen"])
drivedb[i, "autoid4"] = lastchars(drivedb[i, "serial"], 4)
drivedb[i, "modelnum"] = substr(modela,2);
GetDriveManufacturer(i)
drivedb[i, "disk_size_raw"] = blocks[a]*1024/1000 -32;
drivedb[i, "disk_size"] = human_readable_number(drivedb[i, "disk_size_raw"], 0, 0, 0, 1);
gsub(".0T", "T", drivedb[i, "disk_size"])
#p(drivedb[i, "disk_size_raw"])
drivedb[i, "reads_raw"] = other_reads[a];
drivedb[i, "writes_raw"] = other_writes[a];
drivedb[i, "reads"] = CommaFormat(other_reads[a]);
drivedb[i, "writes"] = CommaFormat(other_writes[a]);
if(mounted[a] == "") {
drivedb[i, "status_raw"] = "DISK_RAW"
drivedb[i, "status"] = "RAW"
drivedb[i, "disk"] = "RAW";
drivedb[i, "staticon"] = constant["ICON_RAW"];
}
else {
drivedb[i, "status_raw"] = "DISK_MT"
drivedb[i, "status"] = "MT"
drivedb[i, "disk"] = substr(mounted[a], 6)
drivedb[i, "staticon"] = constant["ICON_MT"];
}
drivedb[drivedb[i, "serial"]] = i; #allows indexed access to drive by serial number
drivedb[drivedb[i, "autoid"]] = i; #allows indexed access to drive by auto id (e.g., last 3 digits of S/N)
drivedb[drivedb[i, "autoid4"]] = i;
drivedb[drivedb[i, "dev"]] = i; #allows indexed access to a drive by disk name
drivedb[drivedb[i, "dev"]"1"] = i; #allows indexed access to a drive by disk name
}
}
outstr = ""
outstr = outstr "<fieldset style=\"margin-top:5px;\">"
outstr = outstr "<table width=\"100%\" cellpadding=2 cellspacing=4 border=0>"
outstr = outstr bootdrive
if ( cachedrive != "" ) {
outstr = outstr cachedrive
}
if ( unassigned_drive != "" ) {
outstr = outstr unassigned_drive
}
outstr = outstr "</table></fieldset>"
return outstr
}
#----------------------------------------------------------------------------
# Gets and sets the disk temp value in the drivedb[] array. It also sets
# the "extra" values to change the color of cells. That's why it does the
# setting instead of just returning a value. THe "div" style coloration
# used in unmenu.awk doesn't work too well with the gridded presentation (the
# color does not fill the entire cell). If a drive hits the orange or red
# levels, it changes the color of the entire line. Hopefully that should
# get someone's attention.
# .... uses view[], ColorHtml[], yellow_temp, orange_temp, red_temp, blue_temp