#!/usr/bin/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-2024 Gilles Darold - All rights reserved. #------------------------------------------------------------------------------ use vars qw($VERSION $PROGRAM); use strict qw(vars); use warnings; no warnings 'redundant'; use CGI; use IO::File; use Getopt::Long qw(:config bundling no_ignore_case_always); use File::Basename; use Time::Local qw/timegm_nocheck timelocal_nocheck/; use POSIX qw(locale_h sys_wait_h ceil strftime); setlocale(LC_ALL, 'C'); use Storable qw(store_fd fd_retrieve); $VERSION = '4.0'; $PROGRAM = 'pgCluu'; my $CONFIG_FILE = "/usr/local/etc/pgcluu.conf"; my $SADF_PROG = '/usr/bin/sadf'; my $DISABLE_SAR = 0; my $HTML = ''; my @INCLUDE_DB = (); my @INCLUDE_TB = (); my @INCLUDE_DEV = (); my @INCLUDE_IFACE = (); my $IMG_FORMAT = 'png'; my %DEVFH = (); my $IDX = 1; my $HELP = 0; my $SHOW_VER = 0; my $DEBUG = 0; my $NUMBER_CPU = 0; my $TIMEZONE = '00'; #substr(strftime('%z', localtime()), 0, 3); my $STATS_TIMEZONE = '00'; # Timezone is auto detected from data files my $REVERT_DATE = 0; my $FROM_SA_FILE = 0; my $SADC_INPUT_FILE = ''; my $SAR_INPUT_FILE = ''; my $PIDSTAT_INPUT_FILE = ''; my @DEVICE_LIST = (); my @IFACE_LIST = (); my @GRAPH_COLORS = ('#6e9dc9', '#f4ab3a', '#ac7fa8', '#8dbd0f','#958c12'); my $ZCAT_PROG = '/bin/zcat'; my $CACHE = 0; my $MAX_INDEXES = 5; my @DATABASE_LIST = (); my @DEVICE_SPACE_LIST = (); my %fullpidstatdata = (); # Hash to store full content of pidstat file per type my $MAX_RENDERED_DAYS = 7; my $SAR_UPPER_11_5_6 = 0; my %RELKIND = ( 'r' => 'tables', 'i' => 'indexes', 'S' => 'sequences', 'v' => 'views', 'c' => 'composite types', 't' => 'toast tables' ); my $TOP_STAT = 10; # Global variables that need to be saved in incremental mode our %OVERALL_STATS = (); our %global_infos = (); our @global_databases = (); our @global_tbspnames = (); our %all_stat_database = (); our %all_stat_database_conflicts = (); our %all_database_size = (); our %all_tablespace_size = (); our %all_vacuum_stat = (); our %all_stat_user_tables = (); our %all_stat_user_indexes = (); our %all_stat_invalid_indexes = (); our %all_stat_hash_indexes = (); our %all_statio_user_tables = (); our %all_relation_buffercache = (); our %all_statio_user_indexes = (); our %all_xlog_stat = (); our %all_stat_bgwriter = (); our %all_stat_connections = (); our %all_stat_user_functions = (); our %all_stat_replication = (); our %all_pgbouncer_stats = (); our %all_pgbouncer_ini = (); our %all_pgbouncer_req_stats = (); our %all_class_size = (); our %all_stat_locks = (); our %all_stat_unused_indexes = (); our %all_stat_redundant_indexes = (); our %all_stat_extended_statistics = (); our %all_stat_count_indexes = (); our %all_stat_missing_fkindexes = (); our %all_postgresql_conf = (); our %all_recovery_conf = (); our %all_postgresql_auto_conf = (); our %all_pg_hba_conf = (); our %all_pg_ident_conf = (); our %all_settings = (); our %all_nondefault_settings = (); our %all_db_role_setting = (); our %all_database_buffercache = (); our %all_database_usagecount = (); our %all_database_isdirty = (); our %all_stat_archiver = (); our %all_stat_statements = (); our %all_stat_unlogged = (); our %all_postgresql_conf_diff = (); our %all_recovery_conf_diff = (); our %all_postgresql_auto_conf_diff = (); our %all_pg_hba_conf_diff = (); our %all_pg_ident_conf_diff = (); our %all_settings_diff = (); our %all_db_role_setting_diff = (); our %all_pgbouncer_ini_diff = (); # Names of the variables that need to be saved as binary file our @pg_to_be_stored = ( 'global_infos', 'global_databases', 'global_tbspnames', 'all_stat_database', 'all_stat_database_conflicts', 'all_database_size', 'all_tablespace_size', 'all_vacuum_stat', 'all_stat_user_tables', 'all_stat_user_indexes', 'all_stat_invalid_indexes', 'all_stat_hash_indexes', 'all_statio_user_tables', 'all_relation_buffercache', 'all_statio_user_indexes', 'all_xlog_stat', 'all_stat_bgwriter', 'all_stat_connections', 'all_stat_user_functions', 'all_stat_replication', 'all_pgbouncer_stats', 'all_pgbouncer_ini', 'all_pgbouncer_req_stats', 'all_class_size', 'all_stat_locks', 'all_stat_unused_indexes', 'all_stat_redundant_indexes', 'all_stat_extended_statistics', 'all_stat_count_indexes', 'all_stat_missing_fkindexes', 'all_postgresql_conf', 'all_recovery_conf', 'all_postgresql_auto_conf', 'all_pg_hba_conf', 'all_pg_ident_conf', 'all_settings', 'all_nondefault_settings', 'all_db_role_setting', 'all_database_buffercache', 'all_database_usagecount', 'all_database_isdirty', 'all_stat_archiver', 'all_stat_statements', 'all_stat_unlogged', 'all_pgbouncer_ini_diff', 'all_db_role_setting_diff', 'all_postgresql_conf_diff', 'all_recovery_conf_diff', 'all_postgresql_auto_conf_diff', 'all_pg_hba_conf_diff', 'all_pg_ident_conf_diff', 'all_settings_diff', ); # Names of sar variables that need to be saved as binary file our %sar_cpu_stat = (); our %sar_load_stat = (); our %sar_process_stat = (); our %sar_context_stat = (); our %sar_memory_stat = (); our %sar_dirty_stat = (); our %sar_swap_stat = (); our %sar_pageswap_stat = (); our %sar_block_stat = (); our %sar_srvtime_stat = (); our %sar_rw_devices_stat = (); our %sar_util_devices_stat = (); our %sar_networks_stat = (); our %sar_neterror_stat = (); our %sar_space_devices_stat = (); our %sar_commit_memory_stat = (); our @sar_to_be_stored = ( 'global_infos', 'sar_cpu_stat', 'sar_load_stat', 'sar_process_stat', 'sar_context_stat', 'sar_memory_stat', 'sar_dirty_stat', 'sar_swap_stat', 'sar_pageswap_stat', 'sar_block_stat', 'sar_srvtime_stat', 'sar_rw_devices_stat', 'sar_util_devices_stat', 'sar_networks_stat', 'sar_neterror_stat', 'sar_space_devices_stat', 'sar_commit_memory_stat' ); # Names of pidstat variables that need to be saved as binary file our %pidstat_cpu_stat = (); our %pidstat_context_stat = (); our %pidstat_memory_stat = (); our %pidstat_io_stat = (); our @pidstat_to_be_stored = ( 'pidstat_cpu_stat', 'pidstat_context_stat', 'pidstat_memory_stat', 'pidstat_io_stat' ); # Relation between sar binary file and CGI action parameter. # This is used to only load the binary file related to a report. our %bin_action_map = ( 'system-cpu' => 'sar_cpu_stat', 'system-memory' => 'sar_memory_stat', 'system-dirty' => 'sar_dirty_stat', 'system-swap' => 'sar_swap_stat', 'system-commit_memory' => 'sar_commit_memory_stat', 'system-load' => 'sar_load_stat', 'system-process' => 'sar_process_stat', 'system-runqueue' => 'sar_process_stat', 'system-cswch' => 'sar_context_stat', 'system-pcrea' => 'sar_context_stat', 'system-block' => 'sar_block_stat', 'system-tps' => 'sar_block_stat', 'system-page' => 'sar_pageswap_stat', 'system-fault' => 'sar_pageswap_stat', 'system-scanpage' => 'sar_pageswap_stat', 'system-cpudevice' => 'sar_util_devices_stat', 'system-rwdevice' => 'sar_rw_devices_stat', 'system-tpsdevice' => 'sar_rw_devices_stat', 'system-srvtime' => 'sar_srvtime_stat', 'system-space' => 'sar_space_devices_stat', 'network-utilization' => 'sar_networks_stat', 'network-error' => 'sar_networks_stat', ); our %pg_action_map = ( 'cluster-backends' => 'all_stat_database', 'database-backends' => 'all_stat_database', 'cluster-deadlocks' => 'all_stat_database', 'database-deadlocks' => 'all_stat_database', 'cluster-cache_ratio' => 'all_stat_database', 'database-cache_ratio' => 'all_stat_database', 'cluster-temporary_files' => 'all_stat_database', 'cluster-temporary_bytes' => 'all_stat_database', 'database-temporary_files' => 'all_stat_database', 'database-temporary_bytes' => 'all_stat_database', 'cluster-read_ratio' => 'all_stat_database', 'database-read_ratio' => 'all_stat_database', 'cluster-write_ratio' => 'all_stat_database', 'database-write_ratio' => 'all_stat_database', 'cluster-read_write_query' => 'all_stat_database', 'database-read_write_query' => 'all_stat_database', 'cluster-commits_rollbacks' => 'all_stat_database', 'database-commits_rollbacks' => 'all_stat_database', 'cluster-transactions' => 'all_stat_database', 'database-transactions' => 'all_stat_database', 'cluster-canceled_queries' => 'all_stat_database', 'database-canceled_queries' => 'all_stat_database', 'cluster-connections' => 'all_stat_connections', 'database-connections' => 'all_stat_connections', 'cluster-conflicts' => 'all_stat_database_conflicts', 'database-conflicts' => 'all_stat_database_conflicts', 'cluster-size' => 'all_database_size', 'database-size' => 'all_database_size', 'tablespace-size' => 'all_tablespace_size', 'cluster-buffersused' => 'all_database_buffercache', 'cluster-databaseloaded' => 'all_database_buffercache', 'cluster-usagecount' => 'all_database_usagecount', 'cluster-isdirty' => 'all_database_isdirty', 'cluster-bgwriter_write' => 'all_stat_bgwriter', 'cluster-bgwriter_read' => 'all_stat_bgwriter', 'cluster-bgwriter_count' => 'all_stat_bgwriter', 'cluster-checkpoints' => 'all_stat_bgwriter', 'cluster-checkpoints_time' => 'all_stat_bgwriter', 'cluster-xlog_files' => 'all_xlog_stat', 'cluster-xlog' => 'all_stat_replication', 'cluster-archive' => 'all_stat_archiver', 'cluster-replication' => 'all_stat_replication', 'buffercache-relation' => 'all_relation_buffercache', 'statio-buffercache' => 'all_relation_buffercache', 'table-vacuums-analyzes' => 'all_vacuum_stat', 'table-indexes' => 'all_stat_user_tables', 'table-vacuums-analyzes' => 'all_stat_user_tables', 'table-query-tuples' => 'all_stat_user_tables', 'table-kind-tuples' => 'all_stat_user_tables', 'table-size' => 'all_class_size', 'index-size' => 'all_class_size', 'table-unlogged' => 'all_stat_unlogged', 'table-extended' => 'all_stat_extended_statistics', 'statio-table' => 'all_statio_user_tables', 'index-scan' => 'all_stat_user_indexes', 'index-invalid' => 'all_stat_invalid_indexes', 'index-hash' => 'all_stat_hash_indexes', 'statio-index' => 'all_statio_user_indexes', 'database-function' => 'all_stat_user_functions', 'pgbouncer-connections' => 'all_pgbouncer_stats', 'pgbouncer-duration' => 'all_pgbouncer_req_stats', 'pgbouncer-number' => 'all_pgbouncer_req_stats', 'pgbouncer-wait-total' => 'all_pgbouncer_req_stats', 'pgbouncer-wait-average' => 'all_pgbouncer_req_stats', 'database-lock-types' => 'all_stat_locks', 'database-lock-modes' => 'all_stat_locks', 'database-lock-granted' => 'all_stat_locks', 'unused-index' => 'all_stat_unused_indexes', 'redundant-index' => 'all_stat_redundant_indexes', 'missing-index' => 'all_stat_missing_fkindexes', 'count-index' => 'all_stat_count_indexes', 'cluster-pgconf' => 'all_postgresql_conf', 'cluster-recoveryconf' => 'all_recovery_conf', 'cluster-alterconf' => 'all_postgresql_auto_conf', 'cluster-pghba' => 'all_pg_hba_conf', 'cluster-pgident' => 'all_pg_ident_conf', 'cluster-settings' => 'all_settings', 'cluster-nondefault-settings' => 'all_nondefault_settings', 'cluster-dbrolesetting' => 'all_db_role_setting', 'cluster-pgbouncer' => 'all_pgbouncer_ini', 'database-queries' => 'all_stat_statements', ); our %sysinfo = (); # Hash used to store system information # Store default timestamp my ($o_sec, $o_min, $o_hour, $o_day, $o_month, $o_year) = (0,0,0,0,0,0); my ($e_sec, $e_min, $e_hour, $e_day, $e_month, $e_year) = (0,0,0,0,0,0); # 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 = ''; my $pidstat_year = ''; my $pidstat_month = ''; my $pidstat_day = ''; # Charset used in the html output my $charset = 'utf-8'; # List of reports that do not generate graphs and then # where stats are only read from the last stats dir. my @NOGRAPH_LIST = ( 'home', 'sysinfo', 'database-info', 'table-indexes', 'table-vacuums-analyzes', 'table-quey-tuples', 'table-kind-tuples', 'table-size', 'table-unlogged', 'statio-table', 'index-scan', 'index-size', 'index-invalid', 'index-hash', 'statio-index', 'unused-index', 'redundant-index', 'missing-index', 'count-index', 'database-functions', 'buffercache-relation' ); # Statistics files to use with report my %DB_GRAPH_INFOS = ( 'pg_stat_database.csv' => { '0' => { 'name' => 'cluster-backends', 'title' => 'Global connections', 'description' => 'Global number of clients connected.', 'ylabel' => 'Connections', 'legends' => ['backends'], }, '1' => { 'name' => 'database-backends', 'title' => 'Connections on %s database', 'description' => 'Number of clients connected to a database.', 'ylabel' => 'Connections', 'legends' => ['backends'], }, '2' => { 'name' => 'cluster-read_write_query', 'title' => 'Global affected tuples per operation', 'ylabel' => 'Tuples', 'description' => 'Global affected rows grouped by statement family.', }, '3' => { 'name' => 'database-read_write_query', 'title' => 'Affected tuples per operation on %s database', 'ylabel' => 'Tuples', 'description' => 'Affected rows on databases grouped by statement family.', }, '4' => { 'name' => 'cluster-cache_ratio', 'title' => 'Global cache hit/miss ratio', 'description' => 'Global cache hit/miss ratio.', 'ylabel' => 'Blocks per second', 'legends' => ['Cache hit','Cache miss','hit/miss ratio'], 'y2label' => 'Percentage', }, '5' => { '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', }, '6' => { 'name' => 'cluster-commits_rollbacks', 'title' => 'Global Commits/Rollbacks per second', 'description' => 'Global number of commits / rollbacks per second and number of backends.', 'ylabel' => 'Transaction/sec', 'legends' => ['commit','rollback','backends'], 'y2label' => 'Number of backend', }, '7' => { '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', }, '8' => { 'name' => 'cluster-write_ratio', 'title' => 'Global Write ratio', 'description' => 'Global write ratio, excluding templates and postgres databases.', 'ylabel' => 'Write queries per second', 'legends' => ['Insert','Update','Delete'], }, '9' => { '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'], }, '10' => { 'name' => 'cluster-read_ratio', 'title' => 'Global read tuples', '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)'], }, '11' => { '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)'], }, '12' => { 'name' => 'cluster-deadlocks', 'title' => 'Global number of deadlocks', 'description' => 'Global number of deadlocks detected.', 'ylabel' => 'Number of deadlocks', 'legends' => ['deadlocks'], }, '13' => { 'name' => 'database-deadlocks', 'title' => 'Number of deadlocks on %s database', 'description' => 'Number of deadlocks detected in this database.', 'ylabel' => 'Number of deadlocks', 'legends' => ['deadlocks'], }, '14' => { 'name' => 'cluster-canceled_queries', 'title' => 'Global number of canceled queries', 'description' => 'Global number of queries canceled due to conflicts with recovery. [Conflicts occur only on standby servers]', 'ylabel' => 'Number of queries canceled', 'legends' => ['conflicts'], }, '15' => { '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'], }, '16' => { 'name' => 'cluster-temporary_files', 'title' => 'Global number of temporary files', 'description' => 'Global number of temporary files created by queries.', 'ylabel' => 'Number of files', 'legends' => ['temporary files'], }, '17' => { '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'], }, '18' => { 'name' => 'cluster-temporary_bytes', 'title' => 'Global size of temporary data', 'description' => 'Global amount of data per second written to temporary files created by queries.', 'ylabel' => 'Size per seconde', 'legends' => ['temporary data'], }, '19' => { 'name' => 'database-temporary_bytes', 'title' => 'Size of temporary data on %s database', 'description' => 'Amount of data per seconde written to temporary files created by queries per database.', 'ylabel' => 'Size per seconde', 'legends' => ['temporary data'], }, '20' => { 'name' => 'cluster-transactions', 'title' => 'Transaction throughput per second', 'description' => 'Number of transaction (commit+rollback) issued per second.', 'ylabel' => 'Transaction/sec', 'legends' => ['tps'], }, '21' => { 'name' => 'database-transactions', 'title' => 'Transactions per second on %s database', 'description' => 'Number of transaction (commit+rollback) issued per second.', 'ylabel' => 'Transaction/sec', 'legends' => ['tps'], }, }, 'pg_stat_database_conflicts.csv' => { '0' => { 'name' => 'cluster-conflicts', 'title' => 'Conflicts per type on all database', 'description' => 'Statistics about query cancels occurring due to conflicts with recovery on standby servers.', 'ylabel' => 'Number of conflict', 'legends' => [ 'tablespace', 'lock', 'snapshot', 'bufferpin', 'deadlock' ], }, '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.', 'ylabel' => 'Number of conflict', 'legends' => [ 'tablespace', 'lock', 'snapshot', 'bufferpin', 'deadlock' ], }, }, 'pg_database_size.csv' => { '1' => { 'name' => 'cluster-size', 'title' => 'Size of %s database', 'description' => 'Database sizes.', 'ylabel' => 'Size', 'legends' => ['size'], 'active' => 1, }, '2' => { '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 size and location.', 'ylabel' => 'Size', 'legends' => ['size'], }, }, 'pg_stat_bgwriter.csv' => { '1' => { 'name' => 'cluster-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. Comparing checkpoints timed and requested shows whether you’ve set checkpoint segments usefully.', 'ylabel' => 'Number of checkpoints', 'legends' => ['checkpoints timed','checkpoints requests'], }, '2' => { 'name' => 'cluster-bgwriter_write', 'title' => 'background writer clean stats', 'description' => 'Background writer cache cleaning statistics by checkpoints, lru and backends. Buffers checkpoint are written during checkpoint calls, buffers backend represent client backend that had to write to satisfy an allocation and buffers clean represent background writer cleaning a dirty buffer expected by an allocation.', 'ylabel' => 'Size per second', 'legends' => ['checkpoint','clean','backend'], }, '3' => { 'name' => 'cluster-bgwriter_read', 'title' => 'background writer allocated buffers', 'description' => 'Background total allocated bytes per second. Buffers allocated is the total number of allocated new buffers whether or not it was already cached.', 'ylabel' => 'Size per second', 'legends' => ['allocated'], }, '4' => { 'name' => 'cluster-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'], }, '5' => { 'name' => 'cluster-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' => { '0' => { 'name' => 'cluster-connections', 'title' => 'Connections by type on all database', 'description' => 'Connections by type including idle ones.', 'ylabel' => 'Number of connections', 'legends' => ['Active','Idle','Idle in xact', 'Waiting for a lock'], }, '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_user_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_user_tables.csv' => { '1' => { 'name' => 'statio-table', 'title' => 'Statistics about I/O on %s', 'description' => 'Number of disk blocks read from table or all indexes on this table versus number of buffer hits at end of the audit period.', '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_user_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_user_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 at end of the audit period.', '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. Before removing them, check that the redundant index is not a primary key or an index on a column referencing a foreign key.', 'ylabel' => 'Number', 'legends' => ['Redundant index'], 'active' => 1, 'menu' => 'Redundant indexes', }, }, 'pg_stat_count_indexes.csv' => { '1' => { 'name' => 'zero-index', 'title' => 'Tables without indexes on %s', 'description' => 'List of tables without indexes.', 'ylabel' => 'Number', 'legends' => ['No indexes'], 'active' => 1, 'menu' => 'Tables without index', }, '2' => { 'name' => 'count-index', 'title' => 'Tables with lot of indexes on %s', 'description' => 'List of tables with lot of indexes.', 'ylabel' => 'Number', 'legends' => ['Indexes count'], 'active' => 1, 'menu' => "Table with more than $MAX_INDEXES 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' => 'cluster-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' => 'cluster-xlog', 'title' => 'Xlog written', 'description' => 'Number of xlog data written per second.', 'ylabel' => 'Size per second', 'legends' => ['written'], }, '2' => { 'name' => 'cluster-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 pool %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' => 'Duration', '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'], }, '3' => { 'name' => 'pgbouncer-wait-total', 'title' => 'pgbouncer wait time on %s', 'description' => 'Time spent by clients waiting for a server in microseconds.', 'ylabel' => 'Microseconds', 'legends' => ['total_wait_time'], }, '4' => { 'name' => 'pgbouncer-wait-average', 'title' => 'Average of wait time spent on %s', 'description' => 'Average of time spent by clients waiting for a server in microseconds (average per second).', 'ylabel' => 'Number', 'legends' => ['avg_wait_time'], }, }, '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_nondefault_settings.csv' => { '1' => { 'name' => 'cluster-nondefault-settings', 'title' => 'PostgreSQL Non Default Settings', 'description' => 'Non default configuration directives and values defined in pg_settings.', 'ylabel' => 'Number', 'legends' => ['Settings'], 'active' => 1, 'menu' => 'PostgreSQL non default 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', } }, 'pg_stat_invalid_indexes.csv' => { '1' => { 'name' => 'index-invalid', 'title' => 'Invalid indexes on %s', 'description' => 'List of invalid indexes during concurrency build.', 'ylabel' => 'Number', 'legends' => ['Invalid index'], 'active' => 1, 'menu' => 'Invalid Indexes', }, }, 'pg_stat_hash_indexes.csv' => { '1' => { 'name' => 'index-hash', 'title' => 'Hash indexes on %s', 'description' => 'List of hash indexes during concurrency build.', 'ylabel' => 'Number', 'legends' => ['Hash index'], 'active' => 1, 'menu' => 'Hash Indexes', }, }, 'pg_stat_unlogged.csv' => { '1' => { 'name' => 'table-unlogged', 'title' => 'Unlogged tables on %s', 'description' => 'List of unlogged tables in the database.', 'ylabel' => 'Number', 'legends' => ['Unlogged tables'], 'active' => 1, 'menu' => 'Unlogged tables', }, }, 'pg_stat_ext.csv' => { '1' => { 'name' => 'table-extended', 'title' => 'Extended statistics defined on %s', 'description' => 'List of extended planner statistics created in the database.', 'ylabel' => 'Number', 'legends' => ['Extended stats'], 'active' => 1, 'menu' => 'Extended statistics', }, }, ); my %SAR_GRAPH_INFOS = ( '1' => { 'name' => 'system-cpu', 'title' => 'CPU %s utilization', 'all_title' => 'Global CPU 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. The Idle stat shows the percentage of time that the CPUs were idle and the system did not have an outstanding disk I/O request.', 'all_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. The Idle stat shows the percentage of time that the CPUs were idle and the system did not have an outstanding disk I/O request.', 'ylabel' => 'Percentage', 'legends' => ['Total','System','User','Idle','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-rwdevice', '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 wait/service time for I/O requests on device %s', 'description' => 'Await is the average time (in milliseconds) for I/O requests issued to the device to be served. This includes the time spent by the requests in queue and the time spent servicing them. Srvtime is the average service time (in milliseconds) for I/O requests that were issued to the device.', 'ylabel' => 'Milliseconds', 'y2label' => 'Milliseconds', 'legends' => ['await','svctm'], }, '10' => { 'name' => 'system-runqueue', 'title' => 'Run queue length', 'description' => 'Number of tasks waiting for run time and number of tasks currently blocked, waiting for I/O to complete (sysstat >= 9.1.7).', 'ylabel' => 'Run queue length', 'legends' => ['runq-sz', 'blocked'], }, '11' => { 'name' => 'system-page', 'title' => 'System cache statistics', 'description' => 'Total number of kilobytes the system paged in/out from/to disk per second.', 'ylabel' => 'Size paged', 'legends' => [ 'pgpgin/s', 'pgpgout/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' ], }, '14' => { 'name' => 'system-cswch', 'title' => 'Context switches', 'description' => 'Total number of context switches per second.', 'ylabel' => 'Context switches', 'legends' => ['cswch/s'], }, '15' => { 'name' => 'system-pcrea', 'title' => 'Tasks created', 'description' => 'Total number of tasks created per second.', 'ylabel' => 'Tasks', 'legends' => ['proc/s'], }, '16' => { 'name' => 'system-tps', 'title' => 'Total number of transfers per second', 'description' => 'Total number of transfers per second that were issued to physical devices. A transfer is an I/O request to a physical device. Multiple logical requests can be combined into a single I/O request to the device. A transfer is of indeterminate size.', 'ylabel' => 'Transfers per second', 'legends' => ['tps','rtps','wtps'], }, '17' => { 'name' => 'system-tpsdevice', 'title' => 'Transfert per second on device %s', 'description' => 'Number of transfers per second that were issued to the device, multiple logical requests can be combined into a single I/O request to the device (a transfer is of indeterminate size).', 'ylabel' => 'Number of transfers per second', 'legends' => ['Tps'], }, '18' => { 'name' => 'system-dirty', 'title' => 'Dirty memory to be written', 'description' => 'Amount of memory in kilobytes waiting to get written back to the disk with amount of active and inactive memory (sysstat >= 10.1.2).', 'ylabel' => 'Memory size', 'legends' => ['active','inactive','dirty'], }, '19' => { 'name' => 'system-space', 'title' => 'Disk space utilization on device %s', 'description' => 'Percentage of disk space and inode used on the device. Close to 100% mean no more space or inode left.', 'ylabel' => 'Percentage used', 'legends' => ['Space', 'Inode'], }, '20' => { 'name' => 'system-fault', 'title' => 'System page fault statistics', 'description' => 'Total number of major and minor faults the system has made per second. Major are those which have required loading a memory page from disk and minor from cache. Dataset "minflt/s" is calculated as result of "fault/s - majflt/s".', 'ylabel' => 'Number of faults', 'legends' => [ 'majflt/s', 'minflt/s' ], }, '21' => { 'name' => 'system-scanpage', 'title' => 'System page scanned statistics', 'description' => 'Total number of pages scanned by the kswapd daemon and number of pages scanned directly per second. Number of pages the system has reclaimed from cache (pagecache and swapcache) per second to satisfy its memory demands. "%vmeff" is the efficiency of page reclaim. If it is near 100% then almost every page coming off the tail of the inactive list is being reaped. If it gets too low (e.g. less than 30%) then the virtual memory is having some difficulty.', 'ylabel' => 'Number of pages', 'y2label' => 'Percents', 'legends' => [ 'pgscank/s', 'pgscand/s', 'pgsteal/s', '%vmeff' ], }, '22' => { 'name' => 'system-commit_memory', 'title' => 'Estimated memory to complete the workload', 'description' => 'CommitLimit is the total amount of memory currently available to be allocated on the system based on the overcommit ratio (vm.overcommit_ratio). This limit is only adhered to if strict overcommit accounting is enabled (vm.overcommit_memory = 2). CommitLimit is calculated with the following formula: (MemTotal - Hugetlb) * overcommit_ratio / 100. Committed_AS is the total amount of memory estimated to complete the workload. This value represents the worst case scenario value, and also includes swap memory.', 'ylabel' => 'Size', 'legends' => ['CommitLimit', 'Committed_AS'], }, ); my %PIDSTAT_GRAPH_INFOS = ( '1' => { 'name' => 'postgres-cpu', 'title' => 'PostgreSQL CPU %s utilization', 'all_title' => 'Global CPU utilization', 'description' => 'Percentage of CPU used by PostgreSQL while executing at the user level (application), with or without nice priority. Note that this field does NOT include time spent running a virtual processor.', 'all_description' => 'Percentage of CPU used by PostgreSQL while executing at the user level (application), with or without nice priority. Note that this field does NOT include time spent running a virtual processor.', 'ylabel' => 'Percentage', 'legends' => ['Total','System','User','Wait'], 'active' => 1, }, '2' => { 'name' => 'postgres-memory', 'title' => 'PostgreSQL memory utilization', 'description' => 'Report memory utilization. Virtual Size (VSZ): The virtual memory usage of entire task in kilobytes. Resident Set Size (RSS): The non-swapped physical memory used by the task in kilobytes.', 'ylabel' => 'Memory size', 'legends' => ['VSZ','RSS'], }, '3' => { 'name' => 'postgres-mempercent', 'title' => 'PostgreSQL percentage memory use', 'description' => 'Report percentage of memory use. The tasks\'s currently used share of available physical memory.', 'ylabel' => 'Percent of Memory', 'legends' => ['%MEM'], }, '4' => { 'name' => 'postgres-io', 'title' => 'PostgreSQL I/O statistics', 'description' => 'Number of kilobytes PostgreSQL has caused to be read/written from/to disk per second. Number of kilobytes whose writing to disk has been cancelled by the task. This may occur when the task truncates some dirty pagecache. In this case, some IO which another task has been accounted for will not be happening.', 'ylabel' => 'Kb per second', 'legends' => ['kB_rd/s','kB_wr/s','kB_ccwr/s'], }, '5' => { 'name' => 'postgres-iodelay', 'title' => 'PostgreSQL I/O delay', 'description' => 'Block I/O delay of the task being monitored, measured in clock ticks. This metric includes the delays spent waiting for sync block I/O completion and for swapin block I/O completion.', 'ylabel' => 'Block I/O delay', 'legends' => ['iodelay'], }, '6' => { 'name' => 'postgres-fault', 'title' => 'Page faults statistics', 'description' => 'Total number of minor/major faults the task has made per second, those which have not required loading a memory page from disk..', 'ylabel' => 'Number of faults', 'legends' => [ 'minflt/s', 'majflt/s' ], }, '7' => { 'name' => 'postgres-cswch', 'title' => 'PostgreSQL switching activity', 'description' => 'Total number of voluntary/non voluntary context switches the task made per second. A voluntary context switch occurs when a task blocks because it requires a resource that is unavailable. A involuntary context switch takes place when a task executes for the duration of its time slice and then is forced to relinquish the processor.', 'ylabel' => 'Context switches', 'legends' => ['cswch/s', 'nvcswch/s'], }, ); # Set CGI handle and retrieve current params states my $cgi = new CGI; my $SCRIPT_NAME = $cgi->url() || ''; my $ACTION = $cgi->param('action') || 'home'; my $DATABASE = $cgi->param('db') || ''; my $DEVICE = $cgi->param('dev') || ''; my $BEGIN = $cgi->param('start') || ''; my $END = $cgi->param('end') || ''; my $REAL_ACTION = $ACTION || ''; my $ID_ACTION = -1; my $src_base = ''; my $INPUT_DIR = ''; my $RSC_BASE = '.'; sub read_conf { print STDERR "DEBUG: Reading configuration file $CONFIG_FILE\n" if ($DEBUG); unless(open(IN, $CONFIG_FILE)) { die "ERROR: can not read configuration file $CONFIG_FILE, $!\n"; } while (my $l = ) { chomp($l); $l =~ s/\r//gs; next if (!$l); my ($var, @vals) = split(/[\s]+/, $l); if ($var eq 'INPUT_DIR') { if (-d $vals[0]) { $INPUT_DIR = $vals[0]; } else { die "ERROR: can not find input directory, $vals[0]\n"; } } elsif ($var eq 'RSC_BASE') { $RSC_BASE = $vals[0]; } elsif ($var eq 'INCLUDE_DB') { push(@INCLUDE_DB, @vals); } elsif ($var eq 'INCLUDE_TB') { push(@INCLUDE_TB, @vals); } elsif ($var eq 'INCLUDE_IFACE') { push(@INCLUDE_IFACE, @vals); } elsif ($var eq 'REVERT_DATE') { $REVERT_DATE = $vals[0]; } elsif ($var eq 'MAX_RENDERED_DAYS') { $MAX_RENDERED_DAYS = int($vals[0]); } } # Defined the default backward level where ressources files are stored $RSC_BASE ||= '.'; # Check start/end date time if ($BEGIN) { if ($BEGIN =~ /^(\d{4})-(\d+)-(\d+) (\d+):(\d+)/) { $BEGIN = &timegm_nocheck(0, $5, $4, $3, $2 - 1, $1 - 1900) * 1000; $o_day = sprintf("%02d", $3); $o_month = sprintf("%02d", $2); $o_year = $1; $o_hour = sprintf("%02d", $4); $o_min = sprintf("%02d", $5); $o_sec = '00'; } elsif ($BEGIN =~ /^(\d{4})-(\d+)-(\d+)$/) { $BEGIN = &timegm_nocheck(0, 0, 0, $3, $2 - 1, $1 - 1900) * 1000; $o_day = sprintf("%02d", $3); $o_month = sprintf("%02d", $2); $o_year = $1; $o_hour = '00'; $o_min = '00'; $o_sec = '00'; } else { die "FATAL: bad format for begin datetime, should be yyyy-mm-dd hh:mm:ss\n"; } } if ($END) { if ($END =~ /^(\d{4})-(\d+)-(\d+) (\d+):(\d+)$/) { $END = &timegm_nocheck($6, $5, $4, $3, $2 - 1, $1 - 1900) * 1000; $e_day = sprintf("%02d", $3); $e_month = sprintf("%02d", $2); $e_year = $1; $e_hour = sprintf("%02d", $4); $e_min = sprintf("%02d", $5); $e_sec = '00'; } elsif ($END =~ /^(\d{4})-(\d+)-(\d+)$/) { $END = &timegm_nocheck(0, 0, 0, $3, $2 - 1, $1 - 1900) * 1000; $e_day = printf("%02d", 3); $e_month = sprintf("%02d", $2); $e_year = $1; $e_hour = '00'; $e_min = '00'; $e_sec = '00'; } else { die "FATAL: bad format for ending datetime, should be yyyy-mm-dd hh:mm:ss\n"; } } } #### # Read configuration file #### &read_conf(); #### # Set default report date to today #### if (!$o_year) { ($o_sec, $o_min, $o_hour, $o_day, $o_month, $o_year) = localtime(time); $o_year += 1900; $o_month++; $o_month = sprintf("%02d", $o_month); $o_day = sprintf("%02d", $o_day); $o_hour = sprintf("%02d", $o_hour); $o_min = sprintf("%02d", $o_min); $o_sec = sprintf("%02d", $o_sec); } if (!$e_year) { ($e_sec, $e_min, $e_hour, $e_day, $e_month, $e_year) = localtime(time); $e_year += 1900; $e_month++; $e_month = sprintf("%02d", $e_month); $e_day = sprintf("%02d", $e_day); $e_hour = sprintf("%02d", $e_hour); $e_min = sprintf("%02d", $e_min); $e_sec = sprintf("%02d", $e_sec); } #### # Look into subdirectories to find daily and hourly data files. #### my @WORK_DIRS = &get_data_directories(); # Set path to last directory containing stats by default my $in_dir = $INPUT_DIR || '.'; $in_dir .= "/$WORK_DIRS[-1]" if ($#WORK_DIRS >= 0); #### # Generate page header (common to all reports and include menu) #### &html_header(); #### # Load global information to be able to compose application menus #### #### Show empty data if ($#WORK_DIRS < 0) { &wrong_date_selection(1); &html_footer(); exit 0; } #### Show system related information if ($ACTION eq 'sysinfo') { &show_sysinfo($in_dir); &html_footer(); exit 0; } #### Load statistics from all required directories following the time selection foreach (my $dx = 0; $dx <= $#WORK_DIRS; $dx++) { # For Home menu report we just report current information # about CLuster, Database and System whatever is the Time # selection. There is no cumulative data in these stats. # Same for System and Database Info reports. next if ( grep(/^$ACTION$/, @NOGRAPH_LIST) && $dx < $#WORK_DIRS); # Set absolute path to the working directory $in_dir = "$INPUT_DIR/$WORK_DIRS[$dx]"; # Check if we have binary file in the directory my @binfiles = (); if (-d "$in_dir") { opendir(IDIR, "$in_dir") || die "FATAL: can't opendir $in_dir: $!"; @binfiles = grep { /^.*\.bin$/ } readdir(IDIR); closedir(IDIR); } else { # Input directory does not exists next; } # If we are processiong multiple stat dirs caching is mandatory if ($#binfiles == -1 && $#WORK_DIRS > 0) { print qq{

 

NO CACHE FILE FOUND: Please read documentation about pgCluu caching
}; # Caching is mandatory in CGI mode &html_footer(); exit 0; } # Set system information, database list # and global information to build menu %sysinfo = (); %global_infos = (); @DATABASE_LIST = (); @DEVICE_LIST = (); @IFACE_LIST = (); @DEVICE_SPACE_LIST = (); &read_sysinfo($in_dir); # Set default sysstat file to read (binary or text format) # an extract the disk devices and network interfaces list # if there's no binary files my ($sar_file, $sadc_file) = &set_sysstat_file($in_dir); # Set default pidstat file to read my $pidstat_file = &set_pidstat_file($in_dir); # Detect timezone from csv file when there is no cache file and # look for disk device and network interface from the sar file if ($#binfiles == -1) { if ($STATS_TIMEZONE eq '00') { if (-e "$in_dir/pg_stat_database.csv" && !-z "$in_dir/pg_stat_database.csv") { $STATS_TIMEZONE = &detect_timezone("$in_dir/pg_stat_database.csv"); } elsif (-e "$in_dir/pg_stat_database.csv.gz" ) { $STATS_TIMEZONE = &detect_timezone("$in_dir/pg_stat_database.csv.gz"); } # Force use of same the same timezone for postgresql and system metrics if ($TIMEZONE ne $STATS_TIMEZONE) { $TIMEZONE = $STATS_TIMEZONE; } print STDERR "DEBUG: autodetected timezone value database : $STATS_TIMEZONE, system: $TIMEZONE\n" if ($DEBUG); } } # Action to perform when a sar statistics is requested if (($ACTION eq 'home') || ($ACTION =~ /^(system|device|network)-/)) { # Load statistics from cache files if ($#binfiles >= 0) { my $binstat = $bin_action_map{$ACTION} || $ACTION; &load_sar_binary($in_dir, $binstat); # Set timezone if (($TIMEZONE eq '00') && $global_infos{timezone}) { $TIMEZONE = $global_infos{timezone}; } if (($STATS_TIMEZONE eq '00') && $global_infos{stats_timezone}) { $STATS_TIMEZONE = $global_infos{stats_timezone}; } } # Home page is built from cache file or from csv file, not both elsif ( $sar_file && ($ACTION ne 'home') || ($#binfiles == -1)) { # Then build sar statistics from data file starting at begining # when there's no cache file or starting at last cache offset. # In cache/binary mode we can not process sadc binary data file if (defined $sadc_file && -f "$sadc_file" && $#binfiles == -1) { print STDERR "DEBUG: looking for sadc binary data file $sadc_file\n" if ($DEBUG); foreach my $id (sort keys %SAR_GRAPH_INFOS) { next if (($ACTION ne 'home') && ($REAL_ACTION ne $SAR_GRAPH_INFOS{$id}->{name})); &compute_sarstat_stats($sadc_file, %{$SAR_GRAPH_INFOS{$id}}); } # Read sar file from the start of the file or from the offset stored a previous # run of the cache. Gzipped files do not need to be read again with binary files } elsif ( defined $sar_file && -f "$sar_file" && ($#binfiles == -1 || $sar_file !~ /\.gz$/) ) { # Load sar statistics from file if not already done my %fulldata = &load_sarfile_stats($sar_file); if (-e "$in_dir/fs_stat_use.csv") { push(@{$fulldata{'system-space'}}, &load_fsuse_stats($in_dir, 'fs_stat_use.csv')); } # Get Commit memory stats if (-e "$in_dir/commit_memory.csv") { push(@{$fulldata{'system-commit_memory'}}, &load_commit_memory_stats($in_dir, 'commit_memory.csv')); } print STDERR "DEBUG: looking for sar text data file $sar_file\n" if ($DEBUG); foreach my $id (sort keys %SAR_GRAPH_INFOS) { next if (($ACTION ne 'home') && ($REAL_ACTION ne $SAR_GRAPH_INFOS{$id}->{name})); &compute_sarfile_stats($sar_file, $in_dir, \%fulldata, %{$SAR_GRAPH_INFOS{$id}}); } print STDERR "DEBUG: looking for pidstatt data file $pidstat_file\n" if ($DEBUG); %fullpidstatdata = &load_sarfile_stats($sar_file); foreach my $id (sort keys %PIDSTAT_GRAPH_INFOS) { &compute_pidstatfile_stats($pidstat_file, $in_dir, %{$PIDSTAT_GRAPH_INFOS{$id}}); } } } } # Action to perform when a PostgreSQL statistics is requested if (($ACTION eq 'home') || ($ACTION !~ /^(system|device|network)-/)) { # Load statistics from cache files if ($#binfiles > 0) { my $pgstat = $pg_action_map{$ACTION} || $ACTION; &load_pg_binary($in_dir, $pgstat); # Set timezone if (($TIMEZONE eq '00') && $global_infos{timezone}) { $TIMEZONE = $global_infos{timezone}; } if (($STATS_TIMEZONE eq '00') && $global_infos{stats_timezone}) { $STATS_TIMEZONE = $global_infos{stats_timezone}; } } # Home page is built from cache file or from csv file, not both if (($ACTION ne 'home') || ($#binfiles == -1)) { print STDERR "DEBUG: Building PostgreSQL $ACTION view\n" if ($DEBUG); # Loop over CSV files and graphics definition to generate reports foreach my $k (sort {$a cmp $b} keys %DB_GRAPH_INFOS) { # Do not compute statistics for reports other than the # one requested by the user. my $to_be_proceed = 0; foreach my $n (keys %{$DB_GRAPH_INFOS{$k}}) { $to_be_proceed = 1, last if (($ACTION eq 'home') || ($ACTION eq 'database-info') || ($REAL_ACTION eq $DB_GRAPH_INFOS{$k}{$n}->{name})); } next if (!$to_be_proceed); print STDERR "DEBUG: Building PostgreSQL statistics from $k CSV files\n" if ($DEBUG); # Read statistics from csv file starting at at begining of the # file or last offset when binary files are present if (-e "$in_dir/$k" && !-z "$in_dir/$k") { &compute_postgresql_stat($in_dir, $k, $src_base, %{$DB_GRAPH_INFOS{$k}}); # Gzip data files are only available when they can't be appended anymore so # if we have binary files and gzipped files, binary files contains all stats } elsif (($#binfiles == -1) && -e "$in_dir/$k.gz" && !-z "$in_dir/$k.gz") { &compute_postgresql_stat($in_dir, "$k.gz", $src_base, %{$DB_GRAPH_INFOS{$k}}); } else { # Files use 'all' instead of 'user' with pgcluu_collectd --stat-type option my $f = $k; $f =~ s/_user_/_all_/; # Read statistics from csv file starting at at begining of the # file or last offset when binary files are present if (-e "$in_dir/$f" && !-z "$in_dir/$f") { &compute_postgresql_stat($in_dir, $f, $src_base, %{$DB_GRAPH_INFOS{$k}}); # Gzip data files are only available when they can't be appended anymore so # if we have binary files and gzipped files, binary files contains all stats } elsif (($#binfiles == -1) && -e "$in_dir/$f.gz" && !-z "$in_dir/$f.gz") { &compute_postgresql_stat($in_dir, "$f.gz", $src_base, %{$DB_GRAPH_INFOS{$k}}); } } } } } # Action to perform when a sar statistics is requested if (($ACTION eq 'home') || ($ACTION =~ /^pidstat-/)) { # Load statistics from cache files if ($#binfiles >= 0) { my $binstat = $bin_action_map{$ACTION} || $ACTION; &load_pidstat_binary($in_dir, $binstat); # Set timezone if (($TIMEZONE eq '00') && $global_infos{timezone}) { $TIMEZONE = $global_infos{timezone}; } if (($STATS_TIMEZONE eq '00') && $global_infos{stats_timezone}) { $STATS_TIMEZONE = $global_infos{stats_timezone}; } } # Home page is built from cache file or from csv file, not both elsif ( $pidstat_file && ($ACTION ne 'home') || ($#binfiles == -1)) { # Then build pidstat statistics from data file starting at begining # when there's no cache file or starting at last cache offset. if ( defined $pidstat_file && -f "$pidstat_file" && (($#binfiles == -1) || ($pidstat_file !~ /\.gz$/)) ) { print STDERR "DEBUG: looking for pidstatt data file $pidstat_file\n" if ($DEBUG); %fullpidstatdata = &load_sarfile_stats($sar_file); foreach my $id (sort keys %PIDSTAT_GRAPH_INFOS) { &compute_pidstatfile_stats($pidstat_file, $in_dir, %{$PIDSTAT_GRAPH_INFOS{$id}}); } } } } } #### Show home page information if ($ACTION eq 'home') { &show_home(); } #### Show other pages else { # Show system reports if ($ACTION =~ /^(system|device|network)-/) { # Build sar statistics graphs print STDERR "DEBUG: Building sar statistics reports\n" if ($DEBUG); foreach my $id (sort keys %SAR_GRAPH_INFOS) { next if (($ACTION ne 'home') && ($REAL_ACTION ne $SAR_GRAPH_INFOS{$id}->{name})); print STDERR "DEBUG: Reading sar statistics for $SAR_GRAPH_INFOS{$id}->{name}.\n" if ($DEBUG); &compute_sar_graph($src_base, %{$SAR_GRAPH_INFOS{$id}}); } } # Show pidstat reports elsif ($ACTION =~ /^pidstat-/) { # Build pidstat statistics graphs print STDERR "DEBUG: Building pidstat statistics reports\n" if ($DEBUG); foreach my $id (sort keys %PIDSTAT_GRAPH_INFOS) { next if (($ACTION ne 'home') && ($REAL_ACTION ne "pidstat-$PIDSTAT_GRAPH_INFOS{$id}->{name}")); &compute_pidstat_graph($src_base, %{$PIDSTAT_GRAPH_INFOS{$id}}); } } # Show database general information elsif ($ACTION eq 'database-info') { &write_database_info($DATABASE, $src_base); } else { # Loop over statistic in memory to generate PostgreSQL reports print STDERR "DEBUG: Building PostgreSQL statistics reports\n" if ($DEBUG); # Try to limit report generation to stats that exists in memory. # The storage variable name are the same than the keys in DB_GRAPH_INFOS # minus some transformation. foreach my $k (sort {$a cmp $b} keys %DB_GRAPH_INFOS) { $ID_ACTION = -1; if ($ACTION ne 'home') { foreach my $n (keys %{$DB_GRAPH_INFOS{$k}}) { if ($REAL_ACTION eq $DB_GRAPH_INFOS{$k}{$n}->{name}) { $ID_ACTION = $n; last; } } } else { $ID_ACTION = 0; } next if ($ID_ACTION < 0); my $inmem = $k; $inmem =~ s/\.csv//; $inmem =~ s/\./_/g; $inmem =~ s/^pg_/all_/; if ($inmem eq 'pgbouncer_stats') { $inmem = 'all_pgbouncer_stats'; } if (($inmem =~ /_conf/) && ($inmem !~ /^all/)) { $inmem = 'all_' . $inmem; } # Skip this report if there's no statistics loaded in memory next if ((scalar keys %{$inmem} == 0) && ($ID_ACTION == 0)); print STDERR "DEBUG: Building report for $k (from memory \%$inmem)\n" if ($DEBUG); &compute_postgresql_report($k, $src_base, %{$DB_GRAPH_INFOS{$k}}); } } } #### # Add common HTML footer #### &html_footer(); exit 0; #---------------------------------------------------------------------------------- sub set_sysstat_file { my $input_dir = shift; $input_dir ||= $INPUT_DIR; print STDERR "DEBUG: detecting sar/sadc file in $input_dir/\n" if ($DEBUG); my $sar_file = ''; my $sadc_file = ''; if (!$SADC_INPUT_FILE && !$SAR_INPUT_FILE) { if (-f "$input_dir/sadc_stats.dat") { $sadc_file = "$input_dir/" . 'sadc_stats.dat'; } elsif (-f "$input_dir/sar_stats.dat") { $sar_file = "$input_dir/" . 'sar_stats.dat'; } elsif (-f "$input_dir/sar_stats.dat.gz") { $sar_file = "$input_dir/" . 'sar_stats.dat.gz'; } if (!$sadc_file && !$sar_file) { $DISABLE_SAR = 1 if (!-e "$input_dir/sar_cpu_stat.bin"); return; } } else { $sadc_file = $SADC_INPUT_FILE; $sar_file = $SAR_INPUT_FILE; } # Verify that the sar data file exists. if ($sadc_file && !-f "$sadc_file") { print STDERR "ERROR: sar binary data file $sadc_file can't be found.\n"; exit 1; } if ($sar_file && !-f "$sar_file") { print STDERR "ERROR: sar text data file $sar_file can't be found.\n"; exit 1; } print STDERR "DEBUG: sar/sadc file detected ", ($sar_file) ? $sar_file : $sadc_file, "\n" if ($DEBUG); return ($sar_file, $sadc_file); } sub set_pidstat_file { my $input_dir = shift; $input_dir ||= $INPUT_DIR; print STDERR "DEBUG: detecting pidstat file in $input_dir/\n" if ($DEBUG); my $pidstat_file = ''; if (!$PIDSTAT_INPUT_FILE) { if (-f "$input_dir/pidstat_stats.dat") { $pidstat_file = "$input_dir/" . 'pidstat_stats.dat'; } elsif (-f "$input_dir/pidstat_stats.dat.gz") { $pidstat_file = "$input_dir/" . 'pidstat_stats.dat.gz'; } if (!$pidstat_file) { print STDERR "WARNING: No pidstat_stats.dat file found in $input_dir.\nContinuing normally without reporting pidstat statistics.\n" if ($DEBUG); return; } } else { $pidstat_file = $PIDSTAT_INPUT_FILE; } # Verify that the sar data file exists. if ($pidstat_file && !-f "$pidstat_file") { print STDERR "ERROR: pidstat text data file $pidstat_file can not be found.\n"; exit 1; } print STDERR "DEBUG: pidstat file detected $pidstat_file\n" if ($DEBUG); return $pidstat_file; } sub progress_bar { my ( $got, $total, $width, $char ) = @_; $width ||= 25; $char ||= '='; my $num_width = length $total; sprintf("[%-${width}s] Parsed %${num_width}s bytes of %s (%0.2f%%)\r", $char x (($width-1)*$got/$total). '>', $got, $total, 100*$got/+$total); } sub is_compressed { my $file = shift; return 1 if ($file =~ /\.gz/); return 0; } sub open_filehdl { my $file = shift; my $curfh = new IO::File; if (!is_compressed("$file")) { $curfh->open("< $file") or die "FATAL: can't read file $file: $!\n"; } else { $curfh->open("$ZCAT_PROG $file |") or die "FATAL: can't read pipe from command: $ZCAT_PROG $file, $!\n"; } return $curfh; } sub detect_timezone { my $file = shift; my $tz = '+00'; if (!&is_compressed($file)) { if (!open(IN, "$file")) { die "FATAL: can't read file $file: $!\n"; } } else { if (!open(IN, "$ZCAT_PROG $file |")) { die "FATAL: can't read pipe on command: $ZCAT_PROG $file, $!\n"; } } my $i = 1; while () { my @data = split(/;/); if ($data[0] =~ /^\d+-\d+-\d+ \d+:\d+:\d+([+\-]\d\d)/) { $tz = $1; last; } $i++; last if ($i > 10); } close(IN); return $tz; } sub get_data_id { my ($str, %data_info) = @_; foreach my $i (sort {$a <=> $b} keys %data_info) { if ($data_info{$i}->{name} eq $str) { return $i; } } return -1; } sub set_device_list { my ($sar_file, $sadc_file) = @_; if ($sadc_file && -f "$sadc_file") { my $command = "$SADF_PROG -t -P ALL -d $sadc_file -- -d -p"; print STDERR "DEBUG: looking for device list using command $command'\n" if ($DEBUG); # Load data from file if (!open(IN, "$command |")) { die "FATAL: can't read output from command ($command): $!\n"; } while (my $l = ) { chomp($l); # hostname;interval;timestamp;DEV;tps;rd_sec/s;wr_sec/s;avgrq-sz;avgqu-sz;await;svctm;%util my @data = split(/;/, $l); next if ($data[2] !~ /^\d+/); next if ( $data[3] =~ /^loop\d+/); if (!grep(m#^$data[3]$#, @DEVICE_LIST)) { push(@DEVICE_LIST, $data[3]); } else { last; } } close(IN); $command = "$SADF_PROG -t -P ALL -d $sadc_file -- -n DEV"; print STDERR "DEBUG: looking for network device list using command $command'\n" if ($DEBUG); # Load data from file if (!open(IN, "$command |")) { die "FATAL: can't read output from command ($command): $!\n"; } while (my $l = ) { chomp($l); #hostname;interval;timestamp;IFACE;rxpck/s;txpck/s;... my @data = split(/;/, $l); next if ($data[2] !~ /^\d+/); if (!grep(m#^$data[3]$#, @IFACE_LIST)) { push(@IFACE_LIST, $data[3]); } else { last; } } close(IN); # There is no information about disk space device in sadc file #@DEVICE_SPACE_LIST = ...; } elsif ($sar_file && -f "$sar_file") { print STDERR "DEBUG: looking for devices in sar file $sar_file\n" if ($DEBUG); # Load data from file if (!&is_compressed($sar_file)) { if (!open(IN, "$sar_file")) { die "FATAL: can't read input file $sar_file: $!\n"; } } else { if (!open(IN, "$ZCAT_PROG $sar_file |")) { die "FATAL: can't read pipe from command: $ZCAT_PROG $sar_file, $!\n"; } } my $type = ''; while (my $l = ) { chomp($l); $l =~ s/\r//; # We only read the first sar report to extract device name last if ($l =~ /^Average/); # Skip non relevant part if ($l !~ /^\d+:\d+:\d+/ || !$l) { next; } # Get device type from reports headers if ($l =~ m#(DEV|IFACE|FILESYSTEM)\s+#) { $type = $1; next; } # Extract values from the current line my @values = (); push(@values, split(m#\s+#, $l)); next if ( $values[1] =~ /^loop\d+/); # skip loop device # Set device list following the type if ($type eq 'DEV') { push(@DEVICE_LIST, $values[1]) if (!grep(/^$values[1]$/, @DEVICE_LIST)); } elsif ($type eq 'IFACE') { push(@IFACE_LIST, $values[1]) if (!grep(/^$values[1]$/, @IFACE_LIST)); } elsif ($type eq 'FILESYSTEM') { push(@DEVICE_SPACE_LIST, $values[8]) if (!grep(/^$values[8]$/, @DEVICE_SPACE_LIST)); } } close(IN); } } sub write_database_info { my $db = shift; my $src_base = shift; return if (($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB))); my $next = $#{$sysinfo{EXTENSION}{$db}} + 1; my $extlist = join(',', @{$sysinfo{EXTENSION}{$db}}); $extlist = ' (' . $extlist . ')' if ($extlist); my $nsch = $#{$sysinfo{SCHEMA}{$db}} + 1; my $schlist = join(',', @{$sysinfo{SCHEMA}{$db}}); $schlist = ' (' . $schlist . ')' if ($schlist); my $njson = $#{$sysinfo{JSON}{$db}} + 1; my $jsonlist = join(',', @{$sysinfo{JSON}{$db}}); $jsonlist = ' (' . $jsonlist . ')' if ($jsonlist); my $procount = $sysinfo{PROCEDURE}{$db} || 0; my $trigcount = $sysinfo{TRIGGER}{$db} || 0; my $last_vacuum = $OVERALL_STATS{'database'}{$db}{last_vacuum} || '-'; my $last_analyze = $OVERALL_STATS{'database'}{$db}{last_analyze} || '-'; my $last_autovacuum = $OVERALL_STATS{'database'}{$db}{last_autovacuum} || '-'; my $last_autoanalyze = $OVERALL_STATS{'database'}{$db}{last_autoanalyze} || '-'; my $last_reset = $OVERALL_STATS{'database'}{$db}{'stat_reset'} || ''; my $objects_count = ''; foreach my $k (sort keys %RELKIND) { $objects_count .= qq{
  • $OVERALL_STATS{'class'}{$db}{$k} } . lcfirst($RELKIND{$k}) . qq{
  • } if (exists $OVERALL_STATS{'class'}{$db}{$k}); } $OVERALL_STATS{database}{$db}{invalid_indexes} ||= 0; $OVERALL_STATS{database}{$db}{hash_indexes} ||= 0; $OVERALL_STATS{database}{$db}{unlogged} ||= 0; my $dbsize = &pretty_print_size($OVERALL_STATS{'database'}{$db}{'size'}); print qq{



    • Database $db

      • $dbsize Total size
      • $next Installed extensions$extlist
      • $OVERALL_STATS{database}{$db}{unlogged} Unlogged tables
      • $OVERALL_STATS{database}{$db}{invalid_indexes} Invalid indexes
      • $OVERALL_STATS{database}{$db}{hash_indexes} Hash indexes
      • $nsch Schemas$schlist
      • }; print qq{
      • $njson json vs jsonb columns$jsonlist
      • } if ($jsonlist); print qq{
      • $last_vacuum Last manual vacuum
      • $last_analyze Last manual analyze
      • $last_autovacuum Last auto vacuum
      • $last_autoanalyze Last auto analyze
      • $last_reset Last database stat reset
      • $procount Stored procedures
      • $trigcount Triggers
      • $objects_count
    }; } sub compute_postgresql_stat { my ($input_dir, $file, $src_base, %data_info) = @_; # Compute graphs following the data file my $fctname = $file; $fctname =~ s/\.csv(\.gz)?//; $fctname =~ s/\.gz//; $fctname =~ s/\./_/g; my $offset = 0; $offset = $global_infos{"$input_dir/$file"} if (exists $global_infos{"$input_dir/$file"}); print STDERR "DEBUG: Reading statistics in file $input_dir/$file starting at offset $offset\n" if ($DEBUG); # Call the function associated to the action and get back the new offset # offset is used in incremental mode to avoir parsing the entire file. $global_infos{"$input_dir/$file"} = $fctname->($input_dir, $file, $offset); } sub compute_postgresql_report { my ($file, $src_base, %data_info) = @_; # Compute graphs following the data file my $fctname = $file; $fctname =~ s/\.csv(\.gz)?//; $fctname =~ s/\.gz//; $fctname =~ s/_all_/_user_/g; $fctname =~ s/\./_/g; print STDERR "DEBUG: creating reports from statistics $fctname.\n" if ($DEBUG); $fctname .= '_report'; $fctname->($src_base, $DATABASE, %data_info); } # Compute statistics of database statistics sub pg_stat_database { my ($input_dir, $file, $offset) = @_; my %start_vals = (); my $tmp_val = 0; my %db_list = (); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); $curfh->seek($offset,0); while (my $l = <$curfh>) { $offset += length($l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # timestamp | datid | datname | numbackends | xact_commit | xact_rollback | blks_read | blks_hit | tup_returned | tup_fetched | tup_inserted | tup_updated | tup_deleted | conflicts | stats_reset | temp_files | temp_bytes | deadlocks | blk_read_time | blk_write_time # Store list of database $db_list{$data[2]} = 1; # Store previous data push(@{$start_vals{$data[2]}}, @data) if ($#{$start_vals{$data[2]}} < 0); $OVERALL_STATS{'start_date'} = $data[0] if (!$OVERALL_STATS{'start_date'} || ($OVERALL_STATS{'start_date'} gt $data[0])); $OVERALL_STATS{'end_date'} = $data[0] if (!$OVERALL_STATS{'end_date'} || ($OVERALL_STATS{'end_date'} lt $data[0])); # Store interval between previous run $all_stat_database{$data[0]}{$data[2]}{interval} = ($data[0] - $start_vals{$data[2]}[0])/1000; $all_stat_database{$data[0]}{all}{interval} = ($data[0] - $start_vals{$data[2]}[0])/1000; if ($#data >= 8) { (($data[8] - $start_vals{$data[2]}[8]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[8] - $start_vals{$data[2]}[8]); if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) { $all_stat_database{$data[0]}{$data[2]}{returned} = $tmp_val; $all_stat_database{$data[0]}{all}{returned} += $tmp_val; } else { $OVERALL_STATS{'cluster'}{returned} += $tmp_val; $OVERALL_STATS{'database'}{$data[2]}{returned} += $tmp_val; } (($data[9] - $start_vals{$data[2]}[9]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[9] - $start_vals{$data[2]}[9]); if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) { $all_stat_database{$data[0]}{$data[2]}{fetched} = $tmp_val; $all_stat_database{$data[0]}{all}{fetched} += $tmp_val; } else { $OVERALL_STATS{'cluster'}{fetched} += $tmp_val; $OVERALL_STATS{'database'}{$data[2]}{fetched} += $tmp_val; } # Gather insert statement (($data[10] - $start_vals{$data[2]}[10]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[10] - $start_vals{$data[2]}[10]); if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) { $all_stat_database{$data[0]}{$data[2]}{insert} = $tmp_val; $all_stat_database{$data[0]}{all}{insert} += $tmp_val; } else { $OVERALL_STATS{'cluster'}{insert} += $tmp_val; $OVERALL_STATS{'database'}{$data[2]}{insert} += $tmp_val; } # Gather update statement (($data[11] - $start_vals{$data[2]}[11]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[11] - $start_vals{$data[2]}[11]); if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) { $all_stat_database{$data[0]}{$data[2]}{update} = $tmp_val; $all_stat_database{$data[0]}{all}{update} += $tmp_val; } else { $OVERALL_STATS{'cluster'}{update} += $tmp_val; $OVERALL_STATS{'database'}{$data[2]}{update} += $tmp_val; } # Gather delete statement (($data[12] - $start_vals{$data[2]}[12]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[12] - $start_vals{$data[2]}[12]); if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) { $all_stat_database{$data[0]}{$data[2]}{delete} = $tmp_val; $all_stat_database{$data[0]}{all}{delete} += $tmp_val; } else { $OVERALL_STATS{'cluster'}{delete} += $tmp_val; $OVERALL_STATS{'database'}{$data[2]}{delete} += $tmp_val; } } # Gather blks_read (($data[6] - $start_vals{$data[2]}[6]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[6] - $start_vals{$data[2]}[6]); if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) { $all_stat_database{$data[0]}{$data[2]}{blks_read} = $tmp_val; $all_stat_database{$data[0]}{all}{blks_read} += $tmp_val; } else { $OVERALL_STATS{'cluster'}{blks_read} += $tmp_val; $OVERALL_STATS{'database'}{$data[2]}{blks_read} += $tmp_val; } # Gather blks_hit (($data[7] - $start_vals{$data[2]}[7]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[7] - $start_vals{$data[2]}[7]); if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) { $all_stat_database{$data[0]}{$data[2]}{blks_hit} = $tmp_val; $all_stat_database{$data[0]}{all}{blks_hit} += $tmp_val; } else { $OVERALL_STATS{'cluster'}{blks_hit} += $tmp_val; $OVERALL_STATS{'database'}{$data[2]}{blks_hit} += $tmp_val; } # Gather number of running backend if ($data[3]) { $all_stat_database{$data[0]}{$data[2]}{nbackend} = $data[3]; $all_stat_database{$data[0]}{all}{nbackend} += $data[3]; $OVERALL_STATS{'cluster'}{nbackend} += $data[3]; $OVERALL_STATS{'database'}{$data[2]}{nbackend} += $data[3]; } # Gather number of committed transaction (($data[4] - $start_vals{$data[2]}[4]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[4] - $start_vals{$data[2]}[4]); if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) { $all_stat_database{$data[0]}{$data[2]}{xact_commit} = $tmp_val; $all_stat_database{$data[0]}{all}{xact_commit} += $tmp_val; $all_stat_database{$data[0]}{$data[2]}{xact_throughput} = $tmp_val; $all_stat_database{$data[0]}{all}{xact_throughput} += $tmp_val; } else { $OVERALL_STATS{'cluster'}{xact_commit} += $tmp_val; $OVERALL_STATS{'database'}{$data[2]}{xact_commit} += $tmp_val; $OVERALL_STATS{'cluster'}{xact_throughput} += $tmp_val; $OVERALL_STATS{'database'}{$data[2]}{xact_throughput} += $tmp_val; } # Gather number of rollbacked transaction (($data[5] - $start_vals{$data[2]}[5]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[5] - $start_vals{$data[2]}[5]); if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) { $all_stat_database{$data[0]}{$data[2]}{xact_rollback} = $tmp_val; $all_stat_database{$data[0]}{all}{xact_rollback} += $tmp_val; $all_stat_database{$data[0]}{$data[2]}{xact_throughput} = +$tmp_val; $all_stat_database{$data[0]}{all}{xact_throughput} += $tmp_val; } else { $OVERALL_STATS{'cluster'}{xact_rollback} += $tmp_val; $OVERALL_STATS{'database'}{$data[2]}{xact_rollback} += $tmp_val; $OVERALL_STATS{'cluster'}{xact_throughput} += $tmp_val; $OVERALL_STATS{'database'}{$data[2]}{xact_throughput} += $tmp_val; } # Gather number of canceled queries if ($#data >= 13) { (($data[13] - $start_vals{$data[2]}[13]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[13] - $start_vals{$data[2]}[13]); if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) { $all_stat_database{$data[0]}{$data[2]}{canceled_queries} = $tmp_val; $all_stat_database{$data[0]}{all}{canceled_queries} += $tmp_val; } else { $OVERALL_STATS{'cluster'}{canceled_queries} += $tmp_val; $OVERALL_STATS{'database'}{$data[2]}{canceled_queries} += $tmp_val; $OVERALL_STATS{'database'}{$data[2]}{'stat_reset'} = $data[14] if (!exists $OVERALL_STATS{'database'}{$data[2]}{'stat_reset'} || ($OVERALL_STATS{'database'}{$data[2]}{'stat_reset'} lt $data[14])); } } # Gather number of temporary data and deadlock if ($#data > 15) { (($data[15] - $start_vals{$data[2]}[15]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[15] - $start_vals{$data[2]}[15]); if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) { $all_stat_database{$data[0]}{$data[2]}{temp_files} = $tmp_val; $all_stat_database{$data[0]}{all}{temp_files} += $tmp_val; } else { $OVERALL_STATS{'cluster'}{temp_files} += $tmp_val; $OVERALL_STATS{'database'}{$data[2]}{temp_files} += $tmp_val; } (($data[16] - $start_vals{$data[2]}[16]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[16] - $start_vals{$data[2]}[16]); if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) { $all_stat_database{$data[0]}{$data[2]}{temp_bytes} = $tmp_val; $all_stat_database{$data[0]}{all}{temp_bytes} += $tmp_val; } else { $OVERALL_STATS{'cluster'}{temp_bytes} += $tmp_val; $OVERALL_STATS{'database'}{$data[2]}{temp_bytes} += $tmp_val; } (($data[17] - $start_vals{$data[2]}[17]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[17] - $start_vals{$data[2]}[17]); if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) { $all_stat_database{$data[0]}{$data[2]}{deadlocks} = $tmp_val; $all_stat_database{$data[0]}{all}{deadlocks} += $tmp_val; } else { $OVERALL_STATS{'cluster'}{deadlocks} += $tmp_val; $OVERALL_STATS{'database'}{$data[2]}{deadlocks} += $tmp_val; } } @{$start_vals{$data[2]}} = (); push(@{$start_vals{$data[2]}}, @data); } $curfh->close(); # Store the full list of database foreach my $d (keys %db_list) { push(@global_databases, $d) if (!grep/^$d$/, @global_databases); } push(@global_databases, 'all') if (($#global_databases >= 0) && !grep(/^all$/, @global_databases)); return $offset; } # Compute overall database statistics sub set_overall_database_stat_from_binary { foreach my $time (sort {$a <=> $b} keys %all_stat_database) { foreach my $db (@global_databases) { next if (($db eq 'all') || (($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB)))); foreach my $k (qw(insert returned fetched update delete blks_read blks_hit nbackend xact_commit xact_rollback canceled_queries deadlocks temp_files temp_bytes xact_throughput)) { next if (!exists $all_stat_database{$time}{$db}{$k}); $OVERALL_STATS{'cluster'}{$k} += $all_stat_database{$time}{$db}{$k}; $OVERALL_STATS{'database'}{$db}{$k} += $all_stat_database{$time}{$db}{$k}; } $OVERALL_STATS{'start_date'} = $time if (!$OVERALL_STATS{'start_date'} || ($OVERALL_STATS{'start_date'} gt $time)); $OVERALL_STATS{'end_date'} = $time if (!$OVERALL_STATS{'end_date'} || ($OVERALL_STATS{'end_date'} lt $time)); } } foreach my $time (sort {$a <=> $b} keys %all_database_size) { foreach my $db (@global_databases) { next if (($db eq 'all') || (($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB)))); $OVERALL_STATS{'database'}{$db}{'size'} = $all_database_size{$time}{$db}; $OVERALL_STATS{'start_date'} = $time if (!$OVERALL_STATS{'start_date'} || ($OVERALL_STATS{'start_date'} gt $time)); $OVERALL_STATS{'end_date'} = $time if (!$OVERALL_STATS{'end_date'} || ($OVERALL_STATS{'end_date'} lt $time)); } } } # Compute overall system statistics sub set_overall_system_stat_from_binary { foreach my $t (sort {$a <=> $b} keys %sar_cpu_stat) { # Skip unwanted lines #next if ($BEGIN && ($t < $BEGIN)); #next if ($END && ($t > $END)); if (!exists $OVERALL_STATS{'system'}{'cpu'} || ($OVERALL_STATS{'system'}{'cpu'}[1] < $sar_cpu_stat{$t}{'all'}{total})) { @{$OVERALL_STATS{'system'}{'cpu'}} = ($t, $sar_cpu_stat{$t}{'all'}{total}); } $OVERALL_STATS{'sar_start_date'} = $t if (!$OVERALL_STATS{'sar_start_date'} || ($OVERALL_STATS{'sar_start_date'} gt $t)); $OVERALL_STATS{'sar_end_date'} = $t if (!$OVERALL_STATS{'sar_end_date'} || ($OVERALL_STATS{'sar_end_date'} lt $t)); } foreach my $t (sort {$a <=> $b} keys %sar_load_stat) { # Skip unwanted lines #next if ($BEGIN && ($t < $BEGIN)); #next if ($END && ($t > $END)); if (!exists $OVERALL_STATS{'system'}{'load'} || ($OVERALL_STATS{'system'}{'load'}[1] < $sar_load_stat{$t}{'ldavg-1'})) { @{$OVERALL_STATS{'system'}{'load'}} = ($t, $sar_load_stat{$t}{'ldavg-1'}); } } foreach my $t (sort {$a <=> $b} keys %sar_process_stat) { # Skip unwanted lines #next if ($BEGIN && ($t < $BEGIN)); #next if ($END && ($t > $END)); if (!exists $OVERALL_STATS{'system'}{'process'} || ($OVERALL_STATS{'system'}{'process'}[1] < $sar_process_stat{$t}{'plist-sz'})) { @{$OVERALL_STATS{'system'}{'process'}} = ($t, $sar_process_stat{$t}{'plist-sz'}); } if (!exists $OVERALL_STATS{'system'}{'blocked'} || ($OVERALL_STATS{'system'}{'blocked'}[1] < $sar_process_stat{$t}{'blocked'})) { @{$OVERALL_STATS{'system'}{'blocked'}} = ($t, $sar_process_stat{$t}{'blocked'}); } } foreach my $t (sort {$a <=> $b} keys %sar_context_stat) { # Skip unwanted lines #next if ($BEGIN && ($t < $BEGIN)); #next if ($END && ($t > $END)); if (!exists $OVERALL_STATS{'system'}{'cswch'} || ($OVERALL_STATS{'system'}{'cswch'}[1] < $sar_context_stat{$t}{'cswch'})) { @{$OVERALL_STATS{'system'}{'cswch'}} = ($t, $sar_context_stat{$t}{'cswch'}); } } foreach my $t (sort {$a <=> $b} keys %sar_memory_stat) { # Skip unwanted lines #next if ($BEGIN && ($t < $BEGIN)); #next if ($END && ($t > $END)); if (!exists $OVERALL_STATS{'system'}{'kbcached'} || ($OVERALL_STATS{'system'}{'kbcached'}[1] > $sar_memory_stat{$t}{'kbcached'})) { @{$OVERALL_STATS{'system'}{'kbcached'}} = ($t, $sar_memory_stat{$t}{'kbcached'}); } } foreach my $t (sort {$a <=> $b} keys %sar_dirty_stat) { # Skip unwanted lines #next if ($BEGIN && ($t < $BEGIN)); #next if ($END && ($t > $END)); if (!exists $OVERALL_STATS{'system'}{'kbdirty'} || ($OVERALL_STATS{'system'}{'kbdirty'}[1] < $sar_dirty_stat{$t}{'kbdirty'})) { @{$OVERALL_STATS{'system'}{'kbdirty'}} = ($t, $sar_dirty_stat{$t}{'kbdirty'}); } } foreach my $t (sort {$a <=> $b} keys %sar_swap_stat) { # Skip unwanted lines #next if ($BEGIN && ($t < $BEGIN)); #next if ($END && ($t > $END)); $sar_swap_stat{$t}{'pswpin'} ||= 0; $sar_swap_stat{$t}{'pswpout'} ||= 0; if (!exists $OVERALL_STATS{'system'}{'pswpin'} || ($OVERALL_STATS{'system'}{'pswpin'}[1] < $sar_swap_stat{$t}{'pswpin'})) { @{$OVERALL_STATS{'system'}{'pswpin'}} = ($t, $sar_swap_stat{$t}{'pswpin'}); } if (!exists $OVERALL_STATS{'system'}{'pswpout'} || ($OVERALL_STATS{'system'}{'pswpout'}[1] < $sar_swap_stat{$t}{'pswpout'})) { @{$OVERALL_STATS{'system'}{'pswpout'}} = ($t, $sar_swap_stat{$t}{'pswpout'}); } } foreach my $t (sort {$a <=> $b} keys %sar_pageswap_stat) { # Skip unwanted lines #next if ($BEGIN && ($t < $BEGIN)); #next if ($END && ($t > $END)); $sar_pageswap_stat{$t}{'pgpgin'} ||= 0; $sar_pageswap_stat{$t}{'pgpgout'} ||= 0; $sar_pageswap_stat{$t}{'majflt'} ||= 0; $sar_pageswap_stat{$t}{'minflt'} ||= 0; $sar_pageswap_stat{$t}{'pgfree'} ||= 0; $sar_pageswap_stat{$t}{'pgscank'} ||= 0; $sar_pageswap_stat{$t}{'pgscand'} ||= 0; $sar_pageswap_stat{$t}{'pgsteal'} ||= 0; $sar_pageswap_stat{$t}{'vmeff'} ||= 0; if (!exists $OVERALL_STATS{'system'}{'pgpgin'} || ($OVERALL_STATS{'system'}{'pgpgin'}[1] < $sar_pageswap_stat{$t}{'pgpgin'})) { @{$OVERALL_STATS{'system'}{'pgpgin'}} = ($t, $sar_pageswap_stat{$t}{'pgpgin'}); } if (!exists $OVERALL_STATS{'system'}{'pgpgout'} || ($OVERALL_STATS{'system'}{'pgpgout'}[1] < $sar_pageswap_stat{$t}{'pgpgout'})) { @{$OVERALL_STATS{'system'}{'pgpgout'}} = ($t, $sar_pageswap_stat{$t}{'pgpgout'}); } if (!exists $OVERALL_STATS{'system'}{'majflt'} || ($OVERALL_STATS{'system'}{'majflt'}[1] < $sar_pageswap_stat{$t}{'majflt'})) { @{$OVERALL_STATS{'system'}{'majflt'}} = ($t, $sar_pageswap_stat{$t}{'majflt'}); } if (!exists $OVERALL_STATS{'system'}{'minflt'} || ($OVERALL_STATS{'system'}{'minflt'}[1] < $sar_pageswap_stat{$t}{'minflt'})) { @{$OVERALL_STATS{'system'}{'minflt'}} = ($t, $sar_pageswap_stat{$t}{'minflt'}); } if (!exists $OVERALL_STATS{'system'}{'pgfree'} || ($OVERALL_STATS{'system'}{'pgfree'}[1] < $sar_pageswap_stat{$t}{'pgfree'})) { @{$OVERALL_STATS{'system'}{'pgfree'}} = ($t, $sar_pageswap_stat{$t}{'pgfree'}); } if (!exists $OVERALL_STATS{'system'}{'pgscank'} || ($OVERALL_STATS{'system'}{'pgscank'}[1] < $sar_pageswap_stat{$t}{'pgscank'})) { @{$OVERALL_STATS{'system'}{'pgscank'}} = ($t, $sar_pageswap_stat{$t}{'pgscank'}); } if (!exists $OVERALL_STATS{'system'}{'pgscand'} || ($OVERALL_STATS{'system'}{'pgscand'}[1] < $sar_pageswap_stat{$t}{'pgscand'})) { @{$OVERALL_STATS{'system'}{'pgscand'}} = ($t, $sar_pageswap_stat{$t}{'pgscand'}); } if (!exists $OVERALL_STATS{'system'}{'pgsteal'} || ($OVERALL_STATS{'system'}{'pgsteal'}[1] < $sar_pageswap_stat{$t}{'pgsteal'})) { @{$OVERALL_STATS{'system'}{'pgsteal'}} = ($t, $sar_pageswap_stat{$t}{'pgsteal'}); } if (!exists $OVERALL_STATS{'system'}{'vmeff'} || ($OVERALL_STATS{'system'}{'vmeff'}[1] < $sar_pageswap_stat{$t}{'vmeff'})) { @{$OVERALL_STATS{'system'}{'vmeff'}} = ($t, $sar_pageswap_stat{$t}{'vmeff'}); } } foreach my $t (sort {$a <=> $b} keys %sar_block_stat) { # Skip unwanted lines #next if ($BEGIN && ($t < $BEGIN)); #next if ($END && ($t > $END)); $sar_block_stat{$t}{'bread'} ||= 0; $sar_block_stat{$t}{'bwrite'} ||= 0; if (!exists $OVERALL_STATS{'system'}{'bread'} || ($OVERALL_STATS{'system'}{'bread'}[1] < $sar_block_stat{$t}{'bread'})) { @{$OVERALL_STATS{'system'}{'bread'}} = ($t, $sar_block_stat{$t}{'bread'}); } if (!exists $OVERALL_STATS{'system'}{'bwrite'} || ($OVERALL_STATS{'system'}{'bwrite'}[1] < $sar_block_stat{$t}{'bwrite'})) { @{$OVERALL_STATS{'system'}{'bwrite'}} = ($t, $sar_block_stat{$t}{'bwrite'}); } } foreach my $t (sort {$a <=> $b} keys %sar_srvtime_stat) { # Skip unwanted lines #next if ($BEGIN && ($t < $BEGIN)); #next if ($END && ($t > $END)); foreach my $dev (keys %{ $sar_srvtime_stat{$t} } ) { next if ($DEVICE && ($dev ne $DEVICE)); if (!exists $OVERALL_STATS{'system'}{'svctm'} || ($OVERALL_STATS{'system'}{'svctm'}[1] < $sar_srvtime_stat{$t}{$dev}{'svctm'})) { @{$OVERALL_STATS{'system'}{'svctm'}} = ($t, $sar_srvtime_stat{$t}{$dev}{'svctm'}, $dev); } } } foreach my $t (sort {$a <=> $b} keys %sar_rw_devices_stat) { # Skip unwanted lines #next if ($BEGIN && ($t < $BEGIN)); #next if ($END && ($t > $END)); foreach my $dev (keys %{ $sar_rw_devices_stat{$t} } ) { next if ($DEVICE && ($dev ne $DEVICE)); $OVERALL_STATS{'system'}{'devices'}{$dev}{read} += $sar_rw_devices_stat{$t}{$dev}{'rd_sec/s'} || 0; $OVERALL_STATS{'system'}{'devices'}{$dev}{write} += $sar_rw_devices_stat{$t}{$dev}{'wr_sec/s'} || 0; $OVERALL_STATS{'system'}{'devices'}{$dev}{tps} = $sar_rw_devices_stat{$t}{$dev}{'tps'} if (!$OVERALL_STATS{'system'}{'devices'}{$dev}{tps} || ($OVERALL_STATS{'system'}{'devices'}{$dev}{tps} < $sar_rw_devices_stat{$t}{$dev}{'tps'})); } } } # Compute graphs of database statistics sub pg_stat_database_report { my ($src_base, $db_glob, %data_info) = @_; my %database_stat = (); my %total_query_type = (); my %has_conn = (); my $has_tuples = 0; my $has_temp = 0; my $has_conflict = 0; my $tz = ($STATS_TIMEZONE*3600*1000); foreach my $time (sort {$a <=> $b} keys %all_stat_database) { foreach my $db (@global_databases) { next if (!$all_stat_database{$time}{$db}{interval}); next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB))); foreach my $k (qw(insert returned fetched update delete blks_read blks_hit nbackend xact_commit xact_rollback canceled_queries deadlocks temp_files temp_bytes xact_throughput)) { $all_stat_database{$time}{$db}{$k} ||= 0; } # It depends on the postgresql version if (!$has_tuples) { foreach my $k (keys %{$all_stat_database{$time}{$db}}) { if (grep(/^$k$/, 'insert','returned','fetched','update','delete')) { $has_tuples = 1; last; } } } if ($has_tuples) { $database_stat{$db}{insert} .= '[' . ($time - $tz) . ',' . int($all_stat_database{$time}{$db}{insert}/$all_stat_database{$time}{$db}{interval}) . '],'; $database_stat{$db}{returned} .= '[' . ($time - $tz) . ',' . int($all_stat_database{$time}{$db}{returned}/$all_stat_database{$time}{$db}{interval}) . '],'; $database_stat{$db}{fetched} .= '[' . ($time - $tz) . ',' . int($all_stat_database{$time}{$db}{fetched}/$all_stat_database{$time}{$db}{interval}) . '],'; $database_stat{$db}{update} .= '[' . ($time - $tz) . ',' . int($all_stat_database{$time}{$db}{update}/$all_stat_database{$time}{$db}{interval}) . '],'; $database_stat{$db}{delete} .= '[' . ($time - $tz) . ',' . int($all_stat_database{$time}{$db}{delete}/$all_stat_database{$time}{$db}{interval}) . '],'; $total_query_type{$db}{'all'} += $all_stat_database{$time}{$db}{insert} + $all_stat_database{$time}{$db}{returned} + $all_stat_database{$time}{$db}{update} + $all_stat_database{$time}{$db}{delete}; $total_query_type{$db}{'insert'} += $all_stat_database{$time}{$db}{insert}; $total_query_type{$db}{'delete'} += $all_stat_database{$time}{$db}{delete}; $total_query_type{$db}{'update'} += $all_stat_database{$time}{$db}{update}; $total_query_type{$db}{'select'} += $all_stat_database{$time}{$db}{returned}; } $all_stat_database{$time}{$db}{blks_read} ||= 0; $all_stat_database{$time}{$db}{blks_hit} ||= 0; $database_stat{$db}{blks_read} .= '[' . ($time - $tz) . ',' . int($all_stat_database{$time}{$db}{blks_read}/$all_stat_database{$time}{$db}{interval}) . '],'; $database_stat{$db}{blks_hit} .= '[' . ($time - $tz) . ',' . int($all_stat_database{$time}{$db}{blks_hit}/$all_stat_database{$time}{$db}{interval}) . '],'; if (($all_stat_database{$time}{$db}{blks_read} + $all_stat_database{$time}{$db}{blks_hit}) > 0) { $database_stat{$db}{ratio_hit_miss} .= '[' . ($time - $tz) . ',' . sprintf("%0.2f", ($all_stat_database{$time}{$db}{blks_hit}*100)/($all_stat_database{$time}{$db}{blks_read} + $all_stat_database{$time}{$db}{blks_hit})) . '],'; } else { $database_stat{$db}{ratio_hit_miss} .= '[' . ($time - $tz) . ',0],'; } $database_stat{$db}{nbackend} .= '[' . ($time - $tz) . ',' . ($all_stat_database{$time}{$db}{nbackend}||0) . '],'; $has_conn{$db} = 1 if ($all_stat_database{$time}{$db}{nbackend}); $database_stat{$db}{xact_commit} .= '[' . ($time - $tz) . ',' . int(($all_stat_database{$time}{$db}{xact_commit}||0)/$all_stat_database{$time}{$db}{interval}) . '],'; $database_stat{$db}{xact_rollback} .= '[' . ($time - $tz) . ',' . int(($all_stat_database{$time}{$db}{xact_rollback}||0)/$all_stat_database{$time}{$db}{interval}) . '],'; $database_stat{$db}{xact_throughput} .= '[' . ($time - $tz) . ',' . int(($all_stat_database{$time}{$db}{xact_throughput}||0)/$all_stat_database{$time}{$db}{interval}) . '],'; # It depends on the postgresql version if (!$has_conflict) { foreach my $k (keys %{$all_stat_database{$time}{$db}}) { if ($k eq 'canceled_queries') { $has_conflict = 1; last; } } } if ($has_conflict) { $database_stat{$db}{canceled_queries} .= '[' . ($time - $tz) . ',' . ($all_stat_database{$time}{$db}{canceled_queries}||0) . '],'; } # It depends on the postgresql version if (!$has_temp) { foreach my $k (keys %{$all_stat_database{$time}{$db}}) { if (grep(/^$k$/, 'deadlocks','temp_files','temp_bytes')) { $has_temp = 1; last; } } } if ($has_temp) { $database_stat{$db}{deadlocks} .= '[' . ($time - $tz) . ',' . ($all_stat_database{$time}{$db}{deadlocks}||0) . '],'; $database_stat{$db}{temp_files} .= '[' . ($time - $tz) . ',' . ($all_stat_database{$time}{$db}{temp_files}||0) . '],'; $database_stat{$db}{temp_bytes} .= '[' . ($time - $tz) . ',' . int(($all_stat_database{$time}{$db}{temp_bytes}||0)/$all_stat_database{$time}{$db}{interval}) . '],'; } } } %all_stat_database = (); foreach my $id (sort {$a <=> $b} keys %data_info) { next if ($id ne $ID_ACTION); foreach my $db (sort keys %database_stat) { next if ($DATABASE && ($db ne $DATABASE)); next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB))); next if ($data_info{$id}{name} ne $REAL_ACTION); if ($data_info{$id}{name} =~ /(database|cluster)-write_ratio/) { if ($has_tuples) { $database_stat{$db}{insert} =~ s/,$//; $database_stat{$db}{update} =~ s/,$//; $database_stat{$db}{delete} =~ s/,$//; } print &jqplot_linegraph_array($IDX++, $data_info{$id}{name}, \%{$data_info{$id}}, $db, $database_stat{$db}{insert}, $database_stat{$db}{update}, $database_stat{$db}{delete}); } elsif ($data_info{$id}{name} =~ /(database|cluster)-read_ratio/) { if ($has_tuples) { $database_stat{$db}{returned} =~ s/,$//; $database_stat{$db}{fetched} =~ s/,$//; } print &jqplot_linegraph_array($IDX++, $data_info{$id}{name}, \%{$data_info{$id}}, $db, $database_stat{$db}{returned}, $database_stat{$db}{fetched}); } elsif ($data_info{$id}{name} =~ /(database|cluster)-read_write_query/) { if (exists $total_query_type{$db}{'all'} && ($total_query_type{$db}{'all'} > 0)) { my %data = (); foreach my $t (keys %{$total_query_type{$db}}) { next if ($t eq 'all'); $data{$t} = sprintf("%0.2f", $total_query_type{$db}{$t}*100/$total_query_type{$db}{'all'}); } print &jqplot_piegraph($IDX++, $data_info{$id}{name}, \%{$data_info{$id}}, $db, %data); } } elsif ($data_info{$id}{name} =~ /(database|cluster)-cache_ratio/) { $database_stat{$db}{blks_read} =~ s/,$//; $database_stat{$db}{blks_hit} =~ s/,$//; print &jqplot_linegraph_array($IDX++, $data_info{$id}{name}, \%{$data_info{$id}}, $db, $database_stat{$db}{blks_hit}, $database_stat{$db}{blks_read}, $database_stat{$db}{ratio_hit_miss}); delete $database_stat{$db}{blks_hit}; delete $database_stat{$db}{blks_read}; delete $database_stat{$db}{ratio_hit_miss}; } elsif ($data_info{$id}{name} =~ /(database|cluster)-commits_rollbacks/) { $database_stat{$db}{xact_commit} =~ s/,$//; $database_stat{$db}{xact_rollback} =~ s/,$//; $database_stat{$db}{nbackend} =~ s/,$//; print &jqplot_linegraph_array($IDX++, $data_info{$id}{name}, \%{$data_info{$id}}, $db, $database_stat{$db}{xact_commit}, $database_stat{$db}{xact_rollback}, $database_stat{$db}{nbackend}); delete $database_stat{$db}{xact_commit}; delete $database_stat{$db}{xact_rollback}; } elsif ($data_info{$id}{name} =~ /(database|cluster)-transactions/) { $database_stat{$db}{xact_throughput} =~ s/,$//; print &jqplot_linegraph_array($IDX++, $data_info{$id}{name}, \%{$data_info{$id}}, $db, $database_stat{$db}{xact_throughput}); delete $database_stat{$db}{xact_throughput}; } } } foreach my $id (sort {$a <=> $b} keys %data_info) { next if ($id ne $ID_ACTION); my %data = (); my $found = 0; foreach my $db (sort keys %database_stat) { next if ($DATABASE && ($DATABASE ne 'all') && ($db ne $DATABASE)); next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB))); if ($data_info{$id}{name} eq 'database-backends' || $data_info{$id}{name} eq 'cluster-backends') { $database_stat{$db}{nbackend} =~ s/,$//; $data{$db} = $database_stat{$db}{nbackend}; if (($db ne 'all') && ($DATABASE ne 'all')) { print &jqplot_linegraph_array($IDX++, $data_info{$id}{name}, \%{$data_info{$id}}, $db, $database_stat{$db}{nbackend}); } delete $database_stat{$db}{nbackend}; } elsif ($has_conflict && ($data_info{$id}{name} =~ /(database|cluster)-canceled_queries/)) { $database_stat{$db}{canceled_queries} =~ s/,$//; $data{$db} = $database_stat{$db}{canceled_queries}; if (($db ne 'all') && ($DATABASE ne 'all')) { print &jqplot_linegraph_array($IDX++, $data_info{$id}{name}, \%{$data_info{$id}}, $db, $database_stat{$db}{canceled_queries}); } delete $database_stat{$db}{canceled_queries}; } elsif ($has_temp && ($data_info{$id}{name} =~ /(database|cluster)-deadlocks/)) { $database_stat{$db}{deadlocks} =~ s/,$//; $data{$db} = $database_stat{$db}{deadlocks}; if (($db ne 'all') && ($DATABASE ne 'all')) { print &jqplot_linegraph_array($IDX++, $data_info{$id}{name}, \%{$data_info{$id}}, $db, $database_stat{$db}{deadlocks}); } delete $database_stat{$db}{deadlocks}; } elsif ($has_temp && ($data_info{$id}{name} =~ /(database|cluster)-temporary_files/)) { $database_stat{$db}{temp_files} =~ s/,$//; $data{$db} = $database_stat{$db}{temp_files}; if (($db ne 'all') && ($DATABASE ne 'all')) { print &jqplot_linegraph_array($IDX++, $data_info{$id}{name}, \%{$data_info{$id}}, $db, $database_stat{$db}{temp_files}); } delete $database_stat{$db}{temp_files}; } elsif ($has_temp && ($data_info{$id}{name} =~ /(database|cluster)-temporary_bytes/)) { $database_stat{$db}{temp_bytes} =~ s/,$//; $data{$db} = $database_stat{$db}{temp_bytes}; if (($db ne 'all') && ($DATABASE ne 'all')) { print &jqplot_linegraph_array($IDX++, $data_info{$id}{name}, \%{$data_info{$id}}, $db, $database_stat{$db}{temp_bytes}); } delete $database_stat{$db}{temp_bytes}; } } if ($db_glob eq 'all') { my $name = $data_info{$id}{name}; $name =~ s/^database/cluster/; if ($has_temp && ($data_info{$id}{name} =~ /(database|cluster)-temporary_files/)) { print &jqplot_linegraph_hash($IDX++, $name, \%{$data_info{$id}}, 'all', %data); } if ($has_temp && ($data_info{$id}{name} =~ /(database|cluster)-temporary_bytes/)) { print &jqplot_linegraph_hash($IDX++, $name, \%{$data_info{$id}}, 'all', %data); } if ($data_info{$id}{name} =~ /(database|cluster)-backends/) { print &jqplot_linegraph_hash($IDX++, $name, \%{$data_info{$id}}, 'all', %data); } if ($has_temp && $data_info{$id}{name} =~ /(database|cluster)-deadlocks/) { print &jqplot_linegraph_hash($IDX++, $name, \%{$data_info{$id}}, 'all', %data); } if ($has_conflict && ($data_info{$id}{name} =~ /(database|cluster)-canceled_queries/)) { print &jqplot_linegraph_hash($IDX++, $name, \%{$data_info{$id}}, 'all', %data); } } } } # Compute statistics of database conflict statistics sub pg_stat_database_conflicts { my ($input_dir, $file, $offset) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my %start_vals = (); my $tmp_val = 0; # Load data from file my $curfh = open_filehdl("$input_dir/$file"); $curfh->seek($offset,0); while (my $l = <$curfh>) { $offset += length($l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # timestamp | datid | datname | confl_tablespace | confl_lock | confl_snapshot | confl_bufferpin | confl_deadlock # Get database size statistics push(@{$start_vals{$data[2]}}, @data) if ($#{$start_vals{$data[2]}} < 0); (($data[3] - $start_vals{$data[2]}[3]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[3] - $start_vals{$data[2]}[3]); $all_stat_database_conflicts{$data[2]}{$data[0]}{tablespace} = $tmp_val; $all_stat_database_conflicts{'all'}{$data[0]}{tablespace} = $tmp_val; (($data[4] - $start_vals{$data[2]}[4]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[4] - $start_vals{$data[2]}[4]); $all_stat_database_conflicts{$data[2]}{$data[0]}{lock} = $tmp_val; $all_stat_database_conflicts{'all'}{$data[0]}{lock} = $tmp_val; (($data[5] - $start_vals{$data[2]}[5]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[5] - $start_vals{$data[2]}[5]); $all_stat_database_conflicts{$data[2]}{$data[0]}{snapshot} += $tmp_val; $all_stat_database_conflicts{'all'}{$data[0]}{snapshot} = $tmp_val; (($data[6] - $start_vals{$data[2]}[6]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[6] - $start_vals{$data[2]}[6]); $all_stat_database_conflicts{$data[2]}{$data[0]}{bufferpin} = $tmp_val; $all_stat_database_conflicts{'all'}{$data[0]}{bufferpin} = $tmp_val; (($data[7] - $start_vals{$data[2]}[7]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[7] - $start_vals{$data[2]}[7]); $all_stat_database_conflicts{$data[2]}{$data[0]}{deadlock} = $tmp_val; $all_stat_database_conflicts{'all'}{$data[0]}{deadlock} = $tmp_val; @{$start_vals{$data[2]}} = (); push(@{$start_vals{$data[2]}}, @data); } $curfh->close(); return $offset; } # Compute graphs of database conflict statistics sub pg_stat_database_conflicts_report { my ($src_base, $db_glob, %data_info) = @_; my %database_stat = (); my $id = &get_data_id($ACTION, %data_info); my $total_val = 0; my $tz = ($STATS_TIMEZONE*3600*1000); my %conflict_type = (); foreach my $db (sort keys %all_stat_database_conflicts) { next if ($DATABASE && ($DATABASE ne 'all') && ($db ne $DATABASE)); next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB))); foreach my $t (sort {$a <=> $b} keys %{$all_stat_database_conflicts{$db}}) { $conflict_type{$db}{tablespace} .= '[' . ($t - $tz) . ',' . ($all_stat_database_conflicts{$db}{$t}{tablespace} || 0) . '],'; $conflict_type{$db}{lock} .= '[' . ($t - $tz) . ',' . ($all_stat_database_conflicts{$db}{$t}{lock} || 0) . '],'; $conflict_type{$db}{snapshot} .= '[' . ($t - $tz) . ',' . ($all_stat_database_conflicts{$db}{$t}{snapshot} || 0) . '],'; $conflict_type{$db}{bufferpin} .= '[' . ($t - $tz) . ',' . ($all_stat_database_conflicts{$db}{$t}{bufferpin} || 0) . '],'; $conflict_type{$db}{deadlock} .= '[' . ($t - $tz) . ',' . ($all_stat_database_conflicts{$db}{$t}{deadlock} || 0) . '],'; } $conflict_type{$db}{tablespace} =~ s/,$//; $conflict_type{$db}{lock} =~ s/,$//; $conflict_type{$db}{snapshot} =~ s/,$//; $conflict_type{$db}{bufferpin} =~ s/,$//; $conflict_type{$db}{deadlock} =~ s/,$//; print &jqplot_linegraph_array($IDX++, $data_info{$id}{name}, \%{$data_info{$id}}, $db, $conflict_type{$db}{tablespace}, $conflict_type{$db}{lock}, $conflict_type{$db}{snapshot}, $conflict_type{$db}{bufferpin}, $conflict_type{$db}{deadlock}); } %all_stat_database_conflicts = (); } # Compute statistics of database size statistics sub pg_database_size { my ($input_dir, $file, $offset) = @_; my %db_list = (); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); $curfh->seek($offset,0); while (my $l = <$curfh>) { $offset += length($l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # date_trunc | datid | datname | size # Store list of database $db_list{$data[2]} = 1; # Get database size statistics if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) { $all_database_size{$data[0]}{$data[2]} = $data[3]; $all_database_size{$data[0]}{'all'} += $data[3]; } else { $OVERALL_STATS{'database'}{$data[2]}{'size'} = $data[3]; $OVERALL_STATS{'start_date'} = $data[0] if (!$OVERALL_STATS{'start_date'} || ($OVERALL_STATS{'start_date'} gt $data[0])); $OVERALL_STATS{'end_date'} = $data[0] if (!$OVERALL_STATS{'end_date'} || ($OVERALL_STATS{'end_date'} lt $data[0])); } } $curfh->close(); # Store the full list of database foreach my $d (keys %db_list) { push(@global_databases, $d) if (!grep/^$d$/, @global_databases); } push(@global_databases, 'all') if (($#global_databases >= 0) && !grep(/^all$/, @global_databases)); return $offset; } # Compute graphs of database size statistics sub pg_database_size_report { my ($src_base, $db_glob, %data_info) = @_; my %database_stat = (); my $total_val = 0; my $tz = ($STATS_TIMEZONE*3600*1000); foreach my $t (sort {$a <=> $b} keys %all_database_size) { foreach my $db (@global_databases) { next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB))); $database_stat{$db}{size} .= '[' . ($t - $tz) . ',' . ($all_database_size{$t}{$db} || 0) . '],'; } } %all_database_size = (); my $id = &get_data_id($ACTION, %data_info); my %data = (); foreach my $db (sort keys %database_stat) { next if ($DATABASE && ($DATABASE ne 'all') && ($db ne $DATABASE)); next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB))); $database_stat{$db}{size} =~ s/,$//; $data{$db} = $database_stat{$db}{size}; if (($db ne 'all') && ($DATABASE ne 'all') && ($ACTION !~ /^cluster/)) { print &jqplot_linegraph_array($IDX++, 'database-size', \%{$data_info{$id}}, $db, $database_stat{$db}{size}); } delete $database_stat{$db}{size}; } if ($ACTION eq 'cluster-size') { print &jqplot_linegraph_hash($IDX++, 'cluster-size', \%{$data_info{$id}}, 'all', %data); } } # Compute statistics of tablespace size sub pg_tablespace_size { my ($input_dir, $file, $offset) = @_; # Load data from file my $curfh = open_filehdl("$input_dir/$file"); my $total_val = 0; $curfh->seek($offset,0); while (my $l = <$curfh>) { $offset += length($l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # timestamp | tbspname | size | path push(@global_tbspnames, $data[1]) if (!grep(/^$data[1]$/, @global_tbspnames)); # Get tablespace size statistics if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) { $all_tablespace_size{$data[0]}{$data[1]}{size} = $data[2]; $all_tablespace_size{$data[0]}{$data[1]}{location} = $data[3]; $all_tablespace_size{$data[0]}{'all'}{size} += $data[2]; } else { $OVERALL_STATS{'tablespace'}{$data[1]}{'size'} = $data[2]; $OVERALL_STATS{'tablespace'}{$data[1]}{'location'} = $data[3]; } } $curfh->close(); push(@global_tbspnames, 'all') if ($#global_tbspnames > 0); return $offset; } # Compute graphs of tablespace size sub pg_tablespace_size_report { my ($src_base, $db, %data_info) = @_; my $id = &get_data_id('tablespace-size', %data_info); my %data = (); my $print_after = ''; my %tablespace_stat = (); my $tz = ($STATS_TIMEZONE*3600*1000); foreach my $time (sort {$a <=> $b} keys %all_tablespace_size) { foreach my $tbsp (@global_tbspnames) { $tablespace_stat{$tbsp}{size} .= '[' . ($time - $tz) . ',' . ($all_tablespace_size{$time}{$tbsp}{size}||0) . '],'; $tablespace_stat{$tbsp}{location} = $all_tablespace_size{$time}{$tbsp}{location} || ''; } } foreach my $tbsp (sort keys %tablespace_stat) { $tablespace_stat{$tbsp}{size} =~ s/,$//; $data{$tbsp} = $tablespace_stat{$tbsp}{size}; if ($tbsp ne 'all') { $print_after .= "

    $tbsp ($tablespace_stat{$tbsp}{location})

    \n"; } } %all_tablespace_size = (); print &jqplot_linegraph_hash($IDX++, 'tablespace-size', \%{$data_info{$id}}, 'all', %data); print $print_after; } # Compute statistics about table accesses and vacuum sub pg_stat_user_tables { my ($input_dir, $file) = @_; %all_stat_user_tables = (); my %start_vals = (); my $tmp_val = 0; # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if (!$l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # timestamp | dbname | relid | schemaname | relname | seq_scan | seq_tup_read | idx_scan | idx_tup_fetch | n_tup_ins | n_tup_upd | n_tup_del | n_tup_hot_upd | n_live_tup | n_dead_tup | last_vacuum | last_autovacuum | last_analyze | last_autoanalyze | vacuum_count | autovacuum_count | analyze_count | autoanalyze_count if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ) { $OVERALL_STATS{'database'}{$data[1]}{last_vacuum} = $data[15] if (!$OVERALL_STATS{'database'}{$data[1]}{last_vacuum} || ($data[15] gt $OVERALL_STATS{'database'}{$data[1]}{last_vacuum})); $OVERALL_STATS{'database'}{$data[1]}{last_autovacuum} = $data[16] if (!$OVERALL_STATS{'database'}{$data[1]}{last_autovacuum} || ($data[16] gt $OVERALL_STATS{'database'}{$data[1]}{last_autovacuum})); $OVERALL_STATS{'database'}{$data[1]}{last_analyze} = $data[17] if (!$OVERALL_STATS{'database'}{$data[1]}{last_analyze} || ($data[17] gt $OVERALL_STATS{'database'}{$data[1]}{last_analyze})); $OVERALL_STATS{'database'}{$data[1]}{last_autoanalyze} = $data[18] if (!$OVERALL_STATS{'database'}{$data[1]}{last_autoanalyze} || ($data[18] gt $OVERALL_STATS{'database'}{$data[1]}{last_autoanalyze})); } else { next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB))); $data[4] = "$data[3].$data[4]"; push(@{$start_vals{$data[1]}{$data[4]}}, @data) if ($#{$start_vals{$data[1]}{$data[4]}} < 0); # Stores last manual vacuum/analyze $all_stat_user_tables{$data[1]}{$data[4]}{last_vacuum} = $data[15] if ($data[15]); $all_stat_user_tables{$data[1]}{$data[4]}{last_autovacuum} = $data[16] if ($data[16]); $all_stat_user_tables{$data[1]}{$data[4]}{last_analyze} = $data[17] if ($data[17]); $all_stat_user_tables{$data[1]}{$data[4]}{last_autoanalyze} = $data[18] if ($data[18]); # Get database statistics (($data[5] - $start_vals{$data[1]}{$data[4]}[5]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[5] - $start_vals{$data[1]}{$data[4]}[5]); $all_vacuum_stat{$data[1]}{$data[4]}{seq_scan} += $tmp_val; $all_stat_user_tables{$data[1]}{$data[4]}{seq_scan} = $data[5] || 0; (($data[7] - $start_vals{$data[1]}{$data[4]}[7]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[7] - $start_vals{$data[1]}{$data[4]}[7]); $all_vacuum_stat{$data[1]}{$data[4]}{idx_scan} += $tmp_val; $all_stat_user_tables{$data[1]}{$data[4]}{idx_scan} = $data[6] || 0; (($data[9] - $start_vals{$data[1]}{$data[4]}[9]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[9] - $start_vals{$data[1]}{$data[4]}[9]); $all_vacuum_stat{$data[1]}{$data[4]}{n_tup_ins} += $tmp_val; $all_stat_user_tables{$data[1]}{$data[4]}{n_tup_ins} = $data[9] || 0; (($data[10] - $start_vals{$data[1]}{$data[4]}[10]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[10] - $start_vals{$data[1]}{$data[4]}[10]); $all_vacuum_stat{$data[1]}{$data[4]}{n_tup_upd} += $tmp_val; $all_stat_user_tables{$data[1]}{$data[4]}{n_tup_upd} = $data[10] || 0; (($data[11] - $start_vals{$data[1]}{$data[4]}[11]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[11] - $start_vals{$data[1]}{$data[4]}[11]); $all_vacuum_stat{$data[1]}{$data[4]}{n_tup_del} += $tmp_val; $all_stat_user_tables{$data[1]}{$data[4]}{n_tup_del} = $data[11] || 0; (($data[12] - $start_vals{$data[1]}{$data[4]}[12]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[12] - $start_vals{$data[1]}{$data[4]}[12]); $all_vacuum_stat{$data[1]}{$data[4]}{n_tup_hot_upd} += $tmp_val; $all_stat_user_tables{$data[1]}{$data[4]}{n_tup_hot_upd} = $data[12] || 0; $all_stat_user_tables{$data[1]}{$data[4]}{n_dead_tup} = $data[14]; $all_stat_user_tables{$data[1]}{$data[4]}{n_live_tup} = $data[13]; $all_stat_user_tables{$data[1]}{$data[4]}{dead_vs_live} = sprintf("%.2f", ($data[14]*100)/(($data[13]+$data[14])||1)); if ($#data > 19) { (($data[19] - $start_vals{$data[1]}{$data[4]}[19]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[19] - $start_vals{$data[1]}{$data[4]}[19]); $all_vacuum_stat{$data[1]}{$data[4]}{vacuum_count} += $tmp_val; $all_stat_user_tables{$data[1]}{$data[4]}{vacuum_count} = $data[19]; (($data[20] - $start_vals{$data[1]}{$data[4]}[20]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[20] - $start_vals{$data[1]}{$data[4]}[20]); $all_vacuum_stat{$data[1]}{$data[4]}{autovacuum_count} += $tmp_val; $all_stat_user_tables{$data[1]}{$data[4]}{autovacuum_count} = $data[20]; (($data[21] - $start_vals{$data[1]}{$data[4]}[21]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[21] - $start_vals{$data[1]}{$data[4]}[21]); $all_vacuum_stat{$data[1]}{$data[4]}{analyze_count} += $tmp_val; $all_stat_user_tables{$data[1]}{$data[4]}{analyze_count} = $data[21]; (($data[22] - $start_vals{$data[1]}{$data[4]}[22]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[22] - $start_vals{$data[1]}{$data[4]}[22]); $all_vacuum_stat{$data[1]}{$data[4]}{autoanalyze_count} += $tmp_val; $all_stat_user_tables{$data[1]}{$data[4]}{autoanalyze_count} = $data[22]; } @{$start_vals{$data[1]}{$data[4]}} = (); push(@{$start_vals{$data[1]}{$data[4]}}, @data); } } $curfh->close(); } sub pg_stat_all_tables { return &pg_stat_user_tables; } # Compute report about table accesses sub pg_stat_user_tables_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); return if (!$db); my $do_vacuum = 0; foreach my $t (keys %{$all_vacuum_stat{$db}}) { foreach my $k (keys %{$all_vacuum_stat{$db}{$t}}) { if (($k =~ /vacuum|analyze/) && $all_vacuum_stat{$db}{$t}{$k}) { $do_vacuum = 1; } } } foreach my $id (sort {$a <=> $b} keys %data_info) { next if ($id ne $ID_ACTION); next if ($data_info{$id}{name} !~ /^table-/); next if ($data_info{$id}{name} ne $REAL_ACTION); my $table_header = ''; my $colspan = ''; if ($data_info{$id}{name} eq 'table-indexes') { $table_header = qq{ Schema.Table Sequencial scan Index scan Index vs Sequencial }; $colspan = ' colspan="5"'; } elsif ($data_info{$id}{name} eq 'table-query-tuples') { $table_header = qq{ Schema.Table Inserted Updated Deleted Hot Updated }; $colspan = ' colspan="6"'; } elsif ($data_info{$id}{name} eq 'table-kind-tuples') { $table_header = qq{ Schema.Table Live tuples Dead tuples Dead vs Live }; $colspan = ' colspan="5"'; } elsif ( $do_vacuum && ($data_info{$id}{name} eq 'table-vacuums-analyzes') ) { $table_header = qq{ Schema.Table Vacuum Autovacuum Analyze Autoanalyze Last vacuum Last autovacuum Last analyze Last autoanalyze }; $colspan = ' colspan="10"'; } if (scalar keys %{$all_vacuum_stat{$db}} == 0) { $table_header = qq{
    NO DATASET
    }; } print qq{




    • $data_info{$id}{menu} on $db database tables

      $data_info{$id}{description}

      $table_header }; foreach my $tb (sort keys %{$all_vacuum_stat{$db}}) { next if ($tb eq 'all'); next if (($#INCLUDE_TB >= 0) && !grep(/^$tb$/, @INCLUDE_TB)); my $table_data = ''; if ($data_info{$id}{name} eq 'table-indexes') { if (!$all_vacuum_stat{$db}{$tb}{seq_scan} && !$all_vacuum_stat{$db}{$tb}{idx_scan}) { next; foreach ('idx_scan','seq_scan') { $all_stat_user_tables{$db}{$tb}{$_} ||= 0; } $all_stat_user_tables{$db}{$tb}{idx_scan_vs_seq_scan} = sprintf("%0.2f", ($all_stat_user_tables{$db}{$tb}{idx_scan}*100)/(($all_stat_user_tables{$db}{$tb}{seq_scan}+$all_stat_user_tables{$db}{$tb}{idx_scan})||1)); $table_data = qq{}; } else { foreach ('idx_scan','seq_scan') { $all_vacuum_stat{$db}{$tb}{$_} ||= 0; } $all_vacuum_stat{$db}{$tb}{idx_scan_vs_seq_scan} = sprintf("%0.2f", ($all_vacuum_stat{$db}{$tb}{idx_scan}*100)/(($all_vacuum_stat{$db}{$tb}{seq_scan}+$all_vacuum_stat{$db}{$tb}{idx_scan})||1)); $table_data = qq{}; } } elsif ($data_info{$id}{name} eq 'table-query-tuples') { if (!$all_vacuum_stat{$db}{$tb}{n_tup_ins} && !$all_vacuum_stat{$db}{$tb}{n_tup_upd} && !$all_vacuum_stat{$db}{$tb}{n_tup_del} && !$all_vacuum_stat{$db}{$tb}{n_tup_hot_upd}) { next; foreach ('n_tup_ins','n_tup_upd','n_tup_del','n_tup_hot_upd') { $all_stat_user_tables{$db}{$tb}{$_} ||= 0; } $table_data = qq{}; } else { foreach ('n_tup_ins','n_tup_upd','n_tup_del','n_tup_hot_upd') { $all_vacuum_stat{$db}{$tb}{$_} ||= 0; } $table_data = qq{}; } } elsif ($data_info{$id}{name} eq 'table-kind-tuples') { if (!$all_stat_user_tables{$db}{$tb}{n_live_tup} && !$all_stat_user_tables{$db}{$tb}{n_dead_tup}) { next; } foreach ('n_live_tup','n_dead_tup','dead_vs_live') { $all_stat_user_tables{$db}{$tb}{$_} ||= 0; } $table_data = qq{}; } elsif ( $do_vacuum && ($data_info{$id}{name} eq 'table-vacuums-analyzes') ) { if (!$all_vacuum_stat{$db}{$tb}{vacuum_count} && !$all_vacuum_stat{$db}{$tb}{autovacuum_count} && !$all_vacuum_stat{$db}{$tb}{analyze_count} && !$all_vacuum_stat{$db}{$tb}{analyze_count}) { next; foreach ('vacuum_count','autovacuum_count','analyze_count','autoanalyze_count') { $all_stat_user_tables{$db}{$tb}{$_} ||= 0; } $table_data = qq{}; } else { foreach ('vacuum_count','autovacuum_count','analyze_count','autoanalyze_count') { $all_vacuum_stat{$db}{$tb}{$_} ||= 0; } $table_data = qq{}; } foreach ('last_vacuum','last_autovacuum','last_analyze','last_autoanalyze') { $all_stat_user_tables{$db}{$tb}{$_} ||= '-'; } $table_data .= qq{}; } if ($table_data) { print $table_data; } } print qq{
      $tb$all_stat_user_tables{$db}{$tb}{seq_scan}$all_stat_user_tables{$db}{$tb}{idx_scan}$all_stat_user_tables{$db}{$tb}{idx_scan_vs_seq_scan}%
      $tb$all_vacuum_stat{$db}{$tb}{seq_scan}$all_vacuum_stat{$db}{$tb}{idx_scan}$all_vacuum_stat{$db}{$tb}{idx_scan_vs_seq_scan}%
      $tb$all_stat_user_tables{$db}{$tb}{n_tup_ins}$all_stat_user_tables{$db}{$tb}{n_tup_upd}$all_stat_user_tables{$db}{$tb}{n_tup_del}$all_stat_user_tables{$db}{$tb}{n_tup_hot_upd}
      $tb$all_vacuum_stat{$db}{$tb}{n_tup_ins}$all_vacuum_stat{$db}{$tb}{n_tup_upd}$all_vacuum_stat{$db}{$tb}{n_tup_del}$all_vacuum_stat{$db}{$tb}{n_tup_hot_upd}
      $tb$all_stat_user_tables{$db}{$tb}{n_live_tup}$all_stat_user_tables{$db}{$tb}{n_dead_tup}$all_stat_user_tables{$db}{$tb}{dead_vs_live}%
      $tb$all_stat_user_tables{$db}{$tb}{vacuum_count}$all_stat_user_tables{$db}{$tb}{autovacuum_count}$all_stat_user_tables{$db}{$tb}{analyze_count}$all_stat_user_tables{$db}{$tb}{autoanalyze_count}
      $tb$all_vacuum_stat{$db}{$tb}{vacuum_count}$all_vacuum_stat{$db}{$tb}{autovacuum_count}$all_vacuum_stat{$db}{$tb}{analyze_count}$all_vacuum_stat{$db}{$tb}{autoanalyze_count}$all_stat_user_tables{$db}{$tb}{last_vacuum}$all_stat_user_tables{$db}{$tb}{last_autovacuum}$all_stat_user_tables{$db}{$tb}{last_analyze}$all_stat_user_tables{$db}{$tb}{last_autoanalyze}
    }; } %all_stat_user_tables = (); } # Compute statistics about index scan sub pg_stat_user_indexes { my ($input_dir, $file) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); %all_stat_user_indexes = (); my %start_vals = (); my $tmp_val = 0; # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if (!$l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # timestamp | dbname | relid | indexrelid | schemaname | relname | indexrelname | idx_scan | idx_tup_read | idx_tup_fetch next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB))); $data[6] = "$data[4].$data[5].$data[6]"; push(@{$start_vals{$data[1]}{$data[6]}}, @data) if ($#{$start_vals{$data[1]}{$data[6]}} < 0); # Get database statistics (($data[7] - $start_vals{$data[1]}{$data[6]}[7]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[7] - $start_vals{$data[1]}{$data[6]}[7]); $all_stat_user_indexes{$data[1]}{$data[6]}{idx_scan} += $tmp_val; (($data[8] - $start_vals{$data[1]}{$data[6]}[8]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[8] - $start_vals{$data[1]}{$data[6]}[8]); $all_stat_user_indexes{$data[1]}{$data[6]}{idx_tup_read} += $tmp_val; (($data[9] - $start_vals{$data[1]}{$data[6]}[9]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[9] - $start_vals{$data[1]}{$data[6]}[9]); $all_stat_user_indexes{$data[1]}{$data[6]}{idx_tup_fetch} += $tmp_val; @{$start_vals{$data[1]}{$data[6]}} = (); push(@{$start_vals{$data[1]}{$data[6]}}, @data); } $curfh->close(); } sub pg_stat_all_indexes { return &pg_stat_user_indexes; } # Compute report about index scan sub pg_stat_user_indexes_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); return if (!$db); foreach my $id (sort {$a <=> $b} keys %data_info) { next if ($id ne $ID_ACTION); next if ($data_info{$id}{name} !~ /^index-/); my $table_header = ''; my $colspan = ' colspan="4"'; if ($data_info{$id}{name} eq 'index-scan') { $table_header = qq{ Schema.Table.Index Index scan Index entries returned Live table rows fetched }; } if (scalar keys %{$all_stat_user_indexes{$db}} == 0) { $table_header = qq{
    NO DATASET
    }; } print qq{




    • $data_info{$id}{menu} on $db database indexes

      $data_info{$id}{description}

      $table_header }; my $found_table_stat = 0; foreach my $idx (sort keys %{$all_stat_user_indexes{$db}}) { next if ($idx eq 'all'); next if (($#INCLUDE_TB >= 0) && !grep(/^$idx$/, @INCLUDE_TB)); my $table_data = ''; if ($data_info{$id}{name} eq 'index-scan') { if (!$all_stat_user_indexes{$db}{$idx}{idx_scan} && !$all_stat_user_indexes{$db}{$idx}{idx_tup_read} && !$all_stat_user_indexes{$db}{$idx}{idx_tup_fetch}) { next; } foreach ('idx_scan','idx_tup_read','idx_tup_fetch') { $all_stat_user_indexes{$db}{$idx}{$_} ||= 0; } $table_data = qq{}; } if ($table_data) { print $table_data; } } print qq{
      $idx$all_stat_user_indexes{$db}{$idx}{idx_scan}$all_stat_user_indexes{$db}{$idx}{idx_tup_read}$all_stat_user_indexes{$db}{$idx}{idx_tup_fetch}
    }; } %all_stat_user_indexes = (); } # Compute statistics about invalid index sub pg_stat_invalid_indexes { my ($input_dir, $file) = @_; %all_stat_invalid_indexes = (); my %start_vals = (); my $tmp_val = 0; # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if (!$l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # timestamp | dbname | schemaname | relname | indexrelname | index_definition $all_stat_invalid_indexes{$data[1]}{$data[2]}{$data[3]}{$data[4]} = $data[5]; $OVERALL_STATS{'database'}{$data[1]}{invalid_indexes}++; $OVERALL_STATS{'cluster'}{invalid_indexes}++; push(@{$OVERALL_STATS{'cluster'}{invalid_indexes_db}}, $data[1]) if (!grep(/^$data[1]$/, @{$OVERALL_STATS{'cluster'}{invalid_indexes_db}})); } $curfh->close(); } # Compute report about invalid index sub pg_stat_invalid_indexes_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); return if (!$db); foreach my $id (sort {$a <=> $b} keys %data_info) { next if ($id ne $ID_ACTION); next if ($data_info{$id}{name} ne 'index-invalid'); my $table_header = ''; my $colspan = ' colspan="4"'; print qq{

      $data_info{$id}{menu} on $db database

      $data_info{$id}{description}

      }; my $found_stat = 0; foreach my $sch (sort keys %{$all_stat_invalid_indexes{$db}}) { foreach my $tb (sort keys %{$all_stat_invalid_indexes{$db}{$sch}}) { next if (($#INCLUDE_TB >= 0) && !grep(/^$tb$/, @INCLUDE_TB)); $found_stat = 1; foreach my $idx (sort keys %{$all_stat_invalid_indexes{$db}{$sch}{$tb}}) { print qq{}; } } } if (!$found_stat) { print qq{
      NO DATASET
      }; } print qq{
      Schema Table Index name Index definition
      $sch$tb$idx$all_stat_invalid_indexes{$db}{$sch}{$tb}{$idx}
      }; # Terminate cluster statistics file print qq{
      }; } %all_stat_invalid_indexes = (); } # Compute statistics about unlogged tables sub pg_stat_unlogged { my ($input_dir, $file) = @_; %all_stat_unlogged = (); my %start_vals = (); my $tmp_val = 0; # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if (!$l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # timestamp | dbname | schemaname | relname | relkind $all_stat_unlogged{$data[1]}{$data[2]}{$data[3]} = $data[4]; $OVERALL_STATS{'database'}{$data[1]}{unlogged}++; $OVERALL_STATS{'cluster'}{unlogged}++; push(@{$OVERALL_STATS{'cluster'}{unlogged_db}}, $data[1]) if (!grep(/^$data[1]$/, @{$OVERALL_STATS{'cluster'}{unlogged_db}})); } $curfh->close(); } # Compute report about unlogged tables sub pg_stat_unlogged_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); return if (!$db); foreach my $id (sort {$a <=> $b} keys %data_info) { next if ($id ne $ID_ACTION); next if ($data_info{$id}{name} ne 'table-unlogged'); my $table_header = ''; my $colspan = ' colspan="2"'; print qq{

        $data_info{$id}{menu} on $db database

        $data_info{$id}{description}

        }; my $found_stat = 0; foreach my $sch (sort keys %{$all_stat_unlogged{$db}}) { foreach my $tb (sort keys %{$all_stat_unlogged{$db}{$sch}}) { next if (($#INCLUDE_TB >= 0) && !grep(/^$tb$/, @INCLUDE_TB)); $found_stat = 1; print qq{}; } } if (!$found_stat) { print qq{
        NO DATASET
        }; } print qq{
        Schema Table
        $sch$tb
        }; # Terminate cluster statistics file print qq{
        }; } %all_stat_unlogged = (); } # Compute statistics about hash index sub pg_stat_hash_indexes { my ($input_dir, $file) = @_; %all_stat_hash_indexes = (); my %start_vals = (); my $tmp_val = 0; # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if (!$l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # timestamp | dbname | schemaname | relname | indexrelname | index_definition $all_stat_hash_indexes{$data[1]}{$data[2]}{$data[3]}{$data[4]} = $data[5]; $OVERALL_STATS{'database'}{$data[1]}{hash_indexes}++; $OVERALL_STATS{'cluster'}{hash_indexes}++; push(@{$OVERALL_STATS{'cluster'}{hash_indexes_db}}, $data[1]) if (!grep(/^$data[1]$/, @{$OVERALL_STATS{'cluster'}{hash_indexes_db}})); } $curfh->close(); } # Compute report about hash index sub pg_stat_hash_indexes_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); return if (!$db); foreach my $id (sort {$a <=> $b} keys %data_info) { next if ($id ne $ID_ACTION); next if ($data_info{$id}{name} ne 'index-hash'); my $table_header = ''; my $colspan = ' colspan="4"'; print qq{

          $data_info{$id}{menu} on $db database

          $data_info{$id}{description}

          }; my $found_stat = 0; foreach my $sch (sort keys %{$all_stat_hash_indexes{$db}}) { foreach my $tb (sort keys %{$all_stat_hash_indexes{$db}{$sch}}) { next if (($#INCLUDE_TB >= 0) && !grep(/^$tb$/, @INCLUDE_TB)); $found_stat = 1; foreach my $idx (sort keys %{$all_stat_hash_indexes{$db}{$sch}{$tb}}) { print qq{}; } } } if (!$found_stat) { print qq{
          NO DATASET
          }; } print qq{
          Schema Table Index name Index definition
          $sch$tb$idx$all_stat_hash_indexes{$db}{$sch}{$tb}{$idx}
          }; # Terminate cluster statistics file print qq{
          }; } %all_stat_hash_indexes = (); } # Compute stats for table I/O sub pg_statio_user_tables { my ($input_dir, $file, $offset) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my %start_vals = (); my $tmp_val = 0; # Load data from file my $curfh = open_filehdl("$input_dir/$file"); $curfh->seek($offset,0); while (my $l = <$curfh>) { $offset += length($l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # timestamp | dbname | relid | schemaname | relname | heap_blks_read | heap_blks_hit | idx_blks_read | idx_blks_hit | toast_blks_read | toast_blks_hit | tidx_blks_read | tidx_blks_hit next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB))); $data[4] = "$data[3].$data[4]"; push(@{$start_vals{$data[1]}{$data[4]}}, @data) if ($#{$start_vals{$data[1]}{$data[4]}} < 0); # Store interval between previous run $all_statio_user_tables{$data[1]}{$data[4]}{interval} = ($data[0] - $start_vals{$data[1]}{$data[4]}[0])/1000; (($data[5] - $start_vals{$data[1]}{$data[4]}[5]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[5] - $start_vals{$data[1]}{$data[4]}[5]); $all_statio_user_tables{$data[1]}{$data[4]}{heap_blks_read} += $tmp_val; (($data[6] - $start_vals{$data[1]}{$data[4]}[6]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[6] - $start_vals{$data[1]}{$data[4]}[6]); $all_statio_user_tables{$data[1]}{$data[4]}{heap_blks_hit} += $tmp_val; (($data[7] - $start_vals{$data[1]}{$data[4]}[7]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[7] - $start_vals{$data[1]}{$data[4]}[7]); $all_statio_user_tables{$data[1]}{$data[4]}{idx_blks_read} += $tmp_val; (($data[8] - $start_vals{$data[1]}{$data[4]}[8]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[8] - $start_vals{$data[1]}{$data[4]}[8]); $all_statio_user_tables{$data[1]}{$data[4]}{idx_blks_hit} += $tmp_val; (($data[9] - $start_vals{$data[1]}{$data[4]}[9]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[9] - $start_vals{$data[1]}{$data[4]}[9]); $all_statio_user_tables{$data[1]}{$data[4]}{toast_blks_read} += $tmp_val; (($data[10] - $start_vals{$data[1]}{$data[4]}[10]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[10] - $start_vals{$data[1]}{$data[4]}[10]); $all_statio_user_tables{$data[1]}{$data[4]}{toast_blks_hit} += $tmp_val; (($data[11] - $start_vals{$data[1]}{$data[4]}[11]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[11] - $start_vals{$data[1]}{$data[4]}[11]); $all_statio_user_tables{$data[1]}{$data[4]}{tidx_blks_read} += $tmp_val; (($data[12] - $start_vals{$data[1]}{$data[4]}[12]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[12] - $start_vals{$data[1]}{$data[4]}[12]); $all_statio_user_tables{$data[1]}{$data[4]}{tidx_blks_hit} += $tmp_val; @{$start_vals{$data[1]}{$data[4]}} = (); push(@{$start_vals{$data[1]}{$data[4]}}, @data); } $curfh->close(); return $offset; } # Compute report for table I/O sub pg_statio_user_tables_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); return if (!$db); foreach my $id (sort {$a <=> $b} keys %data_info) { next if ($id ne $ID_ACTION); next if ($data_info{$id}{name} !~ /^statio-table/); next if ($data_info{$id}{name} ne $REAL_ACTION); my $colspan = ''; my $table_header = qq{ Schema.Table Table blocks read Table blocks hit Index blocks read Index blocks hit }; print qq{




          • $data_info{$id}{menu} on $db database tables

            $data_info{$id}{description}

            $table_header }; my $data_found = 0; foreach my $tb (sort keys %{$all_statio_user_tables{$db}}) { next if ($tb eq 'all'); next if (($#INCLUDE_TB >= 0) && !grep(/^$tb$/, @INCLUDE_TB)); my $table_data = ''; $all_statio_user_tables{$db}{$tb}{idx_blks_read} ||= 0; $all_statio_user_tables{$db}{$tb}{heap_blks_read} ||= 0; $all_statio_user_tables{$db}{$tb}{heap_blks_hit} ||= 0; $all_statio_user_tables{$db}{$tb}{idx_blks_hit} ||= 0; $all_statio_user_tables{$db}{$tb}{toast_blks_read} ||= 0; $all_statio_user_tables{$db}{$tb}{toast_blks_hit} ||= 0; $all_statio_user_tables{$db}{$tb}{tidx_blks_read} ||= 0; $all_statio_user_tables{$db}{$tb}{tidx_blks_hit} ||= 0; # if this is a toast table override the normal table values for easy use if ($all_statio_user_tables{$db}{$tb}{toast_blks_read} || $all_statio_user_tables{$db}{$tb}{toast_blks_hit} || $all_statio_user_tables{$db}{$tb}{tidx_blks_read} || $all_statio_user_tables{$db}{$tb}{tidx_blks_hit} ) { $table_data = qq{}; } else { $table_data = qq{}; } if ($table_data) { print $table_data; $data_found = 1; } } if ($data_found) { $table_header = qq{}; } print qq{
            $tb$all_statio_user_tables{$db}{$tb}{toast_blks_read}$all_statio_user_tables{$db}{$tb}{toast_blks_hit}$all_statio_user_tables{$db}{$tb}{tidx_blks_read}$all_statio_user_tables{$db}{$tb}{tidx_blks_hit}
            $tb$all_statio_user_tables{$db}{$tb}{heap_blks_read}$all_statio_user_tables{$db}{$tb}{heap_blks_hit}$all_statio_user_tables{$db}{$tb}{idx_blks_read}$all_statio_user_tables{$db}{$tb}{idx_blks_hit}
            NO DATASET
          }; } %all_stat_user_tables = (); } # Compute stats for relation buffer cache sub pg_relation_buffercache { my ($input_dir, $file, $offset) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my %start_vals = (); my $tmp_val = 0; # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { $offset += length($l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # date_trunc | datname | relname | buffers | relpages | buffered | buffers % | relation % next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB))); $data[7] = 100 if ($data[7] > 100); $all_relation_buffercache{$data[0]}{$data[1]}{$data[2]}{buffers} = ($data[3] || 0); $all_relation_buffercache{$data[0]}{$data[1]}{$data[2]}{pages} = ($data[4] || 0); $all_relation_buffercache{$data[0]}{$data[1]}{$data[2]}{buffered} = ($data[5] || 0); $all_relation_buffercache{$data[0]}{$data[1]}{$data[2]}{'buffers %'} = ($data[6] || 0); $all_relation_buffercache{$data[0]}{$data[1]}{$data[2]}{'relation %'} = ($data[7] || 0); } $curfh->close(); return $offset; }; # Compute report for relation buffer cache sub pg_relation_buffercache_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); return if (!$db); my %rel_stat = (); my %to_show = (); my %buffercache_stat = (); my $tz = ($STATS_TIMEZONE*3600*1000); foreach my $t (sort {$a <=> $b} keys %all_relation_buffercache) { foreach my $obj ( keys %{$all_relation_buffercache{$t}{$db}} ) { $rel_stat{$db}{$obj}{buffers} .= '[' . ($t - $tz) . ',' . ($all_relation_buffercache{$t}{$db}{$obj}{buffers} || 0) . '],'; $buffercache_stat{$db}{$obj}{buffers} = ($all_relation_buffercache{$t}{$db}{$obj}{buffers} || 0); $rel_stat{$db}{$obj}{pages} .= '[' . ($t - $tz) . ',' . ($all_relation_buffercache{$t}{$db}{$obj}{pages} || 0) . '],'; $buffercache_stat{$db}{$obj}{pages} = ($all_relation_buffercache{$t}{$db}{$obj}{pages} || 0); $rel_stat{$db}{$obj}{buffered} .= '[' . ($t - $tz) . ',' . ($all_relation_buffercache{$t}{$db}{$obj}{buffered} || 0) . '],'; $buffercache_stat{$db}{$obj}{buffered} = ($all_relation_buffercache{$t}{$db}{$obj}{buffered} || 0); $rel_stat{$db}{$obj}{'buffers %'} .= '[' . ($t - $tz) . ',' . ($all_relation_buffercache{$t}{$db}{$obj}{'buffers %'} || 0) . '],'; $buffercache_stat{$db}{$obj}{'buffers %'} = ($all_relation_buffercache{$t}{$db}{$obj}{'buffers %'} || 0); $rel_stat{$db}{$obj}{'relation %'} .= '[' . ($t - $tz) . ',' . ($all_relation_buffercache{$t}{$db}{$obj}{'relation %'} || 0) . '],'; $buffercache_stat{$db}{$obj}{'relation %'} = ($all_relation_buffercache{$t}{$db}{$obj}{'relation %'} || 0); } } %all_relation_buffercache = (); my $id = &get_data_id($ACTION, %data_info); # Get list of object in the shared buffers if ($data_info{$id}{name} eq 'buffercache-relation') { my $colspan = ' colspan="6"'; my $table_header = qq{ Relation Buffers Pages Buffered Buffers % Relation % }; if (!exists $buffercache_stat{$db} || scalar keys %{$buffercache_stat{$db}} == 0) { $table_header = qq{
          NO DATASET
          }; } print qq{




          • $data_info{$id}{menu} on $db database

            $data_info{$id}{description}

            $table_header }; my $found_stat = 0; my $rank = 1; foreach my $rel (sort {$buffercache_stat{$db}{$b}{buffers} <=> $buffercache_stat{$db}{$a}{buffers}} keys %{$buffercache_stat{$db}}) { next if (($#INCLUDE_TB >= 0) && !grep(/^$rel$/, @INCLUDE_TB)); last if ($TOP_STAT && ($rank > $TOP_STAT)); my $table_data = ''; if ($data_info{$id}{name} eq 'buffercache-relation') { if (!$buffercache_stat{$db}{$rel}{buffers} && !$buffercache_stat{$db}{$rel}{pages} && !$buffercache_stat{$db}{$rel}{buffered}) { next; } $to_show{$db}{$rel} = $rank; $table_data = "\n"; } $rank++; if ($table_data) { print $table_data; } } print qq{
            $rel$buffercache_stat{$db}{$rel}{buffers}$buffercache_stat{$db}{$rel}{pages}" . &pretty_print_size($buffercache_stat{$db}{$rel}{buffered}) . "$buffercache_stat{$db}{$rel}{'buffers %'}$buffercache_stat{$db}{$rel}{'relation %'}
          }; } # Show shared buffers usage per object if ($data_info{$id}{name} eq 'statio-buffercache') { my $rank = 1; foreach my $rel (sort {$buffercache_stat{$db}{$b}{buffers} <=> $buffercache_stat{$db}{$a}{buffers}} keys %{$buffercache_stat{$db}}) { next if (($#INCLUDE_TB >= 0) && !grep(/^$rel$/, @INCLUDE_TB)); last if ($TOP_STAT && ($rank > $TOP_STAT)); if (!$buffercache_stat{$db}{$rel}{buffers} && !$buffercache_stat{$db}{$rel}{pages} && !$buffercache_stat{$db}{$rel}{buffered}) { next; } $to_show{$db}{$rel} = $rank; $rank++; } if (exists $to_show{$db}) { foreach my $rel (sort {$to_show{$db}{$a} <=> $to_show{$db}{$b} } keys %{$to_show{$db}}) { my $graph_data = ''; foreach ('buffers','pages','buffered','buffers %','relation %') { $rel_stat{$db}{$rel}{$_} =~ s/,$//; } print &jqplot_linegraph_array($IDX++, 'statio-buffercache', \%{$data_info{$id}}, $rel, $rel_stat{$db}{$rel}{buffered},$rel_stat{$db}{$rel}{'relation %'}); } } else { print &empty_dataset('statio-buffercache', \%{$data_info{$id}}, 'on'); } } %buffercache_stat = (); } # Compute stats for index I/O sub pg_statio_user_indexes { my ($input_dir, $file, $offset) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my %start_vals = (); my $tmp_val = 0; # Load data from file my $curfh = open_filehdl("$input_dir/$file"); $curfh->seek($offset,0); while (my $l = <$curfh>) { $offset += length($l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # timestamp | dbname | relid | indexrelid | schemaname | relname | indexrelname | idx_blks_read | idx_blks_hit next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB))); $data[6] = "$data[4].$data[5].$data[6]"; push(@{$start_vals{$data[1]}{$data[6]}}, @data) if ($#{$start_vals{$data[1]}{$data[6]}} < 0); # Store interval between previous run $all_statio_user_indexes{$data[1]}{$data[6]}{interval} = ($data[0] - $start_vals{$data[1]}{$data[6]}[0])/1000; (($data[7] - $start_vals{$data[1]}{$data[6]}[7]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[7] - $start_vals{$data[1]}{$data[6]}[7]); $all_statio_user_indexes{$data[1]}{$data[6]}{idx_blks_read} += $tmp_val; (($data[8] - $start_vals{$data[1]}{$data[6]}[8]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[8] - $start_vals{$data[1]}{$data[6]}[8]); $all_statio_user_indexes{$data[1]}{$data[6]}{idx_blks_hit} += $tmp_val; @{$start_vals{$data[1]}{$data[6]}} = (); push(@{$start_vals{$data[1]}{$data[6]}}, @data); } $curfh->close(); return $offset; } # Compute report for index I/O sub pg_statio_user_indexes_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); return if (!$db); foreach my $id (sort {$a <=> $b} keys %data_info) { next if ($id ne $ID_ACTION); next if ($data_info{$id}{name} !~ /^statio-index/); my $table_header = ''; my $colspan = ' colspan="4"'; if ($data_info{$id}{name} eq 'index-scan') { $table_header = qq{ Schema.Table.Index Index blocks read Index blocks hits }; } print qq{




          • $data_info{$id}{menu} on $db database indexes

            $data_info{$id}{description}

            $table_header }; my $found_table_stat = 0; foreach my $idx (sort keys %{$all_statio_user_indexes{$db}}) { next if ($idx eq 'all'); next if (($#INCLUDE_TB >= 0) && !grep(/^$idx$/, @INCLUDE_TB)); my $table_data = ''; if (!$all_statio_user_indexes{$db}{$idx}{idx_blks_read} && !$all_statio_user_indexes{$db}{$idx}{idx_blks_hit}) { next; } $table_data = qq{}; if ($table_data) { print $table_data; $found_table_stat = 1; } } if (!$found_table_stat) { $table_header = qq{}; } print qq{
            $idx$all_statio_user_indexes{$db}{$idx}{idx_blks_read}$all_statio_user_indexes{$db}{$idx}{idx_blks_hit}
            NO DATASET
          }; } %all_stat_user_indexes = (); } # Compute statistics of xlog cluster sub pg_xlog_stat { my ($input_dir, $file, $offset) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); $curfh->seek($offset,0); while (my $l = <$curfh>) { $offset += length($l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # timestamp | total_file | last_wal_name | wal_recycled | wal_written | max_wal # case of pgstats file content if ($#data == 3) { $all_xlog_stat{$data[0]}{total}++; } else { $all_xlog_stat{$data[0]}{total} = ($data[1] || 0); if ($#data == 5) { $all_xlog_stat{$data[0]}{recycled} = ($data[3] || 0); $all_xlog_stat{$data[0]}{written} = ($data[4] || 0); $all_xlog_stat{$data[0]}{max_wal} = (POSIX::ceil($data[5]) || 0); } } } $curfh->close(); return $offset; } # Compute graphs of xlog cluster statistics sub pg_xlog_stat_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); return if (!scalar keys %all_xlog_stat); my %xlog_stat = (); my $tz = ($STATS_TIMEZONE*3600*1000); foreach my $t (sort {$a <=> $b} keys %all_xlog_stat) { $xlog_stat{total} .= '[' . ($t - $tz) . ',' . ($all_xlog_stat{$t}{total} || 0) . '],'; $xlog_stat{recycled} .= '[' . ($t - $tz) . ',' . ($all_xlog_stat{$t}{recycled} || 0) . '],'; $xlog_stat{written} .= '[' . ($t - $tz) . ',' . ($all_xlog_stat{$t}{written} || 0) . '],'; $xlog_stat{max_wal} .= '[' . ($t - $tz) . ',' . ($all_xlog_stat{$t}{max_wal} || 0) . '],'; } %all_xlog_stat = (); if ($xlog_stat{total} ) { my $id = &get_data_id('cluster-xlog_files', %data_info); $xlog_stat{total} =~ s/,$//; if (exists $xlog_stat{recycled}) { push(@{$data_info{$id}{legends}}, 'recycled', 'written', 'max_wal'); print &jqplot_linegraph_array($IDX++, 'cluster-xlog_files', \%{$data_info{$id}}, '', $xlog_stat{total}, $xlog_stat{recycled}, $xlog_stat{written}, $xlog_stat{max_wal}); } else { print &jqplot_linegraph_array($IDX++, 'cluster-xlog_files', \%{$data_info{$id}}, '', $xlog_stat{total}); } } } # Compute statistics of bgwriter cluster sub pg_stat_bgwriter { my ($input_dir, $file, $offset) = @_; return if ( $ACTION eq 'database-info' ); my @start_vals = (); my %total_count = (); my $tmp_val = 0; # Load data from file my $curfh = open_filehdl("$input_dir/$file"); $curfh->seek($offset,0); while (my $l = <$curfh>) { $offset += length($l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); if ($#data >= 9) { $OVERALL_STATS{'bgwriter'}{stats_reset} = $data[-1] if (!exists $OVERALL_STATS{'bgwriter'}{stats_reset} || ($OVERALL_STATS{'bgwriter'}{stats_reset} lt $data[-1])); } next if ($ACTION eq 'home'); push(@start_vals, @data) if ($#start_vals < 0); # Store interval between previous run $all_stat_bgwriter{$data[0]}{interval} = ($data[0] - $start_vals[0])/1000; (($data[1] - $start_vals[1]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[1] - $start_vals[1]); $all_stat_bgwriter{$data[0]}{checkpoints_timed} = $tmp_val; (($data[2] - $start_vals[2]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[2] - $start_vals[2]); $all_stat_bgwriter{$data[0]}{checkpoints_req} = $tmp_val; my $id = 0; if ($#data > 10) { $id += 2; (($data[3] - $start_vals[3]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[3] - $start_vals[3]); $all_stat_bgwriter{$data[0]}{checkpoint_write_time} = $tmp_val; (($data[4] - $start_vals[4]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[4] - $start_vals[4]); $all_stat_bgwriter{$data[0]}{checkpoint_sync_time} = $tmp_val; } (($data[3+$id] - $start_vals[3+$id]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[3+$id] - $start_vals[3+$id]); $all_stat_bgwriter{$data[0]}{buffers_checkpoint} = $tmp_val*8192; (($data[4+$id] - $start_vals[4+$id]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[4+$id] - $start_vals[4+$id]); $all_stat_bgwriter{$data[0]}{buffers_clean} = $tmp_val*8192; (($data[5+$id] - $start_vals[5+$id]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[5+$id] - $start_vals[5+$id]); $all_stat_bgwriter{$data[0]}{maxwritten_clean} = $tmp_val; (($data[6+$id] - $start_vals[6+$id]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[6+$id] - $start_vals[6+$id]); $all_stat_bgwriter{$data[0]}{buffers_backend} = $tmp_val*8192; if ($#data >= 9) { (($data[7+$id] - $start_vals[7+$id]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[7+$id] - $start_vals[7+$id]); $all_stat_bgwriter{$data[0]}{buffers_backend_fsync} .= $tmp_val; (($data[8+$id] - $start_vals[8+$id]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[8+$id] - $start_vals[8+$id]); $all_stat_bgwriter{$data[0]}{buffers_alloc} = $tmp_val*8192; } @start_vals = (); push(@start_vals, @data); } $curfh->close(); return $offset; } # Compute graphs of bgwriter cluster statistics sub pg_stat_bgwriter_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); return if (!scalar keys %all_stat_bgwriter); my %bgwriter_stat = (); my %data = (); my $tz = ($STATS_TIMEZONE*3600*1000); foreach my $t (sort {$a <=> $b} keys %all_stat_bgwriter) { next if (!$all_stat_bgwriter{$t}{interval}); $data{'Checkpoint timed'} += $all_stat_bgwriter{$t}{checkpoints_timed}; $data{'Checkpoint requested'} += $all_stat_bgwriter{$t}{checkpoints_req}; $bgwriter_stat{checkpoints_timed} .= '[' . ($t - $tz) . ',' . $all_stat_bgwriter{$t}{checkpoints_timed} . '],'; $bgwriter_stat{checkpoints_req} .= '[' . ($t - $tz) . ',' . $all_stat_bgwriter{$t}{checkpoints_req} . '],'; $bgwriter_stat{checkpoint_write_time} .= '[' . ($t - $tz) . ',' . ($all_stat_bgwriter{$t}{checkpoint_write_time}||0) . '],'; $bgwriter_stat{checkpoint_sync_time} .= '[' . ($t - $tz) . ',' . ($all_stat_bgwriter{$t}{checkpoint_sync_time}||0) . '],'; $bgwriter_stat{buffers_checkpoint} .= '[' . ($t - $tz) . ',' . int(($all_stat_bgwriter{$t}{buffers_checkpoint}||0)/$all_stat_bgwriter{$t}{interval}) . '],'; $bgwriter_stat{buffers_clean} .= '[' . ($t - $tz) . ',' . int(($all_stat_bgwriter{$t}{buffers_clean}||0)/$all_stat_bgwriter{$t}{interval}) . '],'; $bgwriter_stat{buffers_backend} .= '[' . ($t - $tz) . ',' . int(($all_stat_bgwriter{$t}{buffers_backend}||0)/$all_stat_bgwriter{$t}{interval}) . '],'; $bgwriter_stat{buffers_alloc} .= '[' . ($t - $tz) . ',' . int(($all_stat_bgwriter{$t}{buffers_alloc}||0)/$all_stat_bgwriter{$t}{interval}) . '],'; $bgwriter_stat{maxwritten_clean} .= '[' . ($t - $tz) . ',' . ($all_stat_bgwriter{$t}{maxwritten_clean}||0) . '],'; $bgwriter_stat{buffers_backend_fsync} .= '[' . ($t - $tz) . ',' . ((exists $all_stat_bgwriter{$t}{buffers_backend_fsync}) ? $all_stat_bgwriter{$t}{buffers_backend_fsync} : '0') . '],'; } %all_stat_bgwriter = (); my $total_checkpoint = $data{'Checkpoint timed'} + $data{'Checkpoint requested'}; if (($data_info{$ID_ACTION}{name} eq 'cluster-checkpoints') && $total_checkpoint) { $data_info{$ID_ACTION}{legends}[0] .= ' (' . sprintf("%0.2f", $data{'Checkpoint timed'}*100/($total_checkpoint||1)) . '%)'; $data_info{$ID_ACTION}{legends}[1] .= ' (' . sprintf("%0.2f", $data{'Checkpoint requested'}*100/($total_checkpoint||1)) . '%)'; } foreach my $id (sort {$a <=> $b} keys %data_info) { next if ($id ne $ID_ACTION); next if ($data_info{$id}{name} ne $REAL_ACTION); if ($data_info{$id}{name} eq 'cluster-checkpoints') { $bgwriter_stat{checkpoints_timed} =~ s/,$//; $bgwriter_stat{checkpoints_req} =~ s/,$//; print &jqplot_linegraph_array($IDX++, 'cluster-checkpoints', \%{$data_info{$id}}, '', $bgwriter_stat{checkpoints_timed}, $bgwriter_stat{checkpoints_req}); } elsif ($data_info{$id}{name} eq 'cluster-checkpoints_time') { if (exists $bgwriter_stat{checkpoint_write_time}) { $bgwriter_stat{checkpoint_sync_time} =~ s/,$//; $bgwriter_stat{checkpoint_write_time} =~ s/,$//; print &jqplot_linegraph_array($IDX++, 'cluster-checkpoints_time', \%{$data_info{$id}}, '', $bgwriter_stat{checkpoint_write_time}, $bgwriter_stat{checkpoint_sync_time}); } } elsif ($data_info{$id}{name} eq 'cluster-bgwriter_write') { $bgwriter_stat{buffers_checkpoint} =~ s/,$//; $bgwriter_stat{buffers_clean} =~ s/,$//; $bgwriter_stat{buffers_backend} =~ s/,$//; print &jqplot_linegraph_array($IDX++, 'cluster-bgwriter_write', \%{$data_info{$id}}, '', $bgwriter_stat{buffers_checkpoint}, $bgwriter_stat{buffers_clean}, $bgwriter_stat{buffers_backend}); } elsif ($data_info{$id}{name} eq 'cluster-bgwriter_read') { $bgwriter_stat{buffers_alloc} =~ s/,$//; print &jqplot_linegraph_array($IDX++, 'cluster-bgwriter_read', \%{$data_info{$id}}, '', $bgwriter_stat{buffers_alloc}); } elsif ($data_info{$id}{name} eq 'cluster-bgwriter_count') { $bgwriter_stat{maxwritten_clean} =~ s/,$//; $bgwriter_stat{buffers_backend_fsync} =~ s/,$//; print &jqplot_linegraph_array($IDX++, 'cluster-bgwriter_count', \%{$data_info{$id}}, '', $bgwriter_stat{maxwritten_clean}, $bgwriter_stat{buffers_backend_fsync}); } } } # Compute statistics of connections sub pg_stat_connections { my ($input_dir, $file, $offset) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my @start_vals = (); my $tmp_val = 0; my %db_list = (); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); $curfh->seek($offset,0); while (my $l = <$curfh>) { $offset += length($l); my @data = split(/;/, $l); next if (!&normalize_line(\@data, 5)); # timestamp | total | active | waiting | idle_in_xact | datname # Store list of database $db_list{$data[5]} = 1; if ($ACTION eq 'database-connections') { $all_stat_connections{$data[0]}{$data[5]}{total} = $data[1]; $all_stat_connections{$data[0]}{$data[5]}{active} = $data[2]; $all_stat_connections{$data[0]}{$data[5]}{waiting} = $data[3]; $all_stat_connections{$data[0]}{$data[5]}{idle_in_xact} = $data[4]; $all_stat_connections{$data[0]}{$data[5]}{idle} = ($data[1] - $data[2] - $data[4]); } else { $all_stat_connections{$data[0]}{'all'}{total} += $data[1]; $all_stat_connections{$data[0]}{'all'}{active} += $data[2]; $all_stat_connections{$data[0]}{'all'}{waiting} += $data[3]; $all_stat_connections{$data[0]}{'all'}{idle_in_xact} += $data[4]; $all_stat_connections{$data[0]}{'all'}{idle} += ($data[1] - $data[2] - $data[4]); } } $curfh->close(); # Store the full list of database foreach my $d (keys %db_list) { push(@global_databases, $d) if (!grep/^$d$/, @global_databases); } push(@global_databases, 'all') if (($#global_databases >= 0) && !grep(/^all$/, @global_databases)); return $offset; } # Compute graphs of connections statistics sub pg_stat_connections_report { my ($src_base, $db_glob, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my %connections_stat = (); my $tz = ($STATS_TIMEZONE*3600*1000); foreach my $time (sort {$a <=> $b} keys %all_stat_connections) { if ($ACTION eq 'database-connections') { foreach my $db (@global_databases) { next if (($db_glob ne 'all') && ($db ne $db_glob)); next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB))); $connections_stat{$db}{total} .= '[' . ($time - $tz) . ',' . ($all_stat_connections{$time}{$db}{total}||0) . '],'; $connections_stat{$db}{active} .= '[' . ($time - $tz) . ',' . ($all_stat_connections{$time}{$db}{active}||0) . '],'; $connections_stat{$db}{waiting} .= '[' . ($time - $tz) . ',' . ($all_stat_connections{$time}{$db}{waiting}||0) . '],'; $connections_stat{$db}{idle_in_xact} .= '[' . ($time - $tz) . ',' . ($all_stat_connections{$time}{$db}{idle_in_xact}||0) . '],'; $connections_stat{$db}{idle} .= '[' . ($time - $tz) . ',' . ($all_stat_connections{$time}{$db}{idle}||0) . '],'; } } else { $connections_stat{'all'}{total} .= '[' . ($time - $tz) . ',' . ($all_stat_connections{$time}{'all'}{total}||0) . '],'; $connections_stat{'all'}{active} .= '[' . ($time - $tz) . ',' . ($all_stat_connections{$time}{'all'}{active}||0) . '],'; $connections_stat{'all'}{waiting} .= '[' . ($time - $tz) . ',' . ($all_stat_connections{$time}{'all'}{waiting}||0) . '],'; $connections_stat{'all'}{idle_in_xact} .= '[' . ($time - $tz) . ',' . ($all_stat_connections{$time}{'all'}{idle_in_xact}||0) . '],'; $connections_stat{'all'}{idle} .= '[' . ($time - $tz) . ',' . ($all_stat_connections{$time}{'all'}{idle}||0) . '],'; } } %all_stat_connections = (); my $id = &get_data_id($ACTION, %data_info); if (scalar keys %connections_stat > 0) { foreach my $db (sort keys %connections_stat) { next if ($db ne $db_glob); next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB))); $connections_stat{$db}{total} =~ s/,$//; $connections_stat{$db}{active} =~ s/,$//; $connections_stat{$db}{waiting} =~ s/,$//; $connections_stat{$db}{idle_in_xact} =~ s/,$//; $connections_stat{$db}{idle} =~ s/,$//; if ($db ne 'all') { print &jqplot_linegraph_array($IDX++, 'database-connections', \%{$data_info{$id}}, $db, $connections_stat{$db}{active}, $connections_stat{$db}{idle}, $connections_stat{$db}{idle_in_xact}, $connections_stat{$db}{waiting}); } else { print &jqplot_linegraph_array($IDX++, 'cluster-connections', \%{$data_info{$id}}, 'all', $connections_stat{$db}{active}, $connections_stat{$db}{idle}, $connections_stat{$db}{idle_in_xact}, $connections_stat{$db}{waiting}); } } } else { print &empty_dataset('database-connections', \%{$data_info{$id}}, 'indexes'); } } # Compute statistics of user functions call sub pg_stat_user_functions { my ($input_dir, $file) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); %all_stat_user_functions = (); my @start_vals = (); my $tmp_val = 0; # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if (!$l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # timestamp | datname | funcid | schemaname | funcname | calls | total_time | self_time next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB))); push(@start_vals, @data) if ($#start_vals < 0); $data[4] = "$data[3].$data[4]"; (($data[5] - $start_vals[5]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[5] - $start_vals[5]); $all_stat_user_functions{$data[1]}{$data[4]}{calls} += $tmp_val; (($data[6] - $start_vals[6]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[6] - $start_vals[6]); $all_stat_user_functions{$data[1]}{$data[4]}{total_time} += $tmp_val; (($data[7] - $start_vals[7]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[7] - $start_vals[7]); $all_stat_user_functions{$data[1]}{$data[4]}{self_time} += $tmp_val; @start_vals = (); push(@start_vals, @data); } $curfh->close(); } # Compute graphs of user functions call statistics sub pg_stat_user_functions_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); return if (!$db); my $id = &get_data_id('database-functions', %data_info); my $table_header = qq{ Schema.function Calls Total time Self time }; if (!exists $all_stat_user_functions{$db} || scalar keys %{$all_stat_user_functions{$db}} == 0) { $table_header = qq{
          NO DATASET
          }; } my $colspan = ' colspan="4"'; print qq{




          • $data_info{$id}{menu} on $db database

            $data_info{$id}{description}

            $table_header }; my $found_fct_stat = 0; foreach my $fct (sort keys %{$all_stat_user_functions{$db}}) { if (!$all_stat_user_functions{$db}{$fct}{calls} && !$all_stat_user_functions{$db}{$fct}{total_time} && !$all_stat_user_functions{$db}{$fct}{self_time}) { next; } foreach ('calls','total_time','self_time') { $all_stat_user_functions{$db}{$fct}{$_} ||= 0; } print "\n"; } print qq{
            $fct$all_stat_user_functions{$db}{$fct}{calls}" . &format_duration($all_stat_user_functions{$db}{$fct}{total_time}) . "" . &format_duration($all_stat_user_functions{$db}{$fct}{self_time}) . "
          }; } # Compute graphs of replication cluster statistics sub pg_stat_replication { my ($input_dir, $file, $offset) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my @start_vals = (); my $tmp_val = 0; # Load data from file my $curfh = open_filehdl("$input_dir/$file"); $curfh->seek($offset,0); while (my $l = <$curfh>) { $offset += length($l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # timestamp | pid | usesysid | usename | application_name | client_addr | client_hostname | client_port | backend_start | state | master_location | sent_location | write_location | flush_location | replay_location | sync_priority | sync_state # Do not care about BACKUP and pg_basebackup connection if ( (uc($data[9]) eq 'STREAMING') || (uc($data[4]) eq 'WALRECEIVER') ) { my $name = $data[5]; $data[6] =~ s/"//g; $name .= " - $data[6]" if ($data[6]); push(@start_vals, @data) if ($#start_vals < 0); # Store interval between previous run $all_stat_replication{$data[0]}{interval} = ($data[0] - $start_vals[0])/1000; $all_stat_replication{$data[0]}{master_location} = &getNumericalOffset($data[10]) - &getNumericalOffset($start_vals[10]) if (! exists $all_stat_replication{$data[0]}{master_location}); next if (!$data[14] && !$data[11] && !$data[12] && !$data[13]); ((&getNumericalOffset($data[10]) - &getNumericalOffset($data[14])) < 0) ? $tmp_val = 0 : $tmp_val = (&getNumericalOffset($data[10]) - &getNumericalOffset($data[14])); $all_stat_replication{$data[0]}{$name}{replay_location} = $tmp_val; ((&getNumericalOffset($data[10]) - &getNumericalOffset($data[11])) < 0) ? $tmp_val = 0 : $tmp_val = (&getNumericalOffset($data[10]) - &getNumericalOffset($data[11])); $all_stat_replication{$data[0]}{$name}{sent_location} = $tmp_val; ((&getNumericalOffset($data[10]) - &getNumericalOffset($data[12])) < 0) ? $tmp_val = 0 : $tmp_val = (&getNumericalOffset($data[10]) - &getNumericalOffset($data[12])); $all_stat_replication{$data[0]}{$name}{write_location} = $tmp_val; ((&getNumericalOffset($data[10]) - &getNumericalOffset($data[13])) < 0) ? $tmp_val = 0 : $tmp_val = (&getNumericalOffset($data[10]) - &getNumericalOffset($data[13])); $all_stat_replication{$data[0]}{$name}{flush_location} = $tmp_val; @start_vals = (); push(@start_vals, @data); } } $curfh->close(); return $offset; } # Compute graphs of replication cluster statistics sub pg_stat_replication_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my %xlog_stat = (); my $tz = ($STATS_TIMEZONE*3600*1000); foreach my $t (sort {$a <=> $b} keys %all_stat_replication) { foreach my $name (sort {$a cmp $b} keys %{$all_stat_replication{$t}}) { next if ($name eq 'interval'); if ($name eq 'master_location') { next if (!$all_stat_replication{$t}{interval}); $all_stat_replication{$t}{master_location} ||= 0; $xlog_stat{master_location} .= '[' . ($t - $tz) . ',' . int(($all_stat_replication{$t}{master_location}||0)/$all_stat_replication{$t}{interval}) . '],'; next; } $xlog_stat{$name}{replay_location} .= '[' . ($t - $tz) . ',' . ($all_stat_replication{$t}{$name}{replay_location} || 0) . '],'; $xlog_stat{$name}{sent_location} .= '[' . ($t - $tz) . ',' . ($all_stat_replication{$t}{$name}{sent_location} || 0) . '],'; $xlog_stat{$name}{write_location} .= '[' . ($t - $tz) . ',' . ($all_stat_replication{$t}{$name}{write_location} || 0) . '],'; $xlog_stat{$name}{flush_location} .= '[' . ($t - $tz) . ',' . ($all_stat_replication{$t}{$name}{flush_location} || 0) . '],'; } } %all_stat_replication = (); # return if (scalar keys %xlog_stat == 0); foreach my $id (sort {$a <=> $b} keys %data_info) { next if ($id ne $ID_ACTION); next if ($data_info{$id}{name} ne $REAL_ACTION); if ($data_info{$id}{name} eq 'cluster-xlog') { $xlog_stat{master_location} =~ s/,$// if (exists $xlog_stat{master_location}); print &jqplot_linegraph_array($IDX++, 'cluster-xlog', \%{$data_info{$id}}, '', $xlog_stat{master_location}); delete $xlog_stat{master_location} if (exists $xlog_stat{master_location}); } elsif ($data_info{$id}{name} eq 'cluster-replication') { my $has_data = 0; foreach my $host (sort {$a cmp $b} keys %xlog_stat) { next if ($host eq 'master_location'); $has_data = 1; $xlog_stat{$host}{sent_location} =~ s/,$//; $xlog_stat{$host}{write_location} =~ s/,$//; $xlog_stat{$host}{flush_location} =~ s/,$//; $xlog_stat{$host}{replay_location} =~ s/,$//; print &jqplot_linegraph_array($IDX++, 'cluster-replication', \%{$data_info{$id}}, $host, $xlog_stat{$host}{sent_location}, $xlog_stat{$host}{write_location}, $xlog_stat{$host}{replay_location}); } if (!$has_data) { print &jqplot_linegraph_array($IDX++, 'cluster-replication', \%{$data_info{$id}}); } } } } # Compute statistics of pgbouncer sub pgbouncer_stats { my ($input_dir, $file, $offset) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); $curfh->seek($offset,0); while (my $l = <$curfh>) { $offset += length($l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); next if ($data[1] eq 'pgbouncer'); # timestamp|database|user|cl_active|cl_waiting|sv_active|sv_idle|sv_used|sv_tested|sv_login|maxwait $all_pgbouncer_stats{$data[0]}{$data[1]}{$data[2]}{cl_active} += ($data[3] || 0); $all_pgbouncer_stats{$data[0]}{$data[1]}{$data[2]}{cl_waiting} += ($data[4] || 0); $all_pgbouncer_stats{$data[0]}{$data[1]}{$data[2]}{sv_active} += ($data[5] || 0); $all_pgbouncer_stats{$data[0]}{$data[1]}{$data[2]}{sv_idle} += ($data[6] || 0); $all_pgbouncer_stats{$data[0]}{$data[1]}{$data[2]}{sv_used} += ($data[7] || 0); $all_pgbouncer_stats{$data[0]}{$data[1]}{$data[2]}{sv_tested} += ($data[8] || 0); $all_pgbouncer_stats{$data[0]}{$data[1]}{$data[2]}{sv_login} += ($data[9] || 0); $all_pgbouncer_stats{$data[0]}{$data[1]}{$data[2]}{maxwait} += ($data[10] || 0); } $curfh->close(); return $offset; } # Compute graphs of pgbouncer statistics sub pgbouncer_stats_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my %pgbouncer_stat = (); my %total_pool = (); my $tz = ($STATS_TIMEZONE*3600*1000); foreach my $t (sort {$a <=> $b} keys %all_pgbouncer_stats) { foreach my $db (keys %{$all_pgbouncer_stats{$t}}) { foreach my $usr (keys %{$all_pgbouncer_stats{$t}{$db}}) { $pgbouncer_stat{"$db/$usr"}{cl_active} .= '[' . ($t - $tz) . ',' . ($all_pgbouncer_stats{$t}{$db}{$usr}{cl_active} || 0) . '],'; $pgbouncer_stat{"$db/$usr"}{cl_waiting} .= '[' . ($t - $tz) . ',' . ($all_pgbouncer_stats{$t}{$db}{$usr}{cl_waiting} || 0) . '],'; $pgbouncer_stat{"$db/$usr"}{sv_active} .= '[' . ($t - $tz) . ',' . ($all_pgbouncer_stats{$t}{$db}{$usr}{sv_active} || 0) . '],'; $pgbouncer_stat{"$db/$usr"}{sv_idle} .= '[' . ($t - $tz) . ',' . ($all_pgbouncer_stats{$t}{$db}{$usr}{sv_idle} || 0) . '],'; $pgbouncer_stat{"$db/$usr"}{sv_used} .= '[' . ($t - $tz) . ',' . ($all_pgbouncer_stats{$t}{$db}{$usr}{sv_used} || 0) . '],'; $pgbouncer_stat{"$db/$usr"}{sv_tested} .= '[' . ($t - $tz) . ',' . ($all_pgbouncer_stats{$t}{$db}{$usr}{sv_tested} || 0) . '],'; $pgbouncer_stat{"$db/$usr"}{sv_login} .= '[' . ($t - $tz) . ',' . ($all_pgbouncer_stats{$t}{$db}{$usr}{sv_login} || 0) . '],'; $pgbouncer_stat{"$db/$usr"}{maxwait} .= '[' . ($t - $tz) . ',' . ($all_pgbouncer_stats{$t}{$db}{$usr}{maxwait} || 0) . '],'; $total_pool{$db}{cl_active} += $all_pgbouncer_stats{$t}{$db}{$usr}{cl_active}; $total_pool{$db}{cl_waiting} += $all_pgbouncer_stats{$t}{$db}{$usr}{cl_waiting}; $total_pool{$db}{sv_active} += $all_pgbouncer_stats{$t}{$db}{$usr}{sv_active}; $total_pool{$db}{sv_idle} += $all_pgbouncer_stats{$t}{$db}{$usr}{sv_idle}; $total_pool{$db}{sv_used} += $all_pgbouncer_stats{$t}{$db}{$usr}{sv_used}; $total_pool{$db}{sv_tested} += $all_pgbouncer_stats{$t}{$db}{$usr}{sv_tested}; $total_pool{$db}{sv_login} += $all_pgbouncer_stats{$t}{$db}{$usr}{sv_login}; $total_pool{$db}{maxwait} += $all_pgbouncer_stats{$t}{$db}{$usr}{maxwait}; } $pgbouncer_stat{$db}{cl_active} .= '[' . ($t - $tz) . ',' . ($total_pool{$db}{cl_active} || 0) . '],'; $pgbouncer_stat{$db}{cl_waiting} .= '[' . ($t - $tz) . ',' . ($total_pool{$db}{cl_waiting} || 0) . '],'; $pgbouncer_stat{$db}{sv_active} .= '[' . ($t - $tz) . ',' . ($total_pool{$db}{sv_active} || 0) . '],'; $pgbouncer_stat{$db}{sv_idle} .= '[' . ($t - $tz) . ',' . ($total_pool{$db}{sv_idle} || 0) . '],'; $pgbouncer_stat{$db}{sv_used} .= '[' . ($t - $tz) . ',' . ($total_pool{$db}{sv_used} || 0) . '],'; $pgbouncer_stat{$db}{sv_tested} .= '[' . ($t - $tz) . ',' . ($total_pool{$db}{sv_tested} || 0) . '],'; $pgbouncer_stat{$db}{sv_login} .= '[' . ($t - $tz) . ',' . ($total_pool{$db}{sv_login} || 0) . '],'; $pgbouncer_stat{$db}{maxwait} .= '[' . ($t - $tz) . ',' . ($total_pool{$db}{maxwait} || 0) . '],'; # $total_pool{'all'}{cl_active} += $total_pool{$db}{cl_active}; # $total_pool{'all'}{cl_waiting} += $total_pool{$db}{cl_waiting}; # $total_pool{'all'}{sv_active} += $total_pool{$db}{sv_active}; # $total_pool{'all'}{sv_idle} += $total_pool{$db}{sv_idle}; # $total_pool{'all'}{sv_used} += $total_pool{$db}{sv_used}; # $total_pool{'all'}{sv_tested} += $total_pool{$db}{sv_tested}; # $total_pool{'all'}{sv_login} += $total_pool{$db}{sv_login}; # $total_pool{'all'}{maxwait} += $total_pool{$db}{maxwait}; delete $total_pool{$db}; } # $pgbouncer_stat{'all'}{cl_active} .= '[' . ($t - $tz) . ',' . ($total_pool{'all'}{cl_active} || 0) . '],'; # $pgbouncer_stat{'all'}{cl_waiting} .= '[' . ($t - $tz) . ',' . ($total_pool{'all'}{cl_waiting} || 0) . '],'; # $pgbouncer_stat{'all'}{sv_active} .= '[' . ($t - $tz) . ',' . ($total_pool{'all'}{sv_active} || 0) . '],'; # $pgbouncer_stat{'all'}{sv_idle} .= '[' . ($t - $tz) . ',' . ($total_pool{'all'}{sv_idle} || 0) . '],'; # $pgbouncer_stat{'all'}{sv_used} .= '[' . ($t - $tz) . ',' . ($total_pool{'all'}{sv_used} || 0) . '],'; # $pgbouncer_stat{'all'}{sv_tested} .= '[' . ($t - $tz) . ',' . ($total_pool{'all'}{sv_tested} || 0) . '],'; # $pgbouncer_stat{'all'}{sv_login} .= '[' . ($t - $tz) . ',' . ($total_pool{'all'}{sv_login} || 0) . '],'; # $pgbouncer_stat{'all'}{maxwait} .= '[' . ($t - $tz) . ',' . ($total_pool{'all'}{maxwait} || 0) . '],'; } # Build graph dataset for all pgbouncer pool foreach my $id (sort {$a <=> $b} keys %data_info) { next if ($id ne $ID_ACTION); foreach my $db (sort {$a cmp $b} keys %pgbouncer_stat) { next if ($DATABASE && ($db ne $DATABASE)); next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB))); next if ($db eq 'all'); next if ($db =~ /\//); if ($data_info{$id}{name} eq 'pgbouncer-connections') { $pgbouncer_stat{$db}{cl_active} =~ s/,$//; $pgbouncer_stat{$db}{cl_waiting} =~ s/,$//; $pgbouncer_stat{$db}{sv_active} =~ s/,$//; $pgbouncer_stat{$db}{sv_idle} =~ s/,$//; $pgbouncer_stat{$db}{sv_used} =~ s/,$//; $pgbouncer_stat{$db}{maxwait} =~ s/,$//; print &jqplot_linegraph_array($IDX++, 'pgbouncer-connections', \%{$data_info{$id}}, $db, $pgbouncer_stat{$db}{cl_active}, $pgbouncer_stat{$db}{cl_waiting}, $pgbouncer_stat{$db}{sv_active}, $pgbouncer_stat{$db}{sv_idle},$pgbouncer_stat{$db}{sv_used}, $pgbouncer_stat{$db}{maxwait}); foreach my $pool (sort {$a cmp $b} keys %pgbouncer_stat) { next if ($pool !~ /^$db\//); $pgbouncer_stat{$pool}{cl_active} =~ s/,$//; $pgbouncer_stat{$pool}{cl_waiting} =~ s/,$//; $pgbouncer_stat{$pool}{sv_active} =~ s/,$//; $pgbouncer_stat{$pool}{sv_idle} =~ s/,$//; $pgbouncer_stat{$pool}{sv_used} =~ s/,$//; $pgbouncer_stat{$pool}{maxwait} =~ s/,$//; print &jqplot_linegraph_array($IDX++, 'pgbouncer-connections+', \%{$data_info{$id}}, $pool, $pgbouncer_stat{$pool}{cl_active}, $pgbouncer_stat{$pool}{cl_waiting}, $pgbouncer_stat{$pool}{sv_active}, $pgbouncer_stat{$pool}{sv_idle},$pgbouncer_stat{$pool}{sv_used}, $pgbouncer_stat{$pool}{maxwait}); } print "\n"; } } } } sub get_diff { my $file = shift; my $diff_hashref = shift; return if (! -e $file); my $curfh = open_filehdl($file); my $key = ''; while (my $l = <$curfh>) { chomp($l); $l =~ s/\r//; next if ($l =~ /^\+\+\+/); if ($l =~ /^\-\-\-.*\s(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/) { my $tz = ((0-$TIMEZONE)*3600); $key = &timegm_nocheck($6, $5, $4, $3, $2 - 1, $1 - 1900) + $tz; delete $diff_hashref->{$key} if (exists $diff_hashref->{$key}); next; } if ($key) { $diff_hashref->{$key} .= "$l\n"; } } $curfh->close(); } sub show_diff { my %diff = @_; foreach my $k (sort { $b cmp $a } keys %diff) { my $date = localtime($k); print qq{

          Change on $date

          $diff{$k}
          }; } } # Get content of pgbouncer.ini sub pgbouncer_ini { my ($input_dir, $file) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); return if (!-e "$input_dir/pgbouncer.ini"); %all_pgbouncer_ini = (); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if ($l !~ /^[a-z]/); $l =~ s/\s*#.*//; $all_pgbouncer_ini{content} .= "$l\n"; } $curfh->close(); return if (!exists $all_pgbouncer_ini{content}); # Load change on configuration file from diff files &get_diff("$input_dir/$file.diff", \%all_pgbouncer_ini_diff); } # Show relevant content of pgbouncer.ini sub pgbouncer_ini_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my $output = $all_pgbouncer_ini{content} || ''; if (!$output) { $output = '
          NO DATASET
          '; } else { $output = "
          \n$output
          \n"; } my $id = &get_data_id('cluster-pgbouncer', %data_info); print qq{




          • $data_info{$id}{menu}

            $data_info{$id}{description}

            $output
            }; %all_pgbouncer_ini = (); &show_diff(%all_pgbouncer_ini_diff); %all_pgbouncer_ini_diff = (); print qq{
          }; } # Collect statistics about pgbouncer queries sub pgbouncer_req_stats { my ($input_dir, $file, $offset) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my @start_vals = (); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); $curfh->seek($offset,0); while (my $l = <$curfh>) { $offset += length($l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); next if ($data[1] eq 'pgbouncer'); push(@start_vals, @data) if ($#start_vals < 0); my $tmp_val = 0; # timestamp|database|total_requests|total_received|total_sent|total_query_time|avg_req|avg_recv|avg_sent|avg_query # Since 1.8: # timestamp|database|total_xact_count|total_query_count|total_received|total_sent|total_xact_time|total_query_time|total_wait_time|avg_xact_count|avg_query_count|avg_recv|avg_sent|avg_xact_time|avg_query_time|avg_wait_time if ($#data == 9) { (($data[2] - $start_vals[2]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[2] - $start_vals[2]); $all_pgbouncer_req_stats{$data[0]}{$data[1]}{total_requests} += $tmp_val; (($data[3] - $start_vals[3]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[3] - $start_vals[3]); $all_pgbouncer_req_stats{$data[0]}{$data[1]}{total_received} += $tmp_val; (($data[4] - $start_vals[4]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[4] - $start_vals[4]); $all_pgbouncer_req_stats{$data[0]}{$data[1]}{total_sent} += $tmp_val; (($data[5] - $start_vals[5]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[5] - $start_vals[5]); $all_pgbouncer_req_stats{$data[0]}{$data[1]}{total_query_time} += $tmp_val; $all_pgbouncer_req_stats{$data[0]}{$data[1]}{avg_req} += $data[6]; $all_pgbouncer_req_stats{$data[0]}{$data[1]}{avg_recv} += $data[7]; $all_pgbouncer_req_stats{$data[0]}{$data[1]}{avg_sent} += $data[8]; $all_pgbouncer_req_stats{$data[0]}{$data[1]}{avg_query} += $data[9]; } else { (($data[3] - $start_vals[3]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[3] - $start_vals[3]); $all_pgbouncer_req_stats{$data[0]}{$data[1]}{total_requests} += $tmp_val; (($data[4] - $start_vals[4]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[4] - $start_vals[4]); $all_pgbouncer_req_stats{$data[0]}{$data[1]}{total_received} += $tmp_val; (($data[5] - $start_vals[5]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[5] - $start_vals[5]); $all_pgbouncer_req_stats{$data[0]}{$data[1]}{total_sent} += $tmp_val; (($data[7] - $start_vals[7]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[7] - $start_vals[7]); $all_pgbouncer_req_stats{$data[0]}{$data[1]}{total_query_time} += $tmp_val; (($data[8] - $start_vals[8]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[8] - $start_vals[8]); $all_pgbouncer_req_stats{$data[0]}{$data[1]}{total_wait_time} += $tmp_val; $all_pgbouncer_req_stats{$data[0]}{$data[1]}{avg_query_count} += $data[10]; $all_pgbouncer_req_stats{$data[0]}{$data[1]}{avg_recv} += $data[11]; $all_pgbouncer_req_stats{$data[0]}{$data[1]}{avg_sent} += $data[12]; $all_pgbouncer_req_stats{$data[0]}{$data[1]}{avg_query_time} += $data[14]; $all_pgbouncer_req_stats{$data[0]}{$data[1]}{avg_wait_time} += $data[15]; } @start_vals = (); push(@start_vals, @data); } $curfh->close(); return $offset; } # Show report about pgbouncer queries sub pgbouncer_req_stats_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my %pgbouncer_stat = (); my $tz = ($STATS_TIMEZONE*3600*1000); foreach my $t (sort {$a <=> $b} keys %all_pgbouncer_req_stats) { foreach my $db (keys %{$all_pgbouncer_req_stats{$t}}) { foreach my $k (keys %{$all_pgbouncer_req_stats{$t}{$db}}) { $pgbouncer_stat{$db}{$k} .= '[' . ($t - $tz) . ',' . $all_pgbouncer_req_stats{$t}{$db}{$k} . '],'; } } } foreach my $id (sort {$a <=> $b} keys %data_info) { next if ($id ne $ID_ACTION); foreach my $db (sort {$a cmp $b} keys %pgbouncer_stat) { next if ($DATABASE && ($db ne $DATABASE)); next if ($db eq 'all'); next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB))); if ($data_info{$id}{name} eq 'pgbouncer-duration') { # Assure backward compatibility with old data or cache file with # pgbouncer < 1.8 avg_query have been renamed into avg_query_time if (exists $pgbouncer_stat{$db}{avg_query_time}) { if (exists $pgbouncer_stat{$db}{avg_query}) { $pgbouncer_stat{$db}{avg_query} .= $pgbouncer_stat{$db}{avg_query_time}; $pgbouncer_stat{$db}{avg_query_time} = $pgbouncer_stat{$db}{avg_query}; } $pgbouncer_stat{$db}{avg_query_time} =~ s/,$//; $data_info{$id}{legends} = ['avg_query_time']; print &jqplot_linegraph_array($IDX++, 'pgbouncer-duration', \%{$data_info{$id}}, $db, $pgbouncer_stat{$db}{avg_query_time}); } else { $pgbouncer_stat{$db}{avg_query} =~ s/,$//; print &jqplot_linegraph_array($IDX++, 'pgbouncer-duration', \%{$data_info{$id}}, $db, $pgbouncer_stat{$db}{avg_query}); } } elsif ($data_info{$id}{name} eq 'pgbouncer-number') { # Assure backward compatibility with old data or cache file with # pgbouncer < 1.8 avg_req have been renamed into avg_query_count if (exists $pgbouncer_stat{$db}{avg_query_count}) { if (exists $pgbouncer_stat{$db}{avg_req}) { $pgbouncer_stat{$db}{avg_req} .= $pgbouncer_stat{$db}{avg_query_count}; $pgbouncer_stat{$db}{avg_query_count} = $pgbouncer_stat{$db}{avg_req}; } $pgbouncer_stat{$db}{avg_query_count} =~ s/,$//; $data_info{$id}{legends} = ['avg_query_count']; print &jqplot_linegraph_array($IDX++, 'pgbouncer-number', \%{$data_info{$id}}, $db, $pgbouncer_stat{$db}{avg_query_count}); } else { $pgbouncer_stat{$db}{avg_req} =~ s/,$//; print &jqplot_linegraph_array($IDX++, 'pgbouncer-number', \%{$data_info{$id}}, $db, $pgbouncer_stat{$db}{avg_req}); } } elsif ($data_info{$id}{name} eq 'pgbouncer-wait-total') { $pgbouncer_stat{$db}{total_wait_time} =~ s/,$//; print &jqplot_linegraph_array($IDX++, 'pgbouncer-wait-total', \%{$data_info{$id}}, $db, $pgbouncer_stat{$db}{total_wait_time}); } elsif ($data_info{$id}{name} eq 'pgbouncer-wait-average') { $pgbouncer_stat{$db}{avg_wait_time} =~ s/,$//; print &jqplot_linegraph_array($IDX++, 'pgbouncer-wait-average', \%{$data_info{$id}}, $db, $pgbouncer_stat{$db}{avg_wait_time}); } } } } # Compute graphs of object size statistics sub pg_class_size { my ($input_dir, $file) = @_; %all_class_size = (); my %total_class = (); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if (!$l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); if ($data[4] !~ /^[a-zA-Z]$/) { print STDERR "WARNING: incompatible type of file pg_class_size.csv, the second field should be the database name\n"; last; } # timestamp | dbname | nspname | relname | relkind | reltuples | relpages | relsize next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB))); my $size = $data[6]*8192; $size = $data[7] if ($#data == 7); if ($ACTION eq 'database-info') { $total_class{$data[1]}{$data[4]}{"$data[2].$data[3]"} = ''; } else { $all_class_size{$data[1]}{$data[4]}{"$data[2].$data[3]"}{size} = $size; $all_class_size{$data[1]}{$data[4]}{"$data[2].$data[3]"}{tuples} = $data[5]; if ($data[5] > 0) { $all_class_size{$data[1]}{$data[4]}{"$data[2].$data[3]"}{width} = sprintf("%.2f", $size/$data[5]); } else { $all_class_size{$data[1]}{$data[4]}{"$data[2].$data[3]"}{width} = '-'; } } } $curfh->close(); if ($ACTION eq 'database-info') { foreach my $db (sort keys %total_class) { next if ($DATABASE && ($db ne $DATABASE)); next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB))); # Count the number of object foreach my $k (sort keys %RELKIND) { if (exists $total_class{$db}{$k}) { $OVERALL_STATS{'class'}{$db}{$k} = scalar keys %{$total_class{$db}{$k}}; } else { $OVERALL_STATS{'class'}{$db}{$k} = 0; } } } %total_class = (); } } # Compute graphs of object size statistics sub pg_class_size_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); return if (!$db); my %data = (); foreach my $id (sort {$a <=> $b} keys %data_info) { next if ($id ne $ID_ACTION); next if ($data_info{$id}{name} !~ /^(table|index)-/); my $table_header = ''; my $kind = ''; if ($data_info{$id}{name} eq 'table-size') { $kind = 'tables'; $table_header = qq{ Object name Size Tuples Avg width }; } elsif ($data_info{$id}{name} eq 'index-size') { $kind = 'indexes'; $table_header = qq{ Object name Size Tuples Avg width }; } if (scalar keys %{$all_class_size{$db}} == 0) { $table_header = qq{
          NO DATASET
          }; } print qq{




          • $data_info{$id}{menu} on $db database $kind

            $data_info{$id}{description}

            $table_header }; my $found_table_stat = 0; foreach my $k (sort keys %{$all_class_size{$db}}) { next if (($k ne 't') && ($k ne 'r') && ($data_info{$id}{name} eq 'table-size')); next if (($k ne 'i') && ($data_info{$id}{name} eq 'index-size')); my $colspan = ' colspan="5"'; foreach my $tb (sort {$all_class_size{$db}{$k}{$b}{size} <=> $all_class_size{$db}{$k}{$a}{size} } keys %{$all_class_size{$db}{$k}}) { next if (!$all_class_size{$db}{$k}{$tb}{size} && !$all_class_size{$db}{$k}{$tb}{tuples}); next if (($#INCLUDE_TB >= 0) && !grep(/^$tb$/, @INCLUDE_TB)); my $table_data = ''; if ($data_info{$id}{name} =~ /^(table|index)-size$/) { $found_table_stat = 1; foreach ('size','tuples','width') { $all_class_size{$db}{$k}{$tb}{$_} ||= 0; } $table_data = "\n"; } if ($table_data) { print $table_data; } } if (!$found_table_stat) { print qq{
            NO DATASET
            }; } } print qq{
            $tb" . &pretty_print_size($all_class_size{$db}{$k}{$tb}{size}) . "" . int($all_class_size{$db}{$k}{$tb}{tuples}) . "$all_class_size{$db}{$k}{$tb}{width}
          }; } %all_class_size = (); } # Compute graphs of locks statistics sub pg_stat_locks { my ($input_dir, $file, $offset) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); $curfh->seek($offset,0); while (my $l = <$curfh>) { $offset += length($l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # timestamp|database|label|(type|mode|granted)|count next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB))); $data[3] = 'granted' if ($data[3] eq 't'); $data[3] = 'waiting' if ($data[3] eq 'f'); $all_stat_locks{$data[0]}{$data[1]}{$data[2]}{$data[3]} += $data[4]; } $curfh->close(); return $offset; } # Compute graphs of locks statistics sub pg_stat_locks_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); return if (!$db); my %locks_stat = (); my %legends = (); my $tz = ($STATS_TIMEZONE*3600*1000); foreach my $t (keys %all_stat_locks) { foreach my $lbl (keys %{$all_stat_locks{$t}{$db}}) { push(@{$legends{$db}{$lbl}}, 'waiting') if ( grep(/^waiting$/, @{$legends{$db}{$lbl}}) && (${$legends{$db}{$lbl}}[0] eq 'granted') ); foreach my $k (@{$legends{$db}{$lbl}}) { $locks_stat{$db}{$lbl}{$k} .= '[' . ($t - $tz) . ',' . ($all_stat_locks{$t}{$db}{$lbl}{$k}||0) . '],'; } } } %all_stat_locks = (); foreach my $id (sort {$a <=> $b} keys %data_info) { next if ($id ne $ID_ACTION); my @graph_data = (); if ($data_info{$id}{name} eq 'database-lock-types') { foreach my $k (sort keys %{$locks_stat{$db}{lock_type}}) { $locks_stat{$db}{lock_type}{$k} =~ s/,$//; push(@{$data_info{$id}{legends}}, $k); push(@graph_data, $locks_stat{$db}{lock_type}{$k}); } print &jqplot_linegraph_array($IDX++, 'database-lock-types', \%{$data_info{$id}}, $db, @graph_data); } elsif ($data_info{$id}{name} eq 'database-lock-modes') { foreach my $k (sort keys %{$locks_stat{$db}{lock_mode}}) { $locks_stat{$db}{lock_mode}{$k} =~ s/,$//; push(@{$data_info{$id}{legends}}, $k); push(@graph_data, $locks_stat{$db}{lock_mode}{$k}); } print &jqplot_linegraph_array($IDX++, 'database-lock-modes', \%{$data_info{$id}}, $db, @graph_data); } elsif ($data_info{$id}{name} eq 'database-lock-granted') { foreach my $k (sort keys %{$locks_stat{$db}{lock_granted}}) { $locks_stat{$db}{lock_granted}{$k} =~ s/,$//; push(@{$data_info{$id}{legends}}, $k); push(@graph_data, $locks_stat{$db}{lock_granted}{$k}); } print &jqplot_linegraph_array($IDX++, 'database-lock-granted', \%{$data_info{$id}}, $db, @graph_data); } } } # Compute statistics about unused index sub pg_stat_unused_indexes { my ($input_dir, $file) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); %all_stat_unused_indexes = (); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if (!$l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # timestamp | dbname | schemaname | relname | indexrelname | index_code next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB))); push(@{$all_stat_unused_indexes{$data[1]}}, [ ($data[2], $data[3], $data[4], $data[5]) ] ); } $curfh->close(); } # Compute report about unused index sub pg_stat_unused_indexes_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); return if (!$db); my $id = &get_data_id('unused-index', %data_info); my $table_header = qq{ Schema Table Index Code }; if (!exists $all_stat_unused_indexes{$db} || $#{$all_stat_unused_indexes{$db}} < 0) { $table_header = qq{
          NO DATASET
          }; } print qq{




          • $data_info{$id}{menu} on $db database

            $data_info{$id}{description}

            $table_header }; foreach my $r (@{$all_stat_unused_indexes{$db}}) { print '\n"; } print qq{
            ', join('', @$r), "
          }; %all_stat_unused_indexes = (); } # Compute statistics about redundant index sub pg_stat_redundant_indexes { my ($input_dir, $file) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); %all_stat_redundant_indexes = (); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if (!$l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # Do not report indexes when one is partial and not the other one # otherwise keep them for user recheck. next if (grep(/\bWHERE\b/i, $data[2], $data[3]) == 1); # timestamp | dbname | contained | containing next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB))); push(@{$all_stat_redundant_indexes{$data[1]}}, [ ($data[2], $data[3]) ] ); } $curfh->close(); } # Compute report about redundant index sub pg_stat_redundant_indexes_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); return if (!$db); my $id = &get_data_id('redundant-index', %data_info); my $table_header = qq{ Contained Containing }; if (!exists $all_stat_redundant_indexes{$db} || $#{$all_stat_redundant_indexes{$db}} < 0) { $table_header = qq{
          NO DATASET
          }; } print qq{




          • $data_info{$id}{menu} on $db database

            $data_info{$id}{description}

            $table_header }; foreach my $r (@{$all_stat_redundant_indexes{$db}}) { print '\n"; } print qq{
            ', join('', @$r), "
          }; %all_stat_redundant_indexes = (); } # Compute statistics about missing index sub pg_stat_missing_fkindexes { my ($input_dir, $file) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); %all_stat_missing_fkindexes = (); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if (!$l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # timestamp | dbname | relname | ddl next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB))); push(@{$all_stat_missing_fkindexes{$data[1]}}, [ ($data[2], $data[3]) ] ); } $curfh->close(); } # Compute report about missing index sub pg_stat_missing_fkindexes_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); return if (!$db); my $id = &get_data_id('missing-index', %data_info); my $table_header = qq{ Table Missing index }; if (!exists $all_stat_missing_fkindexes{$db} || $#{$all_stat_missing_fkindexes{$db}} < 0) { $table_header = qq{
          NO DATASET
          }; } print qq{




          • $data_info{$id}{menu} on $db database

            $data_info{$id}{description}

            $table_header }; foreach my $r (@{$all_stat_missing_fkindexes{$db}}) { print '\n"; } print qq{
            ', join('', @$r), "
          }; %all_stat_missing_fkindexes = (); } # Compute statistics about indexes count sub pg_stat_count_indexes { my ($input_dir, $file) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); %all_stat_count_indexes = (); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if (!$l); my @data = split(/;/, $l); next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB))); # timestamp | dbname | schema | table | count $all_stat_count_indexes{$data[1]}{$data[2]}{$data[3]} = $data[4]; } $curfh->close(); } # Compute report about table without indexes or with too many indexes sub pg_stat_count_indexes_report { my ($src_base, $dbname, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); return if (!$dbname); foreach my $db (sort keys %all_stat_count_indexes) { next if ($db ne $dbname); next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB))); my $id = &get_data_id('count-index', %data_info); print qq{




          • $data_info{$id}{menu} on $db database

            $data_info{$id}{description}

            }; foreach my $s (sort keys %{$all_stat_count_indexes{$db}}) { foreach my $t (sort keys %{$all_stat_count_indexes{$db}{$s}}) { next if ($all_stat_count_indexes{$db}{$s}{$t} > $MAX_INDEXES); print "\n"; } } print qq{
            Schema table Number of indexes
            $s$t$all_stat_count_indexes{$db}{$s}{$t}
            }; $id = &get_data_id('zero-index', %data_info); print qq{

            $data_info{$id}{menu} on $db database

            $data_info{$id}{description}

            }; foreach my $s (sort keys %{$all_stat_count_indexes{$db}}) { foreach my $t (sort keys %{$all_stat_count_indexes{$db}{$s}}) { next if ($all_stat_count_indexes{$db}{$s}{$t} > 0); print "\n"; } } print qq{
            Schema table
            $s$t
          }; } %all_stat_count_indexes = (); } # Compute statistics about extended statistics sub pg_stat_ext { my ($input_dir, $file) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); %all_stat_extended_statistics = (); # Load data from file my $curfh = open_filehdl("$in_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if (!$l); my @data = split(/;/, $l); next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB))); # timestamp | dbname | schemaname | tablename | stats_schemaname | stats_name | stats_owner | attnames | kinds push(@{$all_stat_extended_statistics{$data[1]}}, [ ($data[4], $data[5], $data[8], $data[7], $data[2], $data[3]) ] ); } $curfh->close(); } # Compute report about extended statistics sub pg_stat_ext_report { my ($src_base, $dbname, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); return if (!$dbname); my $id = &get_data_id('table-extended', %data_info); foreach my $db (sort keys %all_stat_extended_statistics) { next if ($db ne $dbname); next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB))); print qq{

            $data_info{$id}{menu} on $db database

            $data_info{$id}{description}

            }; my %stat_kinds = ('f' => 'dependencies', 'd' => 'ndistinct', 'm' => 'mcv'); foreach my $r (sort {"$a->[4].$a->[5]" cmp "$b->[4].$b->[5]"} @{$all_stat_extended_statistics{$db}}) { $r->[2] =~ s/\{//; $r->[2] =~ s/\}//; my @skind = split(',', $r->[2]); map { s/(.*)/$stat_kinds{$1}/; } @skind; $r->[3] =~ s/\{//; $r->[3] =~ s/\}//; print "\n"; } print qq{
            Table Extended Statistic
            $r->[4].$r->[5]CREATE STATISTICS $r->[0].$r->[1] (", join(',', @skind), ") ON $r->[3] FROM $r->[4].$r->[5];
            }; } %all_stat_extended_statistics = (); } # Get relevant content of postgresql.conf sub postgresql_conf { my ($input_dir, $file) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); %all_postgresql_conf = (); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if ($l !~ /^[a-z]/); $l =~ s/\s*#.*//; $all_postgresql_conf{content} .= "$l\n"; } $curfh->close(); return if (!exists $all_postgresql_conf{content}); # Load change on configuration file from diff files &get_diff("$input_dir/$file.diff", \%all_postgresql_conf_diff); } # Show content of postgresql.conf sub postgresql_conf_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my $output = $all_postgresql_conf{content} || ''; if (!$output) { $output = '
            NO DATASET
            '; } else { $output = "
            \n$output
            \n"; } my $id = &get_data_id('cluster-pgconf', %data_info); print qq{




            • $data_info{$id}{menu}

              $data_info{$id}{description}

              $output
              }; %all_postgresql_conf = (); &show_diff(%all_postgresql_conf_diff); %all_postgresql_conf_diff = (); print qq{
            }; } # Get relevant content of recovery.conf sub recovery_conf { my ($input_dir, $file) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); %all_recovery_conf = (); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if ($l !~ /^[a-z]/); $l =~ s/\s*#.*//; $all_recovery_conf{content} .= "$l\n"; } $curfh->close(); return if (!exists $all_recovery_conf{content}); # Load change on configuration file from diff files &get_diff("$input_dir/$file.diff", \%all_recovery_conf_diff); } # Show content of recovery.conf sub recovery_conf_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my $output = $all_recovery_conf{content} || ''; if (!$output) { $output = '
            NO DATASET
            '; } else { $output = "
            \n$output
            \n"; } my $id = &get_data_id('cluster-recoveryconf', %data_info); print qq{




            • $data_info{$id}{menu}

              $data_info{$id}{description}

              $output
              }; %all_recovery_conf = (); &show_diff(%all_recovery_conf_diff); %all_recovery_conf_diff = (); print qq{
            }; } # Show relevant content of postgresql.auto.conf sub postgresql_auto_conf { my ($input_dir, $file) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); %all_postgresql_auto_conf = (); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if ($l !~ /^[a-z]/); $l =~ s/\s*#.*//; $all_postgresql_auto_conf{content} .= "$l\n"; } $curfh->close(); return if (!exists $all_postgresql_auto_conf{content}); # Load change on configuration file from diff files &get_diff("$input_dir/$file.diff", \%all_postgresql_auto_conf_diff); } # Show relevant content of postgresql.auto.conf sub postgresql_auto_conf_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my $output = $all_postgresql_auto_conf{content} || ''; if (!$output) { $output = '
            NO DATASET
            '; } else { $output = "
            \n$output
            \n"; } my $id = &get_data_id('cluster-alterconf', %data_info); print qq{




            • $data_info{$id}{menu}

              $data_info{$id}{description}

              $output
              }; %all_postgresql_auto_conf = (); &show_diff(%all_postgresql_auto_conf_diff); %all_postgresql_auto_conf_diff = (); print qq{
            }; } # Get relevant content of pg_hba.conf sub pg_hba_conf { my ($input_dir, $file) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); %all_pg_hba_conf = (); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if ($l !~ /^[a-z]/); $l =~ s/\s*#.*//; $all_pg_hba_conf{content} .= "$l\n"; } $curfh->close(); return if (!exists $all_pg_hba_conf{content}); # Load change on configuration file from diff files &get_diff("$input_dir/$file.diff", \%all_pg_hba_conf_diff); } # Show content of pg_hba.conf sub pg_hba_conf_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my $output = $all_pg_hba_conf{content} || ''; if (!$output) { $output = '
            NO DATASET
            '; } else { $output = "
            \n$output
            \n"; } my $id = &get_data_id('cluster-pghba', %data_info); print qq{




            • $data_info{$id}{menu}

              $data_info{$id}{description}

              $output
              }; %all_pg_hba_conf = (); &show_diff(%all_pg_hba_conf_diff); %all_pg_hba_conf_diff = (); print qq{
            }; } # Get relevant content of pg_ident.conf sub pg_ident_conf { my ($input_dir, $file) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); %all_pg_ident_conf = (); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if ($l !~ /^[a-z]/); $l =~ s/\s*#.*//; $all_pg_ident_conf{content} .= "$l\n"; } $curfh->close(); return if (!exists $all_pg_ident_conf{content}); # Load change on configuration file from diff files &get_diff("$input_dir/$file.diff", \%all_pg_ident_conf_diff); } # Show content of pg_ident.conf sub pg_ident_conf_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my $output = $all_pg_ident_conf{content} || ''; if (!$output) { $output = '
            NO DATASET
            '; } else { $output = "
            \n$output
            \n"; } my $id = &get_data_id('cluster-pgident', %data_info); print qq{




            • $data_info{$id}{menu}

              $data_info{$id}{description}

              $output
              }; %all_pg_ident_conf = (); &show_diff(%all_pg_ident_conf_diff); %all_pg_ident_conf_diff = (); print qq{
            }; } # Get configuration from pg_settings sub pg_settings { my ($input_dir, $file) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); %all_settings = (); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if (!$l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # timestamp | label | setting | value | unit | context | source | boot_val | reset_val | pending_restart $all_settings{$data[1]}{$data[2]}{value} = $data[3]; $all_settings{$data[1]}{$data[2]}{unit} = ''; $all_settings{$data[1]}{$data[2]}{bootval} = ''; $all_settings{$data[1]}{$data[2]}{resetval} = ''; if ($#data >= 6) { $all_settings{$data[1]}{$data[2]}{unit} = $data[4]; $all_settings{$data[1]}{$data[2]}{bootval} = $data[7]; $all_settings{$data[1]}{$data[2]}{resetval} = $data[8]; if ($#data >= 9) { $all_settings{$data[1]}{$data[2]}{pending_restart} = $data[9]; } if ($data[2] eq 'data_checksums') { $OVERALL_STATS{'cluster'}{'data_checksums'} = $data[3]; } } } $curfh->close(); # Load change on configuration file from diff files $file =~ s/\.csv/.diff/; &get_diff("$input_dir/$file", \%all_settings_diff); } # Show configuration from pg_settings sub pg_settings_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my $id = &get_data_id('cluster-settings', %data_info); my $output = ''; if (scalar keys %all_settings == 0) { $output = '
            NO DATASET
            '; } else { foreach my $lbl (sort keys %all_settings) { $output .= "$lbl\n"; $output .= "NameCurrentUnitReset valBoot valPending restart\n"; foreach my $set (sort { lc($a) cmp lc($b) } keys %{$all_settings{$lbl}}) { $output .= "$set$all_settings{$lbl}{$set}{value}$all_settings{$lbl}{$set}{unit}"; if ($all_settings{$lbl}{$set}{resetval}) { $output .= "$all_settings{$lbl}{$set}{resetval}"; } else { $output .= ""; } if ($all_settings{$lbl}{$set}{bootval}) { $output .= "$all_settings{$lbl}{$set}{bootval}"; } else { $output .= ""; } if (exists $all_settings{$lbl}{$set}{pending_restart}) { if ($all_settings{$lbl}{$set}{pending_restart} eq 't') { $output .= "$all_settings{$lbl}{$set}{pending_restart}"; } else { $output .= "$all_settings{$lbl}{$set}{pending_restart}"; } } else { $output .= "n/a"; } $output .= "\n"; } } $output = "\n$output
            \n"; %all_settings = (); } %all_settings = (); print qq{




            • $data_info{$id}{menu}

              $data_info{$id}{description}

              $output
              }; &show_diff(%all_settings_diff); %all_settings_diff = (); print qq{
            }; } # Get non default configuration from pg_settings sub pg_nondefault_settings { my ($input_dir, $file) = @_; %all_nondefault_settings = (); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if (!$l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # timestamp | label | setting | value $all_nondefault_settings{$data[1]}{$data[2]}{value} = $data[3]; $all_nondefault_settings{$data[1]}{$data[2]}{unit} = ''; $all_nondefault_settings{$data[1]}{$data[2]}{bootval} = ''; $all_nondefault_settings{$data[1]}{$data[2]}{resetval} = ''; if ($#data >= 6) { $all_nondefault_settings{$data[1]}{$data[2]}{unit} = $data[4]; $all_nondefault_settings{$data[1]}{$data[2]}{bootval} = $data[7]; $all_nondefault_settings{$data[1]}{$data[2]}{resetval} = $data[8]; } } $curfh->close(); } # Show non default configuration from pg_settings sub pg_nondefault_settings_report { my ($src_base, %data_info) = @_; return if (scalar keys %all_nondefault_settings == 0); my $id = &get_data_id('cluster-nondefault-settings', %data_info); print qq{ }; %all_nondefault_settings = (); } # Get configuration from pg_db_role_setting sub pg_db_role_setting { my ($input_dir, $file) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); %all_db_role_setting = (); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if (!$l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # timestamp | database | role | settings $data[1] ||= 'All'; $data[2] ||= 'All'; $all_db_role_setting{$data[1]}{$data[2]} = $data[3]; } $curfh->close(); # Load change on configuration file from diff files $file =~ s/\.csv/.diff/; &get_diff("$input_dir/$file", \%all_db_role_setting_diff); } # Show configuration from pg_db_role_setting sub pg_db_role_setting_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my $id = &get_data_id('cluster-dbrolesetting', %data_info); my $output = ''; if (scalar keys %all_db_role_setting == 0) { $output = '
            NO DATASET
            '; } else { $output = "\n"; $output .= "\n"; foreach my $db (sort keys %all_db_role_setting) { next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB))); foreach my $set (sort { lc($a) cmp lc($b) } keys %{$all_db_role_setting{$db}}) { $output .= "\n"; } } $output .= "
            DatabaseRoleSettings
            $db$set$all_db_role_setting{$db}{$set}
            \n"; %all_db_role_setting = (); } print qq{




            • $data_info{$id}{menu}

              $data_info{$id}{description}

              $output
              }; &show_diff(%all_db_role_setting_diff); %all_db_role_setting_diff = (); print qq{
            }; %all_db_role_setting = (); } # Compute statistics of buffercache database sub pg_database_buffercache { my ($input_dir, $file, $offset) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my %db_list = (); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); $curfh->seek($offset,0); while (my $l = <$curfh>) { $offset += length($l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # Store list of database $db_list{$data[1]} = 1; # date_trunc | datname | buffers | buffered | buffers % | database % $all_database_buffercache{$data[0]}{$data[1]}{shared_buffers_used} = ($data[4]||0); $all_database_buffercache{$data[0]}{$data[1]}{database_loaded} = ($data[5]||0); $all_database_buffercache{$data[0]}{'all'}{shared_buffers_used} += ($data[4]||0); $all_database_buffercache{$data[0]}{'all'}{database_loaded} += ($data[5]||0); } $curfh->close(); # Store the full list of database foreach my $d (keys %db_list) { push(@global_databases, $d) if (!grep/^$d$/, @global_databases); } push(@global_databases, 'all') if (($#global_databases >= 0) && !grep(/^all$/, @global_databases)); return $offset; } # Compute report of buffercache database statistics sub pg_database_buffercache_report { my ($src_base, $db_glob, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my %shared_stat = (); my $tz = ($STATS_TIMEZONE*3600*1000); foreach my $t (sort keys %all_database_buffercache) { foreach my $db (@global_databases) { next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB))); $shared_stat{$db}{shared_buffers_used} .= '[' . ($t - $tz) . ',' . ($all_database_buffercache{$t}{$db}{shared_buffers_used}||0) . '],'; $shared_stat{$db}{database_loaded} .= '[' . ($t - $tz) . ',' . ($all_database_buffercache{$t}{$db}{database_loaded}||0) . '],'; } } %all_database_buffercache = (); foreach my $id (sort {$a <=> $b} keys %data_info) { next if ($id ne $ID_ACTION); if ($data_info{$id}{name} eq 'cluster-buffersused') { my @graph_data = (); foreach my $db (sort keys %shared_stat) { next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB))); push(@{$data_info{$id}{legends}}, "% used by $db"); $shared_stat{$db}{shared_buffers_used} =~ s/,$//; push(@graph_data, $shared_stat{$db}{shared_buffers_used}); } print &jqplot_linegraph_array($IDX++, 'cluster-buffersused', \%{$data_info{$id}}, '', @graph_data); } elsif ($data_info{$id}{name} eq 'cluster-databaseloaded') { my @graph_data = (); foreach my $db (sort keys %shared_stat) { next if ($db eq 'all'); next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB))); push(@{$data_info{$id}{legends}}, "% of $db"); $shared_stat{$db}{database_loaded} =~ s/,$//; push(@graph_data, $shared_stat{$db}{database_loaded}); } print &jqplot_linegraph_array($IDX++, 'cluster-databaseloaded', \%{$data_info{$id}}, '', @graph_data); } } } # Compute statistics of usagecount in shared buffers sub pg_database_usagecount { my ($input_dir, $file, $offset) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); $curfh->seek($offset,0); while (my $l = <$curfh>) { $offset += length($l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # date_trunc | datname | usagecount | buffer | buffers % $all_database_usagecount{$data[0]}{$data[2]} += ($data[4]||0); } $curfh->close(); return $offset; } # Compute graph of usagecount in shared buffers sub pg_database_usagecount_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my %shared_stat = (); my $tz = ($STATS_TIMEZONE*3600*1000); foreach my $t (sort keys %all_database_usagecount) { foreach my $u (sort keys %{$all_database_usagecount{$t}}) { $shared_stat{$u}{usagecount} .= '[' . ($t - $tz) . ',' . $all_database_usagecount{$t}{$u} . '],'; } } %all_database_usagecount = (); foreach my $id (sort {$a <=> $b} keys %data_info) { next if ($id ne $ID_ACTION); if ($data_info{$id}{name} eq 'cluster-usagecount') { my @graph_data = (); foreach my $u (sort keys %shared_stat) { push(@{$data_info{$id}{legends}}, "% of usagecount $u"); $shared_stat{$u}{usagecount} =~ s/,$//; push(@graph_data, $shared_stat{$u}{usagecount}); } print &jqplot_linegraph_array($IDX++, 'cluster-usagecount', \%{$data_info{$id}}, '', @graph_data); } } } # Compute statistics of dirty buffer in cache sub pg_database_isdirty { my ($input_dir, $file, $offset) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); $curfh->seek($offset,0); while (my $l = <$curfh>) { $offset += length($l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # date_trunc | datname | usagecount | isdirty | buffer | buffers % $all_database_isdirty{$data[0]}{$data[2]} += $data[5] if ($data[3] eq 't'); } $curfh->close(); return $offset; } # Compute graphs of dirty buffer in cache sub pg_database_isdirty_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my %shared_stat = (); my $tz = ($STATS_TIMEZONE*3600*1000); foreach my $t (sort keys %all_database_isdirty) { foreach my $u (sort keys %{$all_database_isdirty{$t}}) { $shared_stat{$u}{usagecount} .= '[' . ($t - $tz) . ',' . $all_database_isdirty{$t}{$u} . '],'; } } %all_database_isdirty = (); foreach my $id (sort {$a <=> $b} keys %data_info) { next if ($id ne $ID_ACTION); if ($data_info{$id}{name} eq 'cluster-isdirty') { my @graph_data = (); foreach my $u (sort keys %shared_stat) { push(@{$data_info{$id}{legends}}, "% of usagecount $u"); $shared_stat{$u}{usagecount} =~ s/,$//; push(@graph_data, $shared_stat{$u}{usagecount}); } print &jqplot_linegraph_array($IDX++, 'cluster-isdirty', \%{$data_info{$id}}, '', @graph_data); } } } # Compute statistics of archiver sub pg_stat_archiver { my ($input_dir, $file, $offset) = @_; my @start_vals = (); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); $curfh->seek($offset,0); while (my $l = <$curfh>) { $offset += length($l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); # timestamp | archived_count | last_archived_wal | last_archived_time | failed_count | last_failed_wal | last_failed_time | stats_reset push(@start_vals, @data) if ($#start_vals < 0); $data[3] =~ s/\..*//; $data[6] =~ s/\..*//; $data[7] =~ s/\..*//; # Get archiver size statistics if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) { my $tmp_val = ''; (($data[1] - $start_vals[1]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[1] - $start_vals[1]); $all_stat_archiver{$data[0]}{archived_count} = $tmp_val; (($data[4] - $start_vals[4]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[4] - $start_vals[4]); $all_stat_archiver{$data[0]}{failed_count} = $tmp_val; $all_stat_archiver{$data[0]}{last_archived_wal} = $data[2]; $all_stat_archiver{$data[0]}{last_archived_time} = $data[3]; $all_stat_archiver{$data[0]}{last_failed_wal} = $data[5]; $all_stat_archiver{$data[0]}{last_failed_time} = $data[6]; $all_stat_archiver{$data[0]}{stats_reset} = $data[7]; } else { if (!$OVERALL_STATS{'archiver'}{last_archived_time} || ($data[3] gt $OVERALL_STATS{'archiver'}{last_archived_time})) { $OVERALL_STATS{'archiver'}{last_archived_wal} = $data[2]; $OVERALL_STATS{'archiver'}{last_archived_time} = $data[3]; } if (!$OVERALL_STATS{'archiver'}{last_failed_time} || ($data[6] gt $OVERALL_STATS{'archiver'}{last_failed_time})) { $OVERALL_STATS{'archiver'}{last_failed_wal} = $data[5]; $OVERALL_STATS{'archiver'}{last_failed_time} = $data[6]; } if (!$OVERALL_STATS{'archiver'}{stats_reset} || ($data[7] gt $OVERALL_STATS{'archiver'}{stats_reset})) { $OVERALL_STATS{'archiver'}{stats_reset} = $data[7]; } } @start_vals = (); push(@start_vals, @data); } $curfh->close(); return $offset; } # Compute graphs of archiver statistics sub pg_stat_archiver_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my %archiver_stat = (); my $tz = ($STATS_TIMEZONE*3600*1000); foreach my $t (sort {$a <=> $b} keys %all_stat_archiver) { $archiver_stat{archived_count} .= '[' . ($t - $tz) . ',' . $all_stat_archiver{$t}{archived_count}. '],'; $archiver_stat{failed_count} .= '[' . ($t - $tz) . ',' . $all_stat_archiver{$t}{failed_count}. '],'; } %all_stat_archiver = (); foreach my $id (sort {$a <=> $b} keys %data_info) { next if ($id ne $ID_ACTION); if ($data_info{$id}{name} eq 'cluster-archive') { print &jqplot_linegraph_array($IDX++, 'cluster-archive', \%{$data_info{$id}}, '', $archiver_stat{archived_count}, $archiver_stat{failed_count}); } } } # Compute graphs of statements statistics sub pg_stat_statements { my ($input_dir, $file) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); my $total_val = 0; my @start_vals = (); my $has_temp = 0; %all_stat_statements = (); # Load data from file my $curfh = open_filehdl("$input_dir/$file"); while (my $l = <$curfh>) { chomp($l); next if (!$l); my @data = split(/;/, $l); next if (!&normalize_line(\@data)); next if (($#INCLUDE_DB >= 0) && (!grep($data[2] =~ /^$_$/, @INCLUDE_DB))); # pg 8.4 # timestamp | userid | datname | query | calls | total_time | rows # pg 9.0-9.1 # timestamp | userid | datname | query | calls | total_time | rows | shared_blks_hit | shared_blks_read | shared_blks_written | local_blks_hit | local_blks_read | local_blks_written | temp_blks_read | temp_blks_written # pg 9.2+ # timestamp | userid | datname | query | calls | total_time | rows | shared_blks_hit | shared_blks_read | shared_blks_dirtied | shared_blks_written | local_blks_hit | local_blks_read | local_blks_dirtied | local_blks_written | temp_blks_read | temp_blks_written | blk_read_time | blk_write_time | my $id = 3; next if (!$data[$id]); $all_stat_statements{$data[2]}{$data[$id]}{calls} = ($data[$id+1] || 0); $all_stat_statements{$data[2]}{$data[$id]}{total_time} = ($data[$id+2] || 0); $all_stat_statements{$data[2]}{$data[$id]}{rows} = ($data[$id+3] || 0); if ($#data > 6) { $all_stat_statements{$data[2]}{$data[$id]}{shared_blks_hit} = $data[$id+4]; $all_stat_statements{$data[2]}{$data[$id]}{shared_blks_read} = $data[$id+5]; if ($#data < 18) { $all_stat_statements{$data[2]}{$data[$id]}{shared_blks_written} = $data[$id+6]; $all_stat_statements{$data[2]}{$data[$id]}{local_blks_hit} = $data[$id+7]; $all_stat_statements{$data[2]}{$data[$id]}{local_blks_read} = $data[$id+8]; $all_stat_statements{$data[2]}{$data[$id]}{local_blks_written} = $data[$id+9]; $all_stat_statements{$data[2]}{$data[$id]}{temp_blks_read} = $data[$id+10]; $all_stat_statements{$data[2]}{$data[$id]}{temp_blks_written} = $data[$id+11]; # This is just a flag, the total_time key is not used but must exists to not generate # error on use of unitialised value later. This is ugly but useful $all_stat_statements{$data[2]}{has_temp}{total_time} = 1; } else { $all_stat_statements{$data[2]}{$data[$id]}{shared_blks_dirtied} = ($data[$id+6]*8192); $all_stat_statements{$data[2]}{$data[$id]}{shared_blks_written} = $data[$id+7]; $all_stat_statements{$data[2]}{$data[$id]}{local_blks_hit} = $data[$id+8]; $all_stat_statements{$data[2]}{$data[$id]}{local_blks_read} = $data[$id+9]; $all_stat_statements{$data[2]}{$data[$id]}{local_blks_dirtied} = $data[$id+10]; $all_stat_statements{$data[2]}{$data[$id]}{local_blks_written} = $data[$id+11]; $all_stat_statements{$data[2]}{$data[$id]}{temp_blks_read} = ($data[$id+12]*8192); $all_stat_statements{$data[2]}{$data[$id]}{temp_blks_written} = ($data[$id+13]*8192); $all_stat_statements{$data[2]}{$data[$id]}{blk_read_time} = $data[$id+14]; $all_stat_statements{$data[2]}{$data[$id]}{blk_write_time} = $data[$id+15]; # This is just a flag, the total_time key is not used but must exists to not generate # error on use of unitialised value later. This is ugly but useful $all_stat_statements{$data[2]}{has_temp}{total_time} = 2; if ($data[$id+14] || $data[$id+15]) { $all_stat_statements{$data[2]}{has_temp}{total_time} = 3; } } } } $curfh->close(); } # Compute graphs of statements statistics sub pg_stat_statements_report { my ($src_base, $db, %data_info) = @_; return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ); return if (!$db); my $id = &get_data_id('database-queries', %data_info); my $header = ''; if (exists $all_stat_statements{$db}) { if (exists $all_stat_statements{$db}{has_temp}) { $header .= qq{Temp blocks written}; } if ($all_stat_statements{$db}{has_temp}{total_time} >= 2) { $header .= qq{Blocks readBlocks hitBlocks dirtiedBlocks written}; } if ($all_stat_statements{$db}{has_temp}{total_time} == 3) { $header .= qq{I/O time}; } $header = qq{CallsAvg timeTotal timeRows$headerQuery}; } else { $header = qq{
            NO DATASET
            }; } print qq{




          • $data_info{$id}{menu} on $db database

            $data_info{$id}{description}

            $header }; foreach my $q (sort {$all_stat_statements{$db}{$b}{total_time} <=> $all_stat_statements{$db}{$a}{total_time}} keys %{$all_stat_statements{$db}}) { next if ($q eq 'has_temp'); my $additional_cols = ''; if (exists $all_stat_statements{$db}{has_temp}) { $additional_cols = ""; } if ($all_stat_statements{$db}{has_temp}{total_time} == 2) { $additional_cols .= ""; } if ($all_stat_statements{$db}{has_temp}{total_time} == 3) { $additional_cols .= ""; } my $query = $q; $query =~ s/#SMCLN#/;/g; print "$additional_cols\n"; } print qq{
            " . &pretty_print_number($all_stat_statements{$db}{$q}{temp_blks_written}) . "" . &pretty_print_number($all_stat_statements{$db}{$q}{shared_blks_read}) . "" . &pretty_print_number($all_stat_statements{$db}{$q}{shared_blks_hit}) . "" . &pretty_print_number($all_stat_statements{$db}{$q}{shared_blks_dirtied}) . "" . &pretty_print_number($all_stat_statements{$db}{$q}{shared_blks_written}) . "" . sprintf("%0.2d", ($all_stat_statements{$db}{$q}{blk_read_time}+$all_stat_statements{$db}{$q}{blk_write_time})/($all_stat_statements{$db}{$q}{calls}||1)) . "
            $all_stat_statements{$db}{$q}{calls}" . &format_duration(int($all_stat_statements{$db}{$q}{total_time}/($all_stat_statements{$db}{$q}{calls}||1))) . "" . &format_duration($all_stat_statements{$db}{$q}{total_time}) . "$all_stat_statements{$db}{$q}{rows}$query
          • }; %all_stat_statements = (); } sub normalize_line { my $data = shift; # Get position of the database name my $pos = shift; $pos ||= 2; return 0 if ($data->[0] !~ /^\d+/); $data->[0] = &convert_time($data->[0]); # Skip unwanted lines return 0 if ($BEGIN && ($data->[0] < $BEGIN)); return 0 if ($END && ($data->[0] > $END)); chomp($data->[-1]); map { s/,/\./g; s/^$/0/; } @$data; # Always skip default template database return 0 if ($data->[$pos] =~ /template/); return 1; } sub pretty_print_size { my $val = shift; return 0 if (!$val); return '-' if ($val eq '-'); if ($val >= 1125899906842624) { $val = ($val / 1125899906842624); $val = sprintf("%0.2f", $val) . " PB"; } elsif ($val >= 1099511627776) { $val = ($val / 1099511627776); $val = sprintf("%0.2f", $val) . " TB"; } elsif ($val >= 1073741824) { $val = ($val / 1073741824); $val = sprintf("%0.2f", $val) . " GB"; } elsif ($val >= 1048576) { $val = ($val / 1048576); $val = sprintf("%0.2f", $val) . " MB"; } elsif ($val >= 1024) { $val = ($val / 1024); $val = sprintf("%0.2f", $val) . " KB"; } else { $val = $val . " B"; } return $val; } sub pretty_print_number { my $val = shift; return 0 if (!$val); return '-' if ($val eq '-'); if ($val >= 1000000000000000) { $val = ($val / 1000000000000000); $val = sprintf("%0.2f", $val) . " P"; } elsif ($val >= 1000000000000) { $val = ($val / 1000000000000); $val = sprintf("%0.2f", $val) . " T"; } elsif ($val >= 1000000000) { $val = ($val / 1000000000); $val = sprintf("%0.2f", $val) . " G"; } elsif ($val >= 1000000) { $val = ($val / 1000000); $val = sprintf("%0.2f", $val) . " M"; } elsif ($val >= 1000) { $val = ($val / 1000); $val = sprintf("%0.2f", $val) . " K"; } return $val; } sub show_home { my $input_dir = shift(); # Compute global statistics for home page dashboard my %overall_stat_databases = (); if (exists $OVERALL_STATS{'cluster'}) { $OVERALL_STATS{'cluster'}{'blks_hit'} ||= 0; $OVERALL_STATS{'cluster'}{'blks_read'} ||= 0; $OVERALL_STATS{'cluster'}{'cache_ratio'} = sprintf("%3d", ($OVERALL_STATS{'cluster'}{'blks_hit'} * 100) / (($OVERALL_STATS{'cluster'}{'blks_read'} + $OVERALL_STATS{'cluster'}{'blks_hit'}) || 1)) . "%"; $OVERALL_STATS{'cluster'}{'temp_bytes'} = &pretty_print_size($OVERALL_STATS{'cluster'}{'temp_bytes'}); foreach my $db (keys %{$OVERALL_STATS{'database'}}) { next if ($db eq 'all'); $OVERALL_STATS{'database'}{$db}{'blks_hit'} ||= 0; $OVERALL_STATS{'database'}{$db}{'blks_read'} ||= 0; $OVERALL_STATS{'database'}{$db}{'blks_hit'} ||= 0; $OVERALL_STATS{'database'}{$db}{'cache_ratio'} = sprintf("%3d", ($OVERALL_STATS{'database'}{$db}{'blks_hit'} * 100) / (($OVERALL_STATS{'database'}{$db}{'blks_read'} + $OVERALL_STATS{'database'}{$db}{'blks_hit'}) || 1)); } foreach my $db (keys %{$OVERALL_STATS{'database'}}) { next if ($db eq 'all'); $OVERALL_STATS{'cluster'}{'size'} += ($OVERALL_STATS{'database'}{$db}{'size'} || 0); next if (($#INCLUDE_DB >= 0) && !grep($db =~ /^$_$/, @INCLUDE_DB)); if (exists $OVERALL_STATS{'database'}{$db}{'size'}) { if (!exists $overall_stat_databases{'size'} || $OVERALL_STATS{'database'}{$db}{'size'} > $overall_stat_databases{'size'}[1]) { @{$overall_stat_databases{'size'}} = ($db, $OVERALL_STATS{'database'}{$db}{'size'}); } } if (exists $OVERALL_STATS{'database'}{$db}{'nbackend'}) { if (!exists $overall_stat_databases{'nbackend'} || $OVERALL_STATS{'database'}{$db}{'nbackend'} > $overall_stat_databases{'nbackend'}[1]) { @{$overall_stat_databases{'nbackend'}} = ($db, $OVERALL_STATS{'database'}{$db}{'nbackend'}); } } if (exists $OVERALL_STATS{'database'}{$db}{'returned'}) { if (!exists $overall_stat_databases{'returned'} || $OVERALL_STATS{'database'}{$db}{'returned'} > $overall_stat_databases{'returned'}[1]) { @{$overall_stat_databases{'returned'}} = ($db, $OVERALL_STATS{'database'}{$db}{'returned'}); } } if (exists $OVERALL_STATS{'database'}{$db}{'temp_files'}) { if (!exists $overall_stat_databases{'temp_files'} || $OVERALL_STATS{'database'}{$db} {'temp_files'} > $overall_stat_databases{'temp_files'}[1]) { @{$overall_stat_databases{'temp_files'}} = ($db, $OVERALL_STATS{'database'}{$db}{'temp_files'}); } } if (exists $OVERALL_STATS{'database'}{$db}{'temp_bytes'}) { if (!exists $overall_stat_databases{'temp_bytes'} || $OVERALL_STATS{'database'}{$db}{'temp_bytes'} > $overall_stat_databases{'temp_bytes'}[1]) { @{$overall_stat_databases{'temp_bytes'}} = ($db, $OVERALL_STATS{'database'}{$db}{'temp_bytes'}); } } if (exists $OVERALL_STATS{'database'}{$db}{'deadlocks'}) { if (!exists $overall_stat_databases{'deadlocks'} || $OVERALL_STATS{'database'}{$db}{'deadlocks'} > $overall_stat_databases{'deadlocks'}[1]) { @{$overall_stat_databases{'deadlocks'}} = ($db, $OVERALL_STATS{'database'}{$db}{'deadlocks'}); } } if (exists $OVERALL_STATS{'database'}{$db}{'cache_ratio'}) { if (!exists $overall_stat_databases{'cache_ratio'} || $OVERALL_STATS{'database'}{$db}{'cache_ratio'} < $overall_stat_databases{'cache_ratio'}[1]) { @{$overall_stat_databases{'cache_ratio'}} = ($db, $OVERALL_STATS{'database'}{$db}{'cache_ratio'}); } } } @{$overall_stat_databases{'size'}} = ('unknown', 0) if (!exists $overall_stat_databases{'size'}); if (exists $overall_stat_databases{'size'}) { $overall_stat_databases{'size'}[1] = &pretty_print_size($overall_stat_databases{'size'}[1]); } if (exists $overall_stat_databases{'temp_bytes'}) { $overall_stat_databases{'temp_bytes'}[1] = &pretty_print_size($overall_stat_databases{'temp_bytes'}[1]); } } my %overall_system_stats = (); if (!$DISABLE_SAR) { if (!exists $OVERALL_STATS{'system'}{'cpu'}) { @{$OVERALL_STATS{'system'}{'cpu'}} = ('unknown', 0); } else { ${$OVERALL_STATS{'system'}{'cpu'}}[0] = localtime(${$OVERALL_STATS{'system'}{'cpu'}}[0]/1000); } if (!exists $OVERALL_STATS{'system'}{'load'}) { @{$OVERALL_STATS{'system'}{'load'}} = ('unknown', 0); } else { ${$OVERALL_STATS{'system'}{'load'}}[0] = localtime(${$OVERALL_STATS{'system'}{'load'}}[0]/1000); } if (!exists $OVERALL_STATS{'system'}{'blocked'}) { @{$OVERALL_STATS{'system'}{'blocked'}} = ('unknown', 0); } else { ${$OVERALL_STATS{'system'}{'blocked'}}[0] = localtime(${$OVERALL_STATS{'system'}{'blocked'}}[0]/1000); } if (!exists $OVERALL_STATS{'system'}{'kbcached'}) { @{$OVERALL_STATS{'system'}{'kbcached'}} = ('unknown', 0); } else { ${$OVERALL_STATS{'system'}{'kbcached'}}[0] = localtime(${$OVERALL_STATS{'system'}{'kbcached'}}[0]/1000); } if (!exists $OVERALL_STATS{'system'}{'kbdirty'}) { @{$OVERALL_STATS{'system'}{'kbdirty'}} = ('unknown', 0); } else { ${$OVERALL_STATS{'system'}{'kbdirty'}}[0] = localtime(${$OVERALL_STATS{'system'}{'kbdirty'}}[0]/1000); } if (!exists $OVERALL_STATS{'system'}{'bread'}) { @{$OVERALL_STATS{'system'}{'bread'}} = ('unknown', 0); } else { ${$OVERALL_STATS{'system'}{'bread'}}[0] = localtime(${$OVERALL_STATS{'system'}{'bread'}}[0]/1000); } if (!exists $OVERALL_STATS{'system'}{'bwrite'}) { @{$OVERALL_STATS{'system'}{'bwrite'}} = ('unknown', 0); } else { ${$OVERALL_STATS{'system'}{'bwrite'}}[0] = localtime(${$OVERALL_STATS{'system'}{'bwrite'}}[0]/1000); } if (!exists $OVERALL_STATS{'system'}{'svctm'}) { @{$OVERALL_STATS{'system'}{'svctm'}} = ('unknown', 0, 'unknown'); } else { ${$OVERALL_STATS{'system'}{'svctm'}}[0] = localtime(${$OVERALL_STATS{'system'}{'svctm'}}[0]/1000); } if (exists $OVERALL_STATS{'system'}{'devices'}) { foreach my $d (sort keys %{$OVERALL_STATS{'system'}{'devices'}}) { if (! exists $overall_system_stats{read} || ($overall_system_stats{read}[1] < $OVERALL_STATS{'system'}{'devices'}{$d}{read})) { @{$overall_system_stats{read}} = ($d, $OVERALL_STATS{'system'}{'devices'}{$d}{read}); } if (! exists $overall_system_stats{write} || ($overall_system_stats{write}[1] < $OVERALL_STATS{'system'}{'devices'}{$d}{write})) { @{$overall_system_stats{write}} = ($d, $OVERALL_STATS{'system'}{'devices'}{$d}{write}); } if (! exists $overall_system_stats{tps} || ($overall_system_stats{tps}[1] < $OVERALL_STATS{'system'}{'devices'}{$d}{tps})) { @{$overall_system_stats{tps}} = ($d, $OVERALL_STATS{'system'}{'devices'}{$d}{tps}); } } } if (exists $OVERALL_STATS{'system'}{'space'}) { foreach my $d (sort keys %{$OVERALL_STATS{'system'}{'space'}}) { if (! exists $overall_system_stats{'fsused'} || ($overall_system_stats{'fsused'}[1] < $OVERALL_STATS{'system'}{'space'}{$d}{'fsused'})) { @{$overall_system_stats{'fsused'}} = ($d, $OVERALL_STATS{'system'}{'space'}{$d}{'fsused'}); } if (! exists $overall_system_stats{'iused'} || ($overall_system_stats{'iused'}[1] < $OVERALL_STATS{'system'}{'space'}{$d}{'iused'})) { @{$overall_system_stats{'iused'}} = ($d, $OVERALL_STATS{'system'}{'space'}{$d}{'iused'}); } } } if (!exists $overall_system_stats{read}) { @{$overall_system_stats{read}} = ('unknown', 0); } if (!exists $overall_system_stats{write}) { @{$overall_system_stats{write}} = ('unknown', 0); } if (!exists $overall_system_stats{tps}) { @{$overall_system_stats{tps}} = ('unknown', 0); } if (!exists $overall_system_stats{fsused}) { @{$overall_system_stats{fsused}} = ('unknown', 0); } if (!exists $overall_system_stats{iused}) { @{$overall_system_stats{iused}} = ('unknown', 0); } $overall_system_stats{read}[1] = &pretty_print_size($overall_system_stats{read}[1]); $overall_system_stats{write}[1] = &pretty_print_size($overall_system_stats{write}[1]); @{$overall_system_stats{kbcached}} = ($OVERALL_STATS{'system'}{'kbcached'}[0], &pretty_print_size($OVERALL_STATS{'system'}{'kbcached'}[1])); @{$overall_system_stats{kbdirty}} = ($OVERALL_STATS{'system'}{'kbdirty'}[0], &pretty_print_size($OVERALL_STATS{'system'}{'kbdirty'}[1])); @{$overall_system_stats{bread}} = ($OVERALL_STATS{'system'}{'bread'}[0], &pretty_print_size($OVERALL_STATS{'system'}{'bread'}[1])); @{$overall_system_stats{bwrite}} = ($OVERALL_STATS{'system'}{'bwrite'}[0], &pretty_print_size($OVERALL_STATS{'system'}{'bwrite'}[1])); } my $numcol = 4; if ($DISABLE_SAR) { $numcol = 6; } elsif (!exists $OVERALL_STATS{'system'}) { $numcol = 12; } print <




          • EOF my $tz = ((0-$STATS_TIMEZONE)*3600); if (exists $OVERALL_STATS{'start_date'}) { $OVERALL_STATS{'start_date'} = ($OVERALL_STATS{'start_date'}/1000) + $tz; $OVERALL_STATS{'end_date'} = ($OVERALL_STATS{'end_date'}/1000) + $tz; } my $start_date = localtime($OVERALL_STATS{'start_date'}||0) || 'Unknown start date'; my $end_date = localtime($OVERALL_STATS{'end_date'}||0) || 'Unknown end date'; if (exists $OVERALL_STATS{'sar_start_date'}) { $OVERALL_STATS{'sar_start_date'} = ($OVERALL_STATS{'sar_start_date'}/1000); $OVERALL_STATS{'sar_end_date'} = ($OVERALL_STATS{'sar_end_date'}/1000); } my $sar_start_date = localtime($OVERALL_STATS{'sar_start_date'}||0) || 'Unknown start date'; my $sar_end_date = localtime($OVERALL_STATS{'sar_end_date'}||0) || 'Unknown end date'; my $parts_info = ''; if (exists $OVERALL_STATS{'cluster'}) { $OVERALL_STATS{'cluster'}{'size'} ||= 0; $OVERALL_STATS{'cluster'}{'nbackend'} ||= 0; $OVERALL_STATS{'cluster'}{'returned'} ||= 0; $OVERALL_STATS{'cluster'}{'cache_ratio'} ||= 0; $OVERALL_STATS{'cluster'}{'temp_files'} ||= 0; $OVERALL_STATS{'cluster'}{'temp_bytes'} ||= 0; $OVERALL_STATS{'cluster'}{'deadlocks'} ||= 0; my $temp_file_info = ''; if ($OVERALL_STATS{'cluster'}{'temp_files'}) { $temp_file_info = qq{
          • $OVERALL_STATS{'cluster'}{'temp_files'} Temporary files
          • $OVERALL_STATS{'cluster'}{'temp_bytes'} Temporary files size
          • }; } my $deadlock_info = ''; if ($OVERALL_STATS{'cluster'}{'deadlocks'}) { $deadlock_info = qq{
          • $OVERALL_STATS{'cluster'}{'deadlocks'} Deadlocks
          • }; } my $extnum = $#{$OVERALL_STATS{'cluster'}{'extensions'}} + 1; my $extensions_info = ''; if ($extnum) { my $extlist = join(', ', @{$OVERALL_STATS{'cluster'}{'extensions'}}); $extensions_info = qq{
          • $extnum Extensions ($extlist)
          • }; } my $nparts = $#{$OVERALL_STATS{'cluster'}{'partitionned_tables'}} + 1; if ($nparts) { my %partitions = (); foreach my $pt (sort @{$OVERALL_STATS{'cluster'}{'partitionned_tables'}}) { $pt =~ s/^([^\.]+)\.//; $partitions{$1} .= "$pt;"; } $parts_info = qq{
          • $nparts Partitioned tables
            • }; foreach my $t (keys %partitions) { $parts_info .= qq{
            • $t $partitions{$t}
            }; } } $sysinfo{PGVERSION}{'full_version'} ||= ''; $sysinfo{PGVERSION}{'uptime'} ||= ''; my $database_number = scalar keys %{$OVERALL_STATS{'database'}}; $OVERALL_STATS{'cluster'}{'size'} ||= '-'; $OVERALL_STATS{'cluster'}{'nbackend'} ||= '-'; $OVERALL_STATS{'cluster'}{'returned'} ||= '-'; $OVERALL_STATS{'cluster'}{'cache_ratio'} ||= '-'; my $bgwriter_reset = ''; if (exists $OVERALL_STATS{'bgwriter'}{stats_reset}) { $bgwriter_reset = "
          • $OVERALL_STATS{'bgwriter'}{stats_reset} Last bgwriter stats reset
          • "; } my $cluster_size = &pretty_print_size($OVERALL_STATS{'cluster'}{'size'}); $OVERALL_STATS{'cluster'}{unlogged} ||= 0; my $unlogged_dblist = ''; if (exists $OVERALL_STATS{'cluster'}{unlogged_db}) { $unlogged_dblist = ' (' . join(', ', @{$OVERALL_STATS{'cluster'}{unlogged_db}}) . ')'; } $OVERALL_STATS{'cluster'}{invalid_indexes} ||= 0; my $invalid_dblist = ''; if (exists $OVERALL_STATS{'cluster'}{invalid_indexes_db}) { $invalid_dblist = ' (' . join(', ', @{$OVERALL_STATS{'cluster'}{invalid_indexes_db}}) . ')'; } $OVERALL_STATS{'cluster'}{hash_indexes} ||= 0; my $hash_dblist = ''; if (exists $OVERALL_STATS{'cluster'}{hash_indexes_db}) { $hash_dblist = ' (' . join(', ', @{$OVERALL_STATS{'cluster'}{hash_indexes_db}}) . ')'; } # On version prior to 9.3 this is not applicable $OVERALL_STATS{'cluster'}{'data_checksums'} ||= 'N/A'; print <

            Cluster

            $start_date to $end_date
            • $OVERALL_STATS{'cluster'}{'data_checksums'} Data checksums
            • $cluster_size Cluster size
            • $database_number Databases
            • $OVERALL_STATS{'cluster'}{'nbackend'} Connections
            • $OVERALL_STATS{'cluster'}{'returned'} Tuples returned
            • $OVERALL_STATS{'cluster'}{'cache_ratio'} Hit cache ratio
            • $OVERALL_STATS{'cluster'}{'unlogged'} Unlogged tables$unlogged_dblist
            • $OVERALL_STATS{'cluster'}{'invalid_indexes'} Invalid indexes$invalid_dblist
            • $OVERALL_STATS{'cluster'}{'hash_indexes'} Hash indexes$hash_dblist
            • $temp_file_info $deadlock_info $extensions_info $bgwriter_reset

            Databases

            • EOF if (exists $overall_stat_databases{'size'}) { print <$overall_stat_databases{'size'}[1] Largest database
              ($overall_stat_databases{'size'}[0]) EOF } if (exists $overall_stat_databases{'nbackend'}) { print <$overall_stat_databases{'nbackend'}[1] Most connections
              ($overall_stat_databases{'nbackend'}[0]) EOF } if (exists $overall_stat_databases{'returned'}) { print qq{
            • $overall_stat_databases{'returned'}[1] Most tuples returned
              ($overall_stat_databases{'returned'}[0])
            • }; } if (exists $overall_stat_databases{'cache_ratio'}) { push(@{$overall_stat_databases{'cache_ratio'}}, '-', '-') if ($#{$overall_stat_databases{'cache_ratio'}} < 0); print <$overall_stat_databases{'cache_ratio'}[1]% Worst cache utilization
              ($overall_stat_databases{'cache_ratio'}[0]) EOF } if (exists $overall_stat_databases{'temp_files'} && $overall_stat_databases{'temp_files'}[1]) { print <$overall_stat_databases{'temp_files'}[1] Most temporary files
              ($overall_stat_databases{'temp_files'}[0]) EOF } if (exists $overall_stat_databases{'temp_bytes'} && $overall_stat_databases{'temp_bytes'}[1]) { print <$overall_stat_databases{'temp_bytes'}[1] Most temporary bytes
              ($overall_stat_databases{'temp_bytes'}[0]) EOF } if (exists $overall_stat_databases{'deadlocks'} && $overall_stat_databases{'deadlocks'}[1]) { print <$overall_stat_databases{'deadlocks'}[1] Most deadlocks
              ($overall_stat_databases{'deadlocks'}[0]) EOF } print <
            EOF } if (!$DISABLE_SAR) { print <

            System

            $sar_start_date to $sar_end_date
            • $OVERALL_STATS{'system'}{'cpu'}[1]% Highest CPU utilization
              ($OVERALL_STATS{'system'}{'cpu'}[0])
            • $OVERALL_STATS{'system'}{'load'}[1] Highest system load
              ($OVERALL_STATS{'system'}{'load'}[0])
            • $OVERALL_STATS{'system'}{'blocked'}[1] Highest blocked processes
              ($OVERALL_STATS{'system'}{'blocked'}[0])
            • $OVERALL_STATS{'system'}{'svctm'}[1] ms Highest device service time
              ($OVERALL_STATS{'system'}{'svctm'}[0] on device $OVERALL_STATS{'system'}{'svctm'}[2])
            • $overall_system_stats{kbcached}[1] Lowest system cache
              ($overall_system_stats{kbcached}[0])
            • $overall_system_stats{kbdirty}[1] Highest dirty memory
              ($overall_system_stats{kbdirty}[0])
            • $overall_system_stats{read}[1] Most read device
              ($overall_system_stats{read}[0])
            • $overall_system_stats{write}[1] Most written device
              ($overall_system_stats{write}[0])
            • $overall_system_stats{tps}[1] Highest tps on device
              ($overall_system_stats{tps}[0])
            EOF } print < EOF if (exists $sysinfo{PGVERSION}) { my $cache_info = ''; $cache_info = "
          • Cache was last built on $sysinfo{CACHE}{last_run}
          • " if (exists $sysinfo{CACHE}); my $uptime = ''; $uptime = "
          • Up since $sysinfo{PGVERSION}{'uptime'}
          • " if ($sysinfo{PGVERSION}{'uptime'}); print <
            • $cache_info
            • $sysinfo{PGVERSION}{'full_version'}
            • $uptime
          EOF } if (exists $OVERALL_STATS{'archiver'}) { my $archiver_infos = ''; if (exists $OVERALL_STATS{'archiver'}{last_archived_wal}) { $archiver_infos = qq{
        • $OVERALL_STATS{'archiver'}{last_archived_wal} Last archived wal
        • }; $archiver_infos .= qq{
        • $OVERALL_STATS{'archiver'}{last_archived_time} Last archived time
        • }; } if (exists $OVERALL_STATS{'archiver'}{last_failed_wal}) { $archiver_infos .= qq{
        • $OVERALL_STATS{'archiver'}{last_failed_wal} Last failed wal
        • }; $archiver_infos .= qq{
        • $OVERALL_STATS{'archiver'}{last_failed_time} Last failed time
        • }; } if (exists $OVERALL_STATS{'archiver'}{stats_reset}) { $archiver_infos .= qq{
        • $OVERALL_STATS{'archiver'}{stats_reset} Last stats reset
        • }; } print <

          Archiver

          • $archiver_infos
        EOF } if ($parts_info) { print <

        Partitioning

        • $parts_info
      EOF } if (exists $sysinfo{INSTALLATION}) { my $package_infos = join('', @{$sysinfo{INSTALLATION}}); print <

      Packages

      • $package_infos
      EOF } if (exists $sysinfo{CRONTAB}) { my $cron_infos = join('', @{$sysinfo{CRONTAB}}); print <

      Crontab entries

      • $cron_infos
      EOF } print <
    EOF } sub wrong_date_selection { my $show_last_stats = shift; if ($show_last_stats) { $show_last_stats = &last_know_statistics(); } my $end_date = timelocal_nocheck(0, 0, 0, $o_day, $o_month - 1, $o_year - 1900) + 86400; $end_date = strftime("%Y-%m-%d %H:%M:00",localtime($end_date)); print <





  • No data found

    $PROGRAM is not able to find any data relative to your date selection.

    • Start: $o_year-$o_month-$o_day $o_hour:00:00
    • End : $end_date

    Please choose more accurate dates or use time selector menu.

    $show_last_stats
  • EOF } sub last_know_statistics { my $start_stats = ''; my $end_stats = ''; # Search the path to last computed statistics # Search years / months / days / hours directories if (not opendir(DIR, "$INPUT_DIR")) { return "

    FATAL: Can't open directory $INPUT_DIR: $!

    \n"; } my @years = grep { /^\d+$/ && -d "$INPUT_DIR/$_" } readdir(DIR); closedir(DIR); if ($#years >= 0) { foreach my $y (sort { $b <=> $a } @years) { if (not opendir(DIR, "$INPUT_DIR/$y")) { return "

    FATAL: Can't open directory $INPUT_DIR/$y: $!

    \n"; } my @months = grep { /^\d+$/ && -d "$INPUT_DIR/$y/$_" } readdir(DIR); closedir(DIR); foreach my $m (sort { $b <=> $a } @months) { if (not opendir(DIR, "$INPUT_DIR/$y/$m")) { return "

    FATAL: Can't open directory $INPUT_DIR/$y/$m: $!

    \n"; } my @days = grep { /^\d+$/ && -d "$INPUT_DIR/$y/$m/$_" } readdir(DIR); closedir(DIR); foreach my $d (sort { $b <=> $a } @days) { if (not opendir(DIR, "$INPUT_DIR/$y/$m/$d")) { return "

    FATAL: Can't open directory $INPUT_DIR/$y/$m/$d: $!

    \n"; } $start_stats = "$y-$m-$d\%2000:00"; $end_stats = timelocal_nocheck(0, 0, 0, $d, $m - 1, $y - 1900) + 86400; $end_stats = strftime("%Y-%m-%d%%2000:00",localtime($end_stats)); # my @hours = grep { /^\d+$/ && -d "$INPUT_DIR/$y/$m/$d/$_" } readdir(DIR); # closedir(DIR); # if ($#hours == -1) { # $start_stats = "$y-$m-$d\%2000:00"; # $end_stats = timelocal_nocheck(0, 0, 0, $d, $m - 1, $y - 1900) + 86400; # $end_stats = strftime("%Y-%m-%d%%20%H:%M",localtime($end_stats)); # } else { # foreach my $h (sort { $b <=> $a } @hours) { # $start_stats = "$y-$m-$d\%20$h:00"; # $end_stats = timegm_nocheck(0, 0, $h, $d, $m - 1, $y - 1900) + 3600; # $end_stats = strftime("%Y-%m-%d%%20%H:%M",localtime($end_stats)); # last; # } # } last; } last; } last; } } if ($start_stats) { return "

    Last known statistics

    \n"; } return "

    No statistics found

    \n"; } sub show_about { print <





  • About $PROGRAM

    $PROGRAM is a Perl program used to perform a full audit of a PostgreSQL Cluster. It is divided in two parts, a collector used to grab statistics on the PostgreSQL cluster using psql and sysstat, a grapher that will generate all HTML output. It is fully open source and free of charge.

    License

    $PROGRAM is licenced under the PostgreSQL Licence a liberal Open Source license, similar to the BSD or MIT licenses.

    That mean that all parts of the program are open source and free of charge.

    This is the case for both, the collector and the grapher programs.

    Download

    Official releases at SourceForge:
    [ http://sourceforge.net/projects/pgcluu/ ].

    Source code at github:
    [ https://github.com/darold/pgcluu ].

    ChangeLog can be read on-line on GitHub repository here

    Offical web site is hosted at pgcluu.darold.net

    Authors

    $PROGRAM is an original development of Gilles Darold.

    Some parts of the collector are taken from pgstats a C program writen by Guillaume Lelarge and especially the SQL queries including the compatibility with all PostgreSQL versions.

    Btw $PROGRAM grapher is compatible with files generated by pgstats, sar and sadc so you can use it independently to graph those data. Some part of the sar output parser are taken from SysUsage

  • EOF } sub show_sysinfo { my $input_dir = shift; &read_sysinfo($input_dir); $sysinfo{UPTIME}{'uptime'} = '-' if (!exists $sysinfo{UPTIME}{'uptime'}); my $release_version = ''; if ($sysinfo{RELEASE}{'version'}) { $release_version = qq{
  • $sysinfo{RELEASE}{'version'} Version
  • }; } my $sysctl_info = ''; my $hugepage_info = ''; foreach my $k (sort keys %{$sysinfo{SYSTEM}}) { next if ($k =~ /^kernel.*shm/); if ($k =~ /transparent_hugepage/) { my $k2 = $k; $k2 =~ s/\/sys\/kernel\/mm\/transparent_hugepage\///; $sysinfo{SYSTEM}{$k} =~ s/.*\[(.*)\].*/$1/; $hugepage_info .= <$k2 $sysinfo{SYSTEM}{$k} EOF } else { my $lbl = $k; $lbl =~ s/kernel\.//; $sysctl_info .= "
  • $lbl $sysinfo{SYSTEM}{$k}
  • \n"; } } my $core_info = ''; if (exists $sysinfo{CPU}{'cpu cores'}) { my $nsockets = $sysinfo{CPU}{'processor'}/($sysinfo{CPU}{'cpu cores'}||1); $core_info = qq{
  • $nsockets Sockets
  • $sysinfo{CPU}{'cpu cores'} Cores per CPU
  • }; } if ($hugepage_info) { $hugepage_info = </sys/kernel/mm/transparent_hugepage/
    • $hugepage_info
    EOF } if (exists $sysinfo{KERNEL}{'kernel'} || exists $sysinfo{CPU}{'processor'}) { print <



  • System

    OS information
    • $sysinfo{UPTIME}{'uptime'} Uptime
    • $sysinfo{KERNEL}{'hostname'} Hostname
    • $sysinfo{KERNEL}{'kernel'} Kernel
    • $sysinfo{KERNEL}{'arch'} Arch
    • $sysinfo{RELEASE}{'name'} Distribution
    • $release_version

    Kernel

    $hugepage_info sysctl parameters
    • $sysctl_info

    CPU

    CPUs information
    • $sysinfo{CPU}{'model name'}
    • $sysinfo{CPU}{'cpu MHz'} Speed
    • $sysinfo{CPU}{'cache size'} Cache
    • $core_info
    • $sysinfo{CPU}{'processor'} Cores

    Memory

    Memory information
    • $sysinfo{MEMORY}{'memtotal'} Total memory
    • $sysinfo{MEMORY}{'memfree'} Free memory
    • $sysinfo{MEMORY}{'buffers'} Buffers
    • $sysinfo{MEMORY}{'cached'} Cached
    • $sysinfo{MEMORY}{'swaptotal'} Total swap
    • $sysinfo{MEMORY}{'swapfree'} Free swap
    • $sysinfo{MEMORY}{'pagetables'} Page Tables
    • EOF if (exists $sysinfo{MEMORY}{'shmem'}) { print <$sysinfo{MEMORY}{'shmem'} Shared memory EOF } if (exists $sysinfo{MEMORY}{'commitlimit'}) { print <$sysinfo{MEMORY}{'commitlimit'} Commit limit
    • $sysinfo{MEMORY}{'committed_as'} Committed
    • EOF } if (exists $sysinfo{SYSTEM}{'kernel.shmmax'} and exists $sysinfo{SYSTEM}{'kernel.shmall'}) { $sysinfo{SYSTEM}{'kernel.shmmax'} = pretty_print_size($sysinfo{SYSTEM}{'kernel.shmmax'}); $sysinfo{SYSTEM}{'kernel.shmall'} = pretty_print_size($sysinfo{SYSTEM}{'kernel.shmall'} * 1024 * 4); print < sysctl parameters
      • $sysinfo{SYSTEM}{'kernel.shmmax'} kernel.shmmax
      • $sysinfo{SYSTEM}{'kernel.shmall'} kernel.shmall
      • EOF } } else { print <



      • No System information available

    EOF } if (exists $sysinfo{DF} || exists $sysinfo{MOUNT}) { my @df_infos = (); push(@df_infos, @{$sysinfo{DF}}) if (exists $sysinfo{DF}); my @mount_infos = (); push(@mount_infos, @{$sysinfo{MOUNT}}) if (exists $sysinfo{MOUNT}); print <

    Filesystem

    • @df_infos
      FilesystemSizeUsedFreeUse%Mount
    • @mount_infos
      FilesystemMounttypeOptions
    EOF } if (exists $sysinfo{PROCESS}) { print <

    Process list

    • @{$sysinfo{PROCESS}}
      USERPID%CPU%MEMVSZRSSTTYSTATSTARTTIMECOMMAND
  • EOF } print < EOF } sub html_header { my @db_list = @_; my $pgcluu_ico = 'data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAACAAAAAjCAYAAAD17ghaAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A /wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB98GCwcGIvGIhhwAAAOBSURBVFjD vZdZiI1hGMd/55gFM/Ylss4YGsuQLDP2C3uWGyVzI1mypOxSCAmFO2WJUJaoKReDIhcmSbYaaphG msgWMXZmmPnc/L96ejvfd86ZOeOp03e+733e9/m/z/5EaBxFgWFAgd6fAg+BBv4D9QBuAj8BT79f wG2gT3MK7gSs0y09PSt1+z8GzBagY6qFFwNvjZCfwEygNdAKmAJ8NOvvgOWpEFwAXDEH1wAngPQA vzjsALlu/CQp6gKcBr6bwy4A+Qns7QucNPt+AGeBrokIjgArgM/mgCpgcpx9LbTX0ljgsTnnG7Aa yAhTd7XZ8BfYKtW6NA7oad63yB9iAVsD1JpzXwDDXcZlhqEWOAfkhdx4krM+QsKCqJd8x4buGn+x P/BVH8uBIQG3bipFBPqeMclwhMQDKgK82/fwZMIqO05SqpDM9VEgRx/vyO5B6N843yaHAM4HRoUA KNczN2psVx+yoR4oNe9zgRvAfr2XKgf49AAoCTnP8520sbZeoudAmXA2sFL5I+mqlij1BLYBWUCd STo9DE8bIA2Yn0oAUfnAUWA3sA+4q7VvwC3DWyNfuggcSAWAlsBi3Wy0bFcInAEuSyOl8odF8qfB 4lsBdIgHIC3Oegbw0omGzsobc8z3qXrmGAfLVP6vaYoGvqqi/XDU/gvoJjDdgXZae69MGgFeOeAb 7QPZ0tRSYK1ufkz9QTXwGngO7BXQkbL/GAGNS4ektmMxKlqGOp4nxlyzTEfkOb+DCTr/WfEfiaeB PKCfwi1fTnXcJC3PPD2F34BU5oHnakrSJLxMNo8ap/TM/17A/URDMBEAtcAl4JNKboEERozwiDGd J5/ZCCxIFoAXwLNR9b/I4fUMCM/RBMCEBGqBl6YOFpXPaIyiVCPvznHUHolhBktVIZf2a8YHgIkq w3VqwVoEbLrmeP8LYDOwU+HmrzXIZO0DAGwAfmuWmOYe7insxscIyaEaRL6oNyg0azNMI9ugAcal IuCRkVNm+4kosMss1mv8cm+RrvTaOiBki6VRV3tXnelpR1AZGKUhs84wrwLaNqJnyFaB8s+pUydU GG9jujqeCrO5MsmecKGj7ipgngpUUrTTaaXLgUEh/Lmaku1UtKep7XRv4Lwzip9yzJIJHJFAn69E gFJG04FnRsAnYDuwyRlIq9UjNgu1Uof0OkYlfKMuKCuZA/8B+QsSxkN8YYwAAAAASUVORK5CYII= '; my $date = localtime(time); print qq{Content-Type: text/html; charset=$charset $PROGRAM
    }; } sub html_footer { my $db = shift(); print qq{

    © Gilles Darold 2012-2024

    Report generated by $PROGRAM $VERSION.

    }; print &generate_menu(); print qq{ }; } sub generate_menu { my $date = localtime(time); my $pgcluu_logo = 'data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAJgAAAAsCAYAAACZmXFCAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A /wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB98GCwcUDSKty5YAABOVSURBVHja 7Vx7lF1Vff6+fe5MJi8SQh4ESIDI+2nrQtQCihVRsFhZKmh9oKII6rJSq6uCj7ZSLK0Wn0trVSit BbUiRV0KUqlFRZRHKmCUdwpESEgCCTOTuXd/X/+Y3xl3DvfOI6Qugdlr3TV3zj1nn31++/t9v9fe B3icTdLY95wzbI/9X36fbk/Nxm290DbI0cs7nQ5TSgO255BMtgdTSoMkc/Pc6TYNsHFbzhkAUFVV DbQB288E8BIABwLoA3A/gO+QvILk+pLpUkrTUp9ukzaP+0g6V9L9kmzbxd9BSZfaPsL2QMl8NUin 23Tr6mvZXizpTZKuk+T4PCzp6pzztyXdXYBtnaQP296/V3/T7SncSke90+nMsv1Hki6TtMWjLdv+ L9tvyTkvzznvmHM+VtKFkjYWQLve9jsl7TYNtOkGSVuBK+d8hKTPSlpds5btm22fLWm/Lr7aTpJe Y/u7trfENUOSLpd0kqS50yCbZi3YPjTn/PeSbpXUCaA8KOlvbR8uaaB5XQ0Y25C0wvZbJV1bmNP7 JH055/ySZvAw3Z46ftYM2++zfYukwdrU5Zz/RdIzcs6zukWY3djIdp+k3SW9W9LGYL+2pPttX5Rz XlaCdJrRxp+bJxzz28bIyEgJlMNyzt+X1C5YZ42kE3POA+vXr0cDEP0551Q8+GLbe3e5Twpwfl9S J0DbzjnfL+kU23yyM9p4yedev413ze+8nMoB5pwXSzrH9oMFsO6X9AlJyxvn1g+/QNIHcs77FwI5 Led8Qi9Nsz075/w2STcU9xm0/XVJz3gy+mZNkISFmC9poaQdmsrVBI7tubb/xPYrbL9S0sk55wOf SBS8NOd8aTHhm2x/0fZh40247QFJz805L2ow2LwePl0J0mWS/tz26ohILelXpW/2RAZZ6YsWcjlZ 0vk5569I+o7tqyR9U9IXcs5nSjqw0+mMAazuI+d8YM55cyjikKTBnPP7nyiCmCHpvQW4rpP0opGR kaoJjDCJrdIk9vLBymt6BQJxbE/bFxbR6bckrXgS+U9zbZ8i6ReScuHPupC5JWVJG3LO/yRpeUO2 B0naVJ+bcx6U9KHf+YcPUOwi6eoY/E9zzvuNE1XOkHRczvnQyTBMocUzbS+S1Net3+Hh4UrS50L4 d9h+8RMZVAUDLZb0sQJEGn3E3wCsBlzxWWf7pMYcHJRz3tRwKT74uy6HFLXBuQAWkATJH1ZVtao8 qVGorgDsAWDX6AA555mSDpE0rxDsnHa7PVZ7tP0020eTnNvsd8uWLRgYGMgkPx+F8R0ALCn9ku3h 90zF3HbxgaZ036qqkHNeAOBcAO8iaZKK30myTXKt7TW215DcWHSxBUD7ycDerZjQfgD9HpXi4ATX DAG4CMBwcezVAM4A8Mmqqi7IOR9D8uiU0iUAVoZQ15AcArC52WF/fz8KwcN2C6NFcwJwr0mcaIVG 8/ca7OMV3ut+62J+r756sXVKCfEMle3TALxxtFs7noe2bwdwBYCfAHg0ju1K8tm2n0Vyju1qIhDX Y6rvO56yBOAf81zN8QfJTPiME8m/Tje14qQxAdhOEzyUAWwqju1t+1Tbvw/gyJzzNQDOt70fyR0B nA4AVVU9BOChbuCov5NkMIUnYpyYxD7bewJYYLsDoJVS2gTgFyQlaU/bB6eUFgYj3Gn7+pTScHNi bG81LtsH2N7X9jySm0jeTnJlXLcryaW2FcPeYvvulNLmuk9J+6aU3lo8D+PzI5IfJPnDULhy8i4C 8CwAxwN4eDwGLeUXEz4gaS+Sc2OOKkmPAlhZVZVjDtDpdKqU0n4kF0rKJPtIrie5spBFZXt327uQ 7JBsBfH8D8lOLafAyh62l9nOJCuSm2zfQnILALQm0vpJmIkdAcyNGy4i+YdhQgngkJxzq6qqTn1y u92eVP8kJ2PS5gN4u+0XxWT1214ZObWX234ryT0BzLItkg+RvErSuSml1QGEJrDm2H697dcBWE5y BoAR22skXUbyfADPt312CL1l+z6SZwG4vp4kkscBWF6Ci+Q9ts9JKX2vZITapKaU1gP4tqQf92Lu 8bIAJM8GcCiADKAieSeAlwEYKcA4h+TbbR8bIJgB4Drbry5M+GwArwfw2njGftt3AzgJwIYCIzMB vArAacHE/bZXkTwNwL1jAJuI7mqtLEzMcpLn2b5b0pUkB0OoO0WfbZIDkvpJJklH2T4FwOerqvrx RAnFAOtk5NoPYHeSZVJ3Y0rp3bbfSXJhA7gLAOwNYHHO+fSqqh4sTYKkGQBOBfBhALNLmdheQnI/ AAfbvhXAPsU9F9ieU8irn+RR8SwOXzIDuILkf5dmq5ZpznnMvKaUNpRmpqqqCWUSbs4KAPsVc9qS lBrnVQB2A7BnIes1je4qALuGctatL46XMqkALAGwrJDVcMwLxgBWD74XyIKCZ0rqD/NyakQ5q1NK v7S9Lk59EMCVts8BkEj+AsBOJD8M4EgAS22fQfKu7bHK1aNOW6f4TgD7AjiwLqYXAHJ8EoATSd5o +zySI4U5PtT2WSRn13m5WKFby2gAwEsBPAdAh2QrJr1TMg7JebafW1gEAtgY5nFTba62mtEuvtFU 5BNA7jRciC0pJTdlBiAXjI2QYTl+A8gNi7KlyapxbW6MtePiwq0YbALWOJLkzpK+TvL4OH8hgNkA Pg7gHgCXpJR+Jek8APsD+EuS+9uuM86H2346gLu6Ca92Hqcg1LGxx3eF2STJywH8Rxx7QVB5LZCK 5Nts/1u73b6jr68PJGcCeAuAhbWASKbwOy60vc72gSTfE1pbYHBrxziy9LNioupjDwK4c7IBymQi 1YncmXAL2A20UwmSaj+yeX4vYir/34rBJqiTPUpyTTh2fXFufwj7SwD+MzQZJP8OQF+sGTs4Jgq2 ZwBYIqmVUupM9HCtVmvSICvGSZLfInkygKGIjL5Ocp3td0giSdneGcDxrVbrU6MEplkk31QDJ8Z8 h+3TSF4bzAcAK0n+awHCbmMqqxgplGeD7QemykyTcfK7BSm1MuWcNdVIsUyQF8rrbWHYVHZU+lld fLAfkrwypdQheXXBuCoipZbt/vh/iKRSShtJDkX/QyTXbty4sdPL1ysfrtPpTFqTQ1PrvN5Hwy90 VVVOKW20fRnJB1JKiaMNkRaocs4k+bxamHEObF9M8oY4pqqqZPtySdeEC1BOQDmmHYuI23FshOTw tjLWZNimOKcGv7pZiXK8PRRkDA8FS7lXXnE869fqQoVdTVen00FVVTMiHP0MgINsD5G8NqV0ku2D AQwHS7UB3ATgKgA32b4EwPHBLNcsWLCga+5mWzS7FECkWX4N4K5mf3H8zmDc+roDAMwIs3l02U8k O2+vfbTifiMAVgE4ohn1Ft/XFoxSp15mRnT222h1PjH3yntN5Hd3K/H1yiuO199joshuKA0k72D7 TyMv8jeSjk8ptaK6/w/xezmgDoDLAZy+du3ady1atOhTAO6NnFFPzZnqXsrSf4y/68okcBEBb7b9 SD3pRVQ5g+Sg7V1KVo8+HurhTNfrlXrNzmABeIWZXBjVj1t/i9v43GUly4SgaMyBez1nk9K6+tUT TWyR13kOgLMBvM/2ISmloQiL32R7h7iZi0G1AJxg+4wlS5YgpXTHeODqBrbJbHEr+qqZog1AXbL3 3aKnqhZelHJKf4bsMtDa9ZogJzVI8sH6+jA5C0g+baIcX1miKs8pv3czyz3mvq/LbzPrXV5TYbBu OdNIW8wajxTSFGz9orgJAfyBpHm23xshe23zWUdOYf9p+8RYxzS/rjtOdmHdZLW8Nm1x/sJIADbb bADzYnJqv+iROglp++4Alovzl3TDNIDFRTjfDWAbAfygeB5HVeOYnPPS8Zz00qSVQGyY+27gcBdZ zkgpseEvLSa5qARiD7m7YdX6euTeFtUy7TavaSIkF5pzW5SIqvAlTib5qlLQjURpnb0+yPanbH8k 57xiYGBgXICVTv5kV2s2tHkpyaVdtH4hgGWNybgrWFXhL47ly0hWtg9qt9sDjdvNBfDM8dikr68v A/geAEU0Wv/4PAAn9grti4TvvpL2KFl8AjMG251wX8rzZ9TMU5SB9iS5x0SFAZK50dcs202QzcHo ZuueLs5jTGQThsUD/hzAN8OBvhtAXWdTUWcr7XX9v4O9TiP5Ztsze5m+icLnSWT/60j2dNuprK1F gnR55K7q+1xnuxPn/YzkMMlUMNPLqqp6Wb2qw/YSAGeT3L8oqzym8BzHryB5c2NsC0ieGdv3FnVR 5n1t/xnJjwN4+hS9+g0ANjUYaamkI4r+dyX5mvA93UvmkkZqP7P4fRHJo8tcH4C3RUXDPVh1zK6O AaRbaBsXPhrrj3aJMsPTS0e3YDE3SiSO74nkQWHC/rdHIKFteWFK4bjXYH9lrLu6PEo0LwRwchEl JtsZwLfjLwA8bPszAM4stHgZgHNsH297cyyMPGo8v7VQyHttnwvgy8FitVxXAPgAgBfbvt32WpKz YvL3tH1opHiqqbgPJDfa3tBYlDCL5Eds/x6AIdvH2H5B03lvAqOqqmFJdxX+pqKi8X7be0naYPsI kicUc97NZUUrEm/DUdQkyfndlmbEQ9xu+14AJzRMoRtrt1zetHiAobLw2pyU4hUDbQBD9SqAKWSb STLbHghNPS7GMQ/AQPhpdTBwEYBba59H0paU0j8D+GMAK8JsKupxy+toMCb+HgBLo7jbjQFq/+kb JN8ftc1UMPoCkscAOJpkO/rtDxmmWEnh8aK/bgnRMMvHhb/nGP8hAPYKRZob/XfCQWcv98j2qkjT 7FWDDMB+4Xd3ANRLilwr7XhO/gaMvrAEkQ86sqGNpT/EwndTwRojAB4AsL528GstCbOTSf6I5APd IqNYw//ueNh1AO6bDMAagqftayNB2gKwmOTiGlwhUAK4y/bHY2nPqKa1WiB5K8m/AvBIsE4qos2+ WI7yjyQ/Ybu/nOyIUscUJpRz2Pb5GF1w2C5WVdTs0Re+zczyfrZbPVwVFlUXllFq/L3A9rWFOGrL NCeUrEPysyS/V4MrPt2CvVtIfhe/oaYahbOiUlEB+DGAL9RF8BhHKqPsFBq80fZXo1C5v6QLJJ0Z PkczZTAM4DuhZakA6ccAHEZyH9t/Wfdf+zwAfhQmayt2zDn3Szre9tdIvjR+vsH2zVM1lVEJaIVv 8FHbGyXVZoCRm7sOwBskreySkW5LuhijiwSvClO+FsB9US46JfpeXESHXet0tbxSSo/a/jSAY0he HD7scCgDi0WWJvkAyWtIfgTA1Q0lzCQ3214LYC3JR8IibKVoKaXTbX8j/DEWlmW17Q+FeV4HYBPJ eiXtI8Uusbqfh0l+jOSFgQ8WgdsaAJ8G8HLbd0bw9+uo1z4i6TdsVJjBWZHjOquuY9m+nuSnAXy1 XBwXC/2OCjqea/tG21+uqurhYtLeEuZhN9u32D61qqprG0ndw2y/B8Cx0Q9iIl9H8rZ2u42+vr7x 2GsXAJ+sI7ManABemFJ6KBzcZ2N0zVoGcBvJK0NAY0tmuq1wzTnPJ7l7mJXNsXJkvaSZAC4k+Ypi lepK22+squqG8YrSOecZkQs7wPYyADuE9o+klO6XtArAr6qqWtfl2lkppWfGKgcGQO9OKd3TxaWZ D+DZUZwfkPQAyetJ3hTPug/JBUEoLZKPpJRuLqsrBQHMA3A4yYNIzpa0NqV0Pcmf5pwTyWUxD4o0 1RBGF3yOjFm9Rgb+9bbvjR0u9YaEayQt7RKmYnBwsGstMf6fl3PePec8t5g4ttvt/tgIsanY8LAh 5/y5ctfRRAsObe9i+98bmyZ+2i1CGy+hWRamJc3OOfePw5IHSGrHPRUbN75oe8eJ2HUqTNxtD+pk cofb+lbJ7b1z/DHjaABjhe0LbN8XW/ydcx6y/Q7byyS1xhtMt4HF6zXnS3qRpJ8XgNhg++pyF9FE Kzt6ASzn7Jzzz8YD2HhCk7RzbDL+C9sHSlpie358lkg6XNKNoXg5zP8WSW+c7OSOd8723APa7Gtb d4BvV+B1YaAX275E0v0555rNfmD7DbZ3v+KKKyY7cTtKOlbSlyRtKTb2ft/2GfXiwMkCqwSYpG1i sB7jXBJv/3GE6ZdL+nx8vmv70fitU9zz4nrT8fQ7NSbZSrTb3iHnfHK8E2wohDos6XLbJ5emoeko htCPtP0J2/cVIPiJpPfY3v3xaIWkXWxf2thTeMPjANjOti8rNgCP/a1bYy/jN+v9odNvB3qcbGZ7 qaR3BEOMbRCNF809t8v1KySdFbuZy9c2nWf7kO1BucFglzU2sd4kafE2PvM8SX8t6V5JIz02xW7O Od8Ub21c8Xh9nyd742TYrCzA5pwPSSm90vabi3D9jog0vwZgg6TjUkonAXhO5FgE4GsAviTp6lar Ndyr/ykCbJbt50e5YiTySr8GcGm9NW2yyhTRF20vsb0vgL1J7kZyVp1QBLCZ5C8lrZL0876+vk55 /XTbTk6jpBm2j7b9FdvDodlt26uCQcot7jdKeoPtnba3Q7t69eoaFMk22+0267zXVPvvdn6n0+mT NNP2rJzzY4q9vd6HNt22U2QSrx56re2rbA+XvkqYxg9Kelqn00nbO1L6//J5JmPqpkG1HU3keCal zh3ZXkrysHoJMkZXW1xH8rZyW9i0GZlu28QgnU4HtplzbknqyzmnRiQ6LbCnaPs/zGhC2bEgIrsA AAAASUVORK5CYII='; my $menu_str = qq{ }; return $str; } sub getNumericalOffset { my $stringofs = shift; my @pieces = split /\//, $stringofs; die "Invalid offset: $stringofs" unless ($#pieces == 1); # First part is logid, second part is record offset return (hex("ffffffff") * hex($pieces[0])) + hex($pieces[1]); } sub read_sysinfo { my $input_dir = shift; # Empty arrays before filling them my @toclear = qw/DF MOUNT PROCESS PCI CRONTAB INSTALLATION EXTENSION SCHEMA JSON/; foreach my $s (@toclear) { delete $sysinfo{$s}; } print STDERR "DEBUG: Looking for system information in directory $input_dir\n" if ($DEBUG); if (-e "$input_dir/sys_cache.bin") { print STDERR "DEBUG: Loading system information from cache file $input_dir/sys_cache.bin\n" if ($DEBUG); &load_sysinfo_binary($input_dir, "sys_cache.bin"); $sysinfo{CACHE}{last_run} = localtime((stat("$input_dir/sys_cache.bin"))[9]) || ''; } elsif (-e "$input_dir/sysinfo.txt") { print STDERR "DEBUG: Loading system information from file $input_dir/sysinfo.txt\n" if ($DEBUG); %sysinfo = &read_sysinfo_file("$input_dir/sysinfo.txt"); $sysinfo{RELEASE}{'name'} ||= 'unknown'; } elsif (-e "$input_dir/sysinfo.txt.gz") { print STDERR "DEBUG: Loading system information from file $input_dir/sysinfo.txt.gz\n" if ($DEBUG); %sysinfo = &read_sysinfo_file("$input_dir/sysinfo.txt.gz"); $sysinfo{RELEASE}{'name'} ||= 'unknown'; } # Get the list of database from registered extension and schema foreach my $db (keys %{$sysinfo{EXTENSION}}) { push(@DATABASE_LIST, $db) if (!grep(/^$db$/, @DATABASE_LIST)); } foreach my $db (keys %{$sysinfo{SCHEMA}}) { push(@DATABASE_LIST, $db) if (!grep(/^$db$/, @DATABASE_LIST)); } # Load global information from cache file if (-e "$input_dir/global_infos.bin") { &load_sar_binary($input_dir, 'global_infos'); # Look for disk device and network interface from global info if (exists $global_infos{DEVICE_LIST}) { foreach my $d (@{$global_infos{DEVICE_LIST}}) { push(@DEVICE_LIST, $d) if (!grep(/^$d$/, @DEVICE_LIST)); } } if (exists $global_infos{IFACE_LIST}) { foreach my $d (@{$global_infos{IFACE_LIST}}) { push(@IFACE_LIST, $d) if (!grep(/^$d$/, @IFACE_LIST)); } } if (exists $global_infos{DEVICE_SPACE_LIST}) { foreach my $d (@{$global_infos{DEVICE_SPACE_LIST}}) { push(@DEVICE_SPACE_LIST, $d) if (!grep(/^$d$/, @DEVICE_SPACE_LIST)); } } } else { # Look for disk device and network interface from the sar file if (!$DISABLE_SAR && -e "$input_dir/sar_stats.dat") { &set_device_list("$input_dir/sar_stats.dat"); } } } sub read_sysinfo_file { my $file = shift; if (!is_compressed($file)) { open(IN, $file) or die "ERROR: can't read file $file, $!\n"; } else { open(IN, "$ZCAT_PROG $file |") or die "ERROR: can't read pipe on command: $ZCAT_PROG $file, $!\n"; } my %sysinfo = (); my $section = ''; while (my $l = ) { chomp($l); if ($l =~ /^\[(.*)\]$/) { $section = $1; next; } if ($section eq 'CPU') { my ($key, $val) = split(/\s+:\s+/, $l); if ($key eq 'processor') { $sysinfo{$section}{$key} = $val + 1; } elsif ($key eq 'model name') { $val =~ s/\s+\@\s+(.*)$//; $sysinfo{$section}{'cpu MHz'} = $1; $sysinfo{$section}{$key} = $val; } else { $sysinfo{$section}{$key} = $val; } } elsif ($section eq 'KERNEL') { my @kinf = split(/\s+/, $l); $sysinfo{$section}{'hostname'} = $kinf[1]; $sysinfo{$section}{'kernel'} = "$kinf[0] $kinf[2] $kinf[3] $kinf[4]"; $sysinfo{$section}{'arch'} = "$kinf[-2] $kinf[-1]"; } elsif ($section eq 'UPTIME') { $sysinfo{$section}{'all'} = $l; if ($l =~ /\s*([^,]+), (.*)/) { $sysinfo{$section}{'uptime'} = $1; $sysinfo{$section}{'infos'} = $2; } } elsif ($section eq 'RELEASE') { my ($key, $val) = split(/=/, $l); if ($val) { $val =~ s/"//g; $sysinfo{$section}{lc($key)} = $val; } else { $sysinfo{RELEASE}{'name'} = $key; $sysinfo{RELEASE}{'version'} = ''; } } elsif ($section eq 'MEMORY') { my ($key, $val) = split(/:\s+/, $l); if ($val =~ s/ kB//) { $sysinfo{$section}{lc($key)} = &pretty_print_size($val*1000); } else { $sysinfo{$section}{lc($key)} = $val; } } elsif ($section eq 'DF') { next if ($l !~ /^[\s\/]/); if ($l =~ s/^\s+//) { $sysinfo{$section}[-1] =~ s/<\/tr>$//; $sysinfo{$section}[-1] .= join('', split(/\s+/, $l)) . ""; next; } push(@{$sysinfo{$section}}, '' . join('', split(/\s+/, $l)) . ""); } elsif ($section eq 'MOUNT') { next if ($l !~ /^\//); push(@{$sysinfo{$section}}, '' . join('', split(/\s+on\s+|\s+type\s+|\s+/, $l)) . ''); } elsif ($section eq 'SYSTEM') { my ($key, $val) = split(/\s*[=:]\s+/, $l); $sysinfo{$section}{$key} = $val if ($key && defined $val); } elsif ($section eq 'PGVERSION') { $sysinfo{$section}{full_version} = $l; if ($l =~ /^PostgreSQL (\d+)\.(\d+)\.(\d+)/) { $sysinfo{$section}{major} = "$1.$2"; $sysinfo{$section}{minor} = "$1.$2.$3"; } elsif ($l =~ /^PostgreSQL (\d+)\.(\d+)/) { $sysinfo{$section}{major} = "$1.$2"; $sysinfo{$section}{minor} = "$1.$2.0"; } elsif ($l =~ /^EnterpriseDB (\d+)\.(\d+)\.(\d+)/) { $sysinfo{$section}{major} = "$1.$2"; $sysinfo{$section}{minor} = "$1.$2.$3"; } elsif ($l =~ /(\d+)\.(\d+)\.(\d+)/) { $sysinfo{$section}{major} = "$1.$2"; $sysinfo{$section}{minor} = "$1.$2.$3"; } else { $sysinfo{$section}{major} = ''; $sysinfo{$section}{minor} = ''; } } elsif ($section eq 'PGUPTIME') { $sysinfo{PGVERSION}{uptime} = $l; } elsif ($section eq 'EXTENSION') { my ($db, @vals) = split(/[=,]+/, $l); foreach my $e (@vals) { push(@{$sysinfo{$section}{$db}}, $e) if (!grep(/^$e$/, @{$sysinfo{$section}{$db}})); push(@{$OVERALL_STATS{'cluster'}{'extensions'}}, $e) if (!grep(/^$e$/, @{$OVERALL_STATS{'cluster'}{'extensions'}})); } } elsif ($section eq 'SCHEMA') { my ($db, @vals) = split(/[=,]+/, $l); foreach my $s (@vals) { push(@{$sysinfo{$section}{$db}}, $s) if (!grep(/^$s$/, @{$sysinfo{$section}{$db}})); } } elsif ($section eq 'JSON') { my ($db, @vals) = split(/[=,]+/, $l); foreach my $s (@vals) { push(@{$sysinfo{$section}{$db}}, $s) if (!grep(/^$s$/, @{$sysinfo{$section}{$db}})); } } elsif ($section eq 'PROCEDURE') { if ($l =~ /^([^=]+)=(\d+)$/) { $sysinfo{$section}{$1} = $2; } else { # Backward compatibility with version 2.4 my ($db, @vals) = split(/[=,]+/, $l); $sysinfo{$section}{$db} = $#vals + 1; } } elsif ($section eq 'TRIGGER') { my ($db, $val) = split(/[=]+/, $l); $sysinfo{$section}{$db} = $val; } elsif ($section eq 'PROCESS') { my ($USER,$PID,$CPU,$MEM,$VSZ,$RSS,$TTY,$STAT,$START,$TIME,$COMMAND) = split(/\s+/, $l, 11); push(@{$sysinfo{$section}}, '' . join('', $USER,$PID,$CPU,$MEM,$VSZ,$RSS,$TTY,$STAT,$START,$TIME,$COMMAND) . '') if ($l !~/^USER/); } elsif ($section eq 'PARTITIONNED_TABLE') { # limit split to 2 fields, check constraint can contains "=" my ($db, $csv) = split(/[=]/, $l, 2); if ($csv) { my ($oid, $parent, $child, $constraint, $kind, $nparts ) = split(/[;]+/, $csv); $sysinfo{$section}{$db}{$oid}{name} = $parent; $sysinfo{$section}{$db}{$oid}{child}{$child} = $constraint; $sysinfo{$section}{$db}{$oid}{kind} = $kind; $sysinfo{$section}{$db}{$oid}{nparts} = $nparts; push(@{$OVERALL_STATS{'cluster'}{'partitionned_tables'}}, "$db.$parent") if (!grep(/^$db.$parent/, @{$OVERALL_STATS{'cluster'}{'partitionned_tables'}})); } } elsif ($section =~ /PARTITION_IMPL (.*) (\d+)/) { $sysinfo{PARTITIONNED_TABLE}{$1}{$2}{implementation} .= "$l\n"; } elsif ($section =~ /^(PCI|CRONTAB|INSTALLATION)$/) { push(@{$sysinfo{$section}}, "$l\n"); } } close(IN); return %sysinfo; } # Format duration sub format_duration { my $time = shift; return '0s' if (!$time); my $days = int($time / 86400000); $time -= ($days * 86400000); my $hours = int($time / 3600000); $time -= ($hours * 3600000); my $minutes = int($time / 60000); $time -= ($minutes * 60000); my $seconds = sprintf("%0.3f", $time / 1000); $days = $days < 1 ? '' : $days . 'd'; $hours = $hours < 1 ? '' : $hours . 'h'; $minutes = $minutes < 1 ? '' : $minutes . 'm'; $seconds =~ s/\.\d+$// if ($minutes); $time = $days . $hours . $minutes . $seconds . 's'; return $time; } sub get_data_directories { my @work_dirs = (); my $local_max_render = $MAX_RENDERED_DAYS; # Lookup for daily or hourly sub directories to scan # Search years / months / days / hours directories if (not opendir(DIR, "$INPUT_DIR")) { print STDERR "FATAL: Can't open directory $INPUT_DIR: $!\n"; return; } my @years = grep { /^\d+$/ && -d "$INPUT_DIR/$_" } readdir(DIR); closedir(DIR); if ($#years >= 0) { foreach my $y (sort { $a <=> $b } @years) { next if ($o_year && ($y < $o_year)); next if ($e_year && ($y > $e_year)); if (not opendir(DIR, "$INPUT_DIR/$y")) { print STDERR "FATAL: Can't open directory $INPUT_DIR/$y: $!\n"; return; } my @months = grep { /^\d+$/ && -d "$INPUT_DIR/$y/$_" } readdir(DIR); closedir(DIR); foreach my $m (sort { $a <=> $b } @months) { next if ($o_month && ("$y$m" lt "$o_year$o_month")); next if ($e_month && ("$y$m" gt "$e_year$e_month")); if (not opendir(DIR, "$INPUT_DIR/$y/$m")) { print STDERR "FATAL: Can't open directory $INPUT_DIR/$y/$m: $!\n"; return; } my @days = grep { /^\d+$/ && -d "$INPUT_DIR/$y/$m/$_" } readdir(DIR); closedir(DIR); foreach my $d (sort { $a <=> $b } @days) { next if ($o_day && ("$y$m$d" lt "$o_year$o_month$o_day")); next if ($e_day && ("$y$m$d" gt "$e_year$e_month$e_day")); if (not opendir(DIR, "$INPUT_DIR/$y/$m/$d")) { print STDERR "FATAL: Can't open directory $INPUT_DIR/$y/$m/$d: $!\n"; return; } my @hbin = grep { /^.*\.bin$/ } readdir(DIR); closedir(DIR); if (not opendir(DIR, "$INPUT_DIR/$y/$m/$d")) { print STDERR "FATAL: Can't open directory $INPUT_DIR/$y/$m/$d: $!\n"; return; } my @hours = grep { /^\d+$/ && -d "$INPUT_DIR/$y/$m/$d/$_" } readdir(DIR); closedir(DIR); if ($#hours == -1 || $#hbin >= 0) { push(@work_dirs, "$y/$m/$d"); } else { $local_max_render = $MAX_RENDERED_DAYS * 24; foreach my $h (sort { $a <=> $b } @hours) { next if ($o_hour && ("$y$m$d$h" lt "$o_year$o_month$o_day$o_hour")); next if ($e_hour && ("$y$m$d$h" gt "$e_year$e_month$e_day$e_hour")); push(@work_dirs, "$y/$m/$d/$h"); } } } } } if ($#work_dirs > $local_max_render) { $local_max_render--; splice(@work_dirs, 0, $local_max_render); } } return @work_dirs; } # Initialise global variables storing PostgreSQL statistics sub clear_db_stats { print STDERR "DEBUG: Cleaning memory from PostgreSQL statistics storages\n" if ($DEBUG); foreach my $name (@pg_to_be_stored) { if (grep(/^$name$/, 'global_databases', 'global_tbspnames', )) { @{$name} = (); } else { %{$name} = (); } } } # Initialise global variables storing statistics sub clear_stats { # Clean PostgreSQL statistics &clear_db_stats(); print STDERR "DEBUG: Cleaning memory from all statistics storages\n" if ($DEBUG); %OVERALL_STATS = (); %sysinfo = (); foreach my $name (@sar_to_be_stored) { %{$name} = (); } foreach my $name (@pidstat_to_be_stored) { %{$name} = (); } } # Load statistics from pg cache into memory sub load_pg_binary { my ($input_dir, $varname) = @_; foreach my $name (@pg_to_be_stored) { next if ($varname ne 'home' && $name ne $varname && !grep($name, 'global_databases', 'global_tbspnames')); # Just load the right binary file next if ( !-e "$input_dir/$name.bin"); print STDERR "DEBUG: Loading PostgreSQL statistics from cache file $in_dir/$name.bin\n" if ($DEBUG); my %stats = (); my $lfh = new IO::File "<$input_dir/$name.bin"; if (not defined $lfh) { die "FATAL: can't read from $input_dir/$name.bin, $!\n"; } %stats = %{ fd_retrieve($lfh) }; $lfh->close(); if (!grep(/^$name$/, 'global_databases', 'global_tbspnames')) { # Setting global information if ($name eq 'global_infos') { my %_global_infos = %{$stats{global_infos}} ; foreach my $inf (keys %_global_infos) { $_global_infos{$inf} //= 0; if ($_global_infos{$inf} =~ /ARRAY/) { push(@{$global_infos{$inf}}, @{$_global_infos{$inf}}); } else { $global_infos{$inf} = $_global_infos{$inf}; } } delete $stats{global_infos}; } else { # Load other storages foreach my $m (keys %stats) { foreach my $t (keys %{$stats{$m}}) { if ($stats{$m}{$t} =~ /HASH/) { foreach my $d (keys %{$stats{$m}{$t}}) { if ($stats{$m}{$t}{$d} =~ /HASH/) { foreach my $k (keys %{$stats{$m}{$t}{$d}}) { ${$m}{$t}{$d}{$k} = $stats{$m}{$t}{$d}{$k}; } } elsif ($stats{$m}{$t}{$d} =~ /ARRAY/) { push(@{${$m}{$t}{$d}}, @{$stats{$m}{$t}{$d}}); } else { ${$m}{$t}{$d} = $stats{$m}{$t}{$d}; } } } elsif ($stats{$m}{$t} =~ /ARRAY/) { push(@{${$m}{$t}}, @{$stats{$m}{$t}}); } else { ${$m}{$t} = $stats{$m}{$t}; } } } } } else { # Look for database and tablespace foreach my $d (@{$stats{$name}}) { push(@{$name}, $d) if (!grep(/^$d$/, @{$name})); } delete $stats{$name}; } } # Preserve backward compatibility with renaming of variable all_statio_all_indexes if (-e "$input_dir/all_statio_all_indexes.bin") { my $lfh = new IO::File "<$input_dir/all_statio_all_indexes.bin"; if (not defined $lfh) { die "FATAL: can't read from $input_dir/all_statio_all_indexes.bin, $!\n"; } my %stats = %{ fd_retrieve($lfh) }; $lfh->close(); foreach my $a (keys %{$stats{'all_statio_all_indexes'}}) { foreach my $b (keys %{$stats{'all_statio_all_indexes'}{$a}}) { foreach my $c (keys %{$stats{'all_statio_all_indexes'}{$a}{$b}}) { foreach my $k (keys %{$stats{'all_statio_all_indexes'}{$a}{$b}{$c}}) { $all_statio_user_indexes{$a}{$b}{$c}{$k} = $stats{'all_statio_all_indexes'}{$a}{$b}{$c}{$k}; } } } } } # Compute overall database statistics from binary file # as they are normally computed when reading data files. set_overall_database_stat_from_binary(); } # Load statistics from sar cache into memory sub load_sar_binary { my ($input_dir, $varname) = @_; foreach my $name (@sar_to_be_stored) { next if ($varname ne 'home' && $name ne $varname); # Just load the right binary file print STDERR "DEBUG: Loading Sar statistics from cache file $in_dir/$name.bin\n" if ($DEBUG); my %stats = (); if (-e "$input_dir/$name.bin") { my $lfh = new IO::File "<$input_dir/$name.bin"; if (not defined $lfh) { die "FATAL: can't read from $input_dir/$name.bin, $!\n"; } %stats = %{ fd_retrieve($lfh) }; $lfh->close(); } # Setting global information if ($name eq 'global_infos') { # Setting global information if (exists $stats{global_infos}) { my %_global_infos = %{$stats{global_infos}} ; foreach my $inf (keys %_global_infos) { $_global_infos{$inf} //= 0; if ($_global_infos{$inf} =~ /ARRAY/) { push(@{$global_infos{$inf}}, @{$_global_infos{$inf}}); } else { $global_infos{$inf} = $_global_infos{$inf}; } } delete $stats{global_infos}; } } else { # Load other sar storages foreach my $m (keys %stats) { foreach my $t (keys %{$stats{$m}}) { foreach my $d (keys %{$stats{$m}{$t}}) { if ($stats{$m}{$t}{$d} =~ /HASH/) { foreach my $k (keys %{$stats{$m}{$t}{$d}}) { ${$m}{$t}{$d}{$k} = $stats{$m}{$t}{$d}{$k}; } } else { ${$m}{$t}{$d} = $stats{$m}{$t}{$d}; } } } } } } # Compute overall system statistics from binary file # as they are normally computed when reading data files. set_overall_system_stat_from_binary(); } # Load statistics from pidstat cache into memory sub load_pidstat_binary { my ($in_dir) = @_; foreach my $name (@pidstat_to_be_stored) { next if (!-e "$in_dir/$name.bin"); my $lfh = IO::File->new("$in_dir/$name.bin", 'r'); if (not defined $lfh) { die "FATAL: can't read file $in_dir/$name.bin, $!\n"; } my %stats = %{ fd_retrieve($lfh) }; $lfh->close(); # Load pidstat storages foreach my $m (keys %stats) { foreach my $t (keys %{$stats{$m}}) { foreach my $d (keys %{$stats{$m}{$t}}) { if ($stats{$m}{$t}{$d} =~ /HASH/) { foreach my $k (keys %{$stats{$m}{$t}{$d}}) { ${$m}{$t}{$d}{$k} = $stats{$m}{$t}{$d}{$k}; } } else { ${$m}{$t}{$d} = $stats{$m}{$t}{$d}; } } } } } } # Load statistics from sysinfo cache into memory sub load_sysinfo_binary { my ($input_dir, $infile) = @_; # Do not load empty file, Storable don't support it return if (-z "$input_dir/$infile"); my $lfh = new IO::File "<$input_dir/$infile"; if (not defined $lfh) { die "FATAL: can't read from $input_dir/$infile, $!\n"; } my %stats = %{ fd_retrieve($lfh) }; $lfh->close(); my %_sysinfo = %{$stats{sysinfo}}; # Empty arrays before filling them my @toclear = qw/DF MOUNT PROCESS PCI CRONTAB INSTALLATION EXTENSION SCHEMA JSON/; foreach my $s (@toclear) { delete $sysinfo{$s}; } # Load other storages foreach my $s (keys %_sysinfo) { if ($_sysinfo{$s} =~ /^HASH/) { foreach my $n (keys %{$_sysinfo{$s}}) { if ($_sysinfo{$s}{$n} =~ /^HASH/) { foreach my $k (keys %{$_sysinfo{$s}{$n}}) { if ($_sysinfo{$s}{$n}{$k} =~ /^HASH/) { foreach my $j (keys %{$_sysinfo{$s}{$n}{$k}}) { if ($_sysinfo{$s}{$n}{$k}{$j} =~ /^HASH/) { foreach my $i (keys %{$_sysinfo{$s}{$n}{$k}{$j}}) { $sysinfo{$s}{$n}{$k}{$j}{$i} = $_sysinfo{$s}{$n}{$k}{$j}{$i}; } } else { $sysinfo{$s}{$n}{$k}{$j} = $_sysinfo{$s}{$n}{$k}{$j}; } } } else { $sysinfo{$s}{$n}{$k} = $_sysinfo{$s}{$n}{$k}; } } } elsif ($_sysinfo{$s}{$n} =~ /^ARRAY/) { push(@{$sysinfo{$s}{$n}}, @{$_sysinfo{$s}{$n}}); } else { $sysinfo{$s}{$n} = $_sysinfo{$s}{$n}; } } } elsif ($_sysinfo{$s} =~ /^ARRAY/) { push(@{$sysinfo{$s}}, @{$_sysinfo{$s}}); } } } sub empty_dataset { my ($divid, $infos, $title) = @_; my $description = $infos->{description} || ''; if ($title ne '') { $title = sprintf($infos->{title}, $title); } else { $title = $infos->{title}; } my $str = qq{




    • $title

      $description

      NO DATASET
    }; return $str; } # Compare given version numbers to the server's version sub backend_minimum_version { my ($numver) = @_; return 0 if (!$numver); return 1 if (!exists $sysinfo{PGVERSION}{'major'} || ($sysinfo{PGVERSION}{'major'} >= $numver)); return 0; }