forked from darold/pgcluu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pgcluu
executable file
·8025 lines (7346 loc) · 727 KB
/
pgcluu
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
#!/usr/bin/env perl
#------------------------------------------------------------------------------
#
# PgCluu - PostgreSQL monitoring tool with statistics collector and grapher
#
# This program is open source, licensed under the PostgreSQL license.
# For license terms, see the LICENSE file.
#
# Author: Gilles Darold
# Copyright: (C) 2012-2015 Gilles Darold - All rights reserved.
#------------------------------------------------------------------------------
use vars qw($VERSION $PROGRAM);
use strict qw(vars);
use warnings;
use IO::File;
use Getopt::Long qw(:config bundling no_ignore_case_always);
use Time::Local 'timegm_nocheck';
use POSIX qw(locale_h sys_wait_h ceil);
setlocale(LC_ALL, 'C');
$VERSION = '2.3';
$PROGRAM = 'pgCluu';
my $OUTPUT_DIR = '';
my $SADF_PROG = '/usr/bin/sadf';
my $DISABLE_SAR = 0;
my $HTML = '';
my $NO_TB_STAT = 0;
my @INCLUDE_DB = ();
my @INCLUDE_TB = ();
my @INCLUDE_DEV = ();
my @INCLUDE_IFACE = ();
my $IMG_FORMAT = 'png';
my $FH = undef;
my %DEVFH = ();
my $IDX = 1;
my $HELP = 0;
my $SHOW_VER = 0;
my $DEBUG = 0;
my $BEGIN = '';
my $END = '';
my $NUMBER_CPU = 0;
my $TIMEZONE = '00';
my $STATS_TIMEZONE = '00';
my $REVERT_DATE = 0;
my $FROM_SA_FILE = 0;
my $SADC_INPUT_FILE = '';
my $SAR_INPUT_FILE = '';
my @DEVICE_LIST = ();
my @IFACE_LIST = ();
my %OVERALL_STATS = ();
my @GRAPH_COLORS = ('#6e9dc9', '#f4ab3a', '#ac7fa8', '#8dbd0f');
my $ZCAT_PROG = '/bin/zcat';
my $INTERVAL = 1;
my %RELKIND = (
'r' => 'tables',
'i' => 'indexes',
'S' => 'sequences',
'v' => 'views',
'c' => 'composite types',
't' => 'toast tables'
);
my $TOP_STAT = 10;
my ($o_sec, $o_min, $o_hour, $o_day, $o_month, $o_year) = localtime(time);
$o_year += 1900;
$o_month++;
# Variable use to construct the date part of the sar output
# it is set with de date found in sar file kernel header.
my $sar_year = '';
my $sar_month = '';
my $sar_day = '';
# Hash used to store system information
my %sysinfo = ();
# Statistics files to use with report
my %DB_GRAPH_INFOS = (
'pg_stat_database.csv' => {
'1' => {
'name' => 'database-backends',
'title' => 'Connections on %s database',
'description' => 'Number of clients connected to a database.',
'ylabel' => 'Connections',
'legends' => ['backends'],
},
'2' => {
'name' => 'database-read_write_query',
'title' => 'Affected tuples per operation on %s database',
'ylabel' => 'Tuples',
'description' => 'Affected rows on databases grouped by statement family.',
},
'3' => {
'name' => 'database-cache_ratio',
'title' => 'Cache hit/miss ratio on %s database',
'description' => 'Per database cache hit/miss ratio.',
'ylabel' => 'Blocks per second',
'legends' => ['Cache hit','Cache miss','hit/miss ratio'],
'y2label' => 'Percentage',
},
'4' => {
'name' => 'database-commits_rollbacks',
'title' => 'Commits/Rollbacks per second on %s database',
'description' => 'Number of commits / rollbacks per second and number of backends per database.',
'ylabel' => 'Transaction/sec',
'legends' => ['commit','rollback','backends'],
'y2label' => 'Number of backend',
},
'5' => {
'name' => 'database-write_ratio',
'title' => 'Write ratio on %s database',
'description' => 'Write ratio on databases excluding templates and postgres.',
'ylabel' => 'Write queries per second',
'legends' => ['Insert','Update','Delete'],
},
'6' => {
'name' => 'database-read_ratio',
'title' => 'Read tuples on %s database',
'description' => 'Show entries returned from the index and live rows fetched from the tables. The latter will be less if any dead or not-yet-committed rows are fetched using the index.',
'ylabel' => 'Tuples per second',
'legends' => ['Table (returned)','Index (fetched)'],
},
'7' => {
'name' => 'database-deadlocks',
'title' => 'Number of deadlocks on %s database',
'description' => 'Number of deadlocks detected in this database.',
'ylabel' => 'Number of deadlocks',
'legends' => ['deadlocks'],
},
'8' => {
'name' => 'database-canceled_queries',
'title' => 'Number of canceled queries on %s database',
'description' => 'Number of queries canceled due to conflicts with recovery in this database. [Conflicts occur only on standby servers]',
'ylabel' => 'Number of queries canceled',
'legends' => ['conflicts'],
},
'9' => {
'name' => 'database-temporary_files',
'title' => 'Number of temporary files on %s database',
'description' => 'Number of temporary files created by queries per database.',
'ylabel' => 'Number of files',
'legends' => ['temporary files'],
},
'10' => {
'name' => 'database-temporary_bytes',
'title' => 'Size of temporary data on %s database',
'description' => 'Amount of data written to temporary files created by queries per database.',
'ylabel' => 'Size per seconde',
'legends' => ['temporary data'],
},
},
'pg_stat_database_conflicts.csv' => {
'1' => {
'name' => 'database-conflicts',
'title' => 'Conflicts per type on %s database',
'description' => 'Per database statistics about query cancels occurring due to conflicts with recovery on standby servers.',
},
},
'pg_database_size.csv' => {
'1' => {
'name' => 'database-size',
'title' => 'Size of %s database',
'description' => 'Database sizes.',
'ylabel' => 'Size',
'legends' => ['size'],
'active' => 1,
},
},
'pg_tablespace_size.csv' => {
'1' => {
'name' => 'tablespace-size',
'title' => 'Size of %s tablespace',
'description' => 'Tablespace sizes.',
'ylabel' => 'Size',
'legends' => ['size'],
},
},
'pg_stat_bgwriter.csv' => {
'1' => {
'name' => 'database-checkpoints',
'title' => 'checkpoints counter stats',
'description' => 'Background writer statistics on checkpoints. Checkpoints timed is checkpoints issued because of checkpoint_timeout and checkpoints request is checkpoint issued by request.',
'ylabel' => 'Number of checkpoints',
'legends' => ['checkpoints timed','checkpoints requests'],
},
'2' => {
'name' => 'database-bgwriter',
'title' => 'background writer clean stats',
'description' => 'Background writer cache cleaning statistics by checkpoints, lru and backends.',
'ylabel' => 'Buffers per second',
'legends' => ['checkpoint buffers','clean buffers','backend buffers'],
},
'3' => {
'name' => 'database-bgwriter_count',
'title' => 'background writer count stats',
'description' => 'Background writer counter stats. Max written clean reports the number of times the background writer stopped a cleaning scan because it had written too many buffers. Buffers backend fsync reports the number of times a backend had to execute its own fsync call (normally the background writer handles those even when the backend does its own write).',
'ylabel' => 'Times per second',
'legends' => ['maxwritten clean','buffers backend fsync'],
},
'4' => {
'name' => 'database-checkpoints_time',
'title' => 'checkpoints write stats',
'description' => 'Background writer statistics on checkpoints. Checkpoint write time reports the total amount of time that has been spent in the portion of checkpoint processing where files are written to disk. Checkpoint sync time reports the total amount of time that has been spent in the portion of checkpoint processing where files are synchronized to disk.',
'ylabel' => 'Duration',
'legends' => ['checkpoint write time','checkpoint sync time'],
},
},
'pg_stat_connections.csv' => {
'1' => {
'name' => 'database-connections',
'title' => 'Connections by type on %s database',
'description' => 'Connections by type including idle ones.',
'ylabel' => 'Number of connections',
'legends' => ['Active','Idle','Idle in xact', 'Waiting for a lock'],
},
},
'pg_stat_user_functions.csv' => {
'1' => {
'name' => 'database-functions',
'title' => 'Functions statistics on database %s',
'description' => 'Statistics about executions times and duration of user functions.',
'ylabel' => 'Duration',
'active' => 1,
'legends' => ['total time','self time'],
'menu' => 'Functions statistics',
},
},
'pg_stat_all_tables.csv' => {
'1' => {
'name' => 'table-indexes',
'title' => 'Sequencial vs Index scan on %s',
'description' => 'Number of sequential scan versus index scan per table during the audit period.',
'ylabel' => 'Number per second',
'legends' => ['sequential scan','index scan','% index scan ratio'],
'y2label' => 'Percent',
'active' => 1,
'menu' => 'Index scan ratio',
},
'2' => {
'name' => 'table-vacuums-analyzes',
'title' => 'Analyze/vacuums count on %s',
'description' => 'Number of analyze, autoanalyze, vacuum and autovacuum count per table during the audit period.',
'ylabel' => 'Number',
'legends' => ['Analyze','Autoanalyze','Vacuum','Autovacuum'],
'active' => 1,
'menu' => 'Vacuums/analyzes',
},
'3' => {
'name' => 'table-query-tuples',
'title' => 'Insert/update/delete and hot update tuples on %s',
'description' => 'Number of insert/update/delete and hot update tuples count per table during the audit period.',
'ylabel' => 'Number per second',
'legends' => ['Insert','Update','Delete','Hot Update'],
'active' => 1,
'menu' => 'insert/update/delete',
},
'4' => {
'name' => 'table-kind-tuples',
'title' => 'Live vs dead tuples on %s',
'description' => 'Number of live and dead tuples per table at end of the audit period.',
'ylabel' => 'Number',
'legends' => ['Live','Dead','% Bloat ratio'],
'y2label' => 'Percent',
'active' => 1,
'menu' => 'Live vs dead tuples',
},
},
'pg_statio_all_tables.csv' => {
'1' => {
'name' => 'statio-table',
'title' => 'Statistics about I/O on %s',
'description' => 'Number of disk blocks read from this table or all indexes on this table versus number of buffer hits in a table or all indexes of this table.',
'ylabel' => 'Number per second',
'legends' => ['heap_blks_read','heap_blks_hit','idx_blks_read','idx_blks_hit'],
'active' => 1,
'menu' => 'Tables I/O stats',
},
},
'pg_stat_all_indexes.csv' => {
'1' => {
'name' => 'index-scan',
'title' => 'Statistics about accesses to index %s',
'description' => 'Number of index entries returned by index scans, and number of live table rows fetched by simple index scans using that index during the audit period.',
'ylabel' => 'Number per second',
'legends' => ['index scans initiated','index entries read','live table rows fetched'],
'y2label' => 'Percent',
'active' => 1,
'menu' => 'Index read/fetch',
},
},
'pg_statio_all_indexes.csv' => {
'1' => {
'name' => 'statio-index',
'title' => 'Statistics about I/O on %s',
'description' => 'Number of disk blocks read from this index versus number of buffer hits in this index.',
'ylabel' => 'Number per second',
'legends' => ['idx_blks_read','idx_blks_hit'],
'active' => 1,
'menu' => 'Indexes I/O stats',
},
},
'pg_stat_unused_indexes.csv' => {
'1' => {
'name' => 'unused-index',
'title' => 'Unused indexes on %s',
'description' => 'List of indexes never used (idx_scan = 0).',
'ylabel' => 'Number',
'legends' => ['Unused index'],
'active' => 1,
'menu' => 'Unused Indexes',
},
},
'pg_stat_redundant_indexes.csv' => {
'1' => {
'name' => 'redundant-index',
'title' => 'Redundant indexes on %s',
'description' => 'List of useless indexes because they are redundant.',
'ylabel' => 'Number',
'legends' => ['Redundant index'],
'active' => 1,
'menu' => 'Redundant indexes',
},
},
'pg_stat_missing_fkindexes.csv' => {
'1' => {
'name' => 'missing-index',
'title' => 'Missing FK indexes on %s',
'description' => 'List of DDL to create missing indexes on foreign keys.',
'ylabel' => 'Number',
'legends' => ['Missing index'],
'active' => 1,
'menu' => 'Missing indexes',
},
},
'pg_xlog_stat.csv' => {
'1' => {
'name' => 'database-xlog_files',
'title' => 'WAL files',
'description' => 'Number of WAL file in the xlog directory.',
'ylabel' => 'Number of files',
'legends' => ['total xlog'],
},
},
'pg_stat_replication.csv' => {
'1' => {
'name' => 'database-xlog',
'title' => 'Xlog written',
'description' => 'Number of xlog data written per second.',
'ylabel' => 'Size per second',
'legends' => ['written'],
},
'2' => {
'name' => 'database-replication',
'title' => 'Replication lag with %s',
'description' => 'Lag of replication between primary and secondary servers.',
'ylabel' => 'Lag sizes',
'legends' => ['Sent','Write','Replay'],
},
},
'pgbouncer_stats.csv' => {
'1' => {
'name' => 'pgbouncer-connections',
'title' => 'pgbouncer connections statistics on %s',
'description' => 'Number of active/waiting clients, active/idle/used server connections and maximum wait duration for client connections in each pgbouncer pool.',
'ylabel' => 'Number of connexions',
'legends' => ['Client active','Client waiting','Server active','Server idle','Server used','Clients wait time'],
'y2label' => 'Duration',
},
},
'pgbouncer_req_stats.csv' => {
'1' => {
'name' => 'pgbouncer-duration',
'title' => 'pgbouncer average queries duration on %s',
'description' => 'Average queries duration in each pgbouncer pool.',
'ylabel' => 'mDuration',
'legends' => ['avg_query'],
},
'2' => {
'name' => 'pgbouncer-number',
'title' => 'pgbouncer queries per second on %s',
'description' => 'Number of queries per second in each pgbouncer pool.',
'ylabel' => 'Number',
'legends' => ['avg_req'],
},
},
'pg_class_size.csv' => {
'1' => {
'name' => 'table-size',
'title' => 'Size of table %s',
'description' => 'Disk space used by the table with number of rows at end of the audit.',
'ylabel' => 'Size',
'legends' => ['Object size', 'Number of tuples' ],
'y2label' => 'Number',
'active' => 1,
'menu' => 'Size and tuples',
},
'2' => {
'name' => 'index-size',
'title' => 'Size of index %s',
'description' => 'Disk space used by the index with number of rows at end of the audit.',
'ylabel' => 'Size',
'legends' => ['Object size', 'Number of tuples' ],
'y2label' => 'Number',
'active' => 1,
'menu' => 'Size and tuples',
},
},
'pg_stat_locks.csv' => {
'1' => {
'name' => 'database-lock-types',
'title' => 'Types of locks on %s database',
'description' => 'Number of locks per type in a database. Type of the lockable object: relation, extend, page, tuple, transactionid, virtualxid, object, userlock, or advisory.',
'ylabel' => 'Number',
'legends' => [],
'active' => 1,
},
'2' => {
'name' => 'database-lock-modes',
'title' => 'Modes of locks on %s database',
'description' => 'Number of locks per lock mode held or desired by all process.',
'ylabel' => 'Number',
'legends' => [],
'active' => 1,
},
'3' => {
'name' => 'database-lock-granted',
'title' => 'Granted locks on %s database',
'description' => 'Number of locks held (granted) or awaited (waiting).',
'ylabel' => 'Number',
'legends' => [],
'active' => 1,
},
},
'postgresql.conf' => {
'1' => {
'name' => 'cluster-pgconf',
'title' => 'PostgreSQL configuration',
'description' => 'Configuration directives and values defined in file postgresql.conf.',
'ylabel' => 'Number',
'legends' => ['Settings'],
'active' => 1,
'menu' => 'PostgreSQL configuration',
},
},
'postgresql.auto.conf' => {
'1' => {
'name' => 'cluster-alterconf',
'title' => 'PostgreSQL system altered configuration',
'description' => 'Configuration directives and values defined using ALTER SYSTEM.',
'ylabel' => 'Number',
'legends' => ['Settings'],
'active' => 1,
'menu' => 'PostgreSQL system altered configuration',
},
},
'recovery.conf' => {
'1' => {
'name' => 'cluster-recoveryconf',
'title' => 'PostgreSQL recovery configuration',
'description' => 'Configuration directives and values defined in file recovery.conf.',
'ylabel' => 'Number',
'legends' => ['Settings'],
'active' => 1,
'menu' => 'PostgreSQL recovery configuration',
},
},
'pg_hba.conf' => {
'1' => {
'name' => 'cluster-pghba',
'title' => 'PostgreSQL authorization',
'description' => 'Client authentication controlled by pg_hba.conf configuration file.',
'ylabel' => 'Number',
'legends' => ['Setting','Value'],
'active' => 1,
'menu' => 'PostgreSQL authorization',
},
},
'pg_ident.conf' => {
'1' => {
'name' => 'cluster-pgident',
'title' => 'PostgreSQL User Name Maps',
'description' => 'Different operating system user / database user mappings might be needed for different connections. They are defined in file pg_ident.conf.',
'ylabel' => 'Number',
'legends' => ['Setting','Value'],
'active' => 1,
'menu' => 'User Name Maps',
},
},
'pg_settings.csv' => {
'1' => {
'name' => 'cluster-settings',
'title' => 'PostgreSQL Settings',
'description' => 'Configuration directives and values defined in pg_settings.',
'ylabel' => 'Number',
'legends' => ['Settings'],
'active' => 1,
'menu' => 'PostgreSQL settings',
},
},
'pg_db_role_setting.csv' => {
'1' => {
'name' => 'cluster-dbrolesetting',
'title' => 'PostgreSQL Database/Roles Settings',
'description' => 'Configuration directives and values defined with ALTER DATABASE and ALTER ROLE.',
'ylabel' => 'Number',
'legends' => ['Settings'],
'active' => 1,
'menu' => 'Database/Roles settings',
},
},
'pgbouncer.ini' => {
'1' => {
'name' => 'cluster-pgbouncer',
'title' => 'Pgbouncer configuration',
'description' => 'Configuration directives and values defined in file pgbouncer.ini.',
'ylabel' => 'Number',
'legends' => ['Setting','Value'],
'active' => 1,
'menu' => 'Pgbouncer settings',
},
},
'pg_database_buffercache.csv' => {
'1' => {
'name' => 'cluster-buffersused',
'title' => 'Shared buffers utilization per database',
'description' => 'Show statistics about percentage of shared buffers used per database.',
'ylabel' => 'Percent',
'legends' => [],
'active' => 1,
'menu' => 'Shared buffers utilization',
},
'2' => {
'name' => 'cluster-databaseloaded',
'title' => 'Percentage of each databases loaded in shared buffers',
'description' => 'Show statistics about percentage of each database loaded in shared buffers.',
'ylabel' => 'Percent',
'legends' => [],
'menu' => 'Databases in shared buffers',
},
},
'pg_database_usagecount.csv' => {
'1' => {
'name' => 'cluster-usagecount',
'title' => 'Shared buffers usagecount distribution',
'description' => 'Show statistics about usagecount distribution in shared buffers.',
'ylabel' => 'Percent',
'legends' => [],
'menu' => 'Usagecount utilization',
'active' => 1,
},
},
'pg_database_isdirty.csv' => {
'1' => {
'name' => 'cluster-isdirty',
'title' => 'Dirty shared buffers usagecount distribution',
'description' => 'Show statistics about usagecount distribution in dirty shared buffers.',
'ylabel' => 'Percent',
'legends' => [],
'menu' => 'Dirty Usagecount',
'active' => 1,
},
},
'pg_relation_buffercache.csv' => {
'1' => {
'name' => 'buffercache-relation',
'title' => 'Statistics about cache utilization for %s database',
'description' => 'Number of shared buffers/pages used by a relation.',
'ylabel' => 'Number',
'legends' => ['buffers'],
'active' => 1,
'menu' => 'Buffercache per relation',
},
'2' => {
'name' => 'statio-buffercache',
'title' => 'Statistics about cache utilization %s relation',
'description' => 'Number of buffers loaded in cache for a relation and the percentage of the relation loaded.',
'ylabel' => 'Number',
'y2label' => 'percent',
'legends' => ['buffered','relation %'],
'menu' => 'Buffer I/O per relation',
},
},
'pg_stat_archiver.csv' => {
'1' => {
'name' => 'cluster-archive',
'title' => 'Statistics about archiver',
'description' => 'Number of WAL files archived with number of failure.',
'ylabel' => 'Number',
'legends' => ['archived count', 'failed count'],
'active' => 1,
'menu' => 'Archiving',
}
},
'pg_stat_statements.csv' => {
'1' => {
'name' => 'database-queries',
'title' => 'Statistics about statements',
'description' => 'Top N statistics about slowest or most used queries.',
'ylabel' => 'Number',
'legends' => ['queries'],
'active' => 1,
'menu' => 'Statements statistics',
}
},
);
my %SAR_GRAPH_INFOS = (
'1' => {
'name' => 'system-cpu',
'title' => 'CPU %s utilization',
'description' => 'Percentage of CPU utilization that occurred while executing at the system level (kernel), the user level (application) and the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.',
'ylabel' => 'Percentage',
'legends' => ['Total','System','User','Iowait'],
'active' => 1,
},
'2' => {
'name' => 'system-load',
'title' => 'System load',
'description' => 'System load average for the last minute, the past 5 and 15 minutes. The load average is calculated as the average number of runnable or running tasks (R state), and the number of tasks in uninterruptible sleep (D state) over the specified interval.',
'ylabel' => 'Process load',
'legends' => ['ldavg-1','ldavg-5','ldavg-15'],
},
'3' => {
'name' => 'system-process',
'title' => 'Number of process',
'description' => 'Number of tasks in the task list.',
'ylabel' => 'Number of process',
'legends' => ['plist-sz'],
},
'4' => {
'name' => 'system-memory',
'title' => 'System memory utilization',
'description' => 'Amount of memory used to cache data or as buffers by the kernel and free memory available.',
'ylabel' => 'Memory size',
'legends' => ['cached','buffers','memfree'],
},
'5' => {
'name' => 'system-swap',
'title' => 'Swap In/Out (pages/seconds)',
'description' => 'Total number of swap pages the system brought in/out per second. The page size usually is 4096 bytes.',
'ylabel' => 'Pages/second',
'legends' => ['pswpin/s','pswpout/s'],
},
'6' => {
'name' => 'system-block',
'title' => 'Block In/Out (blocks/seconds)',
'description' => 'Total amount of data read/write from the devices in blocks per second. Blocks are equivalent to sectors and therefore have a size of 512 bytes.',
'ylabel' => 'Block per second',
'legends' => ['bread/s','bwrtn/s'],
},
'7' => {
'name' => 'system-device',
'title' => 'Data read/write on device %s',
'description' => 'Number of bytes read/write from/to the device.',
'ylabel' => 'Size Read/Written per second',
'legends' => ['Read','Write'],
},
'8' => {
'name' => 'system-cpudevice',
'title' => 'CPU utilization on device %s',
'description' => 'Percentage of CPU time during which I/O requests were issued to the device (bandwidth utilization for the device). Device saturation occurs when this value is close to 100%.',
'ylabel' => 'Percentage of CPU',
'legends' => ['cpu used'],
},
'9' => {
'name' => 'system-srvtime',
'title' => 'Average service/wait time for I/O requests on device %s',
'description' => 'The average service time (in milliseconds) for I/O requests that were issued to the device.',
'ylabel' => 'Milliseconds',
'legends' => ['svctm','await'],
},
'10' => {
'name' => 'system-runqueue',
'title' => 'Run queue length',
'description' => 'Number of tasks waiting for run time.',
'ylabel' => 'Run queue length',
'legends' => ['runq-sz'],
},
'11' => {
'name' => 'system-page',
'title' => 'System cache statistics',
'description' => 'Total number of kilobytes the system paged in/out from/to disk per second, and number of major faults the system has made per second, those which have required loading a memory page from disk.',
'ylabel' => 'Size paged',
'y2label' => 'Number of faults',
'legends' => [ 'pgpgin/s', 'pgpgout/s', 'page faults/s' ],
},
'12' => {
'name' => 'network-utilization',
'title' => 'Network utilization on interface %s',
'description' => 'Report statistics from the network devices utilization.',
'ylabel' => 'Size per second',
'legends' => ['received (rx)', 'transmitted (tx)' ],
},
'13' => {
'name' => 'network-error',
'title' => 'Network errors on interface %s',
'description' => 'Report statistics on failures from the network device. Number of bad packets received, number of errors that happened while transmitting packets, and number of collisions that happened per second while transmitting packets.',
'ylabel' => 'Number per second',
'legends' => ['rx errors', 'tx errors', 'collisions' ],
},
);
# Process command line options and look for an action keyword. There
# are no mandatory options.
my @dbs_opts = ();
my @dev_opts = ();
my @tbs_opts = ();
my @net_opts = ();
GetOptions(
"b|begin=s" => \$BEGIN,
"d|db-only=s" => \@dbs_opts,
"D|device-only=s" => \@dev_opts,
"e|end=s" => \$END,
"h|help!" => \$HELP,
"i|sar-file=s" => \$SAR_INPUT_FILE,
"I|sadc-file=s" => \$SADC_INPUT_FILE,
"n|top-number=i" => \$TOP_STAT,
"N|network-only=s" => \@net_opts,
"o|output=s" => \$OUTPUT_DIR,
"s|sadf=s" => \$SADF_PROG,
"r|reverse-date" => \$REVERT_DATE,
"S|disable-sar!" => \$DISABLE_SAR,
"t|with-table=s" => \@tbs_opts,
"T|no-table!" => \$NO_TB_STAT,
"v|verbose!" => \$DEBUG,
"V|version!" => \$SHOW_VER,
"z|timezone=s" => \$TIMEZONE,
"Z|stats-timezone=s" => \$STATS_TIMEZONE,
"from-sa-file!" => \$FROM_SA_FILE,
) or die usage();
&usage if ($HELP);
# Print version number to stdout
if ($SHOW_VER) {
print "Version: $VERSION\n";
exit 0;
}
my $INPUT_DIR = $ARGV[0] || '';
$INPUT_DIR =~ s/\/$//;
$OUTPUT_DIR =~ s/\/$//;
# Set list of objects to monitor from command line options
# options cna be used multiple time but also as a comma
# separated list of object name.
foreach (@dbs_opts) {
push(@INCLUDE_DB, split(/[,]+/, $_));
}
foreach (@dev_opts) {
push(@INCLUDE_DEV, split(/[,]+/, $_));
}
foreach (@tbs_opts) {
push(@INCLUDE_TB, split(/[,]+/, $_));
}
foreach (@net_opts) {
push(@INCLUDE_IFACE, split(/[,]+/, $_));
}
# Set default sysstat file to read (binary or text format)
if (!$DISABLE_SAR) {
if (!$SADC_INPUT_FILE && !$SAR_INPUT_FILE) {
if (-f "$INPUT_DIR/sadc_stats.dat") {
$SADC_INPUT_FILE = "$INPUT_DIR/" . 'sadc_stats.dat';
} elsif (-f "$INPUT_DIR/sar_stats.dat") {
$SAR_INPUT_FILE = "$INPUT_DIR/" . 'sar_stats.dat';
} elsif (-f "$INPUT_DIR/sar_stats.dat.gz") {
$SAR_INPUT_FILE = "$INPUT_DIR/" . 'sar_stats.dat.gz';
}
if (!$SADC_INPUT_FILE && !$SAR_INPUT_FILE) {
print STDERR "ERROR: No sar data file found. Consider using -S or --disable-sar command line option or use -i / -I option to set the path to the data file.\n";
&usage();
}
}
# Verify that the sar data file exists.
if ($SADC_INPUT_FILE && !-f "$SADC_INPUT_FILE") {
print STDERR "ERROR: sar binary data file $SADC_INPUT_FILE can't be found.\n";
exit 1;
}
if ($SAR_INPUT_FILE && !-f "$SAR_INPUT_FILE") {
print STDERR "ERROR: sar text data file $SAR_INPUT_FILE can't be found.\n";
exit 1;
}
}
if (!$INPUT_DIR || !-d $INPUT_DIR) {
if (!$SAR_INPUT_FILE && !$SADC_INPUT_FILE) {
print STDERR "ERROR: you must specify a valid input directory: $INPUT_DIR.\n";
&usage();
}
}
$OUTPUT_DIR = '.' if (!$OUTPUT_DIR);
# Check if the directory is empty
opendir(IDIR, "$OUTPUT_DIR") || die "FATAL: can't opendir $OUTPUT_DIR: $!";
my @files = grep { /\.html$/ } readdir(IDIR);
closedir(IDIR);
if ($#files >= 0) {
die "FATAL: output directory $OUTPUT_DIR is not empty.";
}
# Check start/end date time
if ($BEGIN) {
if ($BEGIN =~ /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/) {
$BEGIN = &timegm_nocheck($6, $5, $4, $3, $2 - 1, $1 - 1900) * 1000;
$o_day = $3;
$o_month = $2;
$o_year = $1;
} elsif ($BEGIN =~ /^(\d{4})-(\d{2})-(\d{2})$/) {
$BEGIN = &timegm_nocheck(0, 0, 0, $3, $2 - 1, $1 - 1900) * 1000;
$o_day = $3;
$o_month = $2;
$o_year = $1;
} else {
die "FATAL: bad format for begin datetime, should be yyyy-mm-dd hh:mm:ss\n";
}
}
if ($END) {
if ($END =~ /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/) {
$END = &timegm_nocheck($6, $5, $4, $3, $2 - 1, $1 - 1900) * 1000;
} elsif ($END =~ /^(\d{4})-(\d{2})-(\d{2})$/) {
$END = &timegm_nocheck(0, 0, 0, $3, $2 - 1, $1 - 1900) * 1000;
} else {
die "FATAL: bad format for ending datetime, should be yyyy-mm-dd hh:mm:ss\n";
}
}
# Look at system information
if (-e "$INPUT_DIR/sysinfo.txt") {
%sysinfo = &read_sysinfo("$INPUT_DIR/sysinfo.txt");
$sysinfo{RELEASE}{'name'} ||= 'unknown';
} elsif (-e "$INPUT_DIR/sysinfo.txt.gz") {
%sysinfo = &read_sysinfo("$INPUT_DIR/sysinfo.txt.gz");
$sysinfo{RELEASE}{'name'} ||= 'unknown';
}
# Extract the device list first
if (!$DISABLE_SAR) {
@DEVICE_LIST = &get_device_list();
@IFACE_LIST = &get_interface_list();
}
# Write resources files from __DATA__ section if they have not been already copied
&write_resources();
sub init_html_file
{
my $ofile = shift;
# Open a filehandle for each database
my $fhdb = new IO::File ">$ofile";
if (not defined $fhdb) {
die "FATAL: can't write to $ofile, $!\n";
}
&html_header($fhdb);
$fhdb->print("<ul id=\"slides\">\n");
$fhdb->close();
}
sub append_to_html_file
{
my $ofile = shift;
# If file doesn't exist create it
if (! -e $ofile) {
&init_html_file($ofile);
}
# Open a filehandle for each database
my $fhdb = new IO::File ">>$ofile";
if (not defined $fhdb) {
die "FATAL: can't write to $ofile, $!\n";
}
return $fhdb;
}
sub end_html_file
{
my $ofile = shift;
my $fhdb = new IO::File ">>$ofile";
if (not defined $fhdb) {
die "FATAL: can't write to $ofile, $!\n";
}
$fhdb->print("</ul>\n");
&html_footer($fhdb);
$fhdb->close;
}
# parse SQL stats files
if (-d "$INPUT_DIR") {
# Check if there is csv file in the input directory
print "DEBUG: looking for CSV file into directory $INPUT_DIR/\n" if ($DEBUG);
opendir(IDIR, "$INPUT_DIR") || die "FATAL: can't opendir $INPUT_DIR: $!";
my @files = grep { /\.csv(\.gz)?$/ } readdir(IDIR);
closedir(IDIR);
if ($#files < 0) {
die "FATAL: no csv file found in $INPUT_DIR";
}
# Detect interval from csv file
if (-e "$INPUT_DIR/pg_stat_database.csv" && !-z "$INPUT_DIR/pg_stat_database.csv") {
$INTERVAL = &detect_interval("$INPUT_DIR/pg_stat_database.csv");
} elsif (-e "$INPUT_DIR/pg_stat_database.csv.gz" ) {
$INTERVAL = &detect_interval("$INPUT_DIR/pg_stat_database.csv.gz");
}
print "DEBUG: autodetected interval value $INTERVAL\n" if ($DEBUG);
# Loop over CSV files and graphics definition to generate reports
foreach my $k (sort {$a cmp $b} keys %DB_GRAPH_INFOS) {
if (-e "$INPUT_DIR/$k" && !-z "$INPUT_DIR/$k") {
if (-e "$INPUT_DIR/$k" && !-z "$INPUT_DIR/$k") {
&compute_dbstat_graph($k, %{$DB_GRAPH_INFOS{$k}});
}
} elsif (-e "$INPUT_DIR/$k.gz" && !-z "$INPUT_DIR/$k.gz") {
if (-e "$INPUT_DIR/$k.gz" && !-z "$INPUT_DIR/$k.gz") {
&compute_dbstat_graph("$k.gz", %{$DB_GRAPH_INFOS{$k}});
}
} elsif ($k =~ /_all_/) {
my $f = $k;
$f =~ s/_all_/_user_/;
if (-e "$INPUT_DIR/$f" && !-z "$INPUT_DIR/$f") {
&compute_dbstat_graph($f, %{$DB_GRAPH_INFOS{$k}});
} elsif (-e "$INPUT_DIR/$f.gz" && !-z "$INPUT_DIR/$f.gz") {
&compute_dbstat_graph("$f.gz", %{$DB_GRAPH_INFOS{$k}});
}
}
}
# Add database general information
if ( (-e "$INPUT_DIR/sysinfo.txt") || (-e "$INPUT_DIR/sysinfo.txt.gz") ) {
foreach my $db (keys %{$OVERALL_STATS{'database'}}) {
&write_database_info($db);
}
}
# Terminate each database and pgbouncer html file with the footer
opendir(ODIR, "$OUTPUT_DIR") || die "FATAL: can't opendir $OUTPUT_DIR: $!";
@files = grep { /\.html$/ } readdir(ODIR);
closedir(ODIR);
foreach my $f (@files) {
&end_html_file("$OUTPUT_DIR/$f");
}
} elsif (!$SAR_INPUT_FILE) {
print "FATAL: $INPUT_DIR is not a valid data directory\n";
exit 1;
}
# parse SAR stats file
if (!$DISABLE_SAR) {
# Open filehandle
$FH = new IO::File ">$OUTPUT_DIR/system.html";
if (not defined $FH) {
die "FATAL: can't write to $OUTPUT_DIR/system.html, $!\n";
}
&html_header($FH);
print $FH "<ul id=\"slides\">\n";
for (my $i = 0; $i <= $#DEVICE_LIST; $i++) {
# Open a filehandle for each database
$DEVFH{$DEVICE_LIST[$i]} = new IO::File ">$OUTPUT_DIR/system-device$i.html";
if (not defined $DEVFH{$DEVICE_LIST[$i]}) {
die "FATAL: can't write to $OUTPUT_DIR/system-device$i.html, $!\n";
}
&html_header($DEVFH{$DEVICE_LIST[$i]});
$DEVFH{$DEVICE_LIST[$i]}->print("<ul id=\"slides\">\n");
}
for (my $i = 0; $i <= $#IFACE_LIST; $i++) {
# Open a filehandle for each database
$DEVFH{$IFACE_LIST[$i]} = new IO::File ">$OUTPUT_DIR/network-device$i.html";
if (not defined $DEVFH{$IFACE_LIST[$i]}) {
die "FATAL: can't write to $OUTPUT_DIR/network-device$i.html, $!\n";
}
&html_header($DEVFH{$IFACE_LIST[$i]});
$DEVFH{$IFACE_LIST[$i]}->print("<ul id=\"slides\">\n");
}
if (-f "$SADC_INPUT_FILE") {
print "DEBUG: looking for sadc binary data file $SADC_INPUT_FILE\n" if ($DEBUG);
foreach my $id (sort keys %SAR_GRAPH_INFOS) {
&compute_sarstat_graph($SADC_INPUT_FILE, %{$SAR_GRAPH_INFOS{$id}});
}
} elsif (-f "$SAR_INPUT_FILE") {
print "DEBUG: looking for sar text data file $SADC_INPUT_FILE\n" if ($DEBUG);
foreach my $id (sort keys %SAR_GRAPH_INFOS) {
&compute_sarfile_graph($SAR_INPUT_FILE, %{$SAR_GRAPH_INFOS{$id}});
}
} else {
print "WARNING: No sar data file not found. Consider using -S or --disable-sar command line option if you don't have a sysstat data file.\n";
}
print $FH "</ul>\n";