Debian Codegraph @

cgi-bin/pgcluu.cgi

raw ◀ ▶
1 Debian patch touch this file
•1 #!/usr/bin/perl
2 #------------------------------------------------------------------------------
3 #
4 # PgCluu - PostgreSQL monitoring tool with statistics collector and grapher
5 #
6 # This program is open source, licensed under the PostgreSQL license.
7 # For license terms, see the LICENSE file.
8 #
9 # Author: Gilles Darold
10 # Copyright: (C) 2012-2024 Gilles Darold - All rights reserved.
11 #------------------------------------------------------------------------------
12 use vars qw($VERSION $PROGRAM);
13
14 use strict qw(vars);
15 use warnings;
16
17 no warnings 'redundant';
18
19 use CGI;
20 use IO::File;
21 use Getopt::Long qw(:config bundling no_ignore_case_always);
22 use File::Basename;
23 use Time::Local qw/timegm_nocheck timelocal_nocheck/;
24 use POSIX qw(locale_h sys_wait_h ceil strftime);
25 setlocale(LC_ALL, 'C');
26 use Storable qw(store_fd fd_retrieve);
27
28 $VERSION = '4.0';
29 $PROGRAM = 'pgCluu';
30
31
32 my $CONFIG_FILE = "/usr/local/etc/pgcluu.conf";
33 my $SADF_PROG = '/usr/bin/sadf';
34 my $DISABLE_SAR = 0;
35 my $HTML = '';
36 my @INCLUDE_DB = ();
37 my @INCLUDE_TB = ();
38 my @INCLUDE_DEV = ();
39 my @INCLUDE_IFACE = ();
40 my $IMG_FORMAT = 'png';
41 my %DEVFH = ();
42 my $IDX = 1;
43 my $HELP = 0;
44 my $SHOW_VER = 0;
45 my $DEBUG = 0;
46 my $NUMBER_CPU = 0;
47 my $TIMEZONE = '00'; #substr(strftime('%z', localtime()), 0, 3);
48 my $STATS_TIMEZONE = '00'; # Timezone is auto detected from data files
49 my $REVERT_DATE = 0;
50 my $FROM_SA_FILE = 0;
51 my $SADC_INPUT_FILE = '';
52 my $SAR_INPUT_FILE = '';
53 my $PIDSTAT_INPUT_FILE = '';
54 my @DEVICE_LIST = ();
55 my @IFACE_LIST = ();
56 my @GRAPH_COLORS = ('#6e9dc9', '#f4ab3a', '#ac7fa8', '#8dbd0f','#958c12');
57 my $ZCAT_PROG = '/bin/zcat';
58 my $CACHE = 0;
59 my $MAX_INDEXES = 5;
60 my @DATABASE_LIST = ();
61 my @DEVICE_SPACE_LIST = ();
62 my %fullpidstatdata = (); # Hash to store full content of pidstat file per type
63
64 my $MAX_RENDERED_DAYS = 7;
65
66 my $SAR_UPPER_11_5_6 = 0;
67
68 my %RELKIND = (
69 'r' => 'tables',
70 'i' => 'indexes',
71 'S' => 'sequences',
72 'v' => 'views',
73 'c' => 'composite types',
74 't' => 'toast tables'
75 );
76 my $TOP_STAT = 10;
77
78 # Global variables that need to be saved in incremental mode
79 our %OVERALL_STATS = ();
80 our %global_infos = ();
81 our @global_databases = ();
82 our @global_tbspnames = ();
83 our %all_stat_database = ();
84 our %all_stat_database_conflicts = ();
85 our %all_database_size = ();
86 our %all_tablespace_size = ();
87 our %all_vacuum_stat = ();
88 our %all_stat_user_tables = ();
89 our %all_stat_user_indexes = ();
90 our %all_stat_invalid_indexes = ();
91 our %all_stat_hash_indexes = ();
92 our %all_statio_user_tables = ();
93 our %all_relation_buffercache = ();
94 our %all_statio_user_indexes = ();
95 our %all_xlog_stat = ();
96 our %all_stat_bgwriter = ();
97 our %all_stat_connections = ();
98 our %all_stat_user_functions = ();
99 our %all_stat_replication = ();
100 our %all_pgbouncer_stats = ();
101 our %all_pgbouncer_ini = ();
102 our %all_pgbouncer_req_stats = ();
103 our %all_class_size = ();
104 our %all_stat_locks = ();
105 our %all_stat_unused_indexes = ();
106 our %all_stat_redundant_indexes = ();
107 our %all_stat_extended_statistics = ();
108 our %all_stat_count_indexes = ();
109 our %all_stat_missing_fkindexes = ();
110 our %all_postgresql_conf = ();
111 our %all_recovery_conf = ();
112 our %all_postgresql_auto_conf = ();
113 our %all_pg_hba_conf = ();
114 our %all_pg_ident_conf = ();
115 our %all_settings = ();
116 our %all_nondefault_settings = ();
117 our %all_db_role_setting = ();
118 our %all_database_buffercache = ();
119 our %all_database_usagecount = ();
120 our %all_database_isdirty = ();
121 our %all_stat_archiver = ();
122 our %all_stat_statements = ();
123 our %all_stat_unlogged = ();
124 our %all_postgresql_conf_diff = ();
125 our %all_recovery_conf_diff = ();
126 our %all_postgresql_auto_conf_diff = ();
127 our %all_pg_hba_conf_diff = ();
128 our %all_pg_ident_conf_diff = ();
129 our %all_settings_diff = ();
130 our %all_db_role_setting_diff = ();
131 our %all_pgbouncer_ini_diff = ();
132
133 # Names of the variables that need to be saved as binary file
134 our @pg_to_be_stored = (
135 'global_infos',
136 'global_databases',
137 'global_tbspnames',
138 'all_stat_database',
139 'all_stat_database_conflicts',
140 'all_database_size',
141 'all_tablespace_size',
142 'all_vacuum_stat',
143 'all_stat_user_tables',
144 'all_stat_user_indexes',
145 'all_stat_invalid_indexes',
146 'all_stat_hash_indexes',
147 'all_statio_user_tables',
148 'all_relation_buffercache',
149 'all_statio_user_indexes',
150 'all_xlog_stat',
151 'all_stat_bgwriter',
152 'all_stat_connections',
153 'all_stat_user_functions',
154 'all_stat_replication',
155 'all_pgbouncer_stats',
156 'all_pgbouncer_ini',
157 'all_pgbouncer_req_stats',
158 'all_class_size',
159 'all_stat_locks',
160 'all_stat_unused_indexes',
161 'all_stat_redundant_indexes',
162 'all_stat_extended_statistics',
163 'all_stat_count_indexes',
164 'all_stat_missing_fkindexes',
165 'all_postgresql_conf',
166 'all_recovery_conf',
167 'all_postgresql_auto_conf',
168 'all_pg_hba_conf',
169 'all_pg_ident_conf',
170 'all_settings',
171 'all_nondefault_settings',
172 'all_db_role_setting',
173 'all_database_buffercache',
174 'all_database_usagecount',
175 'all_database_isdirty',
176 'all_stat_archiver',
177 'all_stat_statements',
178 'all_stat_unlogged',
179 'all_pgbouncer_ini_diff',
180 'all_db_role_setting_diff',
181 'all_postgresql_conf_diff',
182 'all_recovery_conf_diff',
183 'all_postgresql_auto_conf_diff',
184 'all_pg_hba_conf_diff',
185 'all_pg_ident_conf_diff',
186 'all_settings_diff',
187 );
188
189 # Names of sar variables that need to be saved as binary file
190 our %sar_cpu_stat = ();
191 our %sar_load_stat = ();
192 our %sar_process_stat = ();
193 our %sar_context_stat = ();
194 our %sar_memory_stat = ();
195 our %sar_dirty_stat = ();
196 our %sar_swap_stat = ();
197 our %sar_pageswap_stat = ();
198 our %sar_block_stat = ();
199 our %sar_srvtime_stat = ();
200 our %sar_rw_devices_stat = ();
201 our %sar_util_devices_stat = ();
202 our %sar_networks_stat = ();
203 our %sar_neterror_stat = ();
204 our %sar_space_devices_stat = ();
205 our %sar_commit_memory_stat = ();
206
207 our @sar_to_be_stored = (
208 'global_infos',
209 'sar_cpu_stat',
210 'sar_load_stat',
211 'sar_process_stat',
212 'sar_context_stat',
213 'sar_memory_stat',
214 'sar_dirty_stat',
215 'sar_swap_stat',
216 'sar_pageswap_stat',
217 'sar_block_stat',
218 'sar_srvtime_stat',
219 'sar_rw_devices_stat',
220 'sar_util_devices_stat',
221 'sar_networks_stat',
222 'sar_neterror_stat',
223 'sar_space_devices_stat',
224 'sar_commit_memory_stat'
225 );
226
227 # Names of pidstat variables that need to be saved as binary file
228 our %pidstat_cpu_stat = ();
229 our %pidstat_context_stat = ();
230 our %pidstat_memory_stat = ();
231 our %pidstat_io_stat = ();
232
233 our @pidstat_to_be_stored = (
234 'pidstat_cpu_stat',
235 'pidstat_context_stat',
236 'pidstat_memory_stat',
237 'pidstat_io_stat'
238 );
239
240 # Relation between sar binary file and CGI action parameter.
241 # This is used to only load the binary file related to a report.
242 our %bin_action_map = (
243 'system-cpu' => 'sar_cpu_stat',
244 'system-memory' => 'sar_memory_stat',
245 'system-dirty' => 'sar_dirty_stat',
246 'system-swap' => 'sar_swap_stat',
247 'system-commit_memory' => 'sar_commit_memory_stat',
248 'system-load' => 'sar_load_stat',
249 'system-process' => 'sar_process_stat',
250 'system-runqueue' => 'sar_process_stat',
251 'system-cswch' => 'sar_context_stat',
252 'system-pcrea' => 'sar_context_stat',
253 'system-block' => 'sar_block_stat',
254 'system-tps' => 'sar_block_stat',
255 'system-page' => 'sar_pageswap_stat',
256 'system-fault' => 'sar_pageswap_stat',
257 'system-scanpage' => 'sar_pageswap_stat',
258 'system-cpudevice' => 'sar_util_devices_stat',
259 'system-rwdevice' => 'sar_rw_devices_stat',
260 'system-tpsdevice' => 'sar_rw_devices_stat',
261 'system-srvtime' => 'sar_srvtime_stat',
262 'system-space' => 'sar_space_devices_stat',
263 'network-utilization' => 'sar_networks_stat',
264 'network-error' => 'sar_networks_stat',
265 );
266
267 our %pg_action_map = (
268 'cluster-backends' => 'all_stat_database',
269 'database-backends' => 'all_stat_database',
270 'cluster-deadlocks' => 'all_stat_database',
271 'database-deadlocks' => 'all_stat_database',
272 'cluster-cache_ratio' => 'all_stat_database',
273 'database-cache_ratio' => 'all_stat_database',
274 'cluster-temporary_files' => 'all_stat_database',
275 'cluster-temporary_bytes' => 'all_stat_database',
276 'database-temporary_files' => 'all_stat_database',
277 'database-temporary_bytes' => 'all_stat_database',
278 'cluster-read_ratio' => 'all_stat_database',
279 'database-read_ratio' => 'all_stat_database',
280 'cluster-write_ratio' => 'all_stat_database',
281 'database-write_ratio' => 'all_stat_database',
282 'cluster-read_write_query' => 'all_stat_database',
283 'database-read_write_query' => 'all_stat_database',
284 'cluster-commits_rollbacks' => 'all_stat_database',
285 'database-commits_rollbacks' => 'all_stat_database',
286 'cluster-transactions' => 'all_stat_database',
287 'database-transactions' => 'all_stat_database',
288 'cluster-canceled_queries' => 'all_stat_database',
289 'database-canceled_queries' => 'all_stat_database',
290 'cluster-connections' => 'all_stat_connections',
291 'database-connections' => 'all_stat_connections',
292 'cluster-conflicts' => 'all_stat_database_conflicts',
293 'database-conflicts' => 'all_stat_database_conflicts',
294 'cluster-size' => 'all_database_size',
295 'database-size' => 'all_database_size',
296 'tablespace-size' => 'all_tablespace_size',
297 'cluster-buffersused' => 'all_database_buffercache',
298 'cluster-databaseloaded' => 'all_database_buffercache',
299 'cluster-usagecount' => 'all_database_usagecount',
300 'cluster-isdirty' => 'all_database_isdirty',
301 'cluster-bgwriter_write' => 'all_stat_bgwriter',
302 'cluster-bgwriter_read' => 'all_stat_bgwriter',
303 'cluster-bgwriter_count' => 'all_stat_bgwriter',
304 'cluster-checkpoints' => 'all_stat_bgwriter',
305 'cluster-checkpoints_time' => 'all_stat_bgwriter',
306 'cluster-xlog_files' => 'all_xlog_stat',
307 'cluster-xlog' => 'all_stat_replication',
308 'cluster-archive' => 'all_stat_archiver',
309 'cluster-replication' => 'all_stat_replication',
310 'buffercache-relation' => 'all_relation_buffercache',
311 'statio-buffercache' => 'all_relation_buffercache',
312 'table-vacuums-analyzes' => 'all_vacuum_stat',
313 'table-indexes' => 'all_stat_user_tables',
314 'table-vacuums-analyzes' => 'all_stat_user_tables',
315 'table-query-tuples' => 'all_stat_user_tables',
316 'table-kind-tuples' => 'all_stat_user_tables',
317 'table-size' => 'all_class_size',
318 'index-size' => 'all_class_size',
319 'table-unlogged' => 'all_stat_unlogged',
320 'table-extended' => 'all_stat_extended_statistics',
321 'statio-table' => 'all_statio_user_tables',
322 'index-scan' => 'all_stat_user_indexes',
323 'index-invalid' => 'all_stat_invalid_indexes',
324 'index-hash' => 'all_stat_hash_indexes',
325 'statio-index' => 'all_statio_user_indexes',
326 'database-function' => 'all_stat_user_functions',
327 'pgbouncer-connections' => 'all_pgbouncer_stats',
328 'pgbouncer-duration' => 'all_pgbouncer_req_stats',
329 'pgbouncer-number' => 'all_pgbouncer_req_stats',
330 'pgbouncer-wait-total' => 'all_pgbouncer_req_stats',
331 'pgbouncer-wait-average' => 'all_pgbouncer_req_stats',
332 'database-lock-types' => 'all_stat_locks',
333 'database-lock-modes' => 'all_stat_locks',
334 'database-lock-granted' => 'all_stat_locks',
335 'unused-index' => 'all_stat_unused_indexes',
336 'redundant-index' => 'all_stat_redundant_indexes',
337 'missing-index' => 'all_stat_missing_fkindexes',
338 'count-index' => 'all_stat_count_indexes',
339 'cluster-pgconf' => 'all_postgresql_conf',
340 'cluster-recoveryconf' => 'all_recovery_conf',
341 'cluster-alterconf' => 'all_postgresql_auto_conf',
342 'cluster-pghba' => 'all_pg_hba_conf',
343 'cluster-pgident' => 'all_pg_ident_conf',
344 'cluster-settings' => 'all_settings',
345 'cluster-nondefault-settings' => 'all_nondefault_settings',
346 'cluster-dbrolesetting' => 'all_db_role_setting',
347 'cluster-pgbouncer' => 'all_pgbouncer_ini',
348 'database-queries' => 'all_stat_statements',
349 );
350
351
352 our %sysinfo = (); # Hash used to store system information
353
354 # Store default timestamp
355 my ($o_sec, $o_min, $o_hour, $o_day, $o_month, $o_year) = (0,0,0,0,0,0);
356 my ($e_sec, $e_min, $e_hour, $e_day, $e_month, $e_year) = (0,0,0,0,0,0);
357
358 # Variable use to construct the date part of the sar output
359 # it is set with de date found in sar file kernel header.
360 my $sar_year = '';
361 my $sar_month = '';
362 my $sar_day = '';
363 my $pidstat_year = '';
364 my $pidstat_month = '';
365 my $pidstat_day = '';
366
367 # Charset used in the html output
368 my $charset = 'utf-8';
369
370 # List of reports that do not generate graphs and then
371 # where stats are only read from the last stats dir.
372 my @NOGRAPH_LIST = (
373 'home', 'sysinfo', 'database-info', 'table-indexes', 'table-vacuums-analyzes',
374 'table-quey-tuples', 'table-kind-tuples', 'table-size', 'table-unlogged',
375 'statio-table', 'index-scan', 'index-size', 'index-invalid', 'index-hash',
376 'statio-index', 'unused-index', 'redundant-index', 'missing-index', 'count-index',
377 'database-functions', 'buffercache-relation'
378 );
379
380
381 # Statistics files to use with report
382 my %DB_GRAPH_INFOS = (
383 'pg_stat_database.csv' => {
384 '0' => {
385 'name' => 'cluster-backends',
386 'title' => 'Global connections',
387 'description' => 'Global number of clients connected.',
388 'ylabel' => 'Connections',
389 'legends' => ['backends'],
390 },
391 '1' => {
392 'name' => 'database-backends',
393 'title' => 'Connections on %s database',
394 'description' => 'Number of clients connected to a database.',
395 'ylabel' => 'Connections',
396 'legends' => ['backends'],
397 },
398 '2' => {
399 'name' => 'cluster-read_write_query',
400 'title' => 'Global affected tuples per operation',
401 'ylabel' => 'Tuples',
402 'description' => 'Global affected rows grouped by statement family.',
403 },
404 '3' => {
405 'name' => 'database-read_write_query',
406 'title' => 'Affected tuples per operation on %s database',
407 'ylabel' => 'Tuples',
408 'description' => 'Affected rows on databases grouped by statement family.',
409 },
410 '4' => {
411 'name' => 'cluster-cache_ratio',
412 'title' => 'Global cache hit/miss ratio',
413 'description' => 'Global cache hit/miss ratio.',
414 'ylabel' => 'Blocks per second',
415 'legends' => ['Cache hit','Cache miss','hit/miss ratio'],
416 'y2label' => 'Percentage',
417 },
418 '5' => {
419 'name' => 'database-cache_ratio',
420 'title' => 'Cache hit/miss ratio on %s database',
421 'description' => 'Per database cache hit/miss ratio.',
422 'ylabel' => 'Blocks per second',
423 'legends' => ['Cache hit','Cache miss','hit/miss ratio'],
424 'y2label' => 'Percentage',
425 },
426 '6' => {
427 'name' => 'cluster-commits_rollbacks',
428 'title' => 'Global Commits/Rollbacks per second',
429 'description' => 'Global number of commits / rollbacks per second and number of backends.',
430 'ylabel' => 'Transaction/sec',
431 'legends' => ['commit','rollback','backends'],
432 'y2label' => 'Number of backend',
433 },
434 '7' => {
435 'name' => 'database-commits_rollbacks',
436 'title' => 'Commits/Rollbacks per second on %s database',
437 'description' => 'Number of commits / rollbacks per second and number of backends per database.',
438 'ylabel' => 'Transaction/sec',
439 'legends' => ['commit','rollback','backends'],
440 'y2label' => 'Number of backend',
441 },
442 '8' => {
443 'name' => 'cluster-write_ratio',
444 'title' => 'Global Write ratio',
445 'description' => 'Global write ratio, excluding templates and postgres databases.',
446 'ylabel' => 'Write queries per second',
447 'legends' => ['Insert','Update','Delete'],
448 },
449 '9' => {
450 'name' => 'database-write_ratio',
451 'title' => 'Write ratio on %s database',
452 'description' => 'Write ratio on databases excluding templates and postgres.',
453 'ylabel' => 'Write queries per second',
454 'legends' => ['Insert','Update','Delete'],
455 },
456 '10' => {
457 'name' => 'cluster-read_ratio',
458 'title' => 'Global read tuples',
459 '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.',
460 'ylabel' => 'Tuples per second',
461 'legends' => ['Table (returned)','Index (fetched)'],
462 },
463 '11' => {
464 'name' => 'database-read_ratio',
465 'title' => 'Read tuples on %s database',
466 '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.',
467 'ylabel' => 'Tuples per second',
468 'legends' => ['Table (returned)','Index (fetched)'],
469 },
470 '12' => {
471 'name' => 'cluster-deadlocks',
472 'title' => 'Global number of deadlocks',
473 'description' => 'Global number of deadlocks detected.',
474 'ylabel' => 'Number of deadlocks',
475 'legends' => ['deadlocks'],
476 },
477 '13' => {
478 'name' => 'database-deadlocks',
479 'title' => 'Number of deadlocks on %s database',
480 'description' => 'Number of deadlocks detected in this database.',
481 'ylabel' => 'Number of deadlocks',
482 'legends' => ['deadlocks'],
483 },
484 '14' => {
485 'name' => 'cluster-canceled_queries',
486 'title' => 'Global number of canceled queries',
487 'description' => 'Global number of queries canceled due to conflicts with recovery. [Conflicts occur only on standby servers]',
488 'ylabel' => 'Number of queries canceled',
489 'legends' => ['conflicts'],
490 },
491 '15' => {
492 'name' => 'database-canceled_queries',
493 'title' => 'Number of canceled queries on %s database',
494 'description' => 'Number of queries canceled due to conflicts with recovery in this database. [Conflicts occur only on standby servers]',
495 'ylabel' => 'Number of queries canceled',
496 'legends' => ['conflicts'],
497 },
498 '16' => {
499 'name' => 'cluster-temporary_files',
500 'title' => 'Global number of temporary files',
501 'description' => 'Global number of temporary files created by queries.',
502 'ylabel' => 'Number of files',
503 'legends' => ['temporary files'],
504 },
505 '17' => {
506 'name' => 'database-temporary_files',
507 'title' => 'Number of temporary files on %s database',
508 'description' => 'Number of temporary files created by queries per database.',
509 'ylabel' => 'Number of files',
510 'legends' => ['temporary files'],
511 },
512 '18' => {
513 'name' => 'cluster-temporary_bytes',
514 'title' => 'Global size of temporary data',
515 'description' => 'Global amount of data per second written to temporary files created by queries.',
516 'ylabel' => 'Size per seconde',
517 'legends' => ['temporary data'],
518 },
519 '19' => {
520 'name' => 'database-temporary_bytes',
521 'title' => 'Size of temporary data on %s database',
522 'description' => 'Amount of data per seconde written to temporary files created by queries per database.',
523 'ylabel' => 'Size per seconde',
524 'legends' => ['temporary data'],
525 },
526 '20' => {
527 'name' => 'cluster-transactions',
528 'title' => 'Transaction throughput per second',
529 'description' => 'Number of transaction (commit+rollback) issued per second.',
530 'ylabel' => 'Transaction/sec',
531 'legends' => ['tps'],
532 },
533 '21' => {
534 'name' => 'database-transactions',
535 'title' => 'Transactions per second on %s database',
536 'description' => 'Number of transaction (commit+rollback) issued per second.',
537 'ylabel' => 'Transaction/sec',
538 'legends' => ['tps'],
539 },
540 },
541 'pg_stat_database_conflicts.csv' => {
542 '0' => {
543 'name' => 'cluster-conflicts',
544 'title' => 'Conflicts per type on all database',
545 'description' => 'Statistics about query cancels occurring due to conflicts with recovery on standby servers.',
546 'ylabel' => 'Number of conflict',
547 'legends' => [ 'tablespace', 'lock', 'snapshot', 'bufferpin', 'deadlock' ],
548 },
549 '1' => {
550 'name' => 'database-conflicts',
551 'title' => 'Conflicts per type on %s database',
552 'description' => 'Per database statistics about query cancels occurring due to conflicts with recovery on standby servers.',
553 'ylabel' => 'Number of conflict',
554 'legends' => [ 'tablespace', 'lock', 'snapshot', 'bufferpin', 'deadlock' ],
555 },
556 },
557 'pg_database_size.csv' => {
558 '1' => {
559 'name' => 'cluster-size',
560 'title' => 'Size of %s database',
561 'description' => 'Database sizes.',
562 'ylabel' => 'Size',
563 'legends' => ['size'],
564 'active' => 1,
565 },
566 '2' => {
567 'name' => 'database-size',
568 'title' => 'Size of %s database',
569 'description' => 'Database sizes.',
570 'ylabel' => 'Size',
571 'legends' => ['size'],
572 'active' => 1,
573 },
574 },
575 'pg_tablespace_size.csv' => {
576 '1' => {
577 'name' => 'tablespace-size',
578 'title' => 'Size of %s tablespace',
579 'description' => 'Tablespace size and location.',
580 'ylabel' => 'Size',
581 'legends' => ['size'],
582 },
583 },
584 'pg_stat_bgwriter.csv' => {
585 '1' => {
586 'name' => 'cluster-checkpoints',
587 'title' => 'checkpoints counter stats',
588 '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.',
589 'ylabel' => 'Number of checkpoints',
590 'legends' => ['checkpoints timed','checkpoints requests'],
591 },
592 '2' => {
593 'name' => 'cluster-bgwriter_write',
594 'title' => 'background writer clean stats',
595 '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.',
596 'ylabel' => 'Size per second',
597 'legends' => ['checkpoint','clean','backend'],
598 },
599 '3' => {
600 'name' => 'cluster-bgwriter_read',
601 'title' => 'background writer allocated buffers',
602 'description' => 'Background total allocated bytes per second. Buffers allocated is the total number of allocated new buffers whether or not it was already cached.',
603 'ylabel' => 'Size per second',
604 'legends' => ['allocated'],
605 },
606 '4' => {
607 'name' => 'cluster-bgwriter_count',
608 'title' => 'background writer count stats',
609 '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).',
610 'ylabel' => 'Times per second',
611 'legends' => ['maxwritten clean','buffers backend fsync'],
612 },
613 '5' => {
614 'name' => 'cluster-checkpoints_time',
615 'title' => 'checkpoints write stats',
616 '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.',
617 'ylabel' => 'Duration',
618 'legends' => ['checkpoint write time','checkpoint sync time'],
619 },
620 },
621 'pg_stat_connections.csv' => {
622 '0' => {
623 'name' => 'cluster-connections',
624 'title' => 'Connections by type on all database',
625 'description' => 'Connections by type including idle ones.',
626 'ylabel' => 'Number of connections',
627 'legends' => ['Active','Idle','Idle in xact', 'Waiting for a lock'],
628 },
629 '1' => {
630 'name' => 'database-connections',
631 'title' => 'Connections by type on %s database',
632 'description' => 'Connections by type including idle ones.',
633 'ylabel' => 'Number of connections',
634 'legends' => ['Active','Idle','Idle in xact', 'Waiting for a lock'],
635 },
636 },
637 'pg_stat_user_functions.csv' => {
638 '1' => {
639 'name' => 'database-functions',
640 'title' => 'Functions statistics on database %s',
641 'description' => 'Statistics about executions times and duration of user functions.',
642 'ylabel' => 'Duration',
643 'active' => 1,
644 'legends' => ['total time','self time'],
645 'menu' => 'Functions statistics',
646 },
647 },
648 'pg_stat_user_tables.csv' => {
649 '1' => {
650 'name' => 'table-indexes',
651 'title' => 'Sequencial vs Index scan on %s',
652 'description' => 'Number of sequential scan versus index scan per table during the audit period.',
653 'ylabel' => 'Number per second',
654 'legends' => ['sequential scan','index scan','% index scan ratio'],
655 'y2label' => 'Percent',
656 'active' => 1,
657 'menu' => 'Index scan ratio',
658 },
659 '2' => {
660 'name' => 'table-vacuums-analyzes',
661 'title' => 'Analyze/vacuums count on %s',
662 'description' => 'Number of analyze, autoanalyze, vacuum and autovacuum count per table during the audit period.',
663 'ylabel' => 'Number',
664 'legends' => ['Analyze','Autoanalyze','Vacuum','Autovacuum'],
665 'active' => 1,
666 'menu' => 'Vacuums/analyzes',
667 },
668 '3' => {
669 'name' => 'table-query-tuples',
670 'title' => 'Insert/update/delete and hot update tuples on %s',
671 'description' => 'Number of insert/update/delete and hot update tuples count per table during the audit period.',
672 'ylabel' => 'Number per second',
673 'legends' => ['Insert','Update','Delete','Hot Update'],
674 'active' => 1,
675 'menu' => 'insert/update/delete',
676 },
677 '4' => {
678 'name' => 'table-kind-tuples',
679 'title' => 'Live vs dead tuples on %s',
680 'description' => 'Number of live and dead tuples per table at end of the audit period.',
681 'ylabel' => 'Number',
682 'legends' => ['Live','Dead','% Bloat ratio'],
683 'y2label' => 'Percent',
684 'active' => 1,
685 'menu' => 'Live vs dead tuples',
686 },
687 },
688 'pg_statio_user_tables.csv' => {
689 '1' => {
690 'name' => 'statio-table',
691 'title' => 'Statistics about I/O on %s',
692 '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.',
693 'ylabel' => 'Number per second',
694 'legends' => ['heap_blks_read','heap_blks_hit','idx_blks_read','idx_blks_hit'],
695 'active' => 1,
696 'menu' => 'Tables I/O stats',
697 },
698 },
699 'pg_stat_user_indexes.csv' => {
700 '1' => {
701 'name' => 'index-scan',
702 'title' => 'Statistics about accesses to index %s',
703 '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.',
704 'ylabel' => 'Number per second',
705 'legends' => ['index scans initiated','index entries read','live table rows fetched'],
706 'y2label' => 'Percent',
707 'active' => 1,
708 'menu' => 'Index read/fetch',
709 },
710 },
711 'pg_statio_user_indexes.csv' => {
712 '1' => {
713 'name' => 'statio-index',
714 'title' => 'Statistics about I/O on %s',
715 'description' => 'Number of disk blocks read from this index versus number of buffer hits in this index at end of the audit period.',
716 'ylabel' => 'Number per second',
717 'legends' => ['idx_blks_read','idx_blks_hit'],
718 'active' => 1,
719 'menu' => 'Indexes I/O stats',
720 },
721 },
722 'pg_stat_unused_indexes.csv' => {
723 '1' => {
724 'name' => 'unused-index',
725 'title' => 'Unused indexes on %s',
726 'description' => 'List of indexes never used (idx_scan = 0).',
727 'ylabel' => 'Number',
728 'legends' => ['Unused index'],
729 'active' => 1,
730 'menu' => 'Unused Indexes',
731 },
732 },
733 'pg_stat_redundant_indexes.csv' => {
734 '1' => {
735 'name' => 'redundant-index',
736 'title' => 'Redundant indexes on %s',
737 '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.',
738 'ylabel' => 'Number',
739 'legends' => ['Redundant index'],
740 'active' => 1,
741 'menu' => 'Redundant indexes',
742 },
743 },
744 'pg_stat_count_indexes.csv' => {
745 '1' => {
746 'name' => 'zero-index',
747 'title' => 'Tables without indexes on %s',
748 'description' => 'List of tables without indexes.',
749 'ylabel' => 'Number',
750 'legends' => ['No indexes'],
751 'active' => 1,
752 'menu' => 'Tables without index',
753 },
754 '2' => {
755 'name' => 'count-index',
756 'title' => 'Tables with lot of indexes on %s',
757 'description' => 'List of tables with lot of indexes.',
758 'ylabel' => 'Number',
759 'legends' => ['Indexes count'],
760 'active' => 1,
761 'menu' => "Table with more than $MAX_INDEXES Indexes",
762 },
763 },
764 'pg_stat_missing_fkindexes.csv' => {
765 '1' => {
766 'name' => 'missing-index',
767 'title' => 'Missing FK indexes on %s',
768 'description' => 'List of DDL to create missing indexes on foreign keys.',
769 'ylabel' => 'Number',
770 'legends' => ['Missing index'],
771 'active' => 1,
772 'menu' => 'Missing indexes',
773 },
774 },
775 'pg_xlog_stat.csv' => {
776 '1' => {
777 'name' => 'cluster-xlog_files',
778 'title' => 'WAL files',
779 'description' => 'Number of WAL file in the xlog directory.',
780 'ylabel' => 'Number of files',
781 'legends' => ['total xlog'],
782 },
783 },
784 'pg_stat_replication.csv' => {
785 '1' => {
786 'name' => 'cluster-xlog',
787 'title' => 'Xlog written',
788 'description' => 'Number of xlog data written per second.',
789 'ylabel' => 'Size per second',
790 'legends' => ['written'],
791 },
792 '2' => {
793 'name' => 'cluster-replication',
794 'title' => 'Replication lag with %s',
795 'description' => 'Lag of replication between primary and secondary servers.',
796 'ylabel' => 'Lag sizes',
797 'legends' => ['Sent','Write','Replay'],
798 },
799 },
800 'pgbouncer_stats.csv' => {
801 '1' => {
802 'name' => 'pgbouncer-connections',
803 'title' => 'pgbouncer connections statistics on pool %s',
804 'description' => 'Number of active/waiting clients, active/idle/used server connections and maximum wait duration for client connections in each pgbouncer pool.',
805 'ylabel' => 'Number of connexions',
806 'legends' => ['Client active','Client waiting','Server active','Server idle','Server used','Clients wait time'],
807 'y2label' => 'Duration',
808 },
809 },
810 'pgbouncer_req_stats.csv' => {
811 '1' => {
812 'name' => 'pgbouncer-duration',
813 'title' => 'pgbouncer average queries duration on %s',
814 'description' => 'Average queries duration in each pgbouncer pool.',
815 'ylabel' => 'Duration',
816 'legends' => ['avg_query'],
817 },
818 '2' => {
819 'name' => 'pgbouncer-number',
820 'title' => 'pgbouncer queries per second on %s',
821 'description' => 'Number of queries per second in each pgbouncer pool.',
822 'ylabel' => 'Number',
823 'legends' => ['avg_req'],
824 },
825 '3' => {
826 'name' => 'pgbouncer-wait-total',
827 'title' => 'pgbouncer wait time on %s',
828 'description' => 'Time spent by clients waiting for a server in microseconds.',
829 'ylabel' => 'Microseconds',
830 'legends' => ['total_wait_time'],
831 },
832 '4' => {
833 'name' => 'pgbouncer-wait-average',
834 'title' => 'Average of wait time spent on %s',
835 'description' => 'Average of time spent by clients waiting for a server in microseconds (average per second).',
836 'ylabel' => 'Number',
837 'legends' => ['avg_wait_time'],
838 },
839 },
840 'pg_class_size.csv' => {
841 '1' => {
842 'name' => 'table-size',
843 'title' => 'Size of table %s',
844 'description' => 'Disk space used by the table with number of rows at end of the audit.',
845 'ylabel' => 'Size',
846 'legends' => ['Object size', 'Number of tuples' ],
847 'y2label' => 'Number',
848 'active' => 1,
849 'menu' => 'Size and tuples',
850 },
851 '2' => {
852 'name' => 'index-size',
853 'title' => 'Size of index %s',
854 'description' => 'Disk space used by the index with number of rows at end of the audit.',
855 'ylabel' => 'Size',
856 'legends' => ['Object size', 'Number of tuples' ],
857 'y2label' => 'Number',
858 'active' => 1,
859 'menu' => 'Size and tuples',
860 },
861 },
862 'pg_stat_locks.csv' => {
863 '1' => {
864 'name' => 'database-lock-types',
865 'title' => 'Types of locks on %s database',
866 'description' => 'Number of locks per type in a database. Type of the lockable object: relation, extend, page, tuple, transactionid, virtualxid, object, userlock, or advisory.',
867 'ylabel' => 'Number',
868 'legends' => [],
869 'active' => 1,
870 },
871 '2' => {
872 'name' => 'database-lock-modes',
873 'title' => 'Modes of locks on %s database',
874 'description' => 'Number of locks per lock mode held or desired by all process.',
875 'ylabel' => 'Number',
876 'legends' => [],
877 'active' => 1,
878 },
879 '3' => {
880 'name' => 'database-lock-granted',
881 'title' => 'Granted locks on %s database',
882 'description' => 'Number of locks held (granted) or awaited (waiting).',
883 'ylabel' => 'Number',
884 'legends' => [],
885 'active' => 1,
886 },
887 },
888 'postgresql.conf' => {
889 '1' => {
890 'name' => 'cluster-pgconf',
891 'title' => 'PostgreSQL configuration',
892 'description' => 'Configuration directives and values defined in file postgresql.conf.',
893 'ylabel' => 'Number',
894 'legends' => ['Settings'],
895 'active' => 1,
896 'menu' => 'PostgreSQL configuration',
897 },
898 },
899 'postgresql.auto.conf' => {
900 '1' => {
901 'name' => 'cluster-alterconf',
902 'title' => 'PostgreSQL system altered configuration',
903 'description' => 'Configuration directives and values defined using ALTER SYSTEM.',
904 'ylabel' => 'Number',
905 'legends' => ['Settings'],
906 'active' => 1,
907 'menu' => 'PostgreSQL system altered configuration',
908 },
909 },
910 'recovery.conf' => {
911 '1' => {
912 'name' => 'cluster-recoveryconf',
913 'title' => 'PostgreSQL recovery configuration',
914 'description' => 'Configuration directives and values defined in file recovery.conf.',
915 'ylabel' => 'Number',
916 'legends' => ['Settings'],
917 'active' => 1,
918 'menu' => 'PostgreSQL recovery configuration',
919 },
920 },
921 'pg_hba.conf' => {
922 '1' => {
923 'name' => 'cluster-pghba',
924 'title' => 'PostgreSQL authorization',
925 'description' => 'Client authentication controlled by pg_hba.conf configuration file.',
926 'ylabel' => 'Number',
927 'legends' => ['Setting','Value'],
928 'active' => 1,
929 'menu' => 'PostgreSQL authorization',
930 },
931 },
932 'pg_ident.conf' => {
933 '1' => {
934 'name' => 'cluster-pgident',
935 'title' => 'PostgreSQL User Name Maps',
936 'description' => 'Different operating system user / database user mappings might be needed for different connections. They are defined in file pg_ident.conf.',
937 'ylabel' => 'Number',
938 'legends' => ['Setting','Value'],
939 'active' => 1,
940 'menu' => 'User Name Maps',
941 },
942 },
943 'pg_settings.csv' => {
944 '1' => {
945 'name' => 'cluster-settings',
946 'title' => 'PostgreSQL Settings',
947 'description' => 'Configuration directives and values defined in pg_settings.',
948 'ylabel' => 'Number',
949 'legends' => ['Settings'],
950 'active' => 1,
951 'menu' => 'PostgreSQL settings',
952 },
953 },
954 'pg_nondefault_settings.csv' => {
955 '1' => {
956 'name' => 'cluster-nondefault-settings',
957 'title' => 'PostgreSQL Non Default Settings',
958 'description' => 'Non default configuration directives and values defined in pg_settings.',
959 'ylabel' => 'Number',
960 'legends' => ['Settings'],
961 'active' => 1,
962 'menu' => 'PostgreSQL non default settings',
963 },
964 },
965 'pg_db_role_setting.csv' => {
966 '1' => {
967 'name' => 'cluster-dbrolesetting',
968 'title' => 'PostgreSQL Database/Roles Settings',
969 'description' => 'Configuration directives and values defined with ALTER DATABASE and ALTER ROLE.',
970 'ylabel' => 'Number',
971 'legends' => ['Settings'],
972 'active' => 1,
973 'menu' => 'Database/Roles settings',
974 },
975 },
976 'pgbouncer.ini' => {
977 '1' => {
978 'name' => 'cluster-pgbouncer',
979 'title' => 'Pgbouncer configuration',
980 'description' => 'Configuration directives and values defined in file pgbouncer.ini.',
981 'ylabel' => 'Number',
982 'legends' => ['Setting','Value'],
983 'active' => 1,
984 'menu' => 'Pgbouncer settings',
985 },
986 },
987 'pg_database_buffercache.csv' => {
988 '1' => {
989 'name' => 'cluster-buffersused',
990 'title' => 'Shared buffers utilization per database',
991 'description' => 'Show statistics about percentage of shared buffers used per database.',
992 'ylabel' => 'Percent',
993 'legends' => [],
994 'active' => 1,
995 'menu' => 'Shared buffers utilization',
996 },
997 '2' => {
998 'name' => 'cluster-databaseloaded',
999 'title' => 'Percentage of each databases loaded in shared buffers',
1000 'description' => 'Show statistics about percentage of each database loaded in shared buffers.',
1001 'ylabel' => 'Percent',
1002 'legends' => [],
1003 'menu' => 'Databases in shared buffers',
1004 },
1005 },
1006 'pg_database_usagecount.csv' => {
1007 '1' => {
1008 'name' => 'cluster-usagecount',
1009 'title' => 'Shared buffers usagecount distribution',
1010 'description' => 'Show statistics about usagecount distribution in shared buffers.',
1011 'ylabel' => 'Percent',
1012 'legends' => [],
1013 'menu' => 'Usagecount utilization',
1014 'active' => 1,
1015 },
1016 },
1017 'pg_database_isdirty.csv' => {
1018 '1' => {
1019 'name' => 'cluster-isdirty',
1020 'title' => 'Dirty shared buffers usagecount distribution',
1021 'description' => 'Show statistics about usagecount distribution in dirty shared buffers.',
1022 'ylabel' => 'Percent',
1023 'legends' => [],
1024 'menu' => 'Dirty Usagecount',
1025 'active' => 1,
1026 },
1027 },
1028 'pg_relation_buffercache.csv' => {
1029 '1' => {
1030 'name' => 'buffercache-relation',
1031 'title' => 'Statistics about cache utilization for %s database',
1032 'description' => 'Number of shared buffers/pages used by a relation.',
1033 'ylabel' => 'Number',
1034 'legends' => ['buffers'],
1035 'active' => 1,
1036 'menu' => 'Buffercache per relation',
1037 },
1038 '2' => {
1039 'name' => 'statio-buffercache',
1040 'title' => 'Statistics about cache utilization %s relation',
1041 'description' => 'Number of buffers loaded in cache for a relation and the percentage of the relation loaded.',
1042 'ylabel' => 'Number',
1043 'y2label' => 'percent',
1044 'legends' => ['buffered','relation %'],
1045 'menu' => 'Buffer I/O per relation',
1046 },
1047 },
1048 'pg_stat_archiver.csv' => {
1049 '1' => {
1050 'name' => 'cluster-archive',
1051 'title' => 'Statistics about archiver',
1052 'description' => 'Number of WAL files archived with number of failure.',
1053 'ylabel' => 'Number',
1054 'legends' => ['archived count', 'failed count'],
1055 'active' => 1,
1056 'menu' => 'Archiving',
1057 }
1058 },
1059 'pg_stat_statements.csv' => {
1060 '1' => {
1061 'name' => 'database-queries',
1062 'title' => 'Statistics about statements',
1063 'description' => 'Top N statistics about slowest or most used queries.',
1064 'ylabel' => 'Number',
1065 'legends' => ['queries'],
1066 'active' => 1,
1067 'menu' => 'Statements statistics',
1068 }
1069 },
1070 'pg_stat_invalid_indexes.csv' => {
1071 '1' => {
1072 'name' => 'index-invalid',
1073 'title' => 'Invalid indexes on %s',
1074 'description' => 'List of invalid indexes during concurrency build.',
1075 'ylabel' => 'Number',
1076 'legends' => ['Invalid index'],
1077 'active' => 1,
1078 'menu' => 'Invalid Indexes',
1079 },
1080 },
1081 'pg_stat_hash_indexes.csv' => {
1082 '1' => {
1083 'name' => 'index-hash',
1084 'title' => 'Hash indexes on %s',
1085 'description' => 'List of hash indexes during concurrency build.',
1086 'ylabel' => 'Number',
1087 'legends' => ['Hash index'],
1088 'active' => 1,
1089 'menu' => 'Hash Indexes',
1090 },
1091 },
1092 'pg_stat_unlogged.csv' => {
1093 '1' => {
1094 'name' => 'table-unlogged',
1095 'title' => 'Unlogged tables on %s',
1096 'description' => 'List of unlogged tables in the database.',
1097 'ylabel' => 'Number',
1098 'legends' => ['Unlogged tables'],
1099 'active' => 1,
1100 'menu' => 'Unlogged tables',
1101 },
1102 },
1103 'pg_stat_ext.csv' => {
1104 '1' => {
1105 'name' => 'table-extended',
1106 'title' => 'Extended statistics defined on %s',
1107 'description' => 'List of extended planner statistics created in the database.',
1108 'ylabel' => 'Number',
1109 'legends' => ['Extended stats'],
1110 'active' => 1,
1111 'menu' => 'Extended statistics',
1112 },
1113 },
1114
1115 );
1116
1117 my %SAR_GRAPH_INFOS = (
1118 '1' => {
1119 'name' => 'system-cpu',
1120 'title' => 'CPU %s utilization',
1121 'all_title' => 'Global CPU utilization',
1122 '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.',
1123 '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.',
1124 'ylabel' => 'Percentage',
1125 'legends' => ['Total','System','User','Idle','Iowait'],
1126 'active' => 1,
1127 },
1128 '2' => {
1129 'name' => 'system-load',
1130 'title' => 'System load',
1131 '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.',
1132 'ylabel' => 'Process load',
1133 'legends' => ['ldavg-1','ldavg-5','ldavg-15'],
1134 },
1135 '3' => {
1136 'name' => 'system-process',
1137 'title' => 'Number of process',
1138 'description' => 'Number of tasks in the task list.',
1139 'ylabel' => 'Number of process',
1140 'legends' => ['plist-sz'],
1141 },
1142 '4' => {
1143 'name' => 'system-memory',
1144 'title' => 'System memory utilization',
1145 'description' => 'Amount of memory used to cache data or as buffers by the kernel and free memory available.',
1146 'ylabel' => 'Memory size',
1147 'legends' => ['cached','buffers','memfree'],
1148 },
1149 '5' => {
1150 'name' => 'system-swap',
1151 'title' => 'Swap In/Out (pages/seconds)',
1152 'description' => 'Total number of swap pages the system brought in/out per second. The page size usually is 4096 bytes.',
1153 'ylabel' => 'Pages/second',
1154 'legends' => ['pswpin/s','pswpout/s'],
1155 },
1156 '6' => {
1157 'name' => 'system-block',
1158 'title' => 'Block In/Out (blocks/seconds)',
1159 '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.',
1160 'ylabel' => 'Block per second',
1161 'legends' => ['bread/s','bwrtn/s'],
1162 },
1163 '7' => {
1164 'name' => 'system-rwdevice',
1165 'title' => 'Data read/write on device %s',
1166 'description' => 'Number of bytes read/write from/to the device..',
1167 'ylabel' => 'Size Read/Written per second',
1168 'legends' => ['Read', 'Write'],
1169 },
1170 '8' => {
1171 'name' => 'system-cpudevice',
1172 'title' => 'CPU utilization on device %s',
1173 '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%.',
1174 'ylabel' => 'Percentage of CPU',
1175 'legends' => ['cpu used'],
1176 },
1177 '9' => {
1178 'name' => 'system-srvtime',
1179 'title' => 'Average wait/service time for I/O requests on device %s',
1180 '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.',
1181 'ylabel' => 'Milliseconds',
1182 'y2label' => 'Milliseconds',
1183 'legends' => ['await','svctm'],
1184 },
1185 '10' => {
1186 'name' => 'system-runqueue',
1187 'title' => 'Run queue length',
1188 'description' => 'Number of tasks waiting for run time and number of tasks currently blocked, waiting for I/O to complete (sysstat >= 9.1.7).',
1189 'ylabel' => 'Run queue length',
1190 'legends' => ['runq-sz', 'blocked'],
1191 },
1192 '11' => {
1193 'name' => 'system-page',
1194 'title' => 'System cache statistics',
1195 'description' => 'Total number of kilobytes the system paged in/out from/to disk per second.',
1196 'ylabel' => 'Size paged',
1197 'legends' => [ 'pgpgin/s', 'pgpgout/s' ],
1198 },
1199 '12' => {
1200 'name' => 'network-utilization',
1201 'title' => 'Network utilization on interface %s',
1202 'description' => 'Report statistics from the network devices utilization.',
1203 'ylabel' => 'Size per second',
1204 'legends' => ['received (rx)', 'transmitted (tx)' ],
1205 },
1206 '13' => {
1207 'name' => 'network-error',
1208 'title' => 'Network errors on interface %s',
1209 '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.',
1210 'ylabel' => 'Number per second',
1211 'legends' => ['rx errors', 'tx errors', 'collisions' ],
1212 },
1213 '14' => {
1214 'name' => 'system-cswch',
1215 'title' => 'Context switches',
1216 'description' => 'Total number of context switches per second.',
1217 'ylabel' => 'Context switches',
1218 'legends' => ['cswch/s'],
1219 },
1220 '15' => {
1221 'name' => 'system-pcrea',
1222 'title' => 'Tasks created',
1223 'description' => 'Total number of tasks created per second.',
1224 'ylabel' => 'Tasks',
1225 'legends' => ['proc/s'],
1226 },
1227 '16' => {
1228 'name' => 'system-tps',
1229 'title' => 'Total number of transfers per second',
1230 '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.',
1231 'ylabel' => 'Transfers per second',
1232 'legends' => ['tps','rtps','wtps'],
1233 },
1234 '17' => {
1235 'name' => 'system-tpsdevice',
1236 'title' => 'Transfert per second on device %s',
1237 '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).',
1238 'ylabel' => 'Number of transfers per second',
1239 'legends' => ['Tps'],
1240 },
1241 '18' => {
1242 'name' => 'system-dirty',
1243 'title' => 'Dirty memory to be written',
1244 '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).',
1245 'ylabel' => 'Memory size',
1246 'legends' => ['active','inactive','dirty'],
1247 },
1248 '19' => {
1249 'name' => 'system-space',
1250 'title' => 'Disk space utilization on device %s',
1251 'description' => 'Percentage of disk space and inode used on the device. Close to 100% mean no more space or inode left.',
1252 'ylabel' => 'Percentage used',
1253 'legends' => ['Space', 'Inode'],
1254 },
1255 '20' => {
1256 'name' => 'system-fault',
1257 'title' => 'System page fault statistics',
1258 '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".',
1259 'ylabel' => 'Number of faults',
1260 'legends' => [ 'majflt/s', 'minflt/s' ],
1261 },
1262 '21' => {
1263 'name' => 'system-scanpage',
1264 'title' => 'System page scanned statistics',
1265 '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.',
1266 'ylabel' => 'Number of pages',
1267 'y2label' => 'Percents',
1268 'legends' => [ 'pgscank/s', 'pgscand/s', 'pgsteal/s', '%vmeff' ],
1269 },
1270 '22' => {
1271 'name' => 'system-commit_memory',
1272 'title' => 'Estimated memory to complete the workload',
1273 '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.',
1274 'ylabel' => 'Size',
1275 'legends' => ['CommitLimit', 'Committed_AS'],
1276 },
1277 );
1278
1279 my %PIDSTAT_GRAPH_INFOS = (
1280 '1' => {
1281 'name' => 'postgres-cpu',
1282 'title' => 'PostgreSQL CPU %s utilization',
1283 'all_title' => 'Global CPU utilization',
1284 '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.',
1285 '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.',
1286 'ylabel' => 'Percentage',
1287 'legends' => ['Total','System','User','Wait'],
1288 'active' => 1,
1289 },
1290 '2' => {
1291 'name' => 'postgres-memory',
1292 'title' => 'PostgreSQL memory utilization',
1293 '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.',
1294 'ylabel' => 'Memory size',
1295 'legends' => ['VSZ','RSS'],
1296 },
1297 '3' => {
1298 'name' => 'postgres-mempercent',
1299 'title' => 'PostgreSQL percentage memory use',
1300 'description' => 'Report percentage of memory use. The tasks\'s currently used share of available physical memory.',
1301 'ylabel' => 'Percent of Memory',
1302 'legends' => ['%MEM'],
1303 },
1304 '4' => {
1305 'name' => 'postgres-io',
1306 'title' => 'PostgreSQL I/O statistics',
1307 '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.',
1308 'ylabel' => 'Kb per second',
1309 'legends' => ['kB_rd/s','kB_wr/s','kB_ccwr/s'],
1310 },
1311 '5' => {
1312 'name' => 'postgres-iodelay',
1313 'title' => 'PostgreSQL I/O delay',
1314 '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.',
1315 'ylabel' => 'Block I/O delay',
1316 'legends' => ['iodelay'],
1317 },
1318 '6' => {
1319 'name' => 'postgres-fault',
1320 'title' => 'Page faults statistics',
1321 'description' => 'Total number of minor/major faults the task has made per second, those which have not required loading a memory page from disk..',
1322 'ylabel' => 'Number of faults',
1323 'legends' => [ 'minflt/s', 'majflt/s' ],
1324 },
1325 '7' => {
1326 'name' => 'postgres-cswch',
1327 'title' => 'PostgreSQL switching activity',
1328 '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.',
1329 'ylabel' => 'Context switches',
1330 'legends' => ['cswch/s', 'nvcswch/s'],
1331 },
1332 );
1333
1334 # Set CGI handle and retrieve current params states
1335 my $cgi = new CGI;
1336 my $SCRIPT_NAME = $cgi->url() || '';
1337 my $ACTION = $cgi->param('action') || 'home';
1338 my $DATABASE = $cgi->param('db') || '';
1339 my $DEVICE = $cgi->param('dev') || '';
1340 my $BEGIN = $cgi->param('start') || '';
1341 my $END = $cgi->param('end') || '';
1342
1343 my $REAL_ACTION = $ACTION || '';
1344 my $ID_ACTION = -1;
1345
1346 my $src_base = '';
1347 my $INPUT_DIR = '';
1348 my $RSC_BASE = '.';
1349
1350 sub read_conf
1351 {
1352 print STDERR "DEBUG: Reading configuration file $CONFIG_FILE\n" if ($DEBUG);
1353
1354 unless(open(IN, $CONFIG_FILE)) {
1355 die "ERROR: can not read configuration file $CONFIG_FILE, $!\n";
1356 }
1357
1358 while (my $l = <IN>) {
1359 chomp($l);
1360 $l =~ s/\r//gs;
1361 next if (!$l);
1362
1363 my ($var, @vals) = split(/[\s]+/, $l);
1364 if ($var eq 'INPUT_DIR') {
1365 if (-d $vals[0]) {
1366 $INPUT_DIR = $vals[0];
1367 } else {
1368 die "ERROR: can not find input directory, $vals[0]\n";
1369 }
1370 } elsif ($var eq 'RSC_BASE') {
1371 $RSC_BASE = $vals[0];
1372 } elsif ($var eq 'INCLUDE_DB') {
1373 push(@INCLUDE_DB, @vals);
1374 } elsif ($var eq 'INCLUDE_TB') {
1375 push(@INCLUDE_TB, @vals);
1376 } elsif ($var eq 'INCLUDE_IFACE') {
1377 push(@INCLUDE_IFACE, @vals);
1378 } elsif ($var eq 'REVERT_DATE') {
1379 $REVERT_DATE = $vals[0];
1380 } elsif ($var eq 'MAX_RENDERED_DAYS') {
1381 $MAX_RENDERED_DAYS = int($vals[0]);
1382 }
1383 }
1384 # Defined the default backward level where ressources files are stored
1385 $RSC_BASE ||= '.';
1386
1387 # Check start/end date time
1388 if ($BEGIN) {
1389 if ($BEGIN =~ /^(\d{4})-(\d+)-(\d+) (\d+):(\d+)/) {
1390 $BEGIN = &timegm_nocheck(0, $5, $4, $3, $2 - 1, $1 - 1900) * 1000;
1391 $o_day = sprintf("%02d", $3);
1392 $o_month = sprintf("%02d", $2);
1393 $o_year = $1;
1394 $o_hour = sprintf("%02d", $4);
1395 $o_min = sprintf("%02d", $5);
1396 $o_sec = '00';
1397 } elsif ($BEGIN =~ /^(\d{4})-(\d+)-(\d+)$/) {
1398 $BEGIN = &timegm_nocheck(0, 0, 0, $3, $2 - 1, $1 - 1900) * 1000;
1399 $o_day = sprintf("%02d", $3);
1400 $o_month = sprintf("%02d", $2);
1401 $o_year = $1;
1402 $o_hour = '00';
1403 $o_min = '00';
1404 $o_sec = '00';
1405 } else {
1406 die "FATAL: bad format for begin datetime, should be yyyy-mm-dd hh:mm:ss\n";
1407 }
1408 }
1409 if ($END) {
1410 if ($END =~ /^(\d{4})-(\d+)-(\d+) (\d+):(\d+)$/) {
1411 $END = &timegm_nocheck($6, $5, $4, $3, $2 - 1, $1 - 1900) * 1000;
1412 $e_day = sprintf("%02d", $3);
1413 $e_month = sprintf("%02d", $2);
1414 $e_year = $1;
1415 $e_hour = sprintf("%02d", $4);
1416 $e_min = sprintf("%02d", $5);
1417 $e_sec = '00';
1418 } elsif ($END =~ /^(\d{4})-(\d+)-(\d+)$/) {
1419 $END = &timegm_nocheck(0, 0, 0, $3, $2 - 1, $1 - 1900) * 1000;
1420 $e_day = printf("%02d", 3);
1421 $e_month = sprintf("%02d", $2);
1422 $e_year = $1;
1423 $e_hour = '00';
1424 $e_min = '00';
1425 $e_sec = '00';
1426 } else {
1427 die "FATAL: bad format for ending datetime, should be yyyy-mm-dd hh:mm:ss\n";
1428 }
1429 }
1430 }
1431
1432
1433 ####
1434 # Read configuration file
1435 ####
1436 &read_conf();
1437
1438
1439 ####
1440 # Set default report date to today
1441 ####
1442 if (!$o_year) {
1443 ($o_sec, $o_min, $o_hour, $o_day, $o_month, $o_year) = localtime(time);
1444 $o_year += 1900;
1445 $o_month++;
1446 $o_month = sprintf("%02d", $o_month);
1447 $o_day = sprintf("%02d", $o_day);
1448 $o_hour = sprintf("%02d", $o_hour);
1449 $o_min = sprintf("%02d", $o_min);
1450 $o_sec = sprintf("%02d", $o_sec);
1451 }
1452 if (!$e_year) {
1453 ($e_sec, $e_min, $e_hour, $e_day, $e_month, $e_year) = localtime(time);
1454 $e_year += 1900;
1455 $e_month++;
1456 $e_month = sprintf("%02d", $e_month);
1457 $e_day = sprintf("%02d", $e_day);
1458 $e_hour = sprintf("%02d", $e_hour);
1459 $e_min = sprintf("%02d", $e_min);
1460 $e_sec = sprintf("%02d", $e_sec);
1461 }
1462
1463 ####
1464 # Look into subdirectories to find daily and hourly data files.
1465 ####
1466 my @WORK_DIRS = &get_data_directories();
1467
1468 # Set path to last directory containing stats by default
1469 my $in_dir = $INPUT_DIR || '.';
1470 $in_dir .= "/$WORK_DIRS[-1]" if ($#WORK_DIRS >= 0);
1471
1472 ####
1473 # Generate page header (common to all reports and include menu)
1474 ####
1475 &html_header();
1476
1477 ####
1478 # Load global information to be able to compose application menus
1479 ####
1480
1481 #### Show empty data
1482 if ($#WORK_DIRS < 0) {
1483 &wrong_date_selection(1);
1484 &html_footer();
1485 exit 0;
1486 }
1487
1488
1489 #### Show system related information
1490 if ($ACTION eq 'sysinfo') {
1491 &show_sysinfo($in_dir);
1492 &html_footer();
1493 exit 0;
1494 }
1495
1496 #### Load statistics from all required directories following the time selection
1497 foreach (my $dx = 0; $dx <= $#WORK_DIRS; $dx++)
1498 {
1499 # For Home menu report we just report current information
1500 # about CLuster, Database and System whatever is the Time
1501 # selection. There is no cumulative data in these stats.
1502 # Same for System and Database Info reports.
1503 next if ( grep(/^$ACTION$/, @NOGRAPH_LIST) && $dx < $#WORK_DIRS);
1504
1505 # Set absolute path to the working directory
1506 $in_dir = "$INPUT_DIR/$WORK_DIRS[$dx]";
1507
1508 # Check if we have binary file in the directory
1509 my @binfiles = ();
1510 if (-d "$in_dir") {
1511 opendir(IDIR, "$in_dir") || die "FATAL: can't opendir $in_dir: $!";
1512 @binfiles = grep { /^.*\.bin$/ } readdir(IDIR);
1513 closedir(IDIR);
1514 } else {
1515 # Input directory does not exists
1516 next;
1517 }
1518
1519 # If we are processiong multiple stat dirs caching is mandatory
1520 if ($#binfiles == -1 && $#WORK_DIRS > 0)
1521 {
1522 print qq{<p>&nbsp</p><div class="flotr-graph"><blockquote><b>NO CACHE FILE FOUND:</b> Please read documentation about pgCluu caching</blockquote></div></td>};
1523 # Caching is mandatory in CGI mode
1524 &html_footer();
1525 exit 0;
1526 }
1527
1528 # Set system information, database list
1529 # and global information to build menu
1530 %sysinfo = ();
1531 %global_infos = ();
1532 @DATABASE_LIST = ();
1533 @DEVICE_LIST = ();
1534 @IFACE_LIST = ();
1535 @DEVICE_SPACE_LIST = ();
1536 &read_sysinfo($in_dir);
1537
1538 # Set default sysstat file to read (binary or text format)
1539 # an extract the disk devices and network interfaces list
1540 # if there's no binary files
1541 my ($sar_file, $sadc_file) = &set_sysstat_file($in_dir);
1542
1543 # Set default pidstat file to read
1544 my $pidstat_file = &set_pidstat_file($in_dir);
1545
1546 # Detect timezone from csv file when there is no cache file and
1547 # look for disk device and network interface from the sar file
1548 if ($#binfiles == -1)
1549 {
1550 if ($STATS_TIMEZONE eq '00') {
1551 if (-e "$in_dir/pg_stat_database.csv" && !-z "$in_dir/pg_stat_database.csv") {
1552 $STATS_TIMEZONE = &detect_timezone("$in_dir/pg_stat_database.csv");
1553 } elsif (-e "$in_dir/pg_stat_database.csv.gz" ) {
1554 $STATS_TIMEZONE = &detect_timezone("$in_dir/pg_stat_database.csv.gz");
1555 }
1556 # Force use of same the same timezone for postgresql and system metrics
1557 if ($TIMEZONE ne $STATS_TIMEZONE) {
1558 $TIMEZONE = $STATS_TIMEZONE;
1559 }
1560
1561 print STDERR "DEBUG: autodetected timezone value database : $STATS_TIMEZONE, system: $TIMEZONE\n" if ($DEBUG);
1562 }
1563 }
1564
1565 # Action to perform when a sar statistics is requested
1566 if (($ACTION eq 'home') || ($ACTION =~ /^(system|device|network)-/))
1567 {
1568 # Load statistics from cache files
1569 if ($#binfiles >= 0) {
1570 my $binstat = $bin_action_map{$ACTION} || $ACTION;
1571 &load_sar_binary($in_dir, $binstat);
1572 # Set timezone
1573 if (($TIMEZONE eq '00') && $global_infos{timezone}) {
1574 $TIMEZONE = $global_infos{timezone};
1575 }
1576 if (($STATS_TIMEZONE eq '00') && $global_infos{stats_timezone}) {
1577 $STATS_TIMEZONE = $global_infos{stats_timezone};
1578 }
1579 }
1580
1581 # Home page is built from cache file or from csv file, not both
1582 elsif ( $sar_file && ($ACTION ne 'home') || ($#binfiles == -1))
1583 {
1584 # Then build sar statistics from data file starting at begining
1585 # when there's no cache file or starting at last cache offset.
1586 # In cache/binary mode we can not process sadc binary data file
1587 if (defined $sadc_file && -f "$sadc_file" && $#binfiles == -1)
1588 {
1589 print STDERR "DEBUG: looking for sadc binary data file $sadc_file\n" if ($DEBUG);
1590 foreach my $id (sort keys %SAR_GRAPH_INFOS)
1591 {
1592 next if (($ACTION ne 'home') && ($REAL_ACTION ne $SAR_GRAPH_INFOS{$id}->{name}));
1593 &compute_sarstat_stats($sadc_file, %{$SAR_GRAPH_INFOS{$id}});
1594 }
1595 # Read sar file from the start of the file or from the offset stored a previous
1596 # run of the cache. Gzipped files do not need to be read again with binary files
1597 }
1598 elsif ( defined $sar_file && -f "$sar_file"
1599 && ($#binfiles == -1 || $sar_file !~ /\.gz$/) )
1600 {
1601
1602 # Load sar statistics from file if not already done
1603 my %fulldata = &load_sarfile_stats($sar_file);
1604 if (-e "$in_dir/fs_stat_use.csv") {
1605 push(@{$fulldata{'system-space'}}, &load_fsuse_stats($in_dir, 'fs_stat_use.csv'));
1606 }
1607
1608 # Get Commit memory stats
1609 if (-e "$in_dir/commit_memory.csv") {
1610 push(@{$fulldata{'system-commit_memory'}}, &load_commit_memory_stats($in_dir, 'commit_memory.csv'));
1611 }
1612
1613 print STDERR "DEBUG: looking for sar text data file $sar_file\n" if ($DEBUG);
1614 foreach my $id (sort keys %SAR_GRAPH_INFOS) {
1615 next if (($ACTION ne 'home') && ($REAL_ACTION ne $SAR_GRAPH_INFOS{$id}->{name}));
1616 &compute_sarfile_stats($sar_file, $in_dir, \%fulldata, %{$SAR_GRAPH_INFOS{$id}});
1617 }
1618 print STDERR "DEBUG: looking for pidstatt data file $pidstat_file\n" if ($DEBUG);
1619 %fullpidstatdata = &load_sarfile_stats($sar_file);
1620 foreach my $id (sort keys %PIDSTAT_GRAPH_INFOS) {
1621 &compute_pidstatfile_stats($pidstat_file, $in_dir, %{$PIDSTAT_GRAPH_INFOS{$id}});
1622 }
1623 }
1624 }
1625 }
1626
1627 # Action to perform when a PostgreSQL statistics is requested
1628 if (($ACTION eq 'home') || ($ACTION !~ /^(system|device|network)-/))
1629 {
1630 # Load statistics from cache files
1631 if ($#binfiles > 0)
1632 {
1633 my $pgstat = $pg_action_map{$ACTION} || $ACTION;
1634 &load_pg_binary($in_dir, $pgstat);
1635
1636 # Set timezone
1637 if (($TIMEZONE eq '00') && $global_infos{timezone}) {
1638 $TIMEZONE = $global_infos{timezone};
1639 }
1640 if (($STATS_TIMEZONE eq '00') && $global_infos{stats_timezone}) {
1641 $STATS_TIMEZONE = $global_infos{stats_timezone};
1642 }
1643
1644 }
1645
1646 # Home page is built from cache file or from csv file, not both
1647 if (($ACTION ne 'home') || ($#binfiles == -1)) {
1648
1649 print STDERR "DEBUG: Building PostgreSQL $ACTION view\n" if ($DEBUG);
1650
1651 # Loop over CSV files and graphics definition to generate reports
1652 foreach my $k (sort {$a cmp $b} keys %DB_GRAPH_INFOS) {
1653
1654 # Do not compute statistics for reports other than the
1655 # one requested by the user.
1656 my $to_be_proceed = 0;
1657 foreach my $n (keys %{$DB_GRAPH_INFOS{$k}}) {
1658 $to_be_proceed = 1, last if (($ACTION eq 'home') || ($ACTION eq 'database-info') || ($REAL_ACTION eq $DB_GRAPH_INFOS{$k}{$n}->{name}));
1659 }
1660 next if (!$to_be_proceed);
1661
1662 print STDERR "DEBUG: Building PostgreSQL statistics from $k CSV files\n" if ($DEBUG);
1663
1664 # Read statistics from csv file starting at at begining of the
1665 # file or last offset when binary files are present
1666 if (-e "$in_dir/$k" && !-z "$in_dir/$k") {
1667 &compute_postgresql_stat($in_dir, $k, $src_base, %{$DB_GRAPH_INFOS{$k}});
1668 # Gzip data files are only available when they can't be appended anymore so
1669 # if we have binary files and gzipped files, binary files contains all stats
1670 } elsif (($#binfiles == -1) && -e "$in_dir/$k.gz" && !-z "$in_dir/$k.gz") {
1671 &compute_postgresql_stat($in_dir, "$k.gz", $src_base, %{$DB_GRAPH_INFOS{$k}});
1672 } else {
1673 # Files use 'all' instead of 'user' with pgcluu_collectd --stat-type option
1674 my $f = $k;
1675 $f =~ s/_user_/_all_/;
1676 # Read statistics from csv file starting at at begining of the
1677 # file or last offset when binary files are present
1678 if (-e "$in_dir/$f" && !-z "$in_dir/$f") {
1679 &compute_postgresql_stat($in_dir, $f, $src_base, %{$DB_GRAPH_INFOS{$k}});
1680 # Gzip data files are only available when they can't be appended anymore so
1681 # if we have binary files and gzipped files, binary files contains all stats
1682 } elsif (($#binfiles == -1) && -e "$in_dir/$f.gz" && !-z "$in_dir/$f.gz") {
1683 &compute_postgresql_stat($in_dir, "$f.gz", $src_base, %{$DB_GRAPH_INFOS{$k}});
1684 }
1685 }
1686
1687 }
1688 }
1689
1690 }
1691
1692 # Action to perform when a sar statistics is requested
1693 if (($ACTION eq 'home') || ($ACTION =~ /^pidstat-/))
1694 {
1695 # Load statistics from cache files
1696 if ($#binfiles >= 0) {
1697 my $binstat = $bin_action_map{$ACTION} || $ACTION;
1698 &load_pidstat_binary($in_dir, $binstat);
1699 # Set timezone
1700 if (($TIMEZONE eq '00') && $global_infos{timezone}) {
1701 $TIMEZONE = $global_infos{timezone};
1702 }
1703 if (($STATS_TIMEZONE eq '00') && $global_infos{stats_timezone}) {
1704 $STATS_TIMEZONE = $global_infos{stats_timezone};
1705 }
1706 }
1707
1708 # Home page is built from cache file or from csv file, not both
1709 elsif ( $pidstat_file && ($ACTION ne 'home') || ($#binfiles == -1))
1710 {
1711 # Then build pidstat statistics from data file starting at begining
1712 # when there's no cache file or starting at last cache offset.
1713 if ( defined $pidstat_file && -f "$pidstat_file"
1714 && (($#binfiles == -1) || ($pidstat_file !~ /\.gz$/)) )
1715 {
1716
1717 print STDERR "DEBUG: looking for pidstatt data file $pidstat_file\n" if ($DEBUG);
1718 %fullpidstatdata = &load_sarfile_stats($sar_file);
1719 foreach my $id (sort keys %PIDSTAT_GRAPH_INFOS) {
1720 &compute_pidstatfile_stats($pidstat_file, $in_dir, %{$PIDSTAT_GRAPH_INFOS{$id}});
1721 }
1722 }
1723 }
1724 }
1725 }
1726
1727
1728 #### Show home page information
1729 if ($ACTION eq 'home') {
1730 &show_home();
1731 }
1732 #### Show other pages
1733 else
1734 {
1735 # Show system reports
1736 if ($ACTION =~ /^(system|device|network)-/)
1737 {
1738 # Build sar statistics graphs
1739 print STDERR "DEBUG: Building sar statistics reports\n" if ($DEBUG);
1740 foreach my $id (sort keys %SAR_GRAPH_INFOS) {
1741 next if (($ACTION ne 'home') && ($REAL_ACTION ne $SAR_GRAPH_INFOS{$id}->{name}));
1742 print STDERR "DEBUG: Reading sar statistics for $SAR_GRAPH_INFOS{$id}->{name}.\n" if ($DEBUG);
1743 &compute_sar_graph($src_base, %{$SAR_GRAPH_INFOS{$id}});
1744 }
1745
1746 }
1747 # Show pidstat reports
1748 elsif ($ACTION =~ /^pidstat-/)
1749 {
1750 # Build pidstat statistics graphs
1751 print STDERR "DEBUG: Building pidstat statistics reports\n" if ($DEBUG);
1752 foreach my $id (sort keys %PIDSTAT_GRAPH_INFOS) {
1753 next if (($ACTION ne 'home') && ($REAL_ACTION ne "pidstat-$PIDSTAT_GRAPH_INFOS{$id}->{name}"));
1754 &compute_pidstat_graph($src_base, %{$PIDSTAT_GRAPH_INFOS{$id}});
1755 }
1756 }
1757 # Show database general information
1758 elsif ($ACTION eq 'database-info')
1759 {
1760 &write_database_info($DATABASE, $src_base);
1761 }
1762 else
1763 {
1764 # Loop over statistic in memory to generate PostgreSQL reports
1765 print STDERR "DEBUG: Building PostgreSQL statistics reports\n" if ($DEBUG);
1766
1767 # Try to limit report generation to stats that exists in memory.
1768 # The storage variable name are the same than the keys in DB_GRAPH_INFOS
1769 # minus some transformation.
1770 foreach my $k (sort {$a cmp $b} keys %DB_GRAPH_INFOS) {
1771 $ID_ACTION = -1;
1772 if ($ACTION ne 'home') {
1773 foreach my $n (keys %{$DB_GRAPH_INFOS{$k}}) {
1774 if ($REAL_ACTION eq $DB_GRAPH_INFOS{$k}{$n}->{name}) {
1775 $ID_ACTION = $n;
1776 last;
1777 }
1778 }
1779 } else {
1780 $ID_ACTION = 0;
1781 }
1782 next if ($ID_ACTION < 0);
1783
1784 my $inmem = $k;
1785 $inmem =~ s/\.csv//;
1786 $inmem =~ s/\./_/g;
1787 $inmem =~ s/^pg_/all_/;
1788 if ($inmem eq 'pgbouncer_stats') {
1789 $inmem = 'all_pgbouncer_stats';
1790 }
1791 if (($inmem =~ /_conf/) && ($inmem !~ /^all/)) {
1792 $inmem = 'all_' . $inmem;
1793 }
1794
1795 # Skip this report if there's no statistics loaded in memory
1796 next if ((scalar keys %{$inmem} == 0) && ($ID_ACTION == 0));
1797
1798 print STDERR "DEBUG: Building report for $k (from memory \%$inmem)\n" if ($DEBUG);
1799 &compute_postgresql_report($k, $src_base, %{$DB_GRAPH_INFOS{$k}});
1800 }
1801
1802 }
1803 }
1804
1805 ####
1806 # Add common HTML footer
1807 ####
1808 &html_footer();
1809
1810 exit 0;
1811
1812 #----------------------------------------------------------------------------------
1813
1814 sub set_sysstat_file
1815 {
1816 my $input_dir = shift;
1817
1818 $input_dir ||= $INPUT_DIR;
1819
1820 print STDERR "DEBUG: detecting sar/sadc file in $input_dir/\n" if ($DEBUG);
1821 my $sar_file = '';
1822 my $sadc_file = '';
1823 if (!$SADC_INPUT_FILE && !$SAR_INPUT_FILE) {
1824 if (-f "$input_dir/sadc_stats.dat") {
1825 $sadc_file = "$input_dir/" . 'sadc_stats.dat';
1826 } elsif (-f "$input_dir/sar_stats.dat") {
1827 $sar_file = "$input_dir/" . 'sar_stats.dat';
1828 } elsif (-f "$input_dir/sar_stats.dat.gz") {
1829 $sar_file = "$input_dir/" . 'sar_stats.dat.gz';
1830 }
1831 if (!$sadc_file && !$sar_file) {
1832 $DISABLE_SAR = 1 if (!-e "$input_dir/sar_cpu_stat.bin");
1833 return;
1834 }
1835 } else {
1836 $sadc_file = $SADC_INPUT_FILE;
1837 $sar_file = $SAR_INPUT_FILE;
1838 }
1839
1840 # Verify that the sar data file exists.
1841 if ($sadc_file && !-f "$sadc_file") {
1842 print STDERR "ERROR: sar binary data file $sadc_file can't be found.\n";
1843 exit 1;
1844 }
1845 if ($sar_file && !-f "$sar_file") {
1846 print STDERR "ERROR: sar text data file $sar_file can't be found.\n";
1847 exit 1;
1848 }
1849
1850 print STDERR "DEBUG: sar/sadc file detected ", ($sar_file) ? $sar_file : $sadc_file, "\n" if ($DEBUG);
1851
1852 return ($sar_file, $sadc_file);
1853 }
1854
1855 sub set_pidstat_file
1856 {
1857 my $input_dir = shift;
1858
1859 $input_dir ||= $INPUT_DIR;
1860
1861 print STDERR "DEBUG: detecting pidstat file in $input_dir/\n" if ($DEBUG);
1862 my $pidstat_file = '';
1863 if (!$PIDSTAT_INPUT_FILE) {
1864 if (-f "$input_dir/pidstat_stats.dat") {
1865 $pidstat_file = "$input_dir/" . 'pidstat_stats.dat';
1866 } elsif (-f "$input_dir/pidstat_stats.dat.gz") {
1867 $pidstat_file = "$input_dir/" . 'pidstat_stats.dat.gz';
1868 }
1869 if (!$pidstat_file) {
1870 print STDERR "WARNING: No pidstat_stats.dat file found in $input_dir.\nContinuing normally without reporting pidstat statistics.\n" if ($DEBUG);
1871 return;
1872 }
1873 } else {
1874 $pidstat_file = $PIDSTAT_INPUT_FILE;
1875 }
1876
1877 # Verify that the sar data file exists.
1878 if ($pidstat_file && !-f "$pidstat_file") {
1879 print STDERR "ERROR: pidstat text data file $pidstat_file can not be found.\n";
1880 exit 1;
1881 }
1882
1883 print STDERR "DEBUG: pidstat file detected $pidstat_file\n" if ($DEBUG);
1884
1885 return $pidstat_file;
1886 }
1887
1888 sub progress_bar
1889 {
1890 my ( $got, $total, $width, $char ) = @_;
1891 $width ||= 25; $char ||= '=';
1892 my $num_width = length $total;
1893 sprintf("[%-${width}s] Parsed %${num_width}s bytes of %s (%0.2f%%)\r",
1894 $char x (($width-1)*$got/$total). '>',
1895 $got, $total, 100*$got/+$total);
1896 }
1897
1898 sub is_compressed
1899 {
1900 my $file = shift;
1901
1902 return 1 if ($file =~ /\.gz/);
1903
1904 return 0;
1905 }
1906
1907 sub open_filehdl
1908 {
1909 my $file = shift;
1910
1911 my $curfh = new IO::File;
1912 if (!is_compressed("$file")) {
1913 $curfh->open("< $file") or die "FATAL: can't read file $file: $!\n";
1914 } else {
1915 $curfh->open("$ZCAT_PROG $file |") or die "FATAL: can't read pipe from command: $ZCAT_PROG $file, $!\n";
1916 }
1917 return $curfh;
1918 }
1919
1920 sub detect_timezone
1921 {
1922 my $file = shift;
1923
1924 my $tz = '+00';
1925
1926 if (!&is_compressed($file)) {
1927 if (!open(IN, "$file")) {
1928 die "FATAL: can't read file $file: $!\n";
1929 }
1930 } else {
1931 if (!open(IN, "$ZCAT_PROG $file |")) {
1932 die "FATAL: can't read pipe on command: $ZCAT_PROG $file, $!\n";
1933 }
1934 }
1935 my $i = 1;
1936 while (<IN>) {
1937 my @data = split(/;/);
1938 if ($data[0] =~ /^\d+-\d+-\d+ \d+:\d+:\d+([+\-]\d\d)/) {
1939 $tz = $1;
1940 last;
1941 }
1942 $i++;
1943 last if ($i > 10);
1944 }
1945 close(IN);
1946
1947 return $tz;
1948 }
1949
1950 sub get_data_id
1951 {
1952 my ($str, %data_info) = @_;
1953
1954 foreach my $i (sort {$a <=> $b} keys %data_info) {
1955 if ($data_info{$i}->{name} eq $str) {
1956 return $i;
1957 }
1958 }
1959 return -1;
1960 }
1961
1962 sub set_device_list
1963 {
1964 my ($sar_file, $sadc_file) = @_;
1965
1966 if ($sadc_file && -f "$sadc_file") {
1967
1968 my $command = "$SADF_PROG -t -P ALL -d $sadc_file -- -d -p";
1969 print STDERR "DEBUG: looking for device list using command $command'\n" if ($DEBUG);
1970 # Load data from file
1971 if (!open(IN, "$command |")) {
1972 die "FATAL: can't read output from command ($command): $!\n";
1973 }
1974 while (my $l = <IN>) {
1975 chomp($l);
1976 # hostname;interval;timestamp;DEV;tps;rd_sec/s;wr_sec/s;avgrq-sz;avgqu-sz;await;svctm;%util
1977 my @data = split(/;/, $l);
1978 next if ($data[2] !~ /^\d+/);
1979 next if ( $data[3] =~ /^loop\d+/);
1980 if (!grep(m#^$data[3]$#, @DEVICE_LIST)) {
1981 push(@DEVICE_LIST, $data[3]);
1982 } else {
1983 last;
1984 }
1985 }
1986 close(IN);
1987
1988 $command = "$SADF_PROG -t -P ALL -d $sadc_file -- -n DEV";
1989 print STDERR "DEBUG: looking for network device list using command $command'\n" if ($DEBUG);
1990 # Load data from file
1991 if (!open(IN, "$command |")) {
1992 die "FATAL: can't read output from command ($command): $!\n";
1993 }
1994 while (my $l = <IN>) {
1995 chomp($l);
1996 #hostname;interval;timestamp;IFACE;rxpck/s;txpck/s;...
1997 my @data = split(/;/, $l);
1998 next if ($data[2] !~ /^\d+/);
1999 if (!grep(m#^$data[3]$#, @IFACE_LIST)) {
2000 push(@IFACE_LIST, $data[3]);
2001 } else {
2002 last;
2003 }
2004 }
2005 close(IN);
2006
2007 # There is no information about disk space device in sadc file
2008 #@DEVICE_SPACE_LIST = ...;
2009
2010 } elsif ($sar_file && -f "$sar_file") {
2011
2012 print STDERR "DEBUG: looking for devices in sar file $sar_file\n" if ($DEBUG);
2013 # Load data from file
2014 if (!&is_compressed($sar_file)) {
2015 if (!open(IN, "$sar_file")) {
2016 die "FATAL: can't read input file $sar_file: $!\n";
2017 }
2018 } else {
2019 if (!open(IN, "$ZCAT_PROG $sar_file |")) {
2020 die "FATAL: can't read pipe from command: $ZCAT_PROG $sar_file, $!\n";
2021 }
2022 }
2023 my $type = '';
2024 while (my $l = <IN>)
2025 {
2026 chomp($l);
2027 $l =~ s/\r//;
2028
2029 # We only read the first sar report to extract device name
2030 last if ($l =~ /^Average/);
2031
2032 # Skip non relevant part
2033 if ($l !~ /^\d+:\d+:\d+/ || !$l) {
2034 next;
2035 }
2036
2037 # Get device type from reports headers
2038 if ($l =~ m#(DEV|IFACE|FILESYSTEM)\s+#) {
2039 $type = $1;
2040 next;
2041 }
2042
2043 # Extract values from the current line
2044 my @values = ();
2045 push(@values, split(m#\s+#, $l));
2046 next if ( $values[1] =~ /^loop\d+/); # skip loop device
2047
2048 # Set device list following the type
2049 if ($type eq 'DEV') {
2050 push(@DEVICE_LIST, $values[1]) if (!grep(/^$values[1]$/, @DEVICE_LIST));
2051 } elsif ($type eq 'IFACE') {
2052 push(@IFACE_LIST, $values[1]) if (!grep(/^$values[1]$/, @IFACE_LIST));
2053 } elsif ($type eq 'FILESYSTEM') {
2054 push(@DEVICE_SPACE_LIST, $values[8]) if (!grep(/^$values[8]$/, @DEVICE_SPACE_LIST));
2055 }
2056 }
2057 close(IN);
2058 }
2059 }
2060
2061 sub write_database_info
2062 {
2063 my $db = shift;
2064 my $src_base = shift;
2065
2066 return if (($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB)));
2067
2068 my $next = $#{$sysinfo{EXTENSION}{$db}} + 1;
2069 my $extlist = join(',', @{$sysinfo{EXTENSION}{$db}});
2070 $extlist = ' (' . $extlist . ')' if ($extlist);
2071 my $nsch = $#{$sysinfo{SCHEMA}{$db}} + 1;
2072 my $schlist = join(',', @{$sysinfo{SCHEMA}{$db}});
2073 $schlist = ' (' . $schlist . ')' if ($schlist);
2074 my $njson = $#{$sysinfo{JSON}{$db}} + 1;
2075 my $jsonlist = join(',', @{$sysinfo{JSON}{$db}});
2076 $jsonlist = ' (' . $jsonlist . ')' if ($jsonlist);
2077 my $procount = $sysinfo{PROCEDURE}{$db} || 0;
2078 my $trigcount = $sysinfo{TRIGGER}{$db} || 0;
2079 my $last_vacuum = $OVERALL_STATS{'database'}{$db}{last_vacuum} || '-';
2080 my $last_analyze = $OVERALL_STATS{'database'}{$db}{last_analyze} || '-';
2081 my $last_autovacuum = $OVERALL_STATS{'database'}{$db}{last_autovacuum} || '-';
2082 my $last_autoanalyze = $OVERALL_STATS{'database'}{$db}{last_autoanalyze} || '-';
2083 my $last_reset = $OVERALL_STATS{'database'}{$db}{'stat_reset'} || '';
2084
2085 my $objects_count = '';
2086 foreach my $k (sort keys %RELKIND) {
2087 $objects_count .= qq{<li><span class="figure">$OVERALL_STATS{'class'}{$db}{$k}</span> <span class="figure-label">} . lcfirst($RELKIND{$k}) . qq{</span></li>} if (exists $OVERALL_STATS{'class'}{$db}{$k});
2088 }
2089 $OVERALL_STATS{database}{$db}{invalid_indexes} ||= 0;
2090 $OVERALL_STATS{database}{$db}{hash_indexes} ||= 0;
2091 $OVERALL_STATS{database}{$db}{unlogged} ||= 0;
2092 my $dbsize = &pretty_print_size($OVERALL_STATS{'database'}{$db}{'size'});
2093 print qq{
2094 <ul id="slides">
2095 <li class="slide active-slide" id="database-info-slide">
2096 <div id="database-info"><br/><br/><br/></div>
2097 <div class="row">
2098 <div class="col-md-12">
2099 <div class="panel panel-default">
2100 <div class="panel-heading">
2101 <i class="glyphicon icon-desktop icon-2x pull-left"></i><h2>Database $db</h2>
2102 </div>
2103 <div class="panel-body">
2104 <div class="key-figures">
2105 <ul>
2106 <li></li>
2107 <li><span class="figure">$dbsize</span> <span class="figure-label">Total size</span></li>
2108 <li><span class="figure">$next</span> <span class="figure-label">Installed extensions$extlist</span></li>
2109 <li><span class="figure">$OVERALL_STATS{database}{$db}{unlogged}</span> <span class="figure-label">Unlogged tables</span></li>
2110 <li><span class="figure">$OVERALL_STATS{database}{$db}{invalid_indexes}</span> <span class="figure-label">Invalid indexes</span></li>
2111 <li><span class="figure">$OVERALL_STATS{database}{$db}{hash_indexes}</span> <span class="figure-label">Hash indexes</span></li>
2112 <li><span class="figure">$nsch</span> <span class="figure-label">Schemas$schlist</span></li>
2113 };
2114 print qq{<li><span class="figure">$njson</span> <span class="figure-label">json vs jsonb columns$jsonlist</span></li>} if ($jsonlist);
2115 print qq{
2116 <li><span class="figure">$last_vacuum</span> <span class="figure-label">Last manual vacuum</span></li>
2117 <li><span class="figure">$last_analyze</span> <span class="figure-label">Last manual analyze</span></li>
2118 <li><span class="figure">$last_autovacuum</span> <span class="figure-label">Last auto vacuum</span></li>
2119 <li><span class="figure">$last_autoanalyze</span> <span class="figure-label">Last auto analyze</span></li>
2120 <li><span class="figure">$last_reset</span> <span class="figure-label">Last database stat reset</span></li>
2121 <li><span class="figure">$procount</span> <span class="figure-label">Stored procedures</span></li>
2122 <li><span class="figure">$trigcount</span> <span class="figure-label">Triggers</span></li>
2123 $objects_count
2124 </ul>
2125 </div>
2126 </div>
2127 </div>
2128 </div><!--/span-->
2129 </div>
2130 </li>
2131 </ul>
2132 };
2133
2134 }
2135
2136 sub compute_postgresql_stat
2137 {
2138 my ($input_dir, $file, $src_base, %data_info) = @_;
2139
2140
2141 # Compute graphs following the data file
2142 my $fctname = $file;
2143 $fctname =~ s/\.csv(\.gz)?//;
2144 $fctname =~ s/\.gz//;
2145 $fctname =~ s/\./_/g;
2146 my $offset = 0;
2147 $offset = $global_infos{"$input_dir/$file"} if (exists $global_infos{"$input_dir/$file"});
2148 print STDERR "DEBUG: Reading statistics in file $input_dir/$file starting at offset $offset\n" if ($DEBUG);
2149 # Call the function associated to the action and get back the new offset
2150 # offset is used in incremental mode to avoir parsing the entire file.
2151 $global_infos{"$input_dir/$file"} = $fctname->($input_dir, $file, $offset);
2152 }
2153
2154 sub compute_postgresql_report
2155 {
2156 my ($file, $src_base, %data_info) = @_;
2157
2158 # Compute graphs following the data file
2159 my $fctname = $file;
2160 $fctname =~ s/\.csv(\.gz)?//;
2161 $fctname =~ s/\.gz//;
2162 $fctname =~ s/_all_/_user_/g;
2163 $fctname =~ s/\./_/g;
2164
2165 print STDERR "DEBUG: creating reports from statistics $fctname.\n" if ($DEBUG);
2166 $fctname .= '_report';
2167 $fctname->($src_base, $DATABASE, %data_info);
2168 }
2169
2170 # Compute statistics of database statistics
2171 sub pg_stat_database
2172 {
2173 my ($input_dir, $file, $offset) = @_;
2174
2175 my %start_vals = ();
2176 my $tmp_val = 0;
2177 my %db_list = ();
2178 # Load data from file
2179 my $curfh = open_filehdl("$input_dir/$file");
2180 $curfh->seek($offset,0);
2181 while (my $l = <$curfh>) {
2182 $offset += length($l);
2183 my @data = split(/;/, $l);
2184 next if (!&normalize_line(\@data));
2185
2186 # 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
2187
2188 # Store list of database
2189 $db_list{$data[2]} = 1;
2190 # Store previous data
2191 push(@{$start_vals{$data[2]}}, @data) if ($#{$start_vals{$data[2]}} < 0);
2192
2193 $OVERALL_STATS{'start_date'} = $data[0] if (!$OVERALL_STATS{'start_date'} || ($OVERALL_STATS{'start_date'} gt $data[0]));
2194 $OVERALL_STATS{'end_date'} = $data[0] if (!$OVERALL_STATS{'end_date'} || ($OVERALL_STATS{'end_date'} lt $data[0]));
2195
2196 # Store interval between previous run
2197 $all_stat_database{$data[0]}{$data[2]}{interval} = ($data[0] - $start_vals{$data[2]}[0])/1000;
2198 $all_stat_database{$data[0]}{all}{interval} = ($data[0] - $start_vals{$data[2]}[0])/1000;
2199
2200 if ($#data >= 8) {
2201
2202 (($data[8] - $start_vals{$data[2]}[8]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[8] - $start_vals{$data[2]}[8]);
2203 if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) {
2204 $all_stat_database{$data[0]}{$data[2]}{returned} = $tmp_val;
2205 $all_stat_database{$data[0]}{all}{returned} += $tmp_val;
2206 } else {
2207 $OVERALL_STATS{'cluster'}{returned} += $tmp_val;
2208 $OVERALL_STATS{'database'}{$data[2]}{returned} += $tmp_val;
2209 }
2210
2211 (($data[9] - $start_vals{$data[2]}[9]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[9] - $start_vals{$data[2]}[9]);
2212 if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) {
2213 $all_stat_database{$data[0]}{$data[2]}{fetched} = $tmp_val;
2214 $all_stat_database{$data[0]}{all}{fetched} += $tmp_val;
2215 } else {
2216 $OVERALL_STATS{'cluster'}{fetched} += $tmp_val;
2217 $OVERALL_STATS{'database'}{$data[2]}{fetched} += $tmp_val;
2218 }
2219
2220 # Gather insert statement
2221 (($data[10] - $start_vals{$data[2]}[10]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[10] - $start_vals{$data[2]}[10]);
2222 if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) {
2223 $all_stat_database{$data[0]}{$data[2]}{insert} = $tmp_val;
2224 $all_stat_database{$data[0]}{all}{insert} += $tmp_val;
2225 } else {
2226 $OVERALL_STATS{'cluster'}{insert} += $tmp_val;
2227 $OVERALL_STATS{'database'}{$data[2]}{insert} += $tmp_val;
2228 }
2229
2230 # Gather update statement
2231 (($data[11] - $start_vals{$data[2]}[11]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[11] - $start_vals{$data[2]}[11]);
2232 if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) {
2233 $all_stat_database{$data[0]}{$data[2]}{update} = $tmp_val;
2234 $all_stat_database{$data[0]}{all}{update} += $tmp_val;
2235 } else {
2236 $OVERALL_STATS{'cluster'}{update} += $tmp_val;
2237 $OVERALL_STATS{'database'}{$data[2]}{update} += $tmp_val;
2238 }
2239
2240 # Gather delete statement
2241 (($data[12] - $start_vals{$data[2]}[12]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[12] - $start_vals{$data[2]}[12]);
2242 if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) {
2243 $all_stat_database{$data[0]}{$data[2]}{delete} = $tmp_val;
2244 $all_stat_database{$data[0]}{all}{delete} += $tmp_val;
2245 } else {
2246 $OVERALL_STATS{'cluster'}{delete} += $tmp_val;
2247 $OVERALL_STATS{'database'}{$data[2]}{delete} += $tmp_val;
2248 }
2249
2250 }
2251
2252 # Gather blks_read
2253 (($data[6] - $start_vals{$data[2]}[6]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[6] - $start_vals{$data[2]}[6]);
2254 if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) {
2255 $all_stat_database{$data[0]}{$data[2]}{blks_read} = $tmp_val;
2256 $all_stat_database{$data[0]}{all}{blks_read} += $tmp_val;
2257 } else {
2258 $OVERALL_STATS{'cluster'}{blks_read} += $tmp_val;
2259 $OVERALL_STATS{'database'}{$data[2]}{blks_read} += $tmp_val;
2260 }
2261
2262 # Gather blks_hit
2263 (($data[7] - $start_vals{$data[2]}[7]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[7] - $start_vals{$data[2]}[7]);
2264 if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) {
2265 $all_stat_database{$data[0]}{$data[2]}{blks_hit} = $tmp_val;
2266 $all_stat_database{$data[0]}{all}{blks_hit} += $tmp_val;
2267 } else {
2268 $OVERALL_STATS{'cluster'}{blks_hit} += $tmp_val;
2269 $OVERALL_STATS{'database'}{$data[2]}{blks_hit} += $tmp_val;
2270 }
2271
2272 # Gather number of running backend
2273 if ($data[3]) {
2274 $all_stat_database{$data[0]}{$data[2]}{nbackend} = $data[3];
2275 $all_stat_database{$data[0]}{all}{nbackend} += $data[3];
2276 $OVERALL_STATS{'cluster'}{nbackend} += $data[3];
2277 $OVERALL_STATS{'database'}{$data[2]}{nbackend} += $data[3];
2278 }
2279
2280 # Gather number of committed transaction
2281 (($data[4] - $start_vals{$data[2]}[4]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[4] - $start_vals{$data[2]}[4]);
2282 if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) {
2283 $all_stat_database{$data[0]}{$data[2]}{xact_commit} = $tmp_val;
2284 $all_stat_database{$data[0]}{all}{xact_commit} += $tmp_val;
2285 $all_stat_database{$data[0]}{$data[2]}{xact_throughput} = $tmp_val;
2286 $all_stat_database{$data[0]}{all}{xact_throughput} += $tmp_val;
2287 } else {
2288 $OVERALL_STATS{'cluster'}{xact_commit} += $tmp_val;
2289 $OVERALL_STATS{'database'}{$data[2]}{xact_commit} += $tmp_val;
2290 $OVERALL_STATS{'cluster'}{xact_throughput} += $tmp_val;
2291 $OVERALL_STATS{'database'}{$data[2]}{xact_throughput} += $tmp_val;
2292 }
2293
2294 # Gather number of rollbacked transaction
2295 (($data[5] - $start_vals{$data[2]}[5]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[5] - $start_vals{$data[2]}[5]);
2296 if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) {
2297 $all_stat_database{$data[0]}{$data[2]}{xact_rollback} = $tmp_val;
2298 $all_stat_database{$data[0]}{all}{xact_rollback} += $tmp_val;
2299 $all_stat_database{$data[0]}{$data[2]}{xact_throughput} = +$tmp_val;
2300 $all_stat_database{$data[0]}{all}{xact_throughput} += $tmp_val;
2301 } else {
2302 $OVERALL_STATS{'cluster'}{xact_rollback} += $tmp_val;
2303 $OVERALL_STATS{'database'}{$data[2]}{xact_rollback} += $tmp_val;
2304 $OVERALL_STATS{'cluster'}{xact_throughput} += $tmp_val;
2305 $OVERALL_STATS{'database'}{$data[2]}{xact_throughput} += $tmp_val;
2306 }
2307
2308 # Gather number of canceled queries
2309 if ($#data >= 13) {
2310 (($data[13] - $start_vals{$data[2]}[13]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[13] - $start_vals{$data[2]}[13]);
2311 if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) {
2312 $all_stat_database{$data[0]}{$data[2]}{canceled_queries} = $tmp_val;
2313 $all_stat_database{$data[0]}{all}{canceled_queries} += $tmp_val;
2314 } else {
2315 $OVERALL_STATS{'cluster'}{canceled_queries} += $tmp_val;
2316 $OVERALL_STATS{'database'}{$data[2]}{canceled_queries} += $tmp_val;
2317 $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]));
2318 }
2319 }
2320
2321 # Gather number of temporary data and deadlock
2322 if ($#data > 15) {
2323 (($data[15] - $start_vals{$data[2]}[15]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[15] - $start_vals{$data[2]}[15]);
2324 if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) {
2325 $all_stat_database{$data[0]}{$data[2]}{temp_files} = $tmp_val;
2326 $all_stat_database{$data[0]}{all}{temp_files} += $tmp_val;
2327 } else {
2328 $OVERALL_STATS{'cluster'}{temp_files} += $tmp_val;
2329 $OVERALL_STATS{'database'}{$data[2]}{temp_files} += $tmp_val;
2330 }
2331
2332 (($data[16] - $start_vals{$data[2]}[16]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[16] - $start_vals{$data[2]}[16]);
2333 if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) {
2334 $all_stat_database{$data[0]}{$data[2]}{temp_bytes} = $tmp_val;
2335 $all_stat_database{$data[0]}{all}{temp_bytes} += $tmp_val;
2336 } else {
2337 $OVERALL_STATS{'cluster'}{temp_bytes} += $tmp_val;
2338 $OVERALL_STATS{'database'}{$data[2]}{temp_bytes} += $tmp_val;
2339 }
2340
2341 (($data[17] - $start_vals{$data[2]}[17]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[17] - $start_vals{$data[2]}[17]);
2342 if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) {
2343 $all_stat_database{$data[0]}{$data[2]}{deadlocks} = $tmp_val;
2344 $all_stat_database{$data[0]}{all}{deadlocks} += $tmp_val;
2345 } else {
2346 $OVERALL_STATS{'cluster'}{deadlocks} += $tmp_val;
2347 $OVERALL_STATS{'database'}{$data[2]}{deadlocks} += $tmp_val;
2348 }
2349 }
2350
2351 @{$start_vals{$data[2]}} = ();
2352 push(@{$start_vals{$data[2]}}, @data);
2353 }
2354 $curfh->close();
2355
2356 # Store the full list of database
2357 foreach my $d (keys %db_list) {
2358 push(@global_databases, $d) if (!grep/^$d$/, @global_databases);
2359 }
2360 push(@global_databases, 'all') if (($#global_databases >= 0) && !grep(/^all$/, @global_databases));
2361
2362 return $offset;
2363 }
2364
2365 # Compute overall database statistics
2366 sub set_overall_database_stat_from_binary
2367 {
2368 foreach my $time (sort {$a <=> $b} keys %all_stat_database) {
2369 foreach my $db (@global_databases) {
2370 next if (($db eq 'all') || (($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB))));
2371
2372 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)) {
2373 next if (!exists $all_stat_database{$time}{$db}{$k});
2374 $OVERALL_STATS{'cluster'}{$k} += $all_stat_database{$time}{$db}{$k};
2375 $OVERALL_STATS{'database'}{$db}{$k} += $all_stat_database{$time}{$db}{$k};
2376
2377 }
2378 $OVERALL_STATS{'start_date'} = $time if (!$OVERALL_STATS{'start_date'} || ($OVERALL_STATS{'start_date'} gt $time));
2379 $OVERALL_STATS{'end_date'} = $time if (!$OVERALL_STATS{'end_date'} || ($OVERALL_STATS{'end_date'} lt $time));
2380
2381 }
2382 }
2383 foreach my $time (sort {$a <=> $b} keys %all_database_size) {
2384 foreach my $db (@global_databases) {
2385 next if (($db eq 'all') || (($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB))));
2386 $OVERALL_STATS{'database'}{$db}{'size'} = $all_database_size{$time}{$db};
2387 $OVERALL_STATS{'start_date'} = $time if (!$OVERALL_STATS{'start_date'} || ($OVERALL_STATS{'start_date'} gt $time));
2388 $OVERALL_STATS{'end_date'} = $time if (!$OVERALL_STATS{'end_date'} || ($OVERALL_STATS{'end_date'} lt $time));
2389 }
2390 }
2391 }
2392
2393 # Compute overall system statistics
2394 sub set_overall_system_stat_from_binary
2395 {
2396
2397 foreach my $t (sort {$a <=> $b} keys %sar_cpu_stat)
2398 {
2399 # Skip unwanted lines
2400 #next if ($BEGIN && ($t < $BEGIN));
2401 #next if ($END && ($t > $END));
2402 if (!exists $OVERALL_STATS{'system'}{'cpu'} || ($OVERALL_STATS{'system'}{'cpu'}[1] < $sar_cpu_stat{$t}{'all'}{total})) {
2403 @{$OVERALL_STATS{'system'}{'cpu'}} = ($t, $sar_cpu_stat{$t}{'all'}{total});
2404 }
2405 $OVERALL_STATS{'sar_start_date'} = $t if (!$OVERALL_STATS{'sar_start_date'} || ($OVERALL_STATS{'sar_start_date'} gt $t));
2406 $OVERALL_STATS{'sar_end_date'} = $t if (!$OVERALL_STATS{'sar_end_date'} || ($OVERALL_STATS{'sar_end_date'} lt $t));
2407 }
2408 foreach my $t (sort {$a <=> $b} keys %sar_load_stat) {
2409 # Skip unwanted lines
2410 #next if ($BEGIN && ($t < $BEGIN));
2411 #next if ($END && ($t > $END));
2412
2413 if (!exists $OVERALL_STATS{'system'}{'load'} || ($OVERALL_STATS{'system'}{'load'}[1] < $sar_load_stat{$t}{'ldavg-1'})) {
2414 @{$OVERALL_STATS{'system'}{'load'}} = ($t, $sar_load_stat{$t}{'ldavg-1'});
2415 }
2416 }
2417 foreach my $t (sort {$a <=> $b} keys %sar_process_stat) {
2418 # Skip unwanted lines
2419 #next if ($BEGIN && ($t < $BEGIN));
2420 #next if ($END && ($t > $END));
2421
2422 if (!exists $OVERALL_STATS{'system'}{'process'} || ($OVERALL_STATS{'system'}{'process'}[1] < $sar_process_stat{$t}{'plist-sz'})) {
2423 @{$OVERALL_STATS{'system'}{'process'}} = ($t, $sar_process_stat{$t}{'plist-sz'});
2424 }
2425 if (!exists $OVERALL_STATS{'system'}{'blocked'} || ($OVERALL_STATS{'system'}{'blocked'}[1] < $sar_process_stat{$t}{'blocked'})) {
2426 @{$OVERALL_STATS{'system'}{'blocked'}} = ($t, $sar_process_stat{$t}{'blocked'});
2427 }
2428 }
2429 foreach my $t (sort {$a <=> $b} keys %sar_context_stat) {
2430 # Skip unwanted lines
2431 #next if ($BEGIN && ($t < $BEGIN));
2432 #next if ($END && ($t > $END));
2433
2434 if (!exists $OVERALL_STATS{'system'}{'cswch'} || ($OVERALL_STATS{'system'}{'cswch'}[1] < $sar_context_stat{$t}{'cswch'})) {
2435 @{$OVERALL_STATS{'system'}{'cswch'}} = ($t, $sar_context_stat{$t}{'cswch'});
2436 }
2437 }
2438 foreach my $t (sort {$a <=> $b} keys %sar_memory_stat) {
2439 # Skip unwanted lines
2440 #next if ($BEGIN && ($t < $BEGIN));
2441 #next if ($END && ($t > $END));
2442
2443 if (!exists $OVERALL_STATS{'system'}{'kbcached'} || ($OVERALL_STATS{'system'}{'kbcached'}[1] > $sar_memory_stat{$t}{'kbcached'})) {
2444 @{$OVERALL_STATS{'system'}{'kbcached'}} = ($t, $sar_memory_stat{$t}{'kbcached'});
2445 }
2446 }
2447 foreach my $t (sort {$a <=> $b} keys %sar_dirty_stat) {
2448 # Skip unwanted lines
2449 #next if ($BEGIN && ($t < $BEGIN));
2450 #next if ($END && ($t > $END));
2451
2452 if (!exists $OVERALL_STATS{'system'}{'kbdirty'} || ($OVERALL_STATS{'system'}{'kbdirty'}[1] < $sar_dirty_stat{$t}{'kbdirty'})) {
2453 @{$OVERALL_STATS{'system'}{'kbdirty'}} = ($t, $sar_dirty_stat{$t}{'kbdirty'});
2454 }
2455 }
2456 foreach my $t (sort {$a <=> $b} keys %sar_swap_stat) {
2457 # Skip unwanted lines
2458 #next if ($BEGIN && ($t < $BEGIN));
2459 #next if ($END && ($t > $END));
2460
2461 $sar_swap_stat{$t}{'pswpin'} ||= 0;
2462 $sar_swap_stat{$t}{'pswpout'} ||= 0;
2463 if (!exists $OVERALL_STATS{'system'}{'pswpin'} || ($OVERALL_STATS{'system'}{'pswpin'}[1] < $sar_swap_stat{$t}{'pswpin'})) {
2464 @{$OVERALL_STATS{'system'}{'pswpin'}} = ($t, $sar_swap_stat{$t}{'pswpin'});
2465 }
2466 if (!exists $OVERALL_STATS{'system'}{'pswpout'} || ($OVERALL_STATS{'system'}{'pswpout'}[1] < $sar_swap_stat{$t}{'pswpout'})) {
2467 @{$OVERALL_STATS{'system'}{'pswpout'}} = ($t, $sar_swap_stat{$t}{'pswpout'});
2468 }
2469 }
2470
2471 foreach my $t (sort {$a <=> $b} keys %sar_pageswap_stat) {
2472 # Skip unwanted lines
2473 #next if ($BEGIN && ($t < $BEGIN));
2474 #next if ($END && ($t > $END));
2475
2476 $sar_pageswap_stat{$t}{'pgpgin'} ||= 0;
2477 $sar_pageswap_stat{$t}{'pgpgout'} ||= 0;
2478 $sar_pageswap_stat{$t}{'majflt'} ||= 0;
2479 $sar_pageswap_stat{$t}{'minflt'} ||= 0;
2480 $sar_pageswap_stat{$t}{'pgfree'} ||= 0;
2481 $sar_pageswap_stat{$t}{'pgscank'} ||= 0;
2482 $sar_pageswap_stat{$t}{'pgscand'} ||= 0;
2483 $sar_pageswap_stat{$t}{'pgsteal'} ||= 0;
2484 $sar_pageswap_stat{$t}{'vmeff'} ||= 0;
2485 if (!exists $OVERALL_STATS{'system'}{'pgpgin'} || ($OVERALL_STATS{'system'}{'pgpgin'}[1] < $sar_pageswap_stat{$t}{'pgpgin'})) {
2486 @{$OVERALL_STATS{'system'}{'pgpgin'}} = ($t, $sar_pageswap_stat{$t}{'pgpgin'});
2487 }
2488 if (!exists $OVERALL_STATS{'system'}{'pgpgout'} || ($OVERALL_STATS{'system'}{'pgpgout'}[1] < $sar_pageswap_stat{$t}{'pgpgout'})) {
2489 @{$OVERALL_STATS{'system'}{'pgpgout'}} = ($t, $sar_pageswap_stat{$t}{'pgpgout'});
2490 }
2491 if (!exists $OVERALL_STATS{'system'}{'majflt'} || ($OVERALL_STATS{'system'}{'majflt'}[1] < $sar_pageswap_stat{$t}{'majflt'})) {
2492 @{$OVERALL_STATS{'system'}{'majflt'}} = ($t, $sar_pageswap_stat{$t}{'majflt'});
2493 }
2494 if (!exists $OVERALL_STATS{'system'}{'minflt'} || ($OVERALL_STATS{'system'}{'minflt'}[1] < $sar_pageswap_stat{$t}{'minflt'})) {
2495 @{$OVERALL_STATS{'system'}{'minflt'}} = ($t, $sar_pageswap_stat{$t}{'minflt'});
2496 }
2497 if (!exists $OVERALL_STATS{'system'}{'pgfree'} || ($OVERALL_STATS{'system'}{'pgfree'}[1] < $sar_pageswap_stat{$t}{'pgfree'})) {
2498 @{$OVERALL_STATS{'system'}{'pgfree'}} = ($t, $sar_pageswap_stat{$t}{'pgfree'});
2499 }
2500 if (!exists $OVERALL_STATS{'system'}{'pgscank'} || ($OVERALL_STATS{'system'}{'pgscank'}[1] < $sar_pageswap_stat{$t}{'pgscank'})) {
2501 @{$OVERALL_STATS{'system'}{'pgscank'}} = ($t, $sar_pageswap_stat{$t}{'pgscank'});
2502 }
2503 if (!exists $OVERALL_STATS{'system'}{'pgscand'} || ($OVERALL_STATS{'system'}{'pgscand'}[1] < $sar_pageswap_stat{$t}{'pgscand'})) {
2504 @{$OVERALL_STATS{'system'}{'pgscand'}} = ($t, $sar_pageswap_stat{$t}{'pgscand'});
2505 }
2506 if (!exists $OVERALL_STATS{'system'}{'pgsteal'} || ($OVERALL_STATS{'system'}{'pgsteal'}[1] < $sar_pageswap_stat{$t}{'pgsteal'})) {
2507 @{$OVERALL_STATS{'system'}{'pgsteal'}} = ($t, $sar_pageswap_stat{$t}{'pgsteal'});
2508 }
2509 if (!exists $OVERALL_STATS{'system'}{'vmeff'} || ($OVERALL_STATS{'system'}{'vmeff'}[1] < $sar_pageswap_stat{$t}{'vmeff'})) {
2510 @{$OVERALL_STATS{'system'}{'vmeff'}} = ($t, $sar_pageswap_stat{$t}{'vmeff'});
2511 }
2512 }
2513 foreach my $t (sort {$a <=> $b} keys %sar_block_stat) {
2514 # Skip unwanted lines
2515 #next if ($BEGIN && ($t < $BEGIN));
2516 #next if ($END && ($t > $END));
2517
2518 $sar_block_stat{$t}{'bread'} ||= 0;
2519 $sar_block_stat{$t}{'bwrite'} ||= 0;
2520 if (!exists $OVERALL_STATS{'system'}{'bread'} || ($OVERALL_STATS{'system'}{'bread'}[1] < $sar_block_stat{$t}{'bread'})) {
2521 @{$OVERALL_STATS{'system'}{'bread'}} = ($t, $sar_block_stat{$t}{'bread'});
2522 }
2523 if (!exists $OVERALL_STATS{'system'}{'bwrite'} || ($OVERALL_STATS{'system'}{'bwrite'}[1] < $sar_block_stat{$t}{'bwrite'})) {
2524 @{$OVERALL_STATS{'system'}{'bwrite'}} = ($t, $sar_block_stat{$t}{'bwrite'});
2525 }
2526 }
2527 foreach my $t (sort {$a <=> $b} keys %sar_srvtime_stat) {
2528 # Skip unwanted lines
2529 #next if ($BEGIN && ($t < $BEGIN));
2530 #next if ($END && ($t > $END));
2531 foreach my $dev (keys %{ $sar_srvtime_stat{$t} } ) {
2532 next if ($DEVICE && ($dev ne $DEVICE));
2533 if (!exists $OVERALL_STATS{'system'}{'svctm'} || ($OVERALL_STATS{'system'}{'svctm'}[1] < $sar_srvtime_stat{$t}{$dev}{'svctm'})) {
2534 @{$OVERALL_STATS{'system'}{'svctm'}} = ($t, $sar_srvtime_stat{$t}{$dev}{'svctm'}, $dev);
2535 }
2536 }
2537 }
2538 foreach my $t (sort {$a <=> $b} keys %sar_rw_devices_stat) {
2539 # Skip unwanted lines
2540 #next if ($BEGIN && ($t < $BEGIN));
2541 #next if ($END && ($t > $END));
2542 foreach my $dev (keys %{ $sar_rw_devices_stat{$t} } ) {
2543 next if ($DEVICE && ($dev ne $DEVICE));
2544 $OVERALL_STATS{'system'}{'devices'}{$dev}{read} += $sar_rw_devices_stat{$t}{$dev}{'rd_sec/s'} || 0;
2545 $OVERALL_STATS{'system'}{'devices'}{$dev}{write} += $sar_rw_devices_stat{$t}{$dev}{'wr_sec/s'} || 0;
2546 $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'}));
2547 }
2548 }
2549 }
2550
2551
2552 # Compute graphs of database statistics
2553 sub pg_stat_database_report
2554 {
2555 my ($src_base, $db_glob, %data_info) = @_;
2556
2557 my %database_stat = ();
2558 my %total_query_type = ();
2559 my %has_conn = ();
2560 my $has_tuples = 0;
2561 my $has_temp = 0;
2562 my $has_conflict = 0;
2563 my $tz = ($STATS_TIMEZONE*3600*1000);
2564 foreach my $time (sort {$a <=> $b} keys %all_stat_database) {
2565 foreach my $db (@global_databases) {
2566 next if (!$all_stat_database{$time}{$db}{interval});
2567 next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB)));
2568
2569 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)) {
2570 $all_stat_database{$time}{$db}{$k} ||= 0;
2571
2572 }
2573
2574 # It depends on the postgresql version
2575 if (!$has_tuples) {
2576 foreach my $k (keys %{$all_stat_database{$time}{$db}}) {
2577 if (grep(/^$k$/, 'insert','returned','fetched','update','delete')) {
2578 $has_tuples = 1;
2579 last;
2580 }
2581 }
2582 }
2583 if ($has_tuples) {
2584 $database_stat{$db}{insert} .= '[' . ($time - $tz) . ',' . int($all_stat_database{$time}{$db}{insert}/$all_stat_database{$time}{$db}{interval}) . '],';
2585 $database_stat{$db}{returned} .= '[' . ($time - $tz) . ',' . int($all_stat_database{$time}{$db}{returned}/$all_stat_database{$time}{$db}{interval}) . '],';
2586 $database_stat{$db}{fetched} .= '[' . ($time - $tz) . ',' . int($all_stat_database{$time}{$db}{fetched}/$all_stat_database{$time}{$db}{interval}) . '],';
2587 $database_stat{$db}{update} .= '[' . ($time - $tz) . ',' . int($all_stat_database{$time}{$db}{update}/$all_stat_database{$time}{$db}{interval}) . '],';
2588 $database_stat{$db}{delete} .= '[' . ($time - $tz) . ',' . int($all_stat_database{$time}{$db}{delete}/$all_stat_database{$time}{$db}{interval}) . '],';
2589 $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};
2590
2591 $total_query_type{$db}{'insert'} += $all_stat_database{$time}{$db}{insert};
2592 $total_query_type{$db}{'delete'} += $all_stat_database{$time}{$db}{delete};
2593 $total_query_type{$db}{'update'} += $all_stat_database{$time}{$db}{update};
2594 $total_query_type{$db}{'select'} += $all_stat_database{$time}{$db}{returned};
2595 }
2596 $all_stat_database{$time}{$db}{blks_read} ||= 0;
2597 $all_stat_database{$time}{$db}{blks_hit} ||= 0;
2598 $database_stat{$db}{blks_read} .= '[' . ($time - $tz) . ',' . int($all_stat_database{$time}{$db}{blks_read}/$all_stat_database{$time}{$db}{interval}) . '],';
2599 $database_stat{$db}{blks_hit} .= '[' . ($time - $tz) . ',' . int($all_stat_database{$time}{$db}{blks_hit}/$all_stat_database{$time}{$db}{interval}) . '],';
2600
2601 if (($all_stat_database{$time}{$db}{blks_read} + $all_stat_database{$time}{$db}{blks_hit}) > 0) {
2602 $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})) . '],';
2603 } else {
2604 $database_stat{$db}{ratio_hit_miss} .= '[' . ($time - $tz) . ',0],';
2605 }
2606 $database_stat{$db}{nbackend} .= '[' . ($time - $tz) . ',' . ($all_stat_database{$time}{$db}{nbackend}||0) . '],';
2607 $has_conn{$db} = 1 if ($all_stat_database{$time}{$db}{nbackend});
2608 $database_stat{$db}{xact_commit} .= '[' . ($time - $tz) . ',' . int(($all_stat_database{$time}{$db}{xact_commit}||0)/$all_stat_database{$time}{$db}{interval}) . '],';
2609 $database_stat{$db}{xact_rollback} .= '[' . ($time - $tz) . ',' . int(($all_stat_database{$time}{$db}{xact_rollback}||0)/$all_stat_database{$time}{$db}{interval}) . '],';
2610 $database_stat{$db}{xact_throughput} .= '[' . ($time - $tz) . ',' . int(($all_stat_database{$time}{$db}{xact_throughput}||0)/$all_stat_database{$time}{$db}{interval}) . '],';
2611 # It depends on the postgresql version
2612 if (!$has_conflict) {
2613 foreach my $k (keys %{$all_stat_database{$time}{$db}}) {
2614 if ($k eq 'canceled_queries') {
2615 $has_conflict = 1;
2616 last;
2617 }
2618 }
2619 }
2620 if ($has_conflict) {
2621 $database_stat{$db}{canceled_queries} .= '[' . ($time - $tz) . ',' . ($all_stat_database{$time}{$db}{canceled_queries}||0) . '],';
2622 }
2623 # It depends on the postgresql version
2624 if (!$has_temp) {
2625 foreach my $k (keys %{$all_stat_database{$time}{$db}}) {
2626 if (grep(/^$k$/, 'deadlocks','temp_files','temp_bytes')) {
2627 $has_temp = 1;
2628 last;
2629 }
2630 }
2631 }
2632 if ($has_temp) {
2633 $database_stat{$db}{deadlocks} .= '[' . ($time - $tz) . ',' . ($all_stat_database{$time}{$db}{deadlocks}||0) . '],';
2634 $database_stat{$db}{temp_files} .= '[' . ($time - $tz) . ',' . ($all_stat_database{$time}{$db}{temp_files}||0) . '],';
2635 $database_stat{$db}{temp_bytes} .= '[' . ($time - $tz) . ',' . int(($all_stat_database{$time}{$db}{temp_bytes}||0)/$all_stat_database{$time}{$db}{interval}) . '],';
2636 }
2637 }
2638 }
2639 %all_stat_database = ();
2640
2641 foreach my $id (sort {$a <=> $b} keys %data_info) {
2642 next if ($id ne $ID_ACTION);
2643 foreach my $db (sort keys %database_stat) {
2644 next if ($DATABASE && ($db ne $DATABASE));
2645 next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB)));
2646 next if ($data_info{$id}{name} ne $REAL_ACTION);
2647 if ($data_info{$id}{name} =~ /(database|cluster)-write_ratio/) {
2648
2649 if ($has_tuples) {
2650 $database_stat{$db}{insert} =~ s/,$//;
2651 $database_stat{$db}{update} =~ s/,$//;
2652 $database_stat{$db}{delete} =~ s/,$//;
2653 }
2654 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});
2655
2656 } elsif ($data_info{$id}{name} =~ /(database|cluster)-read_ratio/) {
2657
2658 if ($has_tuples) {
2659 $database_stat{$db}{returned} =~ s/,$//;
2660 $database_stat{$db}{fetched} =~ s/,$//;
2661 }
2662 print &jqplot_linegraph_array($IDX++, $data_info{$id}{name}, \%{$data_info{$id}}, $db, $database_stat{$db}{returned}, $database_stat{$db}{fetched});
2663
2664 } elsif ($data_info{$id}{name} =~ /(database|cluster)-read_write_query/) {
2665 if (exists $total_query_type{$db}{'all'} && ($total_query_type{$db}{'all'} > 0)) {
2666 my %data = ();
2667 foreach my $t (keys %{$total_query_type{$db}}) {
2668 next if ($t eq 'all');
2669 $data{$t} = sprintf("%0.2f", $total_query_type{$db}{$t}*100/$total_query_type{$db}{'all'});
2670 }
2671 print &jqplot_piegraph($IDX++, $data_info{$id}{name}, \%{$data_info{$id}}, $db, %data);
2672 }
2673
2674 } elsif ($data_info{$id}{name} =~ /(database|cluster)-cache_ratio/) {
2675
2676 $database_stat{$db}{blks_read} =~ s/,$//;
2677 $database_stat{$db}{blks_hit} =~ s/,$//;
2678 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});
2679 delete $database_stat{$db}{blks_hit};
2680 delete $database_stat{$db}{blks_read};
2681 delete $database_stat{$db}{ratio_hit_miss};
2682
2683 } elsif ($data_info{$id}{name} =~ /(database|cluster)-commits_rollbacks/) {
2684
2685 $database_stat{$db}{xact_commit} =~ s/,$//;
2686 $database_stat{$db}{xact_rollback} =~ s/,$//;
2687 $database_stat{$db}{nbackend} =~ s/,$//;
2688 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});
2689 delete $database_stat{$db}{xact_commit};
2690 delete $database_stat{$db}{xact_rollback};
2691
2692 } elsif ($data_info{$id}{name} =~ /(database|cluster)-transactions/) {
2693
2694 $database_stat{$db}{xact_throughput} =~ s/,$//;
2695 print &jqplot_linegraph_array($IDX++, $data_info{$id}{name}, \%{$data_info{$id}}, $db, $database_stat{$db}{xact_throughput});
2696 delete $database_stat{$db}{xact_throughput};
2697
2698 }
2699 }
2700 }
2701
2702 foreach my $id (sort {$a <=> $b} keys %data_info) {
2703 next if ($id ne $ID_ACTION);
2704 my %data = ();
2705 my $found = 0;
2706 foreach my $db (sort keys %database_stat) {
2707 next if ($DATABASE && ($DATABASE ne 'all') && ($db ne $DATABASE));
2708 next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB)));
2709
2710 if ($data_info{$id}{name} eq 'database-backends' || $data_info{$id}{name} eq 'cluster-backends') {
2711 $database_stat{$db}{nbackend} =~ s/,$//;
2712 $data{$db} = $database_stat{$db}{nbackend};
2713 if (($db ne 'all') && ($DATABASE ne 'all')) {
2714 print &jqplot_linegraph_array($IDX++, $data_info{$id}{name}, \%{$data_info{$id}}, $db, $database_stat{$db}{nbackend});
2715 }
2716 delete $database_stat{$db}{nbackend};
2717
2718 } elsif ($has_conflict && ($data_info{$id}{name} =~ /(database|cluster)-canceled_queries/)) {
2719
2720 $database_stat{$db}{canceled_queries} =~ s/,$//;
2721 $data{$db} = $database_stat{$db}{canceled_queries};
2722 if (($db ne 'all') && ($DATABASE ne 'all')) {
2723 print &jqplot_linegraph_array($IDX++, $data_info{$id}{name}, \%{$data_info{$id}}, $db, $database_stat{$db}{canceled_queries});
2724 }
2725 delete $database_stat{$db}{canceled_queries};
2726
2727 } elsif ($has_temp && ($data_info{$id}{name} =~ /(database|cluster)-deadlocks/)) {
2728 $database_stat{$db}{deadlocks} =~ s/,$//;
2729 $data{$db} = $database_stat{$db}{deadlocks};
2730 if (($db ne 'all') && ($DATABASE ne 'all')) {
2731 print &jqplot_linegraph_array($IDX++, $data_info{$id}{name}, \%{$data_info{$id}}, $db, $database_stat{$db}{deadlocks});
2732 }
2733 delete $database_stat{$db}{deadlocks};
2734
2735 } elsif ($has_temp && ($data_info{$id}{name} =~ /(database|cluster)-temporary_files/)) {
2736
2737 $database_stat{$db}{temp_files} =~ s/,$//;
2738 $data{$db} = $database_stat{$db}{temp_files};
2739 if (($db ne 'all') && ($DATABASE ne 'all')) {
2740 print &jqplot_linegraph_array($IDX++, $data_info{$id}{name}, \%{$data_info{$id}}, $db, $database_stat{$db}{temp_files});
2741 }
2742 delete $database_stat{$db}{temp_files};
2743
2744 } elsif ($has_temp && ($data_info{$id}{name} =~ /(database|cluster)-temporary_bytes/)) {
2745
2746 $database_stat{$db}{temp_bytes} =~ s/,$//;
2747 $data{$db} = $database_stat{$db}{temp_bytes};
2748 if (($db ne 'all') && ($DATABASE ne 'all')) {
2749 print &jqplot_linegraph_array($IDX++, $data_info{$id}{name}, \%{$data_info{$id}}, $db, $database_stat{$db}{temp_bytes});
2750 }
2751 delete $database_stat{$db}{temp_bytes};
2752
2753 }
2754 }
2755 if ($db_glob eq 'all') {
2756 my $name = $data_info{$id}{name};
2757 $name =~ s/^database/cluster/;
2758 if ($has_temp && ($data_info{$id}{name} =~ /(database|cluster)-temporary_files/)) {
2759 print &jqplot_linegraph_hash($IDX++, $name, \%{$data_info{$id}}, 'all', %data);
2760 }
2761 if ($has_temp && ($data_info{$id}{name} =~ /(database|cluster)-temporary_bytes/)) {
2762 print &jqplot_linegraph_hash($IDX++, $name, \%{$data_info{$id}}, 'all', %data);
2763 }
2764 if ($data_info{$id}{name} =~ /(database|cluster)-backends/) {
2765 print &jqplot_linegraph_hash($IDX++, $name, \%{$data_info{$id}}, 'all', %data);
2766 }
2767 if ($has_temp && $data_info{$id}{name} =~ /(database|cluster)-deadlocks/) {
2768 print &jqplot_linegraph_hash($IDX++, $name, \%{$data_info{$id}}, 'all', %data);
2769 }
2770 if ($has_conflict && ($data_info{$id}{name} =~ /(database|cluster)-canceled_queries/)) {
2771 print &jqplot_linegraph_hash($IDX++, $name, \%{$data_info{$id}}, 'all', %data);
2772 }
2773 }
2774 }
2775 }
2776
2777 # Compute statistics of database conflict statistics
2778 sub pg_stat_database_conflicts
2779 {
2780 my ($input_dir, $file, $offset) = @_;
2781
2782 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
2783
2784 my %start_vals = ();
2785 my $tmp_val = 0;
2786 # Load data from file
2787 my $curfh = open_filehdl("$input_dir/$file");
2788 $curfh->seek($offset,0);
2789 while (my $l = <$curfh>) {
2790 $offset += length($l);
2791 my @data = split(/;/, $l);
2792 next if (!&normalize_line(\@data));
2793 # timestamp | datid | datname | confl_tablespace | confl_lock | confl_snapshot | confl_bufferpin | confl_deadlock
2794
2795 # Get database size statistics
2796 push(@{$start_vals{$data[2]}}, @data) if ($#{$start_vals{$data[2]}} < 0);
2797
2798 (($data[3] - $start_vals{$data[2]}[3]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[3] - $start_vals{$data[2]}[3]);
2799 $all_stat_database_conflicts{$data[2]}{$data[0]}{tablespace} = $tmp_val;
2800 $all_stat_database_conflicts{'all'}{$data[0]}{tablespace} = $tmp_val;
2801
2802 (($data[4] - $start_vals{$data[2]}[4]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[4] - $start_vals{$data[2]}[4]);
2803 $all_stat_database_conflicts{$data[2]}{$data[0]}{lock} = $tmp_val;
2804 $all_stat_database_conflicts{'all'}{$data[0]}{lock} = $tmp_val;
2805
2806 (($data[5] - $start_vals{$data[2]}[5]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[5] - $start_vals{$data[2]}[5]);
2807 $all_stat_database_conflicts{$data[2]}{$data[0]}{snapshot} += $tmp_val;
2808 $all_stat_database_conflicts{'all'}{$data[0]}{snapshot} = $tmp_val;
2809
2810 (($data[6] - $start_vals{$data[2]}[6]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[6] - $start_vals{$data[2]}[6]);
2811 $all_stat_database_conflicts{$data[2]}{$data[0]}{bufferpin} = $tmp_val;
2812 $all_stat_database_conflicts{'all'}{$data[0]}{bufferpin} = $tmp_val;
2813
2814 (($data[7] - $start_vals{$data[2]}[7]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[7] - $start_vals{$data[2]}[7]);
2815 $all_stat_database_conflicts{$data[2]}{$data[0]}{deadlock} = $tmp_val;
2816 $all_stat_database_conflicts{'all'}{$data[0]}{deadlock} = $tmp_val;
2817
2818 @{$start_vals{$data[2]}} = ();
2819 push(@{$start_vals{$data[2]}}, @data);
2820
2821 }
2822 $curfh->close();
2823
2824 return $offset;
2825 }
2826
2827 # Compute graphs of database conflict statistics
2828 sub pg_stat_database_conflicts_report
2829 {
2830 my ($src_base, $db_glob, %data_info) = @_;
2831
2832 my %database_stat = ();
2833 my $id = &get_data_id($ACTION, %data_info);
2834 my $total_val = 0;
2835 my $tz = ($STATS_TIMEZONE*3600*1000);
2836 my %conflict_type = ();
2837 foreach my $db (sort keys %all_stat_database_conflicts) {
2838 next if ($DATABASE && ($DATABASE ne 'all') && ($db ne $DATABASE));
2839 next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB)));
2840 foreach my $t (sort {$a <=> $b} keys %{$all_stat_database_conflicts{$db}}) {
2841 $conflict_type{$db}{tablespace} .= '[' . ($t - $tz) . ',' . ($all_stat_database_conflicts{$db}{$t}{tablespace} || 0) . '],';
2842 $conflict_type{$db}{lock} .= '[' . ($t - $tz) . ',' . ($all_stat_database_conflicts{$db}{$t}{lock} || 0) . '],';
2843 $conflict_type{$db}{snapshot} .= '[' . ($t - $tz) . ',' . ($all_stat_database_conflicts{$db}{$t}{snapshot} || 0) . '],';
2844 $conflict_type{$db}{bufferpin} .= '[' . ($t - $tz) . ',' . ($all_stat_database_conflicts{$db}{$t}{bufferpin} || 0) . '],';
2845 $conflict_type{$db}{deadlock} .= '[' . ($t - $tz) . ',' . ($all_stat_database_conflicts{$db}{$t}{deadlock} || 0) . '],';
2846 }
2847 $conflict_type{$db}{tablespace} =~ s/,$//;
2848 $conflict_type{$db}{lock} =~ s/,$//;
2849 $conflict_type{$db}{snapshot} =~ s/,$//;
2850 $conflict_type{$db}{bufferpin} =~ s/,$//;
2851 $conflict_type{$db}{deadlock} =~ s/,$//;
2852 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});
2853 }
2854 %all_stat_database_conflicts = ();
2855 }
2856
2857 # Compute statistics of database size statistics
2858 sub pg_database_size
2859 {
2860 my ($input_dir, $file, $offset) = @_;
2861
2862 my %db_list = ();
2863
2864 # Load data from file
2865 my $curfh = open_filehdl("$input_dir/$file");
2866 $curfh->seek($offset,0);
2867 while (my $l = <$curfh>) {
2868 $offset += length($l);
2869 my @data = split(/;/, $l);
2870
2871 next if (!&normalize_line(\@data));
2872
2873 # date_trunc | datid | datname | size
2874
2875 # Store list of database
2876 $db_list{$data[2]} = 1;
2877
2878 # Get database size statistics
2879 if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) {
2880 $all_database_size{$data[0]}{$data[2]} = $data[3];
2881 $all_database_size{$data[0]}{'all'} += $data[3];
2882 } else {
2883 $OVERALL_STATS{'database'}{$data[2]}{'size'} = $data[3];
2884 $OVERALL_STATS{'start_date'} = $data[0] if (!$OVERALL_STATS{'start_date'} || ($OVERALL_STATS{'start_date'} gt $data[0]));
2885 $OVERALL_STATS{'end_date'} = $data[0] if (!$OVERALL_STATS{'end_date'} || ($OVERALL_STATS{'end_date'} lt $data[0]));
2886 }
2887 }
2888 $curfh->close();
2889
2890 # Store the full list of database
2891 foreach my $d (keys %db_list) {
2892 push(@global_databases, $d) if (!grep/^$d$/, @global_databases);
2893 }
2894 push(@global_databases, 'all') if (($#global_databases >= 0) && !grep(/^all$/, @global_databases));
2895
2896 return $offset;
2897 }
2898
2899 # Compute graphs of database size statistics
2900 sub pg_database_size_report
2901 {
2902 my ($src_base, $db_glob, %data_info) = @_;
2903
2904 my %database_stat = ();
2905 my $total_val = 0;
2906 my $tz = ($STATS_TIMEZONE*3600*1000);
2907 foreach my $t (sort {$a <=> $b} keys %all_database_size) {
2908 foreach my $db (@global_databases) {
2909 next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB)));
2910 $database_stat{$db}{size} .= '[' . ($t - $tz) . ',' . ($all_database_size{$t}{$db} || 0) . '],';
2911 }
2912 }
2913 %all_database_size = ();
2914
2915 my $id = &get_data_id($ACTION, %data_info);
2916
2917 my %data = ();
2918 foreach my $db (sort keys %database_stat) {
2919 next if ($DATABASE && ($DATABASE ne 'all') && ($db ne $DATABASE));
2920 next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB)));
2921 $database_stat{$db}{size} =~ s/,$//;
2922 $data{$db} = $database_stat{$db}{size};
2923 if (($db ne 'all') && ($DATABASE ne 'all') && ($ACTION !~ /^cluster/)) {
2924 print &jqplot_linegraph_array($IDX++, 'database-size', \%{$data_info{$id}}, $db, $database_stat{$db}{size});
2925 }
2926 delete $database_stat{$db}{size};
2927 }
2928
2929 if ($ACTION eq 'cluster-size') {
2930 print &jqplot_linegraph_hash($IDX++, 'cluster-size', \%{$data_info{$id}}, 'all', %data);
2931 }
2932
2933 }
2934
2935 # Compute statistics of tablespace size
2936 sub pg_tablespace_size
2937 {
2938 my ($input_dir, $file, $offset) = @_;
2939
2940 # Load data from file
2941 my $curfh = open_filehdl("$input_dir/$file");
2942 my $total_val = 0;
2943 $curfh->seek($offset,0);
2944 while (my $l = <$curfh>) {
2945 $offset += length($l);
2946 my @data = split(/;/, $l);
2947 next if (!&normalize_line(\@data));
2948
2949 # timestamp | tbspname | size | path
2950
2951 push(@global_tbspnames, $data[1]) if (!grep(/^$data[1]$/, @global_tbspnames));
2952
2953 # Get tablespace size statistics
2954 if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) {
2955 $all_tablespace_size{$data[0]}{$data[1]}{size} = $data[2];
2956 $all_tablespace_size{$data[0]}{$data[1]}{location} = $data[3];
2957 $all_tablespace_size{$data[0]}{'all'}{size} += $data[2];
2958 } else {
2959 $OVERALL_STATS{'tablespace'}{$data[1]}{'size'} = $data[2];
2960 $OVERALL_STATS{'tablespace'}{$data[1]}{'location'} = $data[3];
2961 }
2962 }
2963 $curfh->close();
2964
2965 push(@global_tbspnames, 'all') if ($#global_tbspnames > 0);
2966
2967 return $offset;
2968 }
2969
2970 # Compute graphs of tablespace size
2971 sub pg_tablespace_size_report
2972 {
2973 my ($src_base, $db, %data_info) = @_;
2974
2975 my $id = &get_data_id('tablespace-size', %data_info);
2976 my %data = ();
2977 my $print_after = '';
2978 my %tablespace_stat = ();
2979 my $tz = ($STATS_TIMEZONE*3600*1000);
2980 foreach my $time (sort {$a <=> $b} keys %all_tablespace_size) {
2981 foreach my $tbsp (@global_tbspnames) {
2982 $tablespace_stat{$tbsp}{size} .= '[' . ($time - $tz) . ',' . ($all_tablespace_size{$time}{$tbsp}{size}||0) . '],';
2983 $tablespace_stat{$tbsp}{location} = $all_tablespace_size{$time}{$tbsp}{location} || '';
2984 }
2985 }
2986 foreach my $tbsp (sort keys %tablespace_stat) {
2987 $tablespace_stat{$tbsp}{size} =~ s/,$//;
2988 $data{$tbsp} = $tablespace_stat{$tbsp}{size};
2989 if ($tbsp ne 'all') {
2990 $print_after .= "<p>$tbsp ($tablespace_stat{$tbsp}{location})</p>\n";
2991 }
2992 }
2993 %all_tablespace_size = ();
2994
2995 print &jqplot_linegraph_hash($IDX++, 'tablespace-size', \%{$data_info{$id}}, 'all', %data);
2996 print $print_after;
2997 }
2998
2999 # Compute statistics about table accesses and vacuum
3000 sub pg_stat_user_tables
3001 {
3002 my ($input_dir, $file) = @_;
3003
3004 %all_stat_user_tables = ();
3005
3006 my %start_vals = ();
3007 my $tmp_val = 0;
3008 # Load data from file
3009 my $curfh = open_filehdl("$input_dir/$file");
3010 while (my $l = <$curfh>) {
3011 chomp($l);
3012 next if (!$l);
3013 my @data = split(/;/, $l);
3014 next if (!&normalize_line(\@data));
3015
3016 # 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
3017
3018 if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') ) {
3019 $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}));
3020 $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}));
3021 $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}));
3022 $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}));
3023 } else {
3024
3025 next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB)));
3026
3027 $data[4] = "$data[3].$data[4]";
3028 push(@{$start_vals{$data[1]}{$data[4]}}, @data) if ($#{$start_vals{$data[1]}{$data[4]}} < 0);
3029
3030 # Stores last manual vacuum/analyze
3031 $all_stat_user_tables{$data[1]}{$data[4]}{last_vacuum} = $data[15] if ($data[15]);
3032 $all_stat_user_tables{$data[1]}{$data[4]}{last_autovacuum} = $data[16] if ($data[16]);
3033 $all_stat_user_tables{$data[1]}{$data[4]}{last_analyze} = $data[17] if ($data[17]);
3034 $all_stat_user_tables{$data[1]}{$data[4]}{last_autoanalyze} = $data[18] if ($data[18]);
3035
3036 # Get database statistics
3037 (($data[5] - $start_vals{$data[1]}{$data[4]}[5]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[5] - $start_vals{$data[1]}{$data[4]}[5]);
3038 $all_vacuum_stat{$data[1]}{$data[4]}{seq_scan} += $tmp_val;
3039 $all_stat_user_tables{$data[1]}{$data[4]}{seq_scan} = $data[5] || 0;
3040 (($data[7] - $start_vals{$data[1]}{$data[4]}[7]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[7] - $start_vals{$data[1]}{$data[4]}[7]);
3041 $all_vacuum_stat{$data[1]}{$data[4]}{idx_scan} += $tmp_val;
3042 $all_stat_user_tables{$data[1]}{$data[4]}{idx_scan} = $data[6] || 0;
3043 (($data[9] - $start_vals{$data[1]}{$data[4]}[9]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[9] - $start_vals{$data[1]}{$data[4]}[9]);
3044 $all_vacuum_stat{$data[1]}{$data[4]}{n_tup_ins} += $tmp_val;
3045 $all_stat_user_tables{$data[1]}{$data[4]}{n_tup_ins} = $data[9] || 0;
3046 (($data[10] - $start_vals{$data[1]}{$data[4]}[10]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[10] - $start_vals{$data[1]}{$data[4]}[10]);
3047 $all_vacuum_stat{$data[1]}{$data[4]}{n_tup_upd} += $tmp_val;
3048 $all_stat_user_tables{$data[1]}{$data[4]}{n_tup_upd} = $data[10] || 0;
3049 (($data[11] - $start_vals{$data[1]}{$data[4]}[11]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[11] - $start_vals{$data[1]}{$data[4]}[11]);
3050 $all_vacuum_stat{$data[1]}{$data[4]}{n_tup_del} += $tmp_val;
3051 $all_stat_user_tables{$data[1]}{$data[4]}{n_tup_del} = $data[11] || 0;
3052 (($data[12] - $start_vals{$data[1]}{$data[4]}[12]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[12] - $start_vals{$data[1]}{$data[4]}[12]);
3053 $all_vacuum_stat{$data[1]}{$data[4]}{n_tup_hot_upd} += $tmp_val;
3054 $all_stat_user_tables{$data[1]}{$data[4]}{n_tup_hot_upd} = $data[12] || 0;
3055 $all_stat_user_tables{$data[1]}{$data[4]}{n_dead_tup} = $data[14];
3056 $all_stat_user_tables{$data[1]}{$data[4]}{n_live_tup} = $data[13];
3057 $all_stat_user_tables{$data[1]}{$data[4]}{dead_vs_live} = sprintf("%.2f", ($data[14]*100)/(($data[13]+$data[14])||1));
3058 if ($#data > 19) {
3059 (($data[19] - $start_vals{$data[1]}{$data[4]}[19]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[19] - $start_vals{$data[1]}{$data[4]}[19]);
3060 $all_vacuum_stat{$data[1]}{$data[4]}{vacuum_count} += $tmp_val;
3061 $all_stat_user_tables{$data[1]}{$data[4]}{vacuum_count} = $data[19];
3062 (($data[20] - $start_vals{$data[1]}{$data[4]}[20]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[20] - $start_vals{$data[1]}{$data[4]}[20]);
3063 $all_vacuum_stat{$data[1]}{$data[4]}{autovacuum_count} += $tmp_val;
3064 $all_stat_user_tables{$data[1]}{$data[4]}{autovacuum_count} = $data[20];
3065 (($data[21] - $start_vals{$data[1]}{$data[4]}[21]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[21] - $start_vals{$data[1]}{$data[4]}[21]);
3066 $all_vacuum_stat{$data[1]}{$data[4]}{analyze_count} += $tmp_val;
3067 $all_stat_user_tables{$data[1]}{$data[4]}{analyze_count} = $data[21];
3068 (($data[22] - $start_vals{$data[1]}{$data[4]}[22]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[22] - $start_vals{$data[1]}{$data[4]}[22]);
3069 $all_vacuum_stat{$data[1]}{$data[4]}{autoanalyze_count} += $tmp_val;
3070 $all_stat_user_tables{$data[1]}{$data[4]}{autoanalyze_count} = $data[22];
3071 }
3072 @{$start_vals{$data[1]}{$data[4]}} = ();
3073 push(@{$start_vals{$data[1]}{$data[4]}}, @data);
3074 }
3075 }
3076 $curfh->close();
3077 }
3078
3079 sub pg_stat_all_tables
3080 {
3081 return &pg_stat_user_tables;
3082 }
3083
3084 # Compute report about table accesses
3085 sub pg_stat_user_tables_report
3086 {
3087 my ($src_base, $db, %data_info) = @_;
3088
3089 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
3090
3091 return if (!$db);
3092
3093 my $do_vacuum = 0;
3094 foreach my $t (keys %{$all_vacuum_stat{$db}}) {
3095 foreach my $k (keys %{$all_vacuum_stat{$db}{$t}}) {
3096 if (($k =~ /vacuum|analyze/) && $all_vacuum_stat{$db}{$t}{$k}) {
3097 $do_vacuum = 1;
3098 }
3099 }
3100 }
3101
3102 foreach my $id (sort {$a <=> $b} keys %data_info) {
3103 next if ($id ne $ID_ACTION);
3104 next if ($data_info{$id}{name} !~ /^table-/);
3105 next if ($data_info{$id}{name} ne $REAL_ACTION);
3106 my $table_header = '';
3107 my $colspan = '';
3108 if ($data_info{$id}{name} eq 'table-indexes') {
3109 $table_header = qq{
3110 <th>Schema.Table</th>
3111 <th>Sequencial scan</th>
3112 <th>Index scan</th>
3113 <th>Index vs Sequencial</th>
3114 };
3115 $colspan = ' colspan="5"';
3116 } elsif ($data_info{$id}{name} eq 'table-query-tuples') {
3117 $table_header = qq{
3118 <th>Schema.Table</th>
3119 <th>Inserted</th>
3120 <th>Updated</th>
3121 <th>Deleted</th>
3122 <th>Hot Updated</th>
3123 };
3124 $colspan = ' colspan="6"';
3125 } elsif ($data_info{$id}{name} eq 'table-kind-tuples') {
3126 $table_header = qq{
3127 <th>Schema.Table</th>
3128 <th>Live tuples</th>
3129 <th>Dead tuples</th>
3130 <th>Dead vs Live</th>
3131 };
3132 $colspan = ' colspan="5"';
3133 } elsif ( $do_vacuum && ($data_info{$id}{name} eq 'table-vacuums-analyzes') ) {
3134 $table_header = qq{
3135 <th>Schema.Table</th>
3136 <th>Vacuum</th>
3137 <th>Autovacuum</th>
3138 <th>Analyze</th>
3139 <th>Autoanalyze</th>
3140 <th>Last vacuum</th>
3141 <th>Last autovacuum</th>
3142 <th>Last analyze</th>
3143 <th>Last autoanalyze</th>
3144 };
3145 $colspan = ' colspan="10"';
3146 }
3147 if (scalar keys %{$all_vacuum_stat{$db}} == 0) {
3148 $table_header = qq{<td><div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div></td>};
3149 }
3150 print qq{
3151 <ul id="slides">
3152 <li class="slide active-slide" id="$data_info{$id}{name}-slide">
3153 <div id="$data_info{$id}{name}"><br/><br/><br/><br/></div>
3154 <div class="row">
3155 <div class="col-md-12">
3156 <div class="panel panel-default">
3157 <div class="panel-heading">
3158 <h2>$data_info{$id}{menu} on $db database tables</h2>
3159 <p>$data_info{$id}{description}</p>
3160 </div>
3161 <div class="panel-body">
3162 <div class="analysis-item row-fluid" id="$db-$data_info{$id}{name}">
3163 <div class="span11">
3164 <table class="table table-striped sortable" id="$db-$data_info{$id}{name}-table">
3165 <thead>
3166 <tr>
3167 $table_header
3168 </tr>
3169 </thead>
3170 <tbody>
3171 };
3172 foreach my $tb (sort keys %{$all_vacuum_stat{$db}}) {
3173 next if ($tb eq 'all');
3174 next if (($#INCLUDE_TB >= 0) && !grep(/^$tb$/, @INCLUDE_TB));
3175 my $table_data = '';
3176 if ($data_info{$id}{name} eq 'table-indexes') {
3177 if (!$all_vacuum_stat{$db}{$tb}{seq_scan} && !$all_vacuum_stat{$db}{$tb}{idx_scan}) {
3178 next;
3179 foreach ('idx_scan','seq_scan') {
3180 $all_stat_user_tables{$db}{$tb}{$_} ||= 0;
3181 }
3182 $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));
3183 $table_data = qq{<tr><th>$tb</th><td>$all_stat_user_tables{$db}{$tb}{seq_scan}</td><td>$all_stat_user_tables{$db}{$tb}{idx_scan}</td><td>$all_stat_user_tables{$db}{$tb}{idx_scan_vs_seq_scan}%</td></tr>};
3184 } else {
3185 foreach ('idx_scan','seq_scan') {
3186 $all_vacuum_stat{$db}{$tb}{$_} ||= 0;
3187 }
3188 $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));
3189 $table_data = qq{<tr><th>$tb</th><td>$all_vacuum_stat{$db}{$tb}{seq_scan}</td><td>$all_vacuum_stat{$db}{$tb}{idx_scan}</td><td>$all_vacuum_stat{$db}{$tb}{idx_scan_vs_seq_scan}%</td></tr>};
3190 }
3191 } elsif ($data_info{$id}{name} eq 'table-query-tuples') {
3192 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}) {
3193 next;
3194 foreach ('n_tup_ins','n_tup_upd','n_tup_del','n_tup_hot_upd') {
3195 $all_stat_user_tables{$db}{$tb}{$_} ||= 0;
3196 }
3197 $table_data = qq{<tr><th>$tb</th><td>$all_stat_user_tables{$db}{$tb}{n_tup_ins}</td><td>$all_stat_user_tables{$db}{$tb}{n_tup_upd}</td><td>$all_stat_user_tables{$db}{$tb}{n_tup_del}</td><td>$all_stat_user_tables{$db}{$tb}{n_tup_hot_upd}</td></tr>};
3198 } else {
3199 foreach ('n_tup_ins','n_tup_upd','n_tup_del','n_tup_hot_upd') {
3200 $all_vacuum_stat{$db}{$tb}{$_} ||= 0;
3201 }
3202 $table_data = qq{<tr><th>$tb</th><td>$all_vacuum_stat{$db}{$tb}{n_tup_ins}</td><td>$all_vacuum_stat{$db}{$tb}{n_tup_upd}</td><td>$all_vacuum_stat{$db}{$tb}{n_tup_del}</td><td>$all_vacuum_stat{$db}{$tb}{n_tup_hot_upd}</td></tr>};
3203 }
3204 } elsif ($data_info{$id}{name} eq 'table-kind-tuples') {
3205 if (!$all_stat_user_tables{$db}{$tb}{n_live_tup} && !$all_stat_user_tables{$db}{$tb}{n_dead_tup}) {
3206 next;
3207 }
3208 foreach ('n_live_tup','n_dead_tup','dead_vs_live') {
3209 $all_stat_user_tables{$db}{$tb}{$_} ||= 0;
3210 }
3211 $table_data = qq{<tr><th>$tb</th><td>$all_stat_user_tables{$db}{$tb}{n_live_tup}</td><td>$all_stat_user_tables{$db}{$tb}{n_dead_tup}</td><td>$all_stat_user_tables{$db}{$tb}{dead_vs_live}%</td></tr>};
3212 } elsif ( $do_vacuum && ($data_info{$id}{name} eq 'table-vacuums-analyzes') ) {
3213 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}) {
3214 next;
3215 foreach ('vacuum_count','autovacuum_count','analyze_count','autoanalyze_count') {
3216 $all_stat_user_tables{$db}{$tb}{$_} ||= 0;
3217 }
3218 $table_data = qq{<tr><th>$tb</th><td>$all_stat_user_tables{$db}{$tb}{vacuum_count}</td><td>$all_stat_user_tables{$db}{$tb}{autovacuum_count}</td><td>$all_stat_user_tables{$db}{$tb}{analyze_count}</td><td>$all_stat_user_tables{$db}{$tb}{autoanalyze_count}</td>};
3219 } else {
3220 foreach ('vacuum_count','autovacuum_count','analyze_count','autoanalyze_count') {
3221 $all_vacuum_stat{$db}{$tb}{$_} ||= 0;
3222 }
3223 $table_data = qq{<tr><th>$tb</th><td>$all_vacuum_stat{$db}{$tb}{vacuum_count}</td><td>$all_vacuum_stat{$db}{$tb}{autovacuum_count}</td><td>$all_vacuum_stat{$db}{$tb}{analyze_count}</td><td>$all_vacuum_stat{$db}{$tb}{autoanalyze_count}</td>};
3224 }
3225 foreach ('last_vacuum','last_autovacuum','last_analyze','last_autoanalyze') {
3226 $all_stat_user_tables{$db}{$tb}{$_} ||= '-';
3227 }
3228 $table_data .= qq{<td>$all_stat_user_tables{$db}{$tb}{last_vacuum}</td><td>$all_stat_user_tables{$db}{$tb}{last_autovacuum}</td><td>$all_stat_user_tables{$db}{$tb}{last_analyze}</td><td>$all_stat_user_tables{$db}{$tb}{last_autoanalyze}</td></tr>};
3229 }
3230 if ($table_data) {
3231 print $table_data;
3232 }
3233 }
3234 print qq{
3235 </tbody>
3236 </table>
3237 </div>
3238 </div>
3239 </div>
3240 </div>
3241 </div>
3242 </li>
3243 </ul>
3244 };
3245 }
3246 %all_stat_user_tables = ();
3247 }
3248
3249 # Compute statistics about index scan
3250 sub pg_stat_user_indexes
3251 {
3252 my ($input_dir, $file) = @_;
3253
3254 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
3255
3256 %all_stat_user_indexes = ();
3257
3258 my %start_vals = ();
3259 my $tmp_val = 0;
3260 # Load data from file
3261 my $curfh = open_filehdl("$input_dir/$file");
3262 while (my $l = <$curfh>) {
3263 chomp($l);
3264 next if (!$l);
3265 my @data = split(/;/, $l);
3266 next if (!&normalize_line(\@data));
3267
3268 # timestamp | dbname | relid | indexrelid | schemaname | relname | indexrelname | idx_scan | idx_tup_read | idx_tup_fetch
3269 next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB)));
3270
3271 $data[6] = "$data[4].$data[5].$data[6]";
3272 push(@{$start_vals{$data[1]}{$data[6]}}, @data) if ($#{$start_vals{$data[1]}{$data[6]}} < 0);
3273
3274 # Get database statistics
3275 (($data[7] - $start_vals{$data[1]}{$data[6]}[7]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[7] - $start_vals{$data[1]}{$data[6]}[7]);
3276 $all_stat_user_indexes{$data[1]}{$data[6]}{idx_scan} += $tmp_val;
3277
3278 (($data[8] - $start_vals{$data[1]}{$data[6]}[8]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[8] - $start_vals{$data[1]}{$data[6]}[8]);
3279 $all_stat_user_indexes{$data[1]}{$data[6]}{idx_tup_read} += $tmp_val;
3280
3281 (($data[9] - $start_vals{$data[1]}{$data[6]}[9]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[9] - $start_vals{$data[1]}{$data[6]}[9]);
3282 $all_stat_user_indexes{$data[1]}{$data[6]}{idx_tup_fetch} += $tmp_val;
3283
3284 @{$start_vals{$data[1]}{$data[6]}} = ();
3285 push(@{$start_vals{$data[1]}{$data[6]}}, @data);
3286 }
3287 $curfh->close();
3288 }
3289
3290 sub pg_stat_all_indexes
3291 {
3292 return &pg_stat_user_indexes;
3293 }
3294
3295 # Compute report about index scan
3296 sub pg_stat_user_indexes_report
3297 {
3298 my ($src_base, $db, %data_info) = @_;
3299
3300 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
3301
3302 return if (!$db);
3303
3304 foreach my $id (sort {$a <=> $b} keys %data_info) {
3305 next if ($id ne $ID_ACTION);
3306 next if ($data_info{$id}{name} !~ /^index-/);
3307 my $table_header = '';
3308 my $colspan = ' colspan="4"';
3309 if ($data_info{$id}{name} eq 'index-scan') {
3310 $table_header = qq{
3311 <th>Schema.Table.Index</th>
3312 <th>Index scan</th>
3313 <th>Index entries returned</th>
3314 <th>Live table rows fetched</th>
3315 };
3316 }
3317 if (scalar keys %{$all_stat_user_indexes{$db}} == 0) {
3318 $table_header = qq{<td><div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div></td>};
3319 }
3320 print qq{
3321 <ul id="slides">
3322 <li class="slide active-slide" id="$data_info{$id}{name}-slide">
3323 <div id="$data_info{$id}{name}"><br/><br/><br/><br/></div>
3324 <div class="row">
3325 <div class="col-md-12">
3326 <div class="panel panel-default">
3327 <div class="panel-heading">
3328 <h2>$data_info{$id}{menu} on $db database indexes</h2>
3329 <p>$data_info{$id}{description}</p>
3330 </div>
3331 <div class="panel-body">
3332 <div class="analysis-item row-fluid" id="$db-$data_info{$id}{name}">
3333 <div class="span11">
3334 <table class="table table-striped sortable" id="$db-$data_info{$id}{name}-table">
3335 <thead>
3336 <tr>
3337 $table_header
3338 </tr>
3339 </thead>
3340 <tbody>
3341 };
3342 my $found_table_stat = 0;
3343 foreach my $idx (sort keys %{$all_stat_user_indexes{$db}}) {
3344 next if ($idx eq 'all');
3345 next if (($#INCLUDE_TB >= 0) && !grep(/^$idx$/, @INCLUDE_TB));
3346 my $table_data = '';
3347 if ($data_info{$id}{name} eq 'index-scan') {
3348 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}) {
3349 next;
3350 }
3351 foreach ('idx_scan','idx_tup_read','idx_tup_fetch') {
3352 $all_stat_user_indexes{$db}{$idx}{$_} ||= 0;
3353 }
3354 $table_data = qq{<tr><th>$idx</th><td>$all_stat_user_indexes{$db}{$idx}{idx_scan}</td><td>$all_stat_user_indexes{$db}{$idx}{idx_tup_read}</td><td>$all_stat_user_indexes{$db}{$idx}{idx_tup_fetch}</td></tr>};
3355 }
3356 if ($table_data) {
3357 print $table_data;
3358 }
3359 }
3360 print qq{
3361 </tbody>
3362 </table>
3363 </div>
3364 </div>
3365 </div>
3366 </div>
3367 </div>
3368 </li>
3369 </ul>
3370 };
3371 }
3372 %all_stat_user_indexes = ();
3373 }
3374
3375 # Compute statistics about invalid index
3376 sub pg_stat_invalid_indexes
3377 {
3378 my ($input_dir, $file) = @_;
3379
3380 %all_stat_invalid_indexes = ();
3381
3382 my %start_vals = ();
3383 my $tmp_val = 0;
3384 # Load data from file
3385 my $curfh = open_filehdl("$input_dir/$file");
3386 while (my $l = <$curfh>) {
3387 chomp($l);
3388 next if (!$l);
3389 my @data = split(/;/, $l);
3390 next if (!&normalize_line(\@data));
3391
3392 # timestamp | dbname | schemaname | relname | indexrelname | index_definition
3393 $all_stat_invalid_indexes{$data[1]}{$data[2]}{$data[3]}{$data[4]} = $data[5];
3394 $OVERALL_STATS{'database'}{$data[1]}{invalid_indexes}++;
3395 $OVERALL_STATS{'cluster'}{invalid_indexes}++;
3396 push(@{$OVERALL_STATS{'cluster'}{invalid_indexes_db}}, $data[1]) if (!grep(/^$data[1]$/, @{$OVERALL_STATS{'cluster'}{invalid_indexes_db}}));
3397 }
3398 $curfh->close();
3399 }
3400
3401 # Compute report about invalid index
3402 sub pg_stat_invalid_indexes_report
3403 {
3404 my ($src_base, $db, %data_info) = @_;
3405
3406 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
3407
3408 return if (!$db);
3409
3410 foreach my $id (sort {$a <=> $b} keys %data_info) {
3411 next if ($id ne $ID_ACTION);
3412 next if ($data_info{$id}{name} ne 'index-invalid');
3413
3414 my $table_header = '';
3415 my $colspan = ' colspan="4"';
3416 print qq{
3417 <ul id="slides">
3418 <div class="row">
3419 <div class="col-md-12">
3420 <div class="panel panel-default">
3421 <div class="panel-heading">
3422 <h2>$data_info{$id}{menu} on $db database</h2>
3423 <p>$data_info{$id}{description}</p>
3424 </div>
3425 <div class="panel-body">
3426 <div class="analysis-item row-fluid" id="$db-$data_info{$id}{name}">
3427 <div class="span11">
3428 <table class="table table-striped sortable" id="$db-$data_info{$id}{name}-table">
3429 <thead>
3430 <tr>
3431 <th>Schema</th>
3432 <th>Table</th>
3433 <th>Index name</th>
3434 <th>Index definition</th>
3435 </tr>
3436 </thead>
3437 <tbody>
3438 };
3439 my $found_stat = 0;
3440 foreach my $sch (sort keys %{$all_stat_invalid_indexes{$db}}) {
3441 foreach my $tb (sort keys %{$all_stat_invalid_indexes{$db}{$sch}}) {
3442 next if (($#INCLUDE_TB >= 0) && !grep(/^$tb$/, @INCLUDE_TB));
3443 $found_stat = 1;
3444 foreach my $idx (sort keys %{$all_stat_invalid_indexes{$db}{$sch}{$tb}}) {
3445 print qq{<tr><th>$sch</th><td>$tb</td><td>$idx</td><td>$all_stat_invalid_indexes{$db}{$sch}{$tb}{$idx}</td></tr>};
3446 }
3447 }
3448 }
3449 if (!$found_stat) {
3450 print qq{<tr><td$colspan><div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div></td></tr>};
3451 }
3452 print qq{
3453 </tbody>
3454 </table>
3455 </div>
3456 </div>
3457 };
3458 # Terminate cluster statistics file
3459 print qq{
3460 </div>
3461 </div>
3462 </div>
3463 };
3464 }
3465 %all_stat_invalid_indexes = ();
3466 }
3467
3468 # Compute statistics about unlogged tables
3469 sub pg_stat_unlogged
3470 {
3471 my ($input_dir, $file) = @_;
3472
3473 %all_stat_unlogged = ();
3474
3475 my %start_vals = ();
3476 my $tmp_val = 0;
3477 # Load data from file
3478 my $curfh = open_filehdl("$input_dir/$file");
3479 while (my $l = <$curfh>) {
3480 chomp($l);
3481 next if (!$l);
3482 my @data = split(/;/, $l);
3483 next if (!&normalize_line(\@data));
3484
3485 # timestamp | dbname | schemaname | relname | relkind
3486 $all_stat_unlogged{$data[1]}{$data[2]}{$data[3]} = $data[4];
3487 $OVERALL_STATS{'database'}{$data[1]}{unlogged}++;
3488 $OVERALL_STATS{'cluster'}{unlogged}++;
3489 push(@{$OVERALL_STATS{'cluster'}{unlogged_db}}, $data[1]) if (!grep(/^$data[1]$/, @{$OVERALL_STATS{'cluster'}{unlogged_db}}));
3490 }
3491 $curfh->close();
3492 }
3493
3494 # Compute report about unlogged tables
3495 sub pg_stat_unlogged_report
3496 {
3497 my ($src_base, $db, %data_info) = @_;
3498
3499 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
3500
3501 return if (!$db);
3502
3503 foreach my $id (sort {$a <=> $b} keys %data_info) {
3504 next if ($id ne $ID_ACTION);
3505 next if ($data_info{$id}{name} ne 'table-unlogged');
3506
3507 my $table_header = '';
3508 my $colspan = ' colspan="2"';
3509 print qq{
3510 <ul id="slides">
3511 <div class="row">
3512 <div class="col-md-12">
3513 <div class="panel panel-default">
3514 <div class="panel-heading">
3515 <h2>$data_info{$id}{menu} on $db database</h2>
3516 <p>$data_info{$id}{description}</p>
3517 </div>
3518 <div class="panel-body">
3519 <div class="analysis-item row-fluid" id="$db-$data_info{$id}{name}">
3520 <div class="span11">
3521 <table class="table table-striped sortable" id="$db-$data_info{$id}{name}-table">
3522 <thead>
3523 <tr>
3524 <th>Schema</th>
3525 <th>Table</th>
3526 </tr>
3527 </thead>
3528 <tbody>
3529 };
3530 my $found_stat = 0;
3531 foreach my $sch (sort keys %{$all_stat_unlogged{$db}}) {
3532 foreach my $tb (sort keys %{$all_stat_unlogged{$db}{$sch}}) {
3533 next if (($#INCLUDE_TB >= 0) && !grep(/^$tb$/, @INCLUDE_TB));
3534 $found_stat = 1;
3535 print qq{<tr><th>$sch</th><td>$tb</td></tr>};
3536 }
3537 }
3538 if (!$found_stat) {
3539 print qq{<tr><td$colspan><div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div></td></tr>};
3540 }
3541 print qq{
3542 </tbody>
3543 </table>
3544 </div>
3545 </div>
3546 };
3547 # Terminate cluster statistics file
3548 print qq{
3549 </div>
3550 </div>
3551 </div>
3552 };
3553 }
3554 %all_stat_unlogged = ();
3555 }
3556
3557 # Compute statistics about hash index
3558 sub pg_stat_hash_indexes
3559 {
3560 my ($input_dir, $file) = @_;
3561
3562 %all_stat_hash_indexes = ();
3563
3564 my %start_vals = ();
3565 my $tmp_val = 0;
3566 # Load data from file
3567 my $curfh = open_filehdl("$input_dir/$file");
3568 while (my $l = <$curfh>) {
3569 chomp($l);
3570 next if (!$l);
3571 my @data = split(/;/, $l);
3572 next if (!&normalize_line(\@data));
3573
3574 # timestamp | dbname | schemaname | relname | indexrelname | index_definition
3575 $all_stat_hash_indexes{$data[1]}{$data[2]}{$data[3]}{$data[4]} = $data[5];
3576 $OVERALL_STATS{'database'}{$data[1]}{hash_indexes}++;
3577 $OVERALL_STATS{'cluster'}{hash_indexes}++;
3578 push(@{$OVERALL_STATS{'cluster'}{hash_indexes_db}}, $data[1]) if (!grep(/^$data[1]$/, @{$OVERALL_STATS{'cluster'}{hash_indexes_db}}));
3579 }
3580 $curfh->close();
3581 }
3582
3583 # Compute report about hash index
3584 sub pg_stat_hash_indexes_report
3585 {
3586 my ($src_base, $db, %data_info) = @_;
3587
3588 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
3589
3590 return if (!$db);
3591
3592 foreach my $id (sort {$a <=> $b} keys %data_info) {
3593 next if ($id ne $ID_ACTION);
3594 next if ($data_info{$id}{name} ne 'index-hash');
3595
3596 my $table_header = '';
3597 my $colspan = ' colspan="4"';
3598 print qq{
3599 <ul id="slides">
3600 <div class="row">
3601 <div class="col-md-12">
3602 <div class="panel panel-default">
3603 <div class="panel-heading">
3604 <h2>$data_info{$id}{menu} on $db database</h2>
3605 <p>$data_info{$id}{description}</p>
3606 </div>
3607 <div class="panel-body">
3608 <div class="analysis-item row-fluid" id="$db-$data_info{$id}{name}">
3609 <div class="span11">
3610 <table class="table table-striped sortable" id="$db-$data_info{$id}{name}-table">
3611 <thead>
3612 <tr>
3613 <th>Schema</th>
3614 <th>Table</th>
3615 <th>Index name</th>
3616 <th>Index definition</th>
3617 </tr>
3618 </thead>
3619 <tbody>
3620 };
3621 my $found_stat = 0;
3622 foreach my $sch (sort keys %{$all_stat_hash_indexes{$db}}) {
3623 foreach my $tb (sort keys %{$all_stat_hash_indexes{$db}{$sch}}) {
3624 next if (($#INCLUDE_TB >= 0) && !grep(/^$tb$/, @INCLUDE_TB));
3625 $found_stat = 1;
3626 foreach my $idx (sort keys %{$all_stat_hash_indexes{$db}{$sch}{$tb}}) {
3627 print qq{<tr><th>$sch</th><td>$tb</td><td>$idx</td><td>$all_stat_hash_indexes{$db}{$sch}{$tb}{$idx}</td></tr>};
3628 }
3629 }
3630 }
3631 if (!$found_stat) {
3632 print qq{<tr><td$colspan><div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div></td></tr>};
3633 }
3634 print qq{
3635 </tbody>
3636 </table>
3637 </div>
3638 </div>
3639 };
3640 # Terminate cluster statistics file
3641 print qq{
3642 </div>
3643 </div>
3644 </div>
3645 };
3646 }
3647 %all_stat_hash_indexes = ();
3648 }
3649
3650 # Compute stats for table I/O
3651 sub pg_statio_user_tables
3652 {
3653 my ($input_dir, $file, $offset) = @_;
3654
3655 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
3656
3657 my %start_vals = ();
3658 my $tmp_val = 0;
3659 # Load data from file
3660 my $curfh = open_filehdl("$input_dir/$file");
3661 $curfh->seek($offset,0);
3662 while (my $l = <$curfh>) {
3663 $offset += length($l);
3664 my @data = split(/;/, $l);
3665 next if (!&normalize_line(\@data));
3666
3667 # 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
3668 next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB)));
3669
3670 $data[4] = "$data[3].$data[4]";
3671
3672 push(@{$start_vals{$data[1]}{$data[4]}}, @data) if ($#{$start_vals{$data[1]}{$data[4]}} < 0);
3673
3674 # Store interval between previous run
3675 $all_statio_user_tables{$data[1]}{$data[4]}{interval} = ($data[0] - $start_vals{$data[1]}{$data[4]}[0])/1000;
3676
3677 (($data[5] - $start_vals{$data[1]}{$data[4]}[5]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[5] - $start_vals{$data[1]}{$data[4]}[5]);
3678 $all_statio_user_tables{$data[1]}{$data[4]}{heap_blks_read} += $tmp_val;
3679
3680 (($data[6] - $start_vals{$data[1]}{$data[4]}[6]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[6] - $start_vals{$data[1]}{$data[4]}[6]);
3681 $all_statio_user_tables{$data[1]}{$data[4]}{heap_blks_hit} += $tmp_val;
3682
3683 (($data[7] - $start_vals{$data[1]}{$data[4]}[7]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[7] - $start_vals{$data[1]}{$data[4]}[7]);
3684 $all_statio_user_tables{$data[1]}{$data[4]}{idx_blks_read} += $tmp_val;
3685
3686 (($data[8] - $start_vals{$data[1]}{$data[4]}[8]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[8] - $start_vals{$data[1]}{$data[4]}[8]);
3687 $all_statio_user_tables{$data[1]}{$data[4]}{idx_blks_hit} += $tmp_val;
3688
3689 (($data[9] - $start_vals{$data[1]}{$data[4]}[9]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[9] - $start_vals{$data[1]}{$data[4]}[9]);
3690 $all_statio_user_tables{$data[1]}{$data[4]}{toast_blks_read} += $tmp_val;
3691
3692 (($data[10] - $start_vals{$data[1]}{$data[4]}[10]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[10] - $start_vals{$data[1]}{$data[4]}[10]);
3693 $all_statio_user_tables{$data[1]}{$data[4]}{toast_blks_hit} += $tmp_val;
3694
3695 (($data[11] - $start_vals{$data[1]}{$data[4]}[11]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[11] - $start_vals{$data[1]}{$data[4]}[11]);
3696 $all_statio_user_tables{$data[1]}{$data[4]}{tidx_blks_read} += $tmp_val;
3697
3698 (($data[12] - $start_vals{$data[1]}{$data[4]}[12]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[12] - $start_vals{$data[1]}{$data[4]}[12]);
3699 $all_statio_user_tables{$data[1]}{$data[4]}{tidx_blks_hit} += $tmp_val;
3700
3701 @{$start_vals{$data[1]}{$data[4]}} = ();
3702 push(@{$start_vals{$data[1]}{$data[4]}}, @data);
3703 }
3704 $curfh->close();
3705
3706 return $offset;
3707 }
3708
3709 # Compute report for table I/O
3710 sub pg_statio_user_tables_report
3711 {
3712 my ($src_base, $db, %data_info) = @_;
3713
3714 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
3715
3716 return if (!$db);
3717
3718 foreach my $id (sort {$a <=> $b} keys %data_info) {
3719 next if ($id ne $ID_ACTION);
3720 next if ($data_info{$id}{name} !~ /^statio-table/);
3721 next if ($data_info{$id}{name} ne $REAL_ACTION);
3722 my $colspan = '';
3723 my $table_header = qq{
3724 <th>Schema.Table</th>
3725 <th>Table blocks read</th>
3726 <th>Table blocks hit</th>
3727 <th>Index blocks read</th>
3728 <th>Index blocks hit</th>
3729 };
3730 print qq{
3731 <ul id="slides">
3732 <li class="slide active-slide" id="$data_info{$id}{name}-slide">
3733 <div id="$data_info{$id}{name}"><br/><br/><br/><br/></div>
3734 <div class="row">
3735 <div class="col-md-12">
3736 <div class="panel panel-default">
3737 <div class="panel-heading">
3738 <h2>$data_info{$id}{menu} on $db database tables</h2>
3739 <p>$data_info{$id}{description}</p>
3740 </div>
3741 <div class="panel-body">
3742 <div class="analysis-item row-fluid" id="$db-$data_info{$id}{name}">
3743 <div class="span11">
3744 <table class="table table-striped sortable" id="$db-$data_info{$id}{name}-table">
3745 <thead>
3746 <tr>
3747 $table_header
3748 </tr>
3749 </thead>
3750 <tbody>
3751 };
3752 my $data_found = 0;
3753 foreach my $tb (sort keys %{$all_statio_user_tables{$db}}) {
3754 next if ($tb eq 'all');
3755 next if (($#INCLUDE_TB >= 0) && !grep(/^$tb$/, @INCLUDE_TB));
3756 my $table_data = '';
3757 $all_statio_user_tables{$db}{$tb}{idx_blks_read} ||= 0;
3758 $all_statio_user_tables{$db}{$tb}{heap_blks_read} ||= 0;
3759 $all_statio_user_tables{$db}{$tb}{heap_blks_hit} ||= 0;
3760 $all_statio_user_tables{$db}{$tb}{idx_blks_hit} ||= 0;
3761 $all_statio_user_tables{$db}{$tb}{toast_blks_read} ||= 0;
3762 $all_statio_user_tables{$db}{$tb}{toast_blks_hit} ||= 0;
3763 $all_statio_user_tables{$db}{$tb}{tidx_blks_read} ||= 0;
3764 $all_statio_user_tables{$db}{$tb}{tidx_blks_hit} ||= 0;
3765 # if this is a toast table override the normal table values for easy use
3766 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} ) {
3767 $table_data = qq{<tr><th>$tb</th><td>$all_statio_user_tables{$db}{$tb}{toast_blks_read}</td><td>$all_statio_user_tables{$db}{$tb}{toast_blks_hit}</td><td>$all_statio_user_tables{$db}{$tb}{tidx_blks_read}</td><td>$all_statio_user_tables{$db}{$tb}{tidx_blks_hit}</td></tr>};
3768 } else {
3769 $table_data = qq{<tr><th>$tb</th><td>$all_statio_user_tables{$db}{$tb}{heap_blks_read}</td><td>$all_statio_user_tables{$db}{$tb}{heap_blks_hit}</td><td>$all_statio_user_tables{$db}{$tb}{idx_blks_read}</td><td>$all_statio_user_tables{$db}{$tb}{idx_blks_hit}</td></tr>};
3770 }
3771 if ($table_data) {
3772 print $table_data;
3773 $data_found = 1;
3774 }
3775 }
3776 if ($data_found) {
3777 $table_header = qq{<td><div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div></td>};
3778 }
3779 print qq{
3780 </tbody>
3781 </table>
3782 </div>
3783 </div>
3784 </div>
3785 </div>
3786 </div>
3787 </li>
3788 </ul>
3789 };
3790 }
3791 %all_stat_user_tables = ();
3792 }
3793
3794 # Compute stats for relation buffer cache
3795 sub pg_relation_buffercache
3796 {
3797 my ($input_dir, $file, $offset) = @_;
3798
3799 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
3800
3801 my %start_vals = ();
3802 my $tmp_val = 0;
3803 # Load data from file
3804 my $curfh = open_filehdl("$input_dir/$file");
3805 while (my $l = <$curfh>) {
3806 $offset += length($l);
3807 my @data = split(/;/, $l);
3808 next if (!&normalize_line(\@data));
3809
3810 # date_trunc | datname | relname | buffers | relpages | buffered | buffers % | relation %
3811
3812 next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB)));
3813
3814 $data[7] = 100 if ($data[7] > 100);
3815 $all_relation_buffercache{$data[0]}{$data[1]}{$data[2]}{buffers} = ($data[3] || 0);
3816 $all_relation_buffercache{$data[0]}{$data[1]}{$data[2]}{pages} = ($data[4] || 0);
3817 $all_relation_buffercache{$data[0]}{$data[1]}{$data[2]}{buffered} = ($data[5] || 0);
3818 $all_relation_buffercache{$data[0]}{$data[1]}{$data[2]}{'buffers %'} = ($data[6] || 0);
3819 $all_relation_buffercache{$data[0]}{$data[1]}{$data[2]}{'relation %'} = ($data[7] || 0);
3820
3821 }
3822 $curfh->close();
3823
3824 return $offset;
3825 };
3826
3827 # Compute report for relation buffer cache
3828 sub pg_relation_buffercache_report
3829 {
3830 my ($src_base, $db, %data_info) = @_;
3831
3832 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
3833
3834 return if (!$db);
3835
3836 my %rel_stat = ();
3837 my %to_show = ();
3838 my %buffercache_stat = ();
3839 my $tz = ($STATS_TIMEZONE*3600*1000);
3840
3841 foreach my $t (sort {$a <=> $b} keys %all_relation_buffercache) {
3842 foreach my $obj ( keys %{$all_relation_buffercache{$t}{$db}} ) {
3843 $rel_stat{$db}{$obj}{buffers} .= '[' . ($t - $tz) . ',' . ($all_relation_buffercache{$t}{$db}{$obj}{buffers} || 0) . '],';
3844 $buffercache_stat{$db}{$obj}{buffers} = ($all_relation_buffercache{$t}{$db}{$obj}{buffers} || 0);
3845 $rel_stat{$db}{$obj}{pages} .= '[' . ($t - $tz) . ',' . ($all_relation_buffercache{$t}{$db}{$obj}{pages} || 0) . '],';
3846 $buffercache_stat{$db}{$obj}{pages} = ($all_relation_buffercache{$t}{$db}{$obj}{pages} || 0);
3847 $rel_stat{$db}{$obj}{buffered} .= '[' . ($t - $tz) . ',' . ($all_relation_buffercache{$t}{$db}{$obj}{buffered} || 0) . '],';
3848 $buffercache_stat{$db}{$obj}{buffered} = ($all_relation_buffercache{$t}{$db}{$obj}{buffered} || 0);
3849 $rel_stat{$db}{$obj}{'buffers %'} .= '[' . ($t - $tz) . ',' . ($all_relation_buffercache{$t}{$db}{$obj}{'buffers %'} || 0) . '],';
3850 $buffercache_stat{$db}{$obj}{'buffers %'} = ($all_relation_buffercache{$t}{$db}{$obj}{'buffers %'} || 0);
3851 $rel_stat{$db}{$obj}{'relation %'} .= '[' . ($t - $tz) . ',' . ($all_relation_buffercache{$t}{$db}{$obj}{'relation %'} || 0) . '],';
3852 $buffercache_stat{$db}{$obj}{'relation %'} = ($all_relation_buffercache{$t}{$db}{$obj}{'relation %'} || 0);
3853 }
3854 }
3855 %all_relation_buffercache = ();
3856
3857 my $id = &get_data_id($ACTION, %data_info);
3858
3859 # Get list of object in the shared buffers
3860 if ($data_info{$id}{name} eq 'buffercache-relation') {
3861 my $colspan = ' colspan="6"';
3862 my $table_header = qq{
3863 <th>Relation</th>
3864 <th>Buffers</th>
3865 <th>Pages</th>
3866 <th>Buffered</th>
3867 <th>Buffers %</th>
3868 <th>Relation %</th>
3869 };
3870 if (!exists $buffercache_stat{$db} || scalar keys %{$buffercache_stat{$db}} == 0) {
3871 $table_header = qq{<td><div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div></td>};
3872 }
3873 print qq{
3874 <ul id="slides">
3875 <li class="slide active-slide" id="$data_info{$id}{name}-slide">
3876 <div id="$data_info{$id}{name}"><br/><br/><br/><br/></div>
3877 <div class="row">
3878 <div class="col-md-12">
3879 <div class="panel panel-default">
3880 <div class="panel-heading">
3881 <h2>$data_info{$id}{menu} on $db database</h2>
3882 <p>$data_info{$id}{description}</p>
3883 </div>
3884 <div class="panel-body">
3885 <div class="analysis-item row-fluid" id="$db-$data_info{$id}{name}">
3886 <div class="span11">
3887 <table class="table table-striped sortable" id="$db-$data_info{$id}{name}-table">
3888 <thead>
3889 <tr>
3890 $table_header
3891 </tr>
3892 </thead>
3893 <tbody>
3894 };
3895 my $found_stat = 0;
3896 my $rank = 1;
3897 foreach my $rel (sort {$buffercache_stat{$db}{$b}{buffers} <=> $buffercache_stat{$db}{$a}{buffers}} keys %{$buffercache_stat{$db}}) {
3898 next if (($#INCLUDE_TB >= 0) && !grep(/^$rel$/, @INCLUDE_TB));
3899 last if ($TOP_STAT && ($rank > $TOP_STAT));
3900 my $table_data = '';
3901 if ($data_info{$id}{name} eq 'buffercache-relation') {
3902 if (!$buffercache_stat{$db}{$rel}{buffers} && !$buffercache_stat{$db}{$rel}{pages} && !$buffercache_stat{$db}{$rel}{buffered}) {
3903 next;
3904 }
3905 $to_show{$db}{$rel} = $rank;
3906 $table_data = "<tr><th>$rel</th><td>$buffercache_stat{$db}{$rel}{buffers}</td><td>$buffercache_stat{$db}{$rel}{pages}</td><td>" . &pretty_print_size($buffercache_stat{$db}{$rel}{buffered}) . "</td><td>$buffercache_stat{$db}{$rel}{'buffers %'}</td><td>$buffercache_stat{$db}{$rel}{'relation %'}</td></tr>\n";
3907 }
3908 $rank++;
3909 if ($table_data) {
3910 print $table_data;
3911 }
3912 }
3913 print qq{
3914 </tbody>
3915 </table>
3916 </div>
3917 </div>
3918 </div>
3919 </div>
3920 </div>
3921 </li>
3922 </ul>
3923 };
3924 }
3925
3926 # Show shared buffers usage per object
3927 if ($data_info{$id}{name} eq 'statio-buffercache') {
3928 my $rank = 1;
3929 foreach my $rel (sort {$buffercache_stat{$db}{$b}{buffers} <=> $buffercache_stat{$db}{$a}{buffers}} keys %{$buffercache_stat{$db}}) {
3930 next if (($#INCLUDE_TB >= 0) && !grep(/^$rel$/, @INCLUDE_TB));
3931 last if ($TOP_STAT && ($rank > $TOP_STAT));
3932 if (!$buffercache_stat{$db}{$rel}{buffers} && !$buffercache_stat{$db}{$rel}{pages} && !$buffercache_stat{$db}{$rel}{buffered}) {
3933 next;
3934 }
3935 $to_show{$db}{$rel} = $rank;
3936 $rank++;
3937 }
3938 if (exists $to_show{$db}) {
3939 foreach my $rel (sort {$to_show{$db}{$a} <=> $to_show{$db}{$b} } keys %{$to_show{$db}}) {
3940 my $graph_data = '';
3941 foreach ('buffers','pages','buffered','buffers %','relation %') {
3942 $rel_stat{$db}{$rel}{$_} =~ s/,$//;
3943 }
3944 print &jqplot_linegraph_array($IDX++, 'statio-buffercache', \%{$data_info{$id}}, $rel, $rel_stat{$db}{$rel}{buffered},$rel_stat{$db}{$rel}{'relation %'});
3945 }
3946 } else {
3947 print &empty_dataset('statio-buffercache', \%{$data_info{$id}}, 'on');
3948 }
3949 }
3950
3951 %buffercache_stat = ();
3952 }
3953
3954 # Compute stats for index I/O
3955 sub pg_statio_user_indexes
3956 {
3957 my ($input_dir, $file, $offset) = @_;
3958
3959 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
3960
3961 my %start_vals = ();
3962 my $tmp_val = 0;
3963 # Load data from file
3964 my $curfh = open_filehdl("$input_dir/$file");
3965 $curfh->seek($offset,0);
3966 while (my $l = <$curfh>) {
3967 $offset += length($l);
3968 my @data = split(/;/, $l);
3969 next if (!&normalize_line(\@data));
3970
3971 # timestamp | dbname | relid | indexrelid | schemaname | relname | indexrelname | idx_blks_read | idx_blks_hit
3972
3973 next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB)));
3974
3975 $data[6] = "$data[4].$data[5].$data[6]";
3976
3977 push(@{$start_vals{$data[1]}{$data[6]}}, @data) if ($#{$start_vals{$data[1]}{$data[6]}} < 0);
3978
3979 # Store interval between previous run
3980 $all_statio_user_indexes{$data[1]}{$data[6]}{interval} = ($data[0] - $start_vals{$data[1]}{$data[6]}[0])/1000;
3981
3982 (($data[7] - $start_vals{$data[1]}{$data[6]}[7]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[7] - $start_vals{$data[1]}{$data[6]}[7]);
3983 $all_statio_user_indexes{$data[1]}{$data[6]}{idx_blks_read} += $tmp_val;
3984
3985 (($data[8] - $start_vals{$data[1]}{$data[6]}[8]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[8] - $start_vals{$data[1]}{$data[6]}[8]);
3986 $all_statio_user_indexes{$data[1]}{$data[6]}{idx_blks_hit} += $tmp_val;
3987
3988 @{$start_vals{$data[1]}{$data[6]}} = ();
3989 push(@{$start_vals{$data[1]}{$data[6]}}, @data);
3990 }
3991 $curfh->close();
3992
3993 return $offset;
3994 }
3995
3996 # Compute report for index I/O
3997 sub pg_statio_user_indexes_report
3998 {
3999 my ($src_base, $db, %data_info) = @_;
4000
4001 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
4002
4003 return if (!$db);
4004
4005 foreach my $id (sort {$a <=> $b} keys %data_info) {
4006 next if ($id ne $ID_ACTION);
4007 next if ($data_info{$id}{name} !~ /^statio-index/);
4008 my $table_header = '';
4009 my $colspan = ' colspan="4"';
4010 if ($data_info{$id}{name} eq 'index-scan') {
4011 $table_header = qq{
4012 <th>Schema.Table.Index</th>
4013 <th>Index blocks read</th>
4014 <th>Index blocks hits</th>
4015 };
4016 }
4017 print qq{
4018 <ul id="slides">
4019 <li class="slide active-slide" id="$data_info{$id}{name}-slide">
4020 <div id="$data_info{$id}{name}"><br/><br/><br/><br/></div>
4021 <div class="row">
4022 <div class="col-md-12">
4023 <div class="panel panel-default">
4024 <div class="panel-heading">
4025 <h2>$data_info{$id}{menu} on $db database indexes</h2>
4026 <p>$data_info{$id}{description}</p>
4027 </div>
4028 <div class="panel-body">
4029 <div class="analysis-item row-fluid" id="$db-$data_info{$id}{name}">
4030 <div class="span11">
4031 <table class="table table-striped sortable" id="$db-$data_info{$id}{name}-table">
4032 <thead>
4033 <tr>
4034 $table_header
4035 </tr>
4036 </thead>
4037 <tbody>
4038 };
4039 my $found_table_stat = 0;
4040 foreach my $idx (sort keys %{$all_statio_user_indexes{$db}}) {
4041 next if ($idx eq 'all');
4042 next if (($#INCLUDE_TB >= 0) && !grep(/^$idx$/, @INCLUDE_TB));
4043 my $table_data = '';
4044 if (!$all_statio_user_indexes{$db}{$idx}{idx_blks_read} && !$all_statio_user_indexes{$db}{$idx}{idx_blks_hit}) {
4045 next;
4046 }
4047 $table_data = qq{<tr><th>$idx</th><td>$all_statio_user_indexes{$db}{$idx}{idx_blks_read}</td><td>$all_statio_user_indexes{$db}{$idx}{idx_blks_hit}</td></tr>};
4048 if ($table_data) {
4049 print $table_data;
4050 $found_table_stat = 1;
4051 }
4052 }
4053 if (!$found_table_stat) {
4054 $table_header = qq{<td><div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div></td>};
4055 }
4056 print qq{
4057 </tbody>
4058 </table>
4059 </div>
4060 </div>
4061 </div>
4062 </div>
4063 </div>
4064 </li>
4065 </ul>
4066 };
4067 }
4068 %all_stat_user_indexes = ();
4069 }
4070
4071 # Compute statistics of xlog cluster
4072 sub pg_xlog_stat
4073 {
4074 my ($input_dir, $file, $offset) = @_;
4075
4076 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
4077
4078 # Load data from file
4079 my $curfh = open_filehdl("$input_dir/$file");
4080 $curfh->seek($offset,0);
4081 while (my $l = <$curfh>) {
4082 $offset += length($l);
4083 my @data = split(/;/, $l);
4084 next if (!&normalize_line(\@data));
4085
4086 # timestamp | total_file | last_wal_name | wal_recycled | wal_written | max_wal
4087
4088 # case of pgstats file content
4089 if ($#data == 3) {
4090 $all_xlog_stat{$data[0]}{total}++;
4091 } else {
4092 $all_xlog_stat{$data[0]}{total} = ($data[1] || 0);
4093 if ($#data == 5) {
4094 $all_xlog_stat{$data[0]}{recycled} = ($data[3] || 0);
4095 $all_xlog_stat{$data[0]}{written} = ($data[4] || 0);
4096 $all_xlog_stat{$data[0]}{max_wal} = (POSIX::ceil($data[5]) || 0);
4097 }
4098 }
4099 }
4100 $curfh->close();
4101
4102 return $offset;
4103 }
4104
4105 # Compute graphs of xlog cluster statistics
4106 sub pg_xlog_stat_report
4107 {
4108 my ($src_base, $db, %data_info) = @_;
4109
4110 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
4111
4112 return if (!scalar keys %all_xlog_stat);
4113
4114 my %xlog_stat = ();
4115 my $tz = ($STATS_TIMEZONE*3600*1000);
4116 foreach my $t (sort {$a <=> $b} keys %all_xlog_stat) {
4117 $xlog_stat{total} .= '[' . ($t - $tz) . ',' . ($all_xlog_stat{$t}{total} || 0) . '],';
4118 $xlog_stat{recycled} .= '[' . ($t - $tz) . ',' . ($all_xlog_stat{$t}{recycled} || 0) . '],';
4119 $xlog_stat{written} .= '[' . ($t - $tz) . ',' . ($all_xlog_stat{$t}{written} || 0) . '],';
4120 $xlog_stat{max_wal} .= '[' . ($t - $tz) . ',' . ($all_xlog_stat{$t}{max_wal} || 0) . '],';
4121 }
4122 %all_xlog_stat = ();
4123
4124 if ($xlog_stat{total} ) {
4125 my $id = &get_data_id('cluster-xlog_files', %data_info);
4126 $xlog_stat{total} =~ s/,$//;
4127 if (exists $xlog_stat{recycled}) {
4128 push(@{$data_info{$id}{legends}}, 'recycled', 'written', 'max_wal');
4129 print &jqplot_linegraph_array($IDX++, 'cluster-xlog_files', \%{$data_info{$id}}, '', $xlog_stat{total}, $xlog_stat{recycled}, $xlog_stat{written}, $xlog_stat{max_wal});
4130 } else {
4131 print &jqplot_linegraph_array($IDX++, 'cluster-xlog_files', \%{$data_info{$id}}, '', $xlog_stat{total});
4132 }
4133 }
4134 }
4135
4136 # Compute statistics of bgwriter cluster
4137 sub pg_stat_bgwriter
4138 {
4139 my ($input_dir, $file, $offset) = @_;
4140
4141 return if ( $ACTION eq 'database-info' );
4142
4143 my @start_vals = ();
4144 my %total_count = ();
4145 my $tmp_val = 0;
4146 # Load data from file
4147 my $curfh = open_filehdl("$input_dir/$file");
4148 $curfh->seek($offset,0);
4149 while (my $l = <$curfh>) {
4150 $offset += length($l);
4151 my @data = split(/;/, $l);
4152 next if (!&normalize_line(\@data));
4153
4154 if ($#data >= 9) {
4155 $OVERALL_STATS{'bgwriter'}{stats_reset} = $data[-1] if (!exists $OVERALL_STATS{'bgwriter'}{stats_reset} || ($OVERALL_STATS{'bgwriter'}{stats_reset} lt $data[-1]));
4156 }
4157
4158 next if ($ACTION eq 'home');
4159 push(@start_vals, @data) if ($#start_vals < 0);
4160
4161 # Store interval between previous run
4162 $all_stat_bgwriter{$data[0]}{interval} = ($data[0] - $start_vals[0])/1000;
4163
4164 (($data[1] - $start_vals[1]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[1] - $start_vals[1]);
4165 $all_stat_bgwriter{$data[0]}{checkpoints_timed} = $tmp_val;
4166 (($data[2] - $start_vals[2]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[2] - $start_vals[2]);
4167 $all_stat_bgwriter{$data[0]}{checkpoints_req} = $tmp_val;
4168 my $id = 0;
4169 if ($#data > 10) {
4170 $id += 2;
4171 (($data[3] - $start_vals[3]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[3] - $start_vals[3]);
4172 $all_stat_bgwriter{$data[0]}{checkpoint_write_time} = $tmp_val;
4173 (($data[4] - $start_vals[4]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[4] - $start_vals[4]);
4174 $all_stat_bgwriter{$data[0]}{checkpoint_sync_time} = $tmp_val;
4175 }
4176 (($data[3+$id] - $start_vals[3+$id]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[3+$id] - $start_vals[3+$id]);
4177 $all_stat_bgwriter{$data[0]}{buffers_checkpoint} = $tmp_val*8192;
4178 (($data[4+$id] - $start_vals[4+$id]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[4+$id] - $start_vals[4+$id]);
4179 $all_stat_bgwriter{$data[0]}{buffers_clean} = $tmp_val*8192;
4180 (($data[5+$id] - $start_vals[5+$id]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[5+$id] - $start_vals[5+$id]);
4181 $all_stat_bgwriter{$data[0]}{maxwritten_clean} = $tmp_val;
4182 (($data[6+$id] - $start_vals[6+$id]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[6+$id] - $start_vals[6+$id]);
4183 $all_stat_bgwriter{$data[0]}{buffers_backend} = $tmp_val*8192;
4184 if ($#data >= 9) {
4185 (($data[7+$id] - $start_vals[7+$id]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[7+$id] - $start_vals[7+$id]);
4186 $all_stat_bgwriter{$data[0]}{buffers_backend_fsync} .= $tmp_val;
4187 (($data[8+$id] - $start_vals[8+$id]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[8+$id] - $start_vals[8+$id]);
4188 $all_stat_bgwriter{$data[0]}{buffers_alloc} = $tmp_val*8192;
4189 }
4190 @start_vals = ();
4191 push(@start_vals, @data);
4192 }
4193 $curfh->close();
4194
4195 return $offset;
4196 }
4197
4198 # Compute graphs of bgwriter cluster statistics
4199 sub pg_stat_bgwriter_report
4200 {
4201 my ($src_base, $db, %data_info) = @_;
4202
4203 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
4204
4205 return if (!scalar keys %all_stat_bgwriter);
4206
4207 my %bgwriter_stat = ();
4208 my %data = ();
4209 my $tz = ($STATS_TIMEZONE*3600*1000);
4210 foreach my $t (sort {$a <=> $b} keys %all_stat_bgwriter) {
4211 next if (!$all_stat_bgwriter{$t}{interval});
4212 $data{'Checkpoint timed'} += $all_stat_bgwriter{$t}{checkpoints_timed};
4213 $data{'Checkpoint requested'} += $all_stat_bgwriter{$t}{checkpoints_req};
4214 $bgwriter_stat{checkpoints_timed} .= '[' . ($t - $tz) . ',' . $all_stat_bgwriter{$t}{checkpoints_timed} . '],';
4215 $bgwriter_stat{checkpoints_req} .= '[' . ($t - $tz) . ',' . $all_stat_bgwriter{$t}{checkpoints_req} . '],';
4216 $bgwriter_stat{checkpoint_write_time} .= '[' . ($t - $tz) . ',' . ($all_stat_bgwriter{$t}{checkpoint_write_time}||0) . '],';
4217 $bgwriter_stat{checkpoint_sync_time} .= '[' . ($t - $tz) . ',' . ($all_stat_bgwriter{$t}{checkpoint_sync_time}||0) . '],';
4218 $bgwriter_stat{buffers_checkpoint} .= '[' . ($t - $tz) . ',' . int(($all_stat_bgwriter{$t}{buffers_checkpoint}||0)/$all_stat_bgwriter{$t}{interval}) . '],';
4219 $bgwriter_stat{buffers_clean} .= '[' . ($t - $tz) . ',' . int(($all_stat_bgwriter{$t}{buffers_clean}||0)/$all_stat_bgwriter{$t}{interval}) . '],';
4220 $bgwriter_stat{buffers_backend} .= '[' . ($t - $tz) . ',' . int(($all_stat_bgwriter{$t}{buffers_backend}||0)/$all_stat_bgwriter{$t}{interval}) . '],';
4221 $bgwriter_stat{buffers_alloc} .= '[' . ($t - $tz) . ',' . int(($all_stat_bgwriter{$t}{buffers_alloc}||0)/$all_stat_bgwriter{$t}{interval}) . '],';
4222 $bgwriter_stat{maxwritten_clean} .= '[' . ($t - $tz) . ',' . ($all_stat_bgwriter{$t}{maxwritten_clean}||0) . '],';
4223 $bgwriter_stat{buffers_backend_fsync} .= '[' . ($t - $tz) . ',' . ((exists $all_stat_bgwriter{$t}{buffers_backend_fsync}) ? $all_stat_bgwriter{$t}{buffers_backend_fsync} : '0') . '],';
4224 }
4225 %all_stat_bgwriter = ();
4226
4227 my $total_checkpoint = $data{'Checkpoint timed'} + $data{'Checkpoint requested'};
4228 if (($data_info{$ID_ACTION}{name} eq 'cluster-checkpoints') && $total_checkpoint) {
4229 $data_info{$ID_ACTION}{legends}[0] .= ' (' . sprintf("%0.2f", $data{'Checkpoint timed'}*100/($total_checkpoint||1)) . '%)';
4230 $data_info{$ID_ACTION}{legends}[1] .= ' (' . sprintf("%0.2f", $data{'Checkpoint requested'}*100/($total_checkpoint||1)) . '%)';
4231 }
4232 foreach my $id (sort {$a <=> $b} keys %data_info) {
4233 next if ($id ne $ID_ACTION);
4234 next if ($data_info{$id}{name} ne $REAL_ACTION);
4235 if ($data_info{$id}{name} eq 'cluster-checkpoints') {
4236 $bgwriter_stat{checkpoints_timed} =~ s/,$//;
4237 $bgwriter_stat{checkpoints_req} =~ s/,$//;
4238 print &jqplot_linegraph_array($IDX++, 'cluster-checkpoints', \%{$data_info{$id}}, '', $bgwriter_stat{checkpoints_timed}, $bgwriter_stat{checkpoints_req});
4239 } elsif ($data_info{$id}{name} eq 'cluster-checkpoints_time') {
4240 if (exists $bgwriter_stat{checkpoint_write_time}) {
4241 $bgwriter_stat{checkpoint_sync_time} =~ s/,$//;
4242 $bgwriter_stat{checkpoint_write_time} =~ s/,$//;
4243 print &jqplot_linegraph_array($IDX++, 'cluster-checkpoints_time', \%{$data_info{$id}}, '', $bgwriter_stat{checkpoint_write_time}, $bgwriter_stat{checkpoint_sync_time});
4244 }
4245 } elsif ($data_info{$id}{name} eq 'cluster-bgwriter_write') {
4246 $bgwriter_stat{buffers_checkpoint} =~ s/,$//;
4247 $bgwriter_stat{buffers_clean} =~ s/,$//;
4248 $bgwriter_stat{buffers_backend} =~ s/,$//;
4249 print &jqplot_linegraph_array($IDX++, 'cluster-bgwriter_write', \%{$data_info{$id}}, '', $bgwriter_stat{buffers_checkpoint}, $bgwriter_stat{buffers_clean}, $bgwriter_stat{buffers_backend});
4250 } elsif ($data_info{$id}{name} eq 'cluster-bgwriter_read') {
4251 $bgwriter_stat{buffers_alloc} =~ s/,$//;
4252 print &jqplot_linegraph_array($IDX++, 'cluster-bgwriter_read', \%{$data_info{$id}}, '', $bgwriter_stat{buffers_alloc});
4253 } elsif ($data_info{$id}{name} eq 'cluster-bgwriter_count') {
4254 $bgwriter_stat{maxwritten_clean} =~ s/,$//;
4255 $bgwriter_stat{buffers_backend_fsync} =~ s/,$//;
4256 print &jqplot_linegraph_array($IDX++, 'cluster-bgwriter_count', \%{$data_info{$id}}, '', $bgwriter_stat{maxwritten_clean}, $bgwriter_stat{buffers_backend_fsync});
4257 }
4258 }
4259 }
4260
4261 # Compute statistics of connections
4262 sub pg_stat_connections
4263 {
4264 my ($input_dir, $file, $offset) = @_;
4265
4266 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
4267
4268 my @start_vals = ();
4269 my $tmp_val = 0;
4270 my %db_list = ();
4271
4272 # Load data from file
4273 my $curfh = open_filehdl("$input_dir/$file");
4274 $curfh->seek($offset,0);
4275 while (my $l = <$curfh>) {
4276 $offset += length($l);
4277 my @data = split(/;/, $l);
4278 next if (!&normalize_line(\@data, 5));
4279
4280 # timestamp | total | active | waiting | idle_in_xact | datname
4281
4282 # Store list of database
4283 $db_list{$data[5]} = 1;
4284
4285 if ($ACTION eq 'database-connections') {
4286 $all_stat_connections{$data[0]}{$data[5]}{total} = $data[1];
4287 $all_stat_connections{$data[0]}{$data[5]}{active} = $data[2];
4288 $all_stat_connections{$data[0]}{$data[5]}{waiting} = $data[3];
4289 $all_stat_connections{$data[0]}{$data[5]}{idle_in_xact} = $data[4];
4290 $all_stat_connections{$data[0]}{$data[5]}{idle} = ($data[1] - $data[2] - $data[4]);
4291 } else {
4292 $all_stat_connections{$data[0]}{'all'}{total} += $data[1];
4293 $all_stat_connections{$data[0]}{'all'}{active} += $data[2];
4294 $all_stat_connections{$data[0]}{'all'}{waiting} += $data[3];
4295 $all_stat_connections{$data[0]}{'all'}{idle_in_xact} += $data[4];
4296 $all_stat_connections{$data[0]}{'all'}{idle} += ($data[1] - $data[2] - $data[4]);
4297 }
4298 }
4299 $curfh->close();
4300
4301 # Store the full list of database
4302 foreach my $d (keys %db_list) {
4303 push(@global_databases, $d) if (!grep/^$d$/, @global_databases);
4304 }
4305 push(@global_databases, 'all') if (($#global_databases >= 0) && !grep(/^all$/, @global_databases));
4306
4307 return $offset;
4308 }
4309
4310 # Compute graphs of connections statistics
4311 sub pg_stat_connections_report
4312 {
4313 my ($src_base, $db_glob, %data_info) = @_;
4314
4315 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
4316
4317 my %connections_stat = ();
4318 my $tz = ($STATS_TIMEZONE*3600*1000);
4319 foreach my $time (sort {$a <=> $b} keys %all_stat_connections)
4320 {
4321 if ($ACTION eq 'database-connections') {
4322 foreach my $db (@global_databases) {
4323 next if (($db_glob ne 'all') && ($db ne $db_glob));
4324 next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB)));
4325 $connections_stat{$db}{total} .= '[' . ($time - $tz) . ',' . ($all_stat_connections{$time}{$db}{total}||0) . '],';
4326 $connections_stat{$db}{active} .= '[' . ($time - $tz) . ',' . ($all_stat_connections{$time}{$db}{active}||0) . '],';
4327 $connections_stat{$db}{waiting} .= '[' . ($time - $tz) . ',' . ($all_stat_connections{$time}{$db}{waiting}||0) . '],';
4328 $connections_stat{$db}{idle_in_xact} .= '[' . ($time - $tz) . ',' . ($all_stat_connections{$time}{$db}{idle_in_xact}||0) . '],';
4329 $connections_stat{$db}{idle} .= '[' . ($time - $tz) . ',' . ($all_stat_connections{$time}{$db}{idle}||0) . '],';
4330 }
4331 } else {
4332 $connections_stat{'all'}{total} .= '[' . ($time - $tz) . ',' . ($all_stat_connections{$time}{'all'}{total}||0) . '],';
4333 $connections_stat{'all'}{active} .= '[' . ($time - $tz) . ',' . ($all_stat_connections{$time}{'all'}{active}||0) . '],';
4334 $connections_stat{'all'}{waiting} .= '[' . ($time - $tz) . ',' . ($all_stat_connections{$time}{'all'}{waiting}||0) . '],';
4335 $connections_stat{'all'}{idle_in_xact} .= '[' . ($time - $tz) . ',' . ($all_stat_connections{$time}{'all'}{idle_in_xact}||0) . '],';
4336 $connections_stat{'all'}{idle} .= '[' . ($time - $tz) . ',' . ($all_stat_connections{$time}{'all'}{idle}||0) . '],';
4337 }
4338 }
4339 %all_stat_connections = ();
4340
4341 my $id = &get_data_id($ACTION, %data_info);
4342 if (scalar keys %connections_stat > 0) {
4343 foreach my $db (sort keys %connections_stat) {
4344 next if ($db ne $db_glob);
4345 next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB)));
4346 $connections_stat{$db}{total} =~ s/,$//;
4347 $connections_stat{$db}{active} =~ s/,$//;
4348 $connections_stat{$db}{waiting} =~ s/,$//;
4349 $connections_stat{$db}{idle_in_xact} =~ s/,$//;
4350 $connections_stat{$db}{idle} =~ s/,$//;
4351 if ($db ne 'all') {
4352 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});
4353 } else {
4354 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});
4355 }
4356 }
4357 } else {
4358 print &empty_dataset('database-connections', \%{$data_info{$id}}, 'indexes');
4359 }
4360 }
4361
4362 # Compute statistics of user functions call
4363 sub pg_stat_user_functions
4364 {
4365 my ($input_dir, $file) = @_;
4366
4367 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
4368
4369 %all_stat_user_functions = ();
4370
4371 my @start_vals = ();
4372 my $tmp_val = 0;
4373 # Load data from file
4374 my $curfh = open_filehdl("$input_dir/$file");
4375 while (my $l = <$curfh>) {
4376 chomp($l);
4377 next if (!$l);
4378 my @data = split(/;/, $l);
4379 next if (!&normalize_line(\@data));
4380
4381 # timestamp | datname | funcid | schemaname | funcname | calls | total_time | self_time
4382
4383 next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB)));
4384
4385 push(@start_vals, @data) if ($#start_vals < 0);
4386
4387 $data[4] = "$data[3].$data[4]";
4388
4389 (($data[5] - $start_vals[5]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[5] - $start_vals[5]);
4390 $all_stat_user_functions{$data[1]}{$data[4]}{calls} += $tmp_val;
4391 (($data[6] - $start_vals[6]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[6] - $start_vals[6]);
4392 $all_stat_user_functions{$data[1]}{$data[4]}{total_time} += $tmp_val;
4393 (($data[7] - $start_vals[7]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[7] - $start_vals[7]);
4394 $all_stat_user_functions{$data[1]}{$data[4]}{self_time} += $tmp_val;
4395
4396 @start_vals = ();
4397 push(@start_vals, @data);
4398 }
4399 $curfh->close();
4400 }
4401
4402 # Compute graphs of user functions call statistics
4403 sub pg_stat_user_functions_report
4404 {
4405 my ($src_base, $db, %data_info) = @_;
4406
4407 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
4408
4409 return if (!$db);
4410
4411 my $id = &get_data_id('database-functions', %data_info);
4412 my $table_header = qq{
4413 <th>Schema.function</th>
4414 <th>Calls</th>
4415 <th>Total time</th>
4416 <th>Self time</th>
4417 };
4418 if (!exists $all_stat_user_functions{$db} || scalar keys %{$all_stat_user_functions{$db}} == 0) {
4419 $table_header = qq{<td><div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div></td>};
4420 }
4421 my $colspan = ' colspan="4"';
4422 print qq{
4423 <ul id="slides">
4424 <li class="slide active-slide" id="database-functions-slide">
4425 <div id="database-functions"><br/><br/><br/><br/></div>
4426 <div class="row">
4427 <div class="col-md-12">
4428 <div class="panel panel-default">
4429 <div class="panel-heading">
4430 <h2>$data_info{$id}{menu} on $db database</h2>
4431 <p>$data_info{$id}{description}</p>
4432 </div>
4433 <div class="panel-body">
4434 <div class="analysis-item row-fluid" id="$db-$data_info{$id}{name}">
4435 <div class="span11">
4436 <table class="table table-striped sortable" id="$db-$data_info{$id}{name}-table">
4437 <thead>
4438 <tr>
4439 $table_header
4440 </tr>
4441 </thead>
4442 <tbody>
4443 };
4444 my $found_fct_stat = 0;
4445 foreach my $fct (sort keys %{$all_stat_user_functions{$db}}) {
4446 if (!$all_stat_user_functions{$db}{$fct}{calls} && !$all_stat_user_functions{$db}{$fct}{total_time} && !$all_stat_user_functions{$db}{$fct}{self_time}) {
4447 next;
4448 }
4449 foreach ('calls','total_time','self_time') {
4450 $all_stat_user_functions{$db}{$fct}{$_} ||= 0;
4451 }
4452 print "<tr><th>$fct</th><td>$all_stat_user_functions{$db}{$fct}{calls}</td><td>" . &format_duration($all_stat_user_functions{$db}{$fct}{total_time}) . "</td><td>" . &format_duration($all_stat_user_functions{$db}{$fct}{self_time}) . "</td></tr>\n";
4453 }
4454 print qq{
4455 </tbody>
4456 </table>
4457 </div>
4458 </div>
4459 </div>
4460 </div>
4461 </div>
4462 </div>
4463 </li>
4464 </ul>
4465 };
4466
4467 }
4468
4469 # Compute graphs of replication cluster statistics
4470 sub pg_stat_replication
4471 {
4472 my ($input_dir, $file, $offset) = @_;
4473
4474 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
4475
4476 my @start_vals = ();
4477 my $tmp_val = 0;
4478 # Load data from file
4479 my $curfh = open_filehdl("$input_dir/$file");
4480 $curfh->seek($offset,0);
4481 while (my $l = <$curfh>) {
4482 $offset += length($l);
4483 my @data = split(/;/, $l);
4484 next if (!&normalize_line(\@data));
4485 # 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
4486 # Do not care about BACKUP and pg_basebackup connection
4487 if ( (uc($data[9]) eq 'STREAMING') || (uc($data[4]) eq 'WALRECEIVER') ) {
4488 my $name = $data[5];
4489 $data[6] =~ s/"//g;
4490 $name .= " - $data[6]" if ($data[6]);
4491
4492 push(@start_vals, @data) if ($#start_vals < 0);
4493
4494 # Store interval between previous run
4495 $all_stat_replication{$data[0]}{interval} = ($data[0] - $start_vals[0])/1000;
4496
4497 $all_stat_replication{$data[0]}{master_location} = &getNumericalOffset($data[10]) - &getNumericalOffset($start_vals[10]) if (! exists $all_stat_replication{$data[0]}{master_location});
4498 next if (!$data[14] && !$data[11] && !$data[12] && !$data[13]);
4499 ((&getNumericalOffset($data[10]) - &getNumericalOffset($data[14])) < 0) ? $tmp_val = 0 : $tmp_val = (&getNumericalOffset($data[10]) - &getNumericalOffset($data[14]));
4500 $all_stat_replication{$data[0]}{$name}{replay_location} = $tmp_val;
4501 ((&getNumericalOffset($data[10]) - &getNumericalOffset($data[11])) < 0) ? $tmp_val = 0 : $tmp_val = (&getNumericalOffset($data[10]) - &getNumericalOffset($data[11]));
4502 $all_stat_replication{$data[0]}{$name}{sent_location} = $tmp_val;
4503 ((&getNumericalOffset($data[10]) - &getNumericalOffset($data[12])) < 0) ? $tmp_val = 0 : $tmp_val = (&getNumericalOffset($data[10]) - &getNumericalOffset($data[12]));
4504 $all_stat_replication{$data[0]}{$name}{write_location} = $tmp_val;
4505 ((&getNumericalOffset($data[10]) - &getNumericalOffset($data[13])) < 0) ? $tmp_val = 0 : $tmp_val = (&getNumericalOffset($data[10]) - &getNumericalOffset($data[13]));
4506 $all_stat_replication{$data[0]}{$name}{flush_location} = $tmp_val;
4507
4508 @start_vals = ();
4509 push(@start_vals, @data);
4510 }
4511 }
4512 $curfh->close();
4513
4514 return $offset;
4515 }
4516
4517 # Compute graphs of replication cluster statistics
4518 sub pg_stat_replication_report
4519 {
4520 my ($src_base, $db, %data_info) = @_;
4521
4522 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
4523
4524 my %xlog_stat = ();
4525 my $tz = ($STATS_TIMEZONE*3600*1000);
4526 foreach my $t (sort {$a <=> $b} keys %all_stat_replication) {
4527 foreach my $name (sort {$a cmp $b} keys %{$all_stat_replication{$t}}) {
4528 next if ($name eq 'interval');
4529 if ($name eq 'master_location') {
4530 next if (!$all_stat_replication{$t}{interval});
4531 $all_stat_replication{$t}{master_location} ||= 0;
4532 $xlog_stat{master_location} .= '[' . ($t - $tz) . ',' . int(($all_stat_replication{$t}{master_location}||0)/$all_stat_replication{$t}{interval}) . '],';
4533 next;
4534 }
4535 $xlog_stat{$name}{replay_location} .= '[' . ($t - $tz) . ',' . ($all_stat_replication{$t}{$name}{replay_location} || 0) . '],';
4536 $xlog_stat{$name}{sent_location} .= '[' . ($t - $tz) . ',' . ($all_stat_replication{$t}{$name}{sent_location} || 0) . '],';
4537 $xlog_stat{$name}{write_location} .= '[' . ($t - $tz) . ',' . ($all_stat_replication{$t}{$name}{write_location} || 0) . '],';
4538 $xlog_stat{$name}{flush_location} .= '[' . ($t - $tz) . ',' . ($all_stat_replication{$t}{$name}{flush_location} || 0) . '],';
4539 }
4540 }
4541 %all_stat_replication = ();
4542 # return if (scalar keys %xlog_stat == 0);
4543
4544
4545 foreach my $id (sort {$a <=> $b} keys %data_info) {
4546 next if ($id ne $ID_ACTION);
4547 next if ($data_info{$id}{name} ne $REAL_ACTION);
4548 if ($data_info{$id}{name} eq 'cluster-xlog') {
4549 $xlog_stat{master_location} =~ s/,$// if (exists $xlog_stat{master_location});
4550 print &jqplot_linegraph_array($IDX++, 'cluster-xlog', \%{$data_info{$id}}, '', $xlog_stat{master_location});
4551 delete $xlog_stat{master_location} if (exists $xlog_stat{master_location});
4552
4553 } elsif ($data_info{$id}{name} eq 'cluster-replication') {
4554 my $has_data = 0;
4555 foreach my $host (sort {$a cmp $b} keys %xlog_stat) {
4556 next if ($host eq 'master_location');
4557 $has_data = 1;
4558 $xlog_stat{$host}{sent_location} =~ s/,$//;
4559 $xlog_stat{$host}{write_location} =~ s/,$//;
4560 $xlog_stat{$host}{flush_location} =~ s/,$//;
4561 $xlog_stat{$host}{replay_location} =~ s/,$//;
4562 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});
4563 }
4564 if (!$has_data) {
4565 print &jqplot_linegraph_array($IDX++, 'cluster-replication', \%{$data_info{$id}});
4566 }
4567 }
4568 }
4569 }
4570
4571 # Compute statistics of pgbouncer
4572 sub pgbouncer_stats
4573 {
4574 my ($input_dir, $file, $offset) = @_;
4575
4576 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
4577
4578 # Load data from file
4579 my $curfh = open_filehdl("$input_dir/$file");
4580 $curfh->seek($offset,0);
4581 while (my $l = <$curfh>) {
4582 $offset += length($l);
4583 my @data = split(/;/, $l);
4584 next if (!&normalize_line(\@data));
4585 next if ($data[1] eq 'pgbouncer');
4586
4587 # timestamp|database|user|cl_active|cl_waiting|sv_active|sv_idle|sv_used|sv_tested|sv_login|maxwait
4588 $all_pgbouncer_stats{$data[0]}{$data[1]}{$data[2]}{cl_active} += ($data[3] || 0);
4589 $all_pgbouncer_stats{$data[0]}{$data[1]}{$data[2]}{cl_waiting} += ($data[4] || 0);
4590 $all_pgbouncer_stats{$data[0]}{$data[1]}{$data[2]}{sv_active} += ($data[5] || 0);
4591 $all_pgbouncer_stats{$data[0]}{$data[1]}{$data[2]}{sv_idle} += ($data[6] || 0);
4592 $all_pgbouncer_stats{$data[0]}{$data[1]}{$data[2]}{sv_used} += ($data[7] || 0);
4593 $all_pgbouncer_stats{$data[0]}{$data[1]}{$data[2]}{sv_tested} += ($data[8] || 0);
4594 $all_pgbouncer_stats{$data[0]}{$data[1]}{$data[2]}{sv_login} += ($data[9] || 0);
4595 $all_pgbouncer_stats{$data[0]}{$data[1]}{$data[2]}{maxwait} += ($data[10] || 0);
4596 }
4597 $curfh->close();
4598
4599 return $offset;
4600 }
4601
4602 # Compute graphs of pgbouncer statistics
4603 sub pgbouncer_stats_report
4604 {
4605 my ($src_base, $db, %data_info) = @_;
4606
4607 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
4608
4609 my %pgbouncer_stat = ();
4610 my %total_pool = ();
4611 my $tz = ($STATS_TIMEZONE*3600*1000);
4612 foreach my $t (sort {$a <=> $b} keys %all_pgbouncer_stats) {
4613 foreach my $db (keys %{$all_pgbouncer_stats{$t}}) {
4614 foreach my $usr (keys %{$all_pgbouncer_stats{$t}{$db}}) {
4615 $pgbouncer_stat{"$db/$usr"}{cl_active} .= '[' . ($t - $tz) . ',' . ($all_pgbouncer_stats{$t}{$db}{$usr}{cl_active} || 0) . '],';
4616 $pgbouncer_stat{"$db/$usr"}{cl_waiting} .= '[' . ($t - $tz) . ',' . ($all_pgbouncer_stats{$t}{$db}{$usr}{cl_waiting} || 0) . '],';
4617 $pgbouncer_stat{"$db/$usr"}{sv_active} .= '[' . ($t - $tz) . ',' . ($all_pgbouncer_stats{$t}{$db}{$usr}{sv_active} || 0) . '],';
4618 $pgbouncer_stat{"$db/$usr"}{sv_idle} .= '[' . ($t - $tz) . ',' . ($all_pgbouncer_stats{$t}{$db}{$usr}{sv_idle} || 0) . '],';
4619 $pgbouncer_stat{"$db/$usr"}{sv_used} .= '[' . ($t - $tz) . ',' . ($all_pgbouncer_stats{$t}{$db}{$usr}{sv_used} || 0) . '],';
4620 $pgbouncer_stat{"$db/$usr"}{sv_tested} .= '[' . ($t - $tz) . ',' . ($all_pgbouncer_stats{$t}{$db}{$usr}{sv_tested} || 0) . '],';
4621 $pgbouncer_stat{"$db/$usr"}{sv_login} .= '[' . ($t - $tz) . ',' . ($all_pgbouncer_stats{$t}{$db}{$usr}{sv_login} || 0) . '],';
4622 $pgbouncer_stat{"$db/$usr"}{maxwait} .= '[' . ($t - $tz) . ',' . ($all_pgbouncer_stats{$t}{$db}{$usr}{maxwait} || 0) . '],';
4623 $total_pool{$db}{cl_active} += $all_pgbouncer_stats{$t}{$db}{$usr}{cl_active};
4624 $total_pool{$db}{cl_waiting} += $all_pgbouncer_stats{$t}{$db}{$usr}{cl_waiting};
4625 $total_pool{$db}{sv_active} += $all_pgbouncer_stats{$t}{$db}{$usr}{sv_active};
4626 $total_pool{$db}{sv_idle} += $all_pgbouncer_stats{$t}{$db}{$usr}{sv_idle};
4627 $total_pool{$db}{sv_used} += $all_pgbouncer_stats{$t}{$db}{$usr}{sv_used};
4628 $total_pool{$db}{sv_tested} += $all_pgbouncer_stats{$t}{$db}{$usr}{sv_tested};
4629 $total_pool{$db}{sv_login} += $all_pgbouncer_stats{$t}{$db}{$usr}{sv_login};
4630 $total_pool{$db}{maxwait} += $all_pgbouncer_stats{$t}{$db}{$usr}{maxwait};
4631 }
4632 $pgbouncer_stat{$db}{cl_active} .= '[' . ($t - $tz) . ',' . ($total_pool{$db}{cl_active} || 0) . '],';
4633 $pgbouncer_stat{$db}{cl_waiting} .= '[' . ($t - $tz) . ',' . ($total_pool{$db}{cl_waiting} || 0) . '],';
4634 $pgbouncer_stat{$db}{sv_active} .= '[' . ($t - $tz) . ',' . ($total_pool{$db}{sv_active} || 0) . '],';
4635 $pgbouncer_stat{$db}{sv_idle} .= '[' . ($t - $tz) . ',' . ($total_pool{$db}{sv_idle} || 0) . '],';
4636 $pgbouncer_stat{$db}{sv_used} .= '[' . ($t - $tz) . ',' . ($total_pool{$db}{sv_used} || 0) . '],';
4637 $pgbouncer_stat{$db}{sv_tested} .= '[' . ($t - $tz) . ',' . ($total_pool{$db}{sv_tested} || 0) . '],';
4638 $pgbouncer_stat{$db}{sv_login} .= '[' . ($t - $tz) . ',' . ($total_pool{$db}{sv_login} || 0) . '],';
4639 $pgbouncer_stat{$db}{maxwait} .= '[' . ($t - $tz) . ',' . ($total_pool{$db}{maxwait} || 0) . '],';
4640 # $total_pool{'all'}{cl_active} += $total_pool{$db}{cl_active};
4641 # $total_pool{'all'}{cl_waiting} += $total_pool{$db}{cl_waiting};
4642 # $total_pool{'all'}{sv_active} += $total_pool{$db}{sv_active};
4643 # $total_pool{'all'}{sv_idle} += $total_pool{$db}{sv_idle};
4644 # $total_pool{'all'}{sv_used} += $total_pool{$db}{sv_used};
4645 # $total_pool{'all'}{sv_tested} += $total_pool{$db}{sv_tested};
4646 # $total_pool{'all'}{sv_login} += $total_pool{$db}{sv_login};
4647 # $total_pool{'all'}{maxwait} += $total_pool{$db}{maxwait};
4648 delete $total_pool{$db};
4649 }
4650 # $pgbouncer_stat{'all'}{cl_active} .= '[' . ($t - $tz) . ',' . ($total_pool{'all'}{cl_active} || 0) . '],';
4651 # $pgbouncer_stat{'all'}{cl_waiting} .= '[' . ($t - $tz) . ',' . ($total_pool{'all'}{cl_waiting} || 0) . '],';
4652 # $pgbouncer_stat{'all'}{sv_active} .= '[' . ($t - $tz) . ',' . ($total_pool{'all'}{sv_active} || 0) . '],';
4653 # $pgbouncer_stat{'all'}{sv_idle} .= '[' . ($t - $tz) . ',' . ($total_pool{'all'}{sv_idle} || 0) . '],';
4654 # $pgbouncer_stat{'all'}{sv_used} .= '[' . ($t - $tz) . ',' . ($total_pool{'all'}{sv_used} || 0) . '],';
4655 # $pgbouncer_stat{'all'}{sv_tested} .= '[' . ($t - $tz) . ',' . ($total_pool{'all'}{sv_tested} || 0) . '],';
4656 # $pgbouncer_stat{'all'}{sv_login} .= '[' . ($t - $tz) . ',' . ($total_pool{'all'}{sv_login} || 0) . '],';
4657 # $pgbouncer_stat{'all'}{maxwait} .= '[' . ($t - $tz) . ',' . ($total_pool{'all'}{maxwait} || 0) . '],';
4658 }
4659
4660 # Build graph dataset for all pgbouncer pool
4661 foreach my $id (sort {$a <=> $b} keys %data_info) {
4662 next if ($id ne $ID_ACTION);
4663 foreach my $db (sort {$a cmp $b} keys %pgbouncer_stat) {
4664 next if ($DATABASE && ($db ne $DATABASE));
4665 next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB)));
4666 next if ($db eq 'all');
4667 next if ($db =~ /\//);
4668 if ($data_info{$id}{name} eq 'pgbouncer-connections') {
4669 $pgbouncer_stat{$db}{cl_active} =~ s/,$//;
4670 $pgbouncer_stat{$db}{cl_waiting} =~ s/,$//;
4671 $pgbouncer_stat{$db}{sv_active} =~ s/,$//;
4672 $pgbouncer_stat{$db}{sv_idle} =~ s/,$//;
4673 $pgbouncer_stat{$db}{sv_used} =~ s/,$//;
4674 $pgbouncer_stat{$db}{maxwait} =~ s/,$//;
4675 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});
4676 foreach my $pool (sort {$a cmp $b} keys %pgbouncer_stat) {
4677 next if ($pool !~ /^$db\//);
4678 $pgbouncer_stat{$pool}{cl_active} =~ s/,$//;
4679 $pgbouncer_stat{$pool}{cl_waiting} =~ s/,$//;
4680 $pgbouncer_stat{$pool}{sv_active} =~ s/,$//;
4681 $pgbouncer_stat{$pool}{sv_idle} =~ s/,$//;
4682 $pgbouncer_stat{$pool}{sv_used} =~ s/,$//;
4683 $pgbouncer_stat{$pool}{maxwait} =~ s/,$//;
4684 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});
4685 }
4686 print "</li>\n";
4687 }
4688 }
4689 }
4690 }
4691
4692 sub get_diff
4693 {
4694 my $file = shift;
4695 my $diff_hashref = shift;
4696
4697 return if (! -e $file);
4698
4699 my $curfh = open_filehdl($file);
4700 my $key = '';
4701 while (my $l = <$curfh>) {
4702 chomp($l);
4703 $l =~ s/\r//;
4704 next if ($l =~ /^\+\+\+/);
4705 if ($l =~ /^\-\-\-.*\s(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/) {
4706 my $tz = ((0-$TIMEZONE)*3600);
4707 $key = &timegm_nocheck($6, $5, $4, $3, $2 - 1, $1 - 1900) + $tz;
4708 delete $diff_hashref->{$key} if (exists $diff_hashref->{$key});
4709 next;
4710 }
4711 if ($key) {
4712 $diff_hashref->{$key} .= "$l\n";
4713 }
4714 }
4715 $curfh->close();
4716 }
4717
4718 sub show_diff
4719 {
4720 my %diff = @_;
4721
4722 foreach my $k (sort { $b cmp $a } keys %diff) {
4723 my $date = localtime($k);
4724 print qq{
4725 <div class="row">
4726 <div class="col-md-12">
4727 <div class="panel panel-default">
4728 <div class="panel-heading">
4729 <h4>Change on $date</h4>
4730 </div>
4731 <div class="panel-body">
4732 <div class="analysis-item row-fluid">
4733 <div class="span11">
4734 <pre>$diff{$k}</pre>
4735 </div>
4736 </div>
4737 </div>
4738 </div>
4739 </div>
4740 </div>
4741 };
4742 }
4743 }
4744
4745
4746 # Get content of pgbouncer.ini
4747 sub pgbouncer_ini
4748 {
4749 my ($input_dir, $file) = @_;
4750
4751 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
4752
4753 return if (!-e "$input_dir/pgbouncer.ini");
4754
4755 %all_pgbouncer_ini = ();
4756
4757 # Load data from file
4758 my $curfh = open_filehdl("$input_dir/$file");
4759 while (my $l = <$curfh>) {
4760 chomp($l);
4761 next if ($l !~ /^[a-z]/);
4762 $l =~ s/\s*#.*//;
4763 $all_pgbouncer_ini{content} .= "$l\n";
4764 }
4765 $curfh->close();
4766
4767 return if (!exists $all_pgbouncer_ini{content});
4768
4769 # Load change on configuration file from diff files
4770 &get_diff("$input_dir/$file.diff", \%all_pgbouncer_ini_diff);
4771
4772 }
4773
4774
4775 # Show relevant content of pgbouncer.ini
4776 sub pgbouncer_ini_report
4777 {
4778 my ($src_base, $db, %data_info) = @_;
4779
4780 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
4781
4782 my $output = $all_pgbouncer_ini{content} || '';
4783
4784 if (!$output) {
4785 $output = '<div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div>';
4786 } else {
4787 $output = "<div style=\"white-space: pre\">\n$output</div>\n";
4788 }
4789 my $id = &get_data_id('cluster-pgbouncer', %data_info);
4790 print qq{
4791 <ul id="slides">
4792 <li class="slide active-slide" id="cluster-pgbouncer-slide">
4793 <div id="cluster-pgbouncer"><br><br><br><br></div>
4794 <div class="row">
4795 <div class="col-md-12">
4796 <div class="panel panel-default">
4797 <div class="panel-heading">
4798 <h2>$data_info{$id}{menu}</h2>
4799 <p>$data_info{$id}{description}</p>
4800 </div>
4801 <div class="panel-body">
4802 <div class="analysis-item row-fluid" id="cluster-pgbouncer-report">
4803 <div class="span11">
4804 $output
4805 </div>
4806 </div>
4807 </div>
4808 </div>
4809 </div>
4810 </div>
4811 };
4812 %all_pgbouncer_ini = ();
4813
4814 &show_diff(%all_pgbouncer_ini_diff);
4815
4816 %all_pgbouncer_ini_diff = ();
4817
4818 print qq{
4819 </li>
4820 </ul>
4821 };
4822
4823 }
4824
4825 # Collect statistics about pgbouncer queries
4826 sub pgbouncer_req_stats
4827 {
4828 my ($input_dir, $file, $offset) = @_;
4829
4830 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
4831
4832 my @start_vals = ();
4833 # Load data from file
4834 my $curfh = open_filehdl("$input_dir/$file");
4835 $curfh->seek($offset,0);
4836 while (my $l = <$curfh>) {
4837 $offset += length($l);
4838 my @data = split(/;/, $l);
4839 next if (!&normalize_line(\@data));
4840 next if ($data[1] eq 'pgbouncer');
4841
4842 push(@start_vals, @data) if ($#start_vals < 0);
4843 my $tmp_val = 0;
4844
4845 # timestamp|database|total_requests|total_received|total_sent|total_query_time|avg_req|avg_recv|avg_sent|avg_query
4846 # Since 1.8:
4847 # 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
4848 if ($#data == 9) {
4849 (($data[2] - $start_vals[2]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[2] - $start_vals[2]);
4850 $all_pgbouncer_req_stats{$data[0]}{$data[1]}{total_requests} += $tmp_val;
4851 (($data[3] - $start_vals[3]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[3] - $start_vals[3]);
4852 $all_pgbouncer_req_stats{$data[0]}{$data[1]}{total_received} += $tmp_val;
4853 (($data[4] - $start_vals[4]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[4] - $start_vals[4]);
4854 $all_pgbouncer_req_stats{$data[0]}{$data[1]}{total_sent} += $tmp_val;
4855 (($data[5] - $start_vals[5]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[5] - $start_vals[5]);
4856 $all_pgbouncer_req_stats{$data[0]}{$data[1]}{total_query_time} += $tmp_val;
4857 $all_pgbouncer_req_stats{$data[0]}{$data[1]}{avg_req} += $data[6];
4858 $all_pgbouncer_req_stats{$data[0]}{$data[1]}{avg_recv} += $data[7];
4859 $all_pgbouncer_req_stats{$data[0]}{$data[1]}{avg_sent} += $data[8];
4860 $all_pgbouncer_req_stats{$data[0]}{$data[1]}{avg_query} += $data[9];
4861 } else {
4862 (($data[3] - $start_vals[3]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[3] - $start_vals[3]);
4863 $all_pgbouncer_req_stats{$data[0]}{$data[1]}{total_requests} += $tmp_val;
4864 (($data[4] - $start_vals[4]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[4] - $start_vals[4]);
4865 $all_pgbouncer_req_stats{$data[0]}{$data[1]}{total_received} += $tmp_val;
4866 (($data[5] - $start_vals[5]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[5] - $start_vals[5]);
4867 $all_pgbouncer_req_stats{$data[0]}{$data[1]}{total_sent} += $tmp_val;
4868 (($data[7] - $start_vals[7]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[7] - $start_vals[7]);
4869 $all_pgbouncer_req_stats{$data[0]}{$data[1]}{total_query_time} += $tmp_val;
4870 (($data[8] - $start_vals[8]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[8] - $start_vals[8]);
4871 $all_pgbouncer_req_stats{$data[0]}{$data[1]}{total_wait_time} += $tmp_val;
4872 $all_pgbouncer_req_stats{$data[0]}{$data[1]}{avg_query_count} += $data[10];
4873 $all_pgbouncer_req_stats{$data[0]}{$data[1]}{avg_recv} += $data[11];
4874 $all_pgbouncer_req_stats{$data[0]}{$data[1]}{avg_sent} += $data[12];
4875 $all_pgbouncer_req_stats{$data[0]}{$data[1]}{avg_query_time} += $data[14];
4876 $all_pgbouncer_req_stats{$data[0]}{$data[1]}{avg_wait_time} += $data[15];
4877 }
4878 @start_vals = ();
4879 push(@start_vals, @data);
4880 }
4881 $curfh->close();
4882
4883 return $offset;
4884 }
4885
4886 # Show report about pgbouncer queries
4887 sub pgbouncer_req_stats_report
4888 {
4889 my ($src_base, $db, %data_info) = @_;
4890
4891 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
4892
4893 my %pgbouncer_stat = ();
4894 my $tz = ($STATS_TIMEZONE*3600*1000);
4895 foreach my $t (sort {$a <=> $b} keys %all_pgbouncer_req_stats) {
4896 foreach my $db (keys %{$all_pgbouncer_req_stats{$t}}) {
4897 foreach my $k (keys %{$all_pgbouncer_req_stats{$t}{$db}}) {
4898 $pgbouncer_stat{$db}{$k} .= '[' . ($t - $tz) . ',' . $all_pgbouncer_req_stats{$t}{$db}{$k} . '],';
4899 }
4900 }
4901 }
4902 foreach my $id (sort {$a <=> $b} keys %data_info) {
4903 next if ($id ne $ID_ACTION);
4904 foreach my $db (sort {$a cmp $b} keys %pgbouncer_stat) {
4905 next if ($DATABASE && ($db ne $DATABASE));
4906 next if ($db eq 'all');
4907 next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB)));
4908 if ($data_info{$id}{name} eq 'pgbouncer-duration') {
4909 # Assure backward compatibility with old data or cache file with
4910 # pgbouncer < 1.8 avg_query have been renamed into avg_query_time
4911 if (exists $pgbouncer_stat{$db}{avg_query_time}) {
4912 if (exists $pgbouncer_stat{$db}{avg_query}) {
4913 $pgbouncer_stat{$db}{avg_query} .= $pgbouncer_stat{$db}{avg_query_time};
4914 $pgbouncer_stat{$db}{avg_query_time} = $pgbouncer_stat{$db}{avg_query};
4915 }
4916 $pgbouncer_stat{$db}{avg_query_time} =~ s/,$//;
4917 $data_info{$id}{legends} = ['avg_query_time'];
4918 print &jqplot_linegraph_array($IDX++, 'pgbouncer-duration', \%{$data_info{$id}}, $db, $pgbouncer_stat{$db}{avg_query_time});
4919 } else {
4920 $pgbouncer_stat{$db}{avg_query} =~ s/,$//;
4921 print &jqplot_linegraph_array($IDX++, 'pgbouncer-duration', \%{$data_info{$id}}, $db, $pgbouncer_stat{$db}{avg_query});
4922 }
4923 } elsif ($data_info{$id}{name} eq 'pgbouncer-number') {
4924 # Assure backward compatibility with old data or cache file with
4925 # pgbouncer < 1.8 avg_req have been renamed into avg_query_count
4926 if (exists $pgbouncer_stat{$db}{avg_query_count}) {
4927 if (exists $pgbouncer_stat{$db}{avg_req}) {
4928 $pgbouncer_stat{$db}{avg_req} .= $pgbouncer_stat{$db}{avg_query_count};
4929 $pgbouncer_stat{$db}{avg_query_count} = $pgbouncer_stat{$db}{avg_req};
4930 }
4931 $pgbouncer_stat{$db}{avg_query_count} =~ s/,$//;
4932 $data_info{$id}{legends} = ['avg_query_count'];
4933 print &jqplot_linegraph_array($IDX++, 'pgbouncer-number', \%{$data_info{$id}}, $db, $pgbouncer_stat{$db}{avg_query_count});
4934 } else {
4935 $pgbouncer_stat{$db}{avg_req} =~ s/,$//;
4936 print &jqplot_linegraph_array($IDX++, 'pgbouncer-number', \%{$data_info{$id}}, $db, $pgbouncer_stat{$db}{avg_req});
4937 }
4938 } elsif ($data_info{$id}{name} eq 'pgbouncer-wait-total') {
4939 $pgbouncer_stat{$db}{total_wait_time} =~ s/,$//;
4940 print &jqplot_linegraph_array($IDX++, 'pgbouncer-wait-total', \%{$data_info{$id}}, $db, $pgbouncer_stat{$db}{total_wait_time});
4941 } elsif ($data_info{$id}{name} eq 'pgbouncer-wait-average') {
4942 $pgbouncer_stat{$db}{avg_wait_time} =~ s/,$//;
4943 print &jqplot_linegraph_array($IDX++, 'pgbouncer-wait-average', \%{$data_info{$id}}, $db, $pgbouncer_stat{$db}{avg_wait_time});
4944 }
4945 }
4946 }
4947 }
4948
4949 # Compute graphs of object size statistics
4950 sub pg_class_size
4951 {
4952 my ($input_dir, $file) = @_;
4953
4954 %all_class_size = ();
4955
4956 my %total_class = ();
4957 # Load data from file
4958 my $curfh = open_filehdl("$input_dir/$file");
4959 while (my $l = <$curfh>) {
4960 chomp($l);
4961 next if (!$l);
4962 my @data = split(/;/, $l);
4963 next if (!&normalize_line(\@data));
4964 if ($data[4] !~ /^[a-zA-Z]$/) {
4965 print STDERR "WARNING: incompatible type of file pg_class_size.csv, the second field should be the database name\n";
4966 last;
4967 }
4968
4969 # timestamp | dbname | nspname | relname | relkind | reltuples | relpages | relsize
4970
4971 next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB)));
4972
4973 my $size = $data[6]*8192;
4974 $size = $data[7] if ($#data == 7);
4975 if ($ACTION eq 'database-info') {
4976 $total_class{$data[1]}{$data[4]}{"$data[2].$data[3]"} = '';
4977 } else {
4978 $all_class_size{$data[1]}{$data[4]}{"$data[2].$data[3]"}{size} = $size;
4979 $all_class_size{$data[1]}{$data[4]}{"$data[2].$data[3]"}{tuples} = $data[5];
4980 if ($data[5] > 0) {
4981 $all_class_size{$data[1]}{$data[4]}{"$data[2].$data[3]"}{width} = sprintf("%.2f", $size/$data[5]);
4982 } else {
4983 $all_class_size{$data[1]}{$data[4]}{"$data[2].$data[3]"}{width} = '-';
4984 }
4985 }
4986 }
4987 $curfh->close();
4988
4989 if ($ACTION eq 'database-info') {
4990 foreach my $db (sort keys %total_class) {
4991 next if ($DATABASE && ($db ne $DATABASE));
4992 next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB)));
4993 # Count the number of object
4994 foreach my $k (sort keys %RELKIND) {
4995 if (exists $total_class{$db}{$k}) {
4996 $OVERALL_STATS{'class'}{$db}{$k} = scalar keys %{$total_class{$db}{$k}};
4997 } else {
4998 $OVERALL_STATS{'class'}{$db}{$k} = 0;
4999 }
5000 }
5001 }
5002 %total_class = ();
5003 }
5004 }
5005
5006 # Compute graphs of object size statistics
5007 sub pg_class_size_report
5008 {
5009 my ($src_base, $db, %data_info) = @_;
5010
5011 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5012
5013 return if (!$db);
5014
5015 my %data = ();
5016 foreach my $id (sort {$a <=> $b} keys %data_info) {
5017 next if ($id ne $ID_ACTION);
5018 next if ($data_info{$id}{name} !~ /^(table|index)-/);
5019 my $table_header = '';
5020 my $kind = '';
5021 if ($data_info{$id}{name} eq 'table-size') {
5022 $kind = 'tables';
5023 $table_header = qq{
5024 <th>Object name</th>
5025 <th>Size</th>
5026 <th>Tuples</th>
5027 <th>Avg width</th>
5028 };
5029 } elsif ($data_info{$id}{name} eq 'index-size') {
5030 $kind = 'indexes';
5031 $table_header = qq{
5032 <th>Object name</th>
5033 <th>Size</th>
5034 <th>Tuples</th>
5035 <th>Avg width</th>
5036 };
5037 }
5038 if (scalar keys %{$all_class_size{$db}} == 0) {
5039 $table_header = qq{<td><div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div></td>};
5040 }
5041 print qq{
5042 <ul id="slides">
5043 <li class="slide active-slide" id="$data_info{$id}{name}-slide">
5044 <div id="$data_info{$id}{name}"><br/><br/><br/><br/></div>
5045 <div class="row">
5046 <div class="col-md-12">
5047 <div class="panel panel-default">
5048 <div class="panel-heading">
5049 <h2>$data_info{$id}{menu} on $db database $kind</h2>
5050 <p>$data_info{$id}{description}</p>
5051 </div>
5052 <div class="panel-body">
5053 <div class="analysis-item row-fluid" id="$db-$data_info{$id}{name}">
5054 <div class="span11">
5055 <table class="table table-striped sortable" id="$db-$data_info{$id}{name}-table">
5056 <thead>
5057 <tr>
5058 $table_header
5059 </tr>
5060 </thead>
5061 <tbody>
5062 };
5063 my $found_table_stat = 0;
5064 foreach my $k (sort keys %{$all_class_size{$db}}) {
5065 next if (($k ne 't') && ($k ne 'r') && ($data_info{$id}{name} eq 'table-size'));
5066 next if (($k ne 'i') && ($data_info{$id}{name} eq 'index-size'));
5067 my $colspan = ' colspan="5"';
5068 foreach my $tb (sort {$all_class_size{$db}{$k}{$b}{size} <=> $all_class_size{$db}{$k}{$a}{size} } keys %{$all_class_size{$db}{$k}}) {
5069 next if (!$all_class_size{$db}{$k}{$tb}{size} && !$all_class_size{$db}{$k}{$tb}{tuples});
5070 next if (($#INCLUDE_TB >= 0) && !grep(/^$tb$/, @INCLUDE_TB));
5071 my $table_data = '';
5072 if ($data_info{$id}{name} =~ /^(table|index)-size$/) {
5073 $found_table_stat = 1;
5074 foreach ('size','tuples','width') {
5075 $all_class_size{$db}{$k}{$tb}{$_} ||= 0;
5076 }
5077 $table_data = "<tr><th>$tb</th><td>" . &pretty_print_size($all_class_size{$db}{$k}{$tb}{size}) . "</td><td>" . int($all_class_size{$db}{$k}{$tb}{tuples}) . "</td><td>$all_class_size{$db}{$k}{$tb}{width}</td></tr>\n";
5078 }
5079 if ($table_data) {
5080 print $table_data;
5081 }
5082 }
5083 if (!$found_table_stat) {
5084 print qq{<tr><td$colspan><div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div></td></tr>};
5085 }
5086 }
5087 print qq{
5088 </tbody>
5089 </table>
5090 </div>
5091 </div>
5092 </div>
5093 </div>
5094 </div>
5095 </div>
5096 </li>
5097 </ul>
5098 };
5099 }
5100
5101 %all_class_size = ();
5102 }
5103
5104 # Compute graphs of locks statistics
5105 sub pg_stat_locks
5106 {
5107 my ($input_dir, $file, $offset) = @_;
5108
5109 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5110
5111 # Load data from file
5112 my $curfh = open_filehdl("$input_dir/$file");
5113 $curfh->seek($offset,0);
5114 while (my $l = <$curfh>) {
5115 $offset += length($l);
5116 my @data = split(/;/, $l);
5117 next if (!&normalize_line(\@data));
5118
5119 # timestamp|database|label|(type|mode|granted)|count
5120
5121 next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB)));
5122
5123 $data[3] = 'granted' if ($data[3] eq 't');
5124 $data[3] = 'waiting' if ($data[3] eq 'f');
5125 $all_stat_locks{$data[0]}{$data[1]}{$data[2]}{$data[3]} += $data[4];
5126 }
5127 $curfh->close();
5128
5129 return $offset;
5130 }
5131
5132 # Compute graphs of locks statistics
5133 sub pg_stat_locks_report
5134 {
5135 my ($src_base, $db, %data_info) = @_;
5136
5137 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5138
5139 return if (!$db);
5140
5141 my %locks_stat = ();
5142 my %legends = ();
5143 my $tz = ($STATS_TIMEZONE*3600*1000);
5144 foreach my $t (keys %all_stat_locks) {
5145 foreach my $lbl (keys %{$all_stat_locks{$t}{$db}}) {
5146 push(@{$legends{$db}{$lbl}}, 'waiting') if ( grep(/^waiting$/, @{$legends{$db}{$lbl}}) && (${$legends{$db}{$lbl}}[0] eq 'granted') );
5147 foreach my $k (@{$legends{$db}{$lbl}}) {
5148 $locks_stat{$db}{$lbl}{$k} .= '[' . ($t - $tz) . ',' . ($all_stat_locks{$t}{$db}{$lbl}{$k}||0) . '],';
5149 }
5150 }
5151 }
5152 %all_stat_locks = ();
5153 foreach my $id (sort {$a <=> $b} keys %data_info) {
5154 next if ($id ne $ID_ACTION);
5155 my @graph_data = ();
5156 if ($data_info{$id}{name} eq 'database-lock-types') {
5157 foreach my $k (sort keys %{$locks_stat{$db}{lock_type}}) {
5158 $locks_stat{$db}{lock_type}{$k} =~ s/,$//;
5159 push(@{$data_info{$id}{legends}}, $k);
5160 push(@graph_data, $locks_stat{$db}{lock_type}{$k});
5161 }
5162 print &jqplot_linegraph_array($IDX++, 'database-lock-types', \%{$data_info{$id}}, $db, @graph_data);
5163 } elsif ($data_info{$id}{name} eq 'database-lock-modes') {
5164 foreach my $k (sort keys %{$locks_stat{$db}{lock_mode}}) {
5165 $locks_stat{$db}{lock_mode}{$k} =~ s/,$//;
5166 push(@{$data_info{$id}{legends}}, $k);
5167 push(@graph_data, $locks_stat{$db}{lock_mode}{$k});
5168 }
5169 print &jqplot_linegraph_array($IDX++, 'database-lock-modes', \%{$data_info{$id}}, $db, @graph_data);
5170 } elsif ($data_info{$id}{name} eq 'database-lock-granted') {
5171 foreach my $k (sort keys %{$locks_stat{$db}{lock_granted}}) {
5172 $locks_stat{$db}{lock_granted}{$k} =~ s/,$//;
5173 push(@{$data_info{$id}{legends}}, $k);
5174 push(@graph_data, $locks_stat{$db}{lock_granted}{$k});
5175 }
5176 print &jqplot_linegraph_array($IDX++, 'database-lock-granted', \%{$data_info{$id}}, $db, @graph_data);
5177 }
5178 }
5179 }
5180
5181 # Compute statistics about unused index
5182 sub pg_stat_unused_indexes
5183 {
5184 my ($input_dir, $file) = @_;
5185
5186 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5187
5188 %all_stat_unused_indexes = ();
5189
5190 # Load data from file
5191 my $curfh = open_filehdl("$input_dir/$file");
5192 while (my $l = <$curfh>) {
5193 chomp($l);
5194 next if (!$l);
5195 my @data = split(/;/, $l);
5196 next if (!&normalize_line(\@data));
5197
5198 # timestamp | dbname | schemaname | relname | indexrelname | index_code
5199
5200 next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB)));
5201
5202 push(@{$all_stat_unused_indexes{$data[1]}}, [ ($data[2], $data[3], $data[4], $data[5]) ] );
5203 }
5204 $curfh->close();
5205 }
5206
5207 # Compute report about unused index
5208 sub pg_stat_unused_indexes_report
5209 {
5210 my ($src_base, $db, %data_info) = @_;
5211
5212 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5213
5214 return if (!$db);
5215
5216 my $id = &get_data_id('unused-index', %data_info);
5217
5218 my $table_header = qq{
5219 <th>Schema</th>
5220 <th>Table</th>
5221 <th>Index</th>
5222 <th>Code</th>
5223 };
5224 if (!exists $all_stat_unused_indexes{$db} || $#{$all_stat_unused_indexes{$db}} < 0) {
5225 $table_header = qq{<td><div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div></td>};
5226 }
5227 print qq{
5228 <ul id="slides">
5229 <li class="slide active-slide" id="$data_info{$id}{name}-slide">
5230 <div id="$data_info{$id}{name}"><br/><br/><br/><br/></div>
5231 <div class="row">
5232 <div class="col-md-12">
5233 <div class="panel panel-default">
5234 <div class="panel-heading">
5235 <h2>$data_info{$id}{menu} on $db database</h2>
5236 <p>$data_info{$id}{description}</p>
5237 </div>
5238 <div class="panel-body">
5239 <div class="analysis-item row-fluid" id="$db-$data_info{$id}{name}">
5240 <div class="span11">
5241 <table class="table table-striped" id="$db-$data_info{$id}{name}-table">
5242 <thead>
5243 <tr>
5244 $table_header
5245 </tr>
5246 </thead>
5247 <tbody>
5248 };
5249 foreach my $r (@{$all_stat_unused_indexes{$db}}) {
5250 print '<tr><td>', join('</td><td>', @$r), "</td></tr>\n";
5251 }
5252 print qq{
5253 </tbody>
5254 </table>
5255 </div>
5256 </div>
5257 </div>
5258 </div>
5259 </div>
5260 </li>
5261 </ul>
5262 };
5263 %all_stat_unused_indexes = ();
5264 }
5265
5266 # Compute statistics about redundant index
5267 sub pg_stat_redundant_indexes
5268 {
5269 my ($input_dir, $file) = @_;
5270
5271 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5272
5273 %all_stat_redundant_indexes = ();
5274
5275 # Load data from file
5276 my $curfh = open_filehdl("$input_dir/$file");
5277 while (my $l = <$curfh>) {
5278 chomp($l);
5279 next if (!$l);
5280 my @data = split(/;/, $l);
5281 next if (!&normalize_line(\@data));
5282
5283 # Do not report indexes when one is partial and not the other one
5284 # otherwise keep them for user recheck.
5285 next if (grep(/\bWHERE\b/i, $data[2], $data[3]) == 1);
5286
5287 # timestamp | dbname | contained | containing
5288
5289 next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB)));
5290
5291 push(@{$all_stat_redundant_indexes{$data[1]}}, [ ($data[2], $data[3]) ] );
5292 }
5293 $curfh->close();
5294 }
5295
5296 # Compute report about redundant index
5297 sub pg_stat_redundant_indexes_report
5298 {
5299 my ($src_base, $db, %data_info) = @_;
5300
5301 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5302
5303 return if (!$db);
5304
5305 my $id = &get_data_id('redundant-index', %data_info);
5306 my $table_header = qq{
5307 <th>Contained</th>
5308 <th>Containing</th>
5309 };
5310 if (!exists $all_stat_redundant_indexes{$db} || $#{$all_stat_redundant_indexes{$db}} < 0) {
5311 $table_header = qq{<td><div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div></td>};
5312 }
5313 print qq{
5314 <ul id="slides">
5315 <li class="slide active-slide" id="$data_info{$id}{name}-slide">
5316 <div id="$data_info{$id}{name}"><br/><br/><br/><br/></div>
5317 <div class="row">
5318 <div class="col-md-12">
5319 <div class="panel panel-default">
5320 <div class="panel-heading">
5321 <h2>$data_info{$id}{menu} on $db database</h2>
5322 <p>$data_info{$id}{description}</p>
5323 </div>
5324 <div class="panel-body">
5325 <div class="analysis-item row-fluid" id="$db-$data_info{$id}{name}">
5326 <div class="span11">
5327 <table class="table table-striped" id="$db-$data_info{$id}{name}-table">
5328 <thead>
5329 <tr>
5330 $table_header
5331 </tr>
5332 </thead>
5333 <tbody>
5334 };
5335 foreach my $r (@{$all_stat_redundant_indexes{$db}}) {
5336 print '<tr><td>', join('</td><td>', @$r), "</td></tr>\n";
5337 }
5338 print qq{
5339 </tbody>
5340 </table>
5341 </div>
5342 </div>
5343 </div>
5344 </div>
5345 </div>
5346 </li>
5347 </ul>
5348 };
5349 %all_stat_redundant_indexes = ();
5350 }
5351
5352 # Compute statistics about missing index
5353 sub pg_stat_missing_fkindexes
5354 {
5355 my ($input_dir, $file) = @_;
5356
5357 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5358
5359 %all_stat_missing_fkindexes = ();
5360
5361 # Load data from file
5362 my $curfh = open_filehdl("$input_dir/$file");
5363 while (my $l = <$curfh>) {
5364 chomp($l);
5365 next if (!$l);
5366 my @data = split(/;/, $l);
5367 next if (!&normalize_line(\@data));
5368
5369 # timestamp | dbname | relname | ddl
5370
5371 next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB)));
5372
5373 push(@{$all_stat_missing_fkindexes{$data[1]}}, [ ($data[2], $data[3]) ] );
5374 }
5375 $curfh->close();
5376 }
5377
5378 # Compute report about missing index
5379 sub pg_stat_missing_fkindexes_report
5380 {
5381 my ($src_base, $db, %data_info) = @_;
5382
5383 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5384
5385 return if (!$db);
5386
5387 my $id = &get_data_id('missing-index', %data_info);
5388 my $table_header = qq{
5389 <th>Table</th>
5390 <th>Missing index</th>
5391 };
5392 if (!exists $all_stat_missing_fkindexes{$db} || $#{$all_stat_missing_fkindexes{$db}} < 0) {
5393 $table_header = qq{<td><div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div></td>};
5394 }
5395 print qq{
5396 <ul id="slides">
5397 <li class="slide active-slide" id="$data_info{$id}{name}-slide">
5398 <div id="$data_info{$id}{name}"><br/><br/><br/><br/></div>
5399 <div class="row">
5400 <div class="col-md-12">
5401 <div class="panel panel-default">
5402 <div class="panel-heading">
5403 <h2>$data_info{$id}{menu} on $db database</h2>
5404 <p>$data_info{$id}{description}</p>
5405 </div>
5406 <div class="panel-body">
5407 <div class="analysis-item row-fluid" id="$db-$data_info{$id}{name}">
5408 <div class="span11">
5409 <table class="table table-striped" id="$db-$data_info{$id}{name}-table">
5410 <thead>
5411 <tr>
5412 $table_header
5413 </tr>
5414 </thead>
5415 <tbody>
5416 };
5417 foreach my $r (@{$all_stat_missing_fkindexes{$db}}) {
5418 print '<tr><td>', join('</td><td>', @$r), "</td></tr>\n";
5419 }
5420 print qq{
5421 </tbody>
5422 </table>
5423 </div>
5424 </div>
5425 </div>
5426 </div>
5427 </div>
5428 </li>
5429 </ul>
5430 };
5431 %all_stat_missing_fkindexes = ();
5432 }
5433
5434 # Compute statistics about indexes count
5435 sub pg_stat_count_indexes
5436 {
5437 my ($input_dir, $file) = @_;
5438
5439 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5440
5441 %all_stat_count_indexes = ();
5442
5443 # Load data from file
5444 my $curfh = open_filehdl("$input_dir/$file");
5445 while (my $l = <$curfh>) {
5446 chomp($l);
5447 next if (!$l);
5448 my @data = split(/;/, $l);
5449
5450 next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB)));
5451
5452 # timestamp | dbname | schema | table | count
5453 $all_stat_count_indexes{$data[1]}{$data[2]}{$data[3]} = $data[4];
5454 }
5455 $curfh->close();
5456 }
5457
5458 # Compute report about table without indexes or with too many indexes
5459 sub pg_stat_count_indexes_report
5460 {
5461 my ($src_base, $dbname, %data_info) = @_;
5462
5463 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5464
5465 return if (!$dbname);
5466
5467 foreach my $db (sort keys %all_stat_count_indexes)
5468 {
5469 next if ($db ne $dbname);
5470 next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB)));
5471
5472 my $id = &get_data_id('count-index', %data_info);
5473 print qq{
5474 <ul id="slides">
5475 <li class="slide active-slide" id="$data_info{$id}{name}-slide">
5476 <div id="$data_info{$id}{name}"><br/><br/><br/><br/></div>
5477 <div class="row">
5478 <div class="col-md-12">
5479 <div class="panel panel-default">
5480 <div class="panel-heading">
5481 <h2>$data_info{$id}{menu} on $db database</h2>
5482 <p>$data_info{$id}{description}</p>
5483 </div>
5484 <div class="panel-body">
5485 <div class="analysis-item row-fluid" id="$db-$data_info{$id}{name}">
5486 <div class="span11">
5487 <table class="table table-striped sortable" id="$db-$data_info{$id}{name}-table">
5488 <thead>
5489 <tr>
5490 <th>Schema</th>
5491 <th>table</th>
5492 <th>Number of indexes</th>
5493 </tr>
5494 </thead>
5495 <tbody>
5496 };
5497 foreach my $s (sort keys %{$all_stat_count_indexes{$db}}) {
5498 foreach my $t (sort keys %{$all_stat_count_indexes{$db}{$s}}) {
5499 next if ($all_stat_count_indexes{$db}{$s}{$t} > $MAX_INDEXES);
5500 print "<tr><td>$s</td><td>$t</td><td>$all_stat_count_indexes{$db}{$s}{$t}</td></tr>\n";
5501 }
5502 }
5503 print qq{
5504 </tbody>
5505 </table>
5506 </div>
5507 </div>
5508 </div>
5509 </div>
5510 </div>
5511 };
5512
5513 $id = &get_data_id('zero-index', %data_info);
5514 print qq{
5515 <div class="row">
5516 <div class="col-md-12">
5517 <div class="panel panel-default">
5518 <div class="panel-heading">
5519 <h2>$data_info{$id}{menu} on $db database</h2>
5520 <p>$data_info{$id}{description}</p>
5521 </div>
5522 <div class="panel-body">
5523 <div class="analysis-item row-fluid" id="$db-$data_info{$id}{name}">
5524 <div class="span11">
5525 <table class="table table-striped" id="$db-$data_info{$id}{name}-table">
5526 <thead>
5527 <tr>
5528 <th>Schema</th>
5529 <th>table</th>
5530 </tr>
5531 </thead>
5532 <tbody>
5533 };
5534 foreach my $s (sort keys %{$all_stat_count_indexes{$db}}) {
5535 foreach my $t (sort keys %{$all_stat_count_indexes{$db}{$s}}) {
5536 next if ($all_stat_count_indexes{$db}{$s}{$t} > 0);
5537 print "<tr><td>$s</td><td>$t</td></tr>\n";
5538 }
5539 }
5540 print qq{
5541 </tbody>
5542 </table>
5543 </div>
5544 </div>
5545 </div>
5546 </div>
5547 </div>
5548 </li>
5549 </ul>
5550 };
5551 }
5552 %all_stat_count_indexes = ();
5553 }
5554
5555 # Compute statistics about extended statistics
5556 sub pg_stat_ext
5557 {
5558 my ($input_dir, $file) = @_;
5559
5560 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5561
5562 %all_stat_extended_statistics = ();
5563
5564 # Load data from file
5565 my $curfh = open_filehdl("$in_dir/$file");
5566 while (my $l = <$curfh>) {
5567 chomp($l);
5568 next if (!$l);
5569 my @data = split(/;/, $l);
5570
5571 next if (($#INCLUDE_DB >= 0) && (!grep($data[1] =~ /^$_$/, @INCLUDE_DB)));
5572
5573 # timestamp | dbname | schemaname | tablename | stats_schemaname | stats_name | stats_owner | attnames | kinds
5574 push(@{$all_stat_extended_statistics{$data[1]}}, [ ($data[4], $data[5], $data[8], $data[7], $data[2], $data[3]) ] );
5575 }
5576 $curfh->close();
5577 }
5578
5579 # Compute report about extended statistics
5580 sub pg_stat_ext_report
5581 {
5582 my ($src_base, $dbname, %data_info) = @_;
5583
5584 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5585
5586 return if (!$dbname);
5587
5588 my $id = &get_data_id('table-extended', %data_info);
5589
5590 foreach my $db (sort keys %all_stat_extended_statistics) {
5591 next if ($db ne $dbname);
5592 next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB)));
5593 print qq{
5594 <ul id="slides">
5595 <div class="row">
5596 <div class="col-md-12">
5597 <div class="panel panel-default">
5598 <div class="panel-heading">
5599 <h2>$data_info{$id}{menu} on $db database</h2>
5600 <p>$data_info{$id}{description}</p>
5601 </div>
5602 <div class="panel-body">
5603 <div class="analysis-item row-fluid" id="$db-$data_info{$id}{name}">
5604 <div class="span11">
5605 <table class="table table-striped" id="$db-$data_info{$id}{name}-table">
5606 <thead>
5607 <tr>
5608 <th>Table</th>
5609 <th>Extended Statistic</th>
5610 </tr>
5611 </thead>
5612 <tbody>
5613 };
5614 my %stat_kinds = ('f' => 'dependencies', 'd' => 'ndistinct', 'm' => 'mcv');
5615 foreach my $r (sort {"$a->[4].$a->[5]" cmp "$b->[4].$b->[5]"} @{$all_stat_extended_statistics{$db}}) {
5616 $r->[2] =~ s/\{//;
5617 $r->[2] =~ s/\}//;
5618 my @skind = split(',', $r->[2]);
5619 map { s/(.*)/$stat_kinds{$1}/; } @skind;
5620 $r->[3] =~ s/\{//;
5621 $r->[3] =~ s/\}//;
5622 print "<tr><td>$r->[4].$r->[5]</td><td>CREATE STATISTICS $r->[0].$r->[1] (", join(',', @skind), ") ON $r->[3] FROM $r->[4].$r->[5];</td></tr>\n";
5623 }
5624 print qq{
5625 </tbody>
5626 </table>
5627 </div>
5628 </div>
5629 </div>
5630 </div>
5631 </div>
5632 };
5633 }
5634 %all_stat_extended_statistics = ();
5635 }
5636
5637
5638 # Get relevant content of postgresql.conf
5639 sub postgresql_conf
5640 {
5641 my ($input_dir, $file) = @_;
5642
5643 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5644
5645 %all_postgresql_conf = ();
5646
5647 # Load data from file
5648 my $curfh = open_filehdl("$input_dir/$file");
5649 while (my $l = <$curfh>) {
5650 chomp($l);
5651 next if ($l !~ /^[a-z]/);
5652 $l =~ s/\s*#.*//;
5653 $all_postgresql_conf{content} .= "$l\n";
5654 }
5655 $curfh->close();
5656
5657 return if (!exists $all_postgresql_conf{content});
5658
5659 # Load change on configuration file from diff files
5660 &get_diff("$input_dir/$file.diff", \%all_postgresql_conf_diff);
5661 }
5662
5663 # Show content of postgresql.conf
5664 sub postgresql_conf_report
5665 {
5666 my ($src_base, $db, %data_info) = @_;
5667
5668 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5669
5670 my $output = $all_postgresql_conf{content} || '';
5671
5672 if (!$output) {
5673 $output = '<div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div>';
5674 } else {
5675 $output = "<div style=\"white-space: pre\">\n$output</div>\n";
5676 }
5677 my $id = &get_data_id('cluster-pgconf', %data_info);
5678 print qq{
5679 <ul id="slides">
5680 <li class="slide active-slide" id="cluster-pgconf-slide">
5681 <div id="cluster-pgconf"><br><br><br><br></div>
5682 <div class="row">
5683 <div class="col-md-12">
5684 <div class="panel panel-default">
5685 <div class="panel-heading">
5686 <h2>$data_info{$id}{menu}</h2>
5687 <p>$data_info{$id}{description}</p>
5688 </div>
5689 <div class="panel-body">
5690 <div class="analysis-item row-fluid" id="cluster-pgconf-report">
5691 <div class="span11">
5692 $output
5693 </div>
5694 </div>
5695 </div>
5696 </div>
5697 </div>
5698 </div>
5699 };
5700
5701 %all_postgresql_conf = ();
5702
5703 &show_diff(%all_postgresql_conf_diff);
5704
5705 %all_postgresql_conf_diff = ();
5706 print qq{
5707 </li>
5708 </ul>
5709 };
5710 }
5711
5712 # Get relevant content of recovery.conf
5713 sub recovery_conf
5714 {
5715 my ($input_dir, $file) = @_;
5716
5717 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5718
5719 %all_recovery_conf = ();
5720
5721 # Load data from file
5722 my $curfh = open_filehdl("$input_dir/$file");
5723 while (my $l = <$curfh>) {
5724 chomp($l);
5725 next if ($l !~ /^[a-z]/);
5726 $l =~ s/\s*#.*//;
5727 $all_recovery_conf{content} .= "$l\n";
5728 }
5729 $curfh->close();
5730
5731 return if (!exists $all_recovery_conf{content});
5732
5733 # Load change on configuration file from diff files
5734 &get_diff("$input_dir/$file.diff", \%all_recovery_conf_diff);
5735
5736 }
5737
5738 # Show content of recovery.conf
5739 sub recovery_conf_report
5740 {
5741 my ($src_base, $db, %data_info) = @_;
5742
5743 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5744
5745 my $output = $all_recovery_conf{content} || '';
5746
5747 if (!$output) {
5748 $output = '<div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div>';
5749 } else {
5750 $output = "<div style=\"white-space: pre\">\n$output</div>\n";
5751 }
5752 my $id = &get_data_id('cluster-recoveryconf', %data_info);
5753 print qq{
5754 <ul id="slides">
5755 <li class="slide active-slide" id="cluster-recoveryconf-slide">
5756 <div id="cluster-recoveryconf"><br><br><br><br></div>
5757 <div class="row">
5758 <div class="col-md-12">
5759 <div class="panel panel-default">
5760 <div class="panel-heading">
5761 <h2>$data_info{$id}{menu}</h2>
5762 <p>$data_info{$id}{description}</p>
5763 </div>
5764 <div class="panel-body">
5765 <div class="analysis-item row-fluid" id="cluster-ercoveryconf-report">
5766 <div class="span11">
5767 $output
5768 </div>
5769 </div>
5770 </div>
5771 </div>
5772 </div>
5773 </div>
5774 };
5775
5776 %all_recovery_conf = ();
5777
5778 &show_diff(%all_recovery_conf_diff);
5779
5780 %all_recovery_conf_diff = ();
5781
5782 print qq{
5783 </li>
5784 </ul>
5785 };
5786 }
5787
5788 # Show relevant content of postgresql.auto.conf
5789 sub postgresql_auto_conf
5790 {
5791 my ($input_dir, $file) = @_;
5792
5793 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5794
5795 %all_postgresql_auto_conf = ();
5796
5797 # Load data from file
5798 my $curfh = open_filehdl("$input_dir/$file");
5799 while (my $l = <$curfh>) {
5800 chomp($l);
5801 next if ($l !~ /^[a-z]/);
5802 $l =~ s/\s*#.*//;
5803 $all_postgresql_auto_conf{content} .= "$l\n";
5804 }
5805 $curfh->close();
5806
5807 return if (!exists $all_postgresql_auto_conf{content});
5808
5809 # Load change on configuration file from diff files
5810 &get_diff("$input_dir/$file.diff", \%all_postgresql_auto_conf_diff);
5811
5812 }
5813
5814 # Show relevant content of postgresql.auto.conf
5815 sub postgresql_auto_conf_report
5816 {
5817 my ($src_base, $db, %data_info) = @_;
5818
5819 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5820
5821 my $output = $all_postgresql_auto_conf{content} || '';
5822
5823 if (!$output) {
5824 $output = '<div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div>';
5825 } else {
5826 $output = "<div style=\"white-space: pre\">\n$output</div>\n";
5827 }
5828 my $id = &get_data_id('cluster-alterconf', %data_info);
5829 print qq{
5830 <ul id="slides">
5831 <li class="slide active-slide" id="cluster-alterconf-slide">
5832 <div id="cluster-alterconf"><br><br><br><br></div>
5833 <div class="row">
5834 <div class="col-md-12">
5835 <div class="panel panel-default">
5836 <div class="panel-heading">
5837 <h2>$data_info{$id}{menu}</h2>
5838 <p>$data_info{$id}{description}</p>
5839 </div>
5840 <div class="panel-body">
5841 <div class="analysis-item row-fluid" id="cluster-alterconf-report">
5842 <div class="span11">
5843 $output
5844 </div>
5845 </div>
5846 </div>
5847 </div>
5848 </div>
5849 </div>
5850 };
5851
5852 %all_postgresql_auto_conf = ();
5853
5854 &show_diff(%all_postgresql_auto_conf_diff);
5855
5856 %all_postgresql_auto_conf_diff = ();
5857
5858 print qq{
5859
5860 </li>
5861 </ul>
5862 };
5863 }
5864
5865 # Get relevant content of pg_hba.conf
5866 sub pg_hba_conf
5867 {
5868 my ($input_dir, $file) = @_;
5869
5870 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5871
5872 %all_pg_hba_conf = ();
5873
5874 # Load data from file
5875 my $curfh = open_filehdl("$input_dir/$file");
5876 while (my $l = <$curfh>) {
5877 chomp($l);
5878 next if ($l !~ /^[a-z]/);
5879 $l =~ s/\s*#.*//;
5880 $all_pg_hba_conf{content} .= "$l\n";
5881 }
5882 $curfh->close();
5883
5884 return if (!exists $all_pg_hba_conf{content});
5885
5886 # Load change on configuration file from diff files
5887 &get_diff("$input_dir/$file.diff", \%all_pg_hba_conf_diff);
5888
5889 }
5890
5891 # Show content of pg_hba.conf
5892 sub pg_hba_conf_report
5893 {
5894 my ($src_base, $db, %data_info) = @_;
5895
5896 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5897
5898 my $output = $all_pg_hba_conf{content} || '';
5899
5900 if (!$output) {
5901 $output = '<div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div>';
5902 } else {
5903 $output = "<div style=\"white-space: pre\">\n$output</div>\n";
5904 }
5905
5906 my $id = &get_data_id('cluster-pghba', %data_info);
5907 print qq{
5908 <ul id="slides">
5909 <li class="slide active-slide" id="cluster-pghba-slide">
5910 <div id="cluster-pghba"><br><br><br><br></div>
5911
5912 <div class="row">
5913 <div class="col-md-12">
5914 <div class="panel panel-default">
5915 <div class="panel-heading">
5916 <h2>$data_info{$id}{menu}</h2>
5917 <p>$data_info{$id}{description}</p>
5918 </div>
5919 <div class="panel-body">
5920 <div class="analysis-item row-fluid" id="cluster-pghba-report">
5921 <div class="span11">
5922 $output
5923 </div>
5924 </div>
5925 </div>
5926 </div>
5927 </div>
5928 </div>
5929 };
5930
5931 %all_pg_hba_conf = ();
5932
5933 &show_diff(%all_pg_hba_conf_diff);
5934
5935 %all_pg_hba_conf_diff = ();
5936
5937 print qq{
5938 </li>
5939 </ul>
5940 };
5941 }
5942
5943 # Get relevant content of pg_ident.conf
5944 sub pg_ident_conf
5945 {
5946 my ($input_dir, $file) = @_;
5947
5948 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5949
5950 %all_pg_ident_conf = ();
5951
5952 # Load data from file
5953 my $curfh = open_filehdl("$input_dir/$file");
5954 while (my $l = <$curfh>) {
5955 chomp($l);
5956 next if ($l !~ /^[a-z]/);
5957 $l =~ s/\s*#.*//;
5958 $all_pg_ident_conf{content} .= "$l\n";
5959 }
5960 $curfh->close();
5961
5962 return if (!exists $all_pg_ident_conf{content});
5963
5964 # Load change on configuration file from diff files
5965 &get_diff("$input_dir/$file.diff", \%all_pg_ident_conf_diff);
5966
5967 }
5968
5969 # Show content of pg_ident.conf
5970 sub pg_ident_conf_report
5971 {
5972 my ($src_base, $db, %data_info) = @_;
5973
5974 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
5975
5976 my $output = $all_pg_ident_conf{content} || '';
5977
5978 if (!$output) {
5979 $output = '<div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div>';
5980 } else {
5981 $output = "<div style=\"white-space: pre\">\n$output</div>\n";
5982 }
5983 my $id = &get_data_id('cluster-pgident', %data_info);
5984 print qq{
5985 <ul id="slides">
5986 <li class="slide active-slide" id="cluster-pgident-slide">
5987 <div id="cluster-pgident"><br><br><br><br></div>
5988
5989 <div class="row">
5990 <div class="col-md-12">
5991 <div class="panel panel-default">
5992 <div class="panel-heading">
5993 <h2>$data_info{$id}{menu}</h2>
5994 <p>$data_info{$id}{description}</p>
5995 </div>
5996 <div class="panel-body">
5997 <div class="analysis-item row-fluid" id="cluster-pgident-report">
5998 <div class="span11">
5999 $output
6000 </div>
6001 </div>
6002 </div>
6003 </div>
6004 </div>
6005 </div>
6006 };
6007
6008 %all_pg_ident_conf = ();
6009
6010 &show_diff(%all_pg_ident_conf_diff);
6011
6012 %all_pg_ident_conf_diff = ();
6013
6014 print qq{
6015 </li>
6016 </ul>
6017 };
6018 }
6019
6020 # Get configuration from pg_settings
6021 sub pg_settings
6022 {
6023 my ($input_dir, $file) = @_;
6024
6025 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
6026
6027 %all_settings = ();
6028
6029 # Load data from file
6030 my $curfh = open_filehdl("$input_dir/$file");
6031 while (my $l = <$curfh>) {
6032 chomp($l);
6033 next if (!$l);
6034 my @data = split(/;/, $l);
6035 next if (!&normalize_line(\@data));
6036
6037 # timestamp | label | setting | value | unit | context | source | boot_val | reset_val | pending_restart
6038 $all_settings{$data[1]}{$data[2]}{value} = $data[3];
6039
6040 $all_settings{$data[1]}{$data[2]}{unit} = '';
6041 $all_settings{$data[1]}{$data[2]}{bootval} = '';
6042 $all_settings{$data[1]}{$data[2]}{resetval} = '';
6043 if ($#data >= 6) {
6044 $all_settings{$data[1]}{$data[2]}{unit} = $data[4];
6045 $all_settings{$data[1]}{$data[2]}{bootval} = $data[7];
6046 $all_settings{$data[1]}{$data[2]}{resetval} = $data[8];
6047 if ($#data >= 9) {
6048 $all_settings{$data[1]}{$data[2]}{pending_restart} = $data[9];
6049 }
6050 if ($data[2] eq 'data_checksums') {
6051 $OVERALL_STATS{'cluster'}{'data_checksums'} = $data[3];
6052 }
6053 }
6054 }
6055 $curfh->close();
6056
6057 # Load change on configuration file from diff files
6058 $file =~ s/\.csv/.diff/;
6059 &get_diff("$input_dir/$file", \%all_settings_diff);
6060
6061 }
6062
6063 # Show configuration from pg_settings
6064 sub pg_settings_report
6065 {
6066 my ($src_base, $db, %data_info) = @_;
6067
6068 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
6069
6070 my $id = &get_data_id('cluster-settings', %data_info);
6071 my $output = '';
6072 if (scalar keys %all_settings == 0) {
6073 $output = '<div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div>';
6074 } else {
6075 foreach my $lbl (sort keys %all_settings) {
6076 $output .= "<tr><th colspan=\"5\">$lbl</th></tr>\n";
6077 $output .= "<tr><th>Name</th><th>Current</th><th>Unit</th><th>Reset val</th><th>Boot val</th><th>Pending restart</th></tr>\n";
6078 foreach my $set (sort { lc($a) cmp lc($b) } keys %{$all_settings{$lbl}}) {
6079 $output .= "<tr><td>$set</td><td>$all_settings{$lbl}{$set}{value}</td><td>$all_settings{$lbl}{$set}{unit}</td>";
6080 if ($all_settings{$lbl}{$set}{resetval}) {
6081 $output .= "<td>$all_settings{$lbl}{$set}{resetval}</td>";
6082 } else {
6083 $output .= "<td></td>";
6084 }
6085 if ($all_settings{$lbl}{$set}{bootval}) {
6086 $output .= "<td>$all_settings{$lbl}{$set}{bootval}</td>";
6087 } else {
6088 $output .= "<td></td>";
6089 }
6090 if (exists $all_settings{$lbl}{$set}{pending_restart}) {
6091 if ($all_settings{$lbl}{$set}{pending_restart} eq 't') {
6092 $output .= "<td><b>$all_settings{$lbl}{$set}{pending_restart}</b></td>";
6093 } else {
6094 $output .= "<td>$all_settings{$lbl}{$set}{pending_restart}</td>";
6095 }
6096 } else {
6097 $output .= "<td>n/a</td>";
6098 }
6099 $output .= "</tr>\n";
6100 }
6101 }
6102 $output = "<table class=\"table table-striped\" id=\"$data_info{$id}{name}-table\"><tbody>\n$output</tbody></table>\n";
6103 %all_settings = ();
6104 }
6105 %all_settings = ();
6106
6107 print qq{
6108 <ul id="slides">
6109 <li class="slide active-slide" id="cluster-settings-slide">
6110 <div id="cluster-settings"><br><br><br><br></div>
6111
6112 <div class="row">
6113 <div class="col-md-12">
6114 <div class="panel panel-default">
6115 <div class="panel-heading">
6116 <h2>$data_info{$id}{menu}</h2>
6117 <p>$data_info{$id}{description}</p>
6118 </div>
6119 <div class="panel-body">
6120 <div class="analysis-item row-fluid" id="$data_info{$id}{name}-report">
6121 <div class="span11">
6122 $output
6123 </div>
6124 </div>
6125 </div>
6126 </div>
6127 </div>
6128 </div>
6129 };
6130
6131 &show_diff(%all_settings_diff);
6132
6133 %all_settings_diff = ();
6134
6135 print qq{
6136 </li>
6137 </ul>
6138 };
6139
6140 }
6141
6142 # Get non default configuration from pg_settings
6143 sub pg_nondefault_settings
6144 {
6145 my ($input_dir, $file) = @_;
6146
6147 %all_nondefault_settings = ();
6148
6149 # Load data from file
6150 my $curfh = open_filehdl("$input_dir/$file");
6151 while (my $l = <$curfh>) {
6152 chomp($l);
6153 next if (!$l);
6154 my @data = split(/;/, $l);
6155 next if (!&normalize_line(\@data));
6156
6157 # timestamp | label | setting | value
6158 $all_nondefault_settings{$data[1]}{$data[2]}{value} = $data[3];
6159 $all_nondefault_settings{$data[1]}{$data[2]}{unit} = '';
6160 $all_nondefault_settings{$data[1]}{$data[2]}{bootval} = '';
6161 $all_nondefault_settings{$data[1]}{$data[2]}{resetval} = '';
6162 if ($#data >= 6) {
6163 $all_nondefault_settings{$data[1]}{$data[2]}{unit} = $data[4];
6164 $all_nondefault_settings{$data[1]}{$data[2]}{bootval} = $data[7];
6165 $all_nondefault_settings{$data[1]}{$data[2]}{resetval} = $data[8];
6166 }
6167 }
6168 $curfh->close();
6169 }
6170
6171 # Show non default configuration from pg_settings
6172 sub pg_nondefault_settings_report
6173 {
6174 my ($src_base, %data_info) = @_;
6175
6176 return if (scalar keys %all_nondefault_settings == 0);
6177
6178 my $id = &get_data_id('cluster-nondefault-settings', %data_info);
6179 print qq{
6180 <li style="display: none;" class="slide" id="cluster-nondefault-settings-slide">
6181 <div id="cluster-nondefault-settings"><br><br><br><br></div>
6182
6183 <div class="row">
6184 <div class="col-md-12">
6185 <div class="panel panel-default">
6186 <div class="panel-heading">
6187 <h2>$data_info{$id}{menu}</h2>
6188 <p>$data_info{$id}{description}</p>
6189 </div>
6190 <div class="panel-body">
6191 <div class="analysis-item row-fluid" id="$data_info{$id}{name}-report">
6192 <div class="span11">
6193 <table class="table table-striped" id="$data_info{$id}{name}-table">
6194 <tbody>
6195 };
6196 foreach my $lbl (sort keys %all_nondefault_settings) {
6197 print "<tr><th colspan=\"5\">$lbl</th></tr>\n";
6198 print "<tr><th>Name</th><th>Current</th><th>Unit</th><th>Reset val</th><th>Boot val</th></tr>\n";
6199 foreach my $set (sort { lc($a) cmp lc($b) } keys %{$all_nondefault_settings{$lbl}}) {
6200 print "<tr><td>$set</td><td>$all_nondefault_settings{$lbl}{$set}{value}</td><td>$all_nondefault_settings{$lbl}{$set}{unit}</td>";
6201 if ($all_nondefault_settings{$lbl}{$set}{resetval}) {
6202 print "<td>$all_nondefault_settings{$lbl}{$set}{resetval}</td>";
6203 } else {
6204 print "<td></td>";
6205 }
6206 if ($all_nondefault_settings{$lbl}{$set}{bootval}) {
6207 print "<td>$all_nondefault_settings{$lbl}{$set}{bootval}</td>";
6208 } else {
6209 print "<td></td>";
6210 }
6211 print "</tr>\n";
6212 }
6213 }
6214 print qq{
6215 </tbody>
6216 </table>
6217 </div>
6218 </div>
6219 </div>
6220 </div>
6221 </div>
6222 </div>
6223 </li>
6224 };
6225 %all_nondefault_settings = ();
6226 }
6227
6228 # Get configuration from pg_db_role_setting
6229 sub pg_db_role_setting
6230 {
6231 my ($input_dir, $file) = @_;
6232
6233 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
6234
6235 %all_db_role_setting = ();
6236
6237 # Load data from file
6238 my $curfh = open_filehdl("$input_dir/$file");
6239 while (my $l = <$curfh>) {
6240 chomp($l);
6241 next if (!$l);
6242 my @data = split(/;/, $l);
6243 next if (!&normalize_line(\@data));
6244
6245 # timestamp | database | role | settings
6246 $data[1] ||= 'All';
6247 $data[2] ||= 'All';
6248 $all_db_role_setting{$data[1]}{$data[2]} = $data[3];
6249 }
6250 $curfh->close();
6251
6252 # Load change on configuration file from diff files
6253 $file =~ s/\.csv/.diff/;
6254 &get_diff("$input_dir/$file", \%all_db_role_setting_diff);
6255
6256 }
6257
6258 # Show configuration from pg_db_role_setting
6259 sub pg_db_role_setting_report
6260 {
6261 my ($src_base, $db, %data_info) = @_;
6262
6263 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
6264
6265 my $id = &get_data_id('cluster-dbrolesetting', %data_info);
6266 my $output = '';
6267 if (scalar keys %all_db_role_setting == 0) {
6268 $output = '<div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div>';
6269 } else {
6270
6271 $output = "<table class=\"table table-striped\" id=\"$data_info{$id}{name}-table\"><tbody>\n";
6272 $output .= "<tr><th>Database</th><th>Role</th><th>Settings</th></tr>\n";
6273 foreach my $db (sort keys %all_db_role_setting) {
6274 next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB)));
6275 foreach my $set (sort { lc($a) cmp lc($b) } keys %{$all_db_role_setting{$db}}) {
6276 $output .= "<tr><td>$db</td><td>$set</td><td>$all_db_role_setting{$db}{$set}</td></tr>\n";
6277 }
6278 }
6279 $output .= "</tbody></table>\n";
6280 %all_db_role_setting = ();
6281 }
6282
6283 print qq{
6284 <ul id="slides">
6285 <li class="slide active-slide" id="cluster-dbrolesetting-slide">
6286 <div id="cluster-dbrolesetting"><br><br><br><br></div>
6287
6288 <div class="row">
6289 <div class="col-md-12">
6290 <div class="panel panel-default">
6291 <div class="panel-heading">
6292 <h2>$data_info{$id}{menu}</h2>
6293 <p>$data_info{$id}{description}</p>
6294 </div>
6295 <div class="panel-body">
6296 <div class="analysis-item row-fluid" id="$data_info{$id}{name}-report">
6297 <div class="span11">
6298 $output
6299 </div>
6300 </div>
6301 </div>
6302 </div>
6303 </div>
6304 </div>
6305 };
6306
6307 &show_diff(%all_db_role_setting_diff);
6308
6309 %all_db_role_setting_diff = ();
6310
6311 print qq{
6312 </li>
6313 </ul>
6314 };
6315 %all_db_role_setting = ();
6316 }
6317
6318
6319 # Compute statistics of buffercache database
6320 sub pg_database_buffercache
6321 {
6322 my ($input_dir, $file, $offset) = @_;
6323
6324 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
6325
6326 my %db_list = ();
6327
6328 # Load data from file
6329 my $curfh = open_filehdl("$input_dir/$file");
6330 $curfh->seek($offset,0);
6331 while (my $l = <$curfh>) {
6332 $offset += length($l);
6333 my @data = split(/;/, $l);
6334 next if (!&normalize_line(\@data));
6335
6336 # Store list of database
6337 $db_list{$data[1]} = 1;
6338
6339 # date_trunc | datname | buffers | buffered | buffers % | database %
6340 $all_database_buffercache{$data[0]}{$data[1]}{shared_buffers_used} = ($data[4]||0);
6341 $all_database_buffercache{$data[0]}{$data[1]}{database_loaded} = ($data[5]||0);
6342 $all_database_buffercache{$data[0]}{'all'}{shared_buffers_used} += ($data[4]||0);
6343 $all_database_buffercache{$data[0]}{'all'}{database_loaded} += ($data[5]||0);
6344 }
6345 $curfh->close();
6346
6347 # Store the full list of database
6348 foreach my $d (keys %db_list) {
6349 push(@global_databases, $d) if (!grep/^$d$/, @global_databases);
6350 }
6351 push(@global_databases, 'all') if (($#global_databases >= 0) && !grep(/^all$/, @global_databases));
6352
6353 return $offset;
6354 }
6355
6356 # Compute report of buffercache database statistics
6357 sub pg_database_buffercache_report
6358 {
6359 my ($src_base, $db_glob, %data_info) = @_;
6360
6361 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
6362
6363 my %shared_stat = ();
6364 my $tz = ($STATS_TIMEZONE*3600*1000);
6365 foreach my $t (sort keys %all_database_buffercache) {
6366 foreach my $db (@global_databases) {
6367 next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB)));
6368 $shared_stat{$db}{shared_buffers_used} .= '[' . ($t - $tz) . ',' . ($all_database_buffercache{$t}{$db}{shared_buffers_used}||0) . '],';
6369 $shared_stat{$db}{database_loaded} .= '[' . ($t - $tz) . ',' . ($all_database_buffercache{$t}{$db}{database_loaded}||0) . '],';
6370 }
6371 }
6372 %all_database_buffercache = ();
6373 foreach my $id (sort {$a <=> $b} keys %data_info) {
6374 next if ($id ne $ID_ACTION);
6375 if ($data_info{$id}{name} eq 'cluster-buffersused') {
6376 my @graph_data = ();
6377 foreach my $db (sort keys %shared_stat) {
6378 next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB)));
6379 push(@{$data_info{$id}{legends}}, "% used by $db");
6380 $shared_stat{$db}{shared_buffers_used} =~ s/,$//;
6381 push(@graph_data, $shared_stat{$db}{shared_buffers_used});
6382 }
6383 print &jqplot_linegraph_array($IDX++, 'cluster-buffersused', \%{$data_info{$id}}, '', @graph_data);
6384 } elsif ($data_info{$id}{name} eq 'cluster-databaseloaded') {
6385 my @graph_data = ();
6386 foreach my $db (sort keys %shared_stat) {
6387 next if ($db eq 'all');
6388 next if (($db ne 'all') && ($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB)));
6389 push(@{$data_info{$id}{legends}}, "% of $db");
6390 $shared_stat{$db}{database_loaded} =~ s/,$//;
6391 push(@graph_data, $shared_stat{$db}{database_loaded});
6392 }
6393 print &jqplot_linegraph_array($IDX++, 'cluster-databaseloaded', \%{$data_info{$id}}, '', @graph_data);
6394 }
6395 }
6396 }
6397
6398 # Compute statistics of usagecount in shared buffers
6399 sub pg_database_usagecount
6400 {
6401 my ($input_dir, $file, $offset) = @_;
6402
6403 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
6404
6405 # Load data from file
6406 my $curfh = open_filehdl("$input_dir/$file");
6407 $curfh->seek($offset,0);
6408 while (my $l = <$curfh>) {
6409 $offset += length($l);
6410 my @data = split(/;/, $l);
6411 next if (!&normalize_line(\@data));
6412
6413 # date_trunc | datname | usagecount | buffer | buffers %
6414 $all_database_usagecount{$data[0]}{$data[2]} += ($data[4]||0);
6415 }
6416 $curfh->close();
6417
6418 return $offset;
6419 }
6420
6421 # Compute graph of usagecount in shared buffers
6422 sub pg_database_usagecount_report
6423 {
6424 my ($src_base, $db, %data_info) = @_;
6425
6426 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
6427
6428 my %shared_stat = ();
6429 my $tz = ($STATS_TIMEZONE*3600*1000);
6430 foreach my $t (sort keys %all_database_usagecount) {
6431 foreach my $u (sort keys %{$all_database_usagecount{$t}}) {
6432 $shared_stat{$u}{usagecount} .= '[' . ($t - $tz) . ',' . $all_database_usagecount{$t}{$u} . '],';
6433 }
6434 }
6435 %all_database_usagecount = ();
6436 foreach my $id (sort {$a <=> $b} keys %data_info) {
6437 next if ($id ne $ID_ACTION);
6438 if ($data_info{$id}{name} eq 'cluster-usagecount') {
6439 my @graph_data = ();
6440 foreach my $u (sort keys %shared_stat) {
6441 push(@{$data_info{$id}{legends}}, "% of usagecount $u");
6442 $shared_stat{$u}{usagecount} =~ s/,$//;
6443 push(@graph_data, $shared_stat{$u}{usagecount});
6444 }
6445 print &jqplot_linegraph_array($IDX++, 'cluster-usagecount', \%{$data_info{$id}}, '', @graph_data);
6446 }
6447 }
6448 }
6449
6450 # Compute statistics of dirty buffer in cache
6451 sub pg_database_isdirty
6452 {
6453 my ($input_dir, $file, $offset) = @_;
6454
6455 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
6456
6457 # Load data from file
6458 my $curfh = open_filehdl("$input_dir/$file");
6459 $curfh->seek($offset,0);
6460 while (my $l = <$curfh>) {
6461 $offset += length($l);
6462 my @data = split(/;/, $l);
6463 next if (!&normalize_line(\@data));
6464 # date_trunc | datname | usagecount | isdirty | buffer | buffers %
6465 $all_database_isdirty{$data[0]}{$data[2]} += $data[5] if ($data[3] eq 't');
6466 }
6467 $curfh->close();
6468
6469 return $offset;
6470 }
6471
6472 # Compute graphs of dirty buffer in cache
6473 sub pg_database_isdirty_report
6474 {
6475 my ($src_base, $db, %data_info) = @_;
6476
6477 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
6478
6479 my %shared_stat = ();
6480 my $tz = ($STATS_TIMEZONE*3600*1000);
6481 foreach my $t (sort keys %all_database_isdirty) {
6482 foreach my $u (sort keys %{$all_database_isdirty{$t}}) {
6483 $shared_stat{$u}{usagecount} .= '[' . ($t - $tz) . ',' . $all_database_isdirty{$t}{$u} . '],';
6484 }
6485 }
6486 %all_database_isdirty = ();
6487 foreach my $id (sort {$a <=> $b} keys %data_info) {
6488 next if ($id ne $ID_ACTION);
6489 if ($data_info{$id}{name} eq 'cluster-isdirty') {
6490 my @graph_data = ();
6491 foreach my $u (sort keys %shared_stat) {
6492 push(@{$data_info{$id}{legends}}, "% of usagecount $u");
6493 $shared_stat{$u}{usagecount} =~ s/,$//;
6494 push(@graph_data, $shared_stat{$u}{usagecount});
6495 }
6496 print &jqplot_linegraph_array($IDX++, 'cluster-isdirty', \%{$data_info{$id}}, '', @graph_data);
6497 }
6498 }
6499 }
6500
6501 # Compute statistics of archiver
6502 sub pg_stat_archiver
6503 {
6504 my ($input_dir, $file, $offset) = @_;
6505
6506 my @start_vals = ();
6507 # Load data from file
6508 my $curfh = open_filehdl("$input_dir/$file");
6509 $curfh->seek($offset,0);
6510 while (my $l = <$curfh>) {
6511 $offset += length($l);
6512 my @data = split(/;/, $l);
6513 next if (!&normalize_line(\@data));
6514
6515 # timestamp | archived_count | last_archived_wal | last_archived_time | failed_count | last_failed_wal | last_failed_time | stats_reset
6516 push(@start_vals, @data) if ($#start_vals < 0);
6517
6518 $data[3] =~ s/\..*//;
6519 $data[6] =~ s/\..*//;
6520 $data[7] =~ s/\..*//;
6521
6522 # Get archiver size statistics
6523 if ( ($ACTION ne 'home') && ($ACTION ne 'database-info') ) {
6524 my $tmp_val = '';
6525 (($data[1] - $start_vals[1]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[1] - $start_vals[1]);
6526 $all_stat_archiver{$data[0]}{archived_count} = $tmp_val;
6527 (($data[4] - $start_vals[4]) < 0) ? $tmp_val = 0 : $tmp_val = ($data[4] - $start_vals[4]);
6528 $all_stat_archiver{$data[0]}{failed_count} = $tmp_val;
6529 $all_stat_archiver{$data[0]}{last_archived_wal} = $data[2];
6530 $all_stat_archiver{$data[0]}{last_archived_time} = $data[3];
6531 $all_stat_archiver{$data[0]}{last_failed_wal} = $data[5];
6532 $all_stat_archiver{$data[0]}{last_failed_time} = $data[6];
6533 $all_stat_archiver{$data[0]}{stats_reset} = $data[7];
6534 } else {
6535 if (!$OVERALL_STATS{'archiver'}{last_archived_time} || ($data[3] gt $OVERALL_STATS{'archiver'}{last_archived_time})) {
6536 $OVERALL_STATS{'archiver'}{last_archived_wal} = $data[2];
6537 $OVERALL_STATS{'archiver'}{last_archived_time} = $data[3];
6538 }
6539 if (!$OVERALL_STATS{'archiver'}{last_failed_time} || ($data[6] gt $OVERALL_STATS{'archiver'}{last_failed_time})) {
6540 $OVERALL_STATS{'archiver'}{last_failed_wal} = $data[5];
6541 $OVERALL_STATS{'archiver'}{last_failed_time} = $data[6];
6542 }
6543 if (!$OVERALL_STATS{'archiver'}{stats_reset} || ($data[7] gt $OVERALL_STATS{'archiver'}{stats_reset})) {
6544 $OVERALL_STATS{'archiver'}{stats_reset} = $data[7];
6545 }
6546 }
6547
6548 @start_vals = ();
6549 push(@start_vals, @data);
6550 }
6551 $curfh->close();
6552
6553 return $offset;
6554 }
6555
6556 # Compute graphs of archiver statistics
6557 sub pg_stat_archiver_report
6558 {
6559 my ($src_base, $db, %data_info) = @_;
6560
6561 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
6562
6563 my %archiver_stat = ();
6564 my $tz = ($STATS_TIMEZONE*3600*1000);
6565 foreach my $t (sort {$a <=> $b} keys %all_stat_archiver) {
6566 $archiver_stat{archived_count} .= '[' . ($t - $tz) . ',' . $all_stat_archiver{$t}{archived_count}. '],';
6567 $archiver_stat{failed_count} .= '[' . ($t - $tz) . ',' . $all_stat_archiver{$t}{failed_count}. '],';
6568 }
6569 %all_stat_archiver = ();
6570 foreach my $id (sort {$a <=> $b} keys %data_info) {
6571 next if ($id ne $ID_ACTION);
6572 if ($data_info{$id}{name} eq 'cluster-archive') {
6573 print &jqplot_linegraph_array($IDX++, 'cluster-archive', \%{$data_info{$id}}, '', $archiver_stat{archived_count}, $archiver_stat{failed_count});
6574 }
6575 }
6576 }
6577
6578 # Compute graphs of statements statistics
6579 sub pg_stat_statements
6580 {
6581 my ($input_dir, $file) = @_;
6582
6583 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
6584
6585 my $total_val = 0;
6586 my @start_vals = ();
6587 my $has_temp = 0;
6588
6589 %all_stat_statements = ();
6590
6591 # Load data from file
6592 my $curfh = open_filehdl("$input_dir/$file");
6593 while (my $l = <$curfh>) {
6594 chomp($l);
6595 next if (!$l);
6596 my @data = split(/;/, $l);
6597 next if (!&normalize_line(\@data));
6598
6599 next if (($#INCLUDE_DB >= 0) && (!grep($data[2] =~ /^$_$/, @INCLUDE_DB)));
6600
6601 # pg 8.4
6602 # timestamp | userid | datname | query | calls | total_time | rows
6603 # pg 9.0-9.1
6604 # 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
6605 # pg 9.2+
6606 # 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 |
6607
6608 my $id = 3;
6609 next if (!$data[$id]);
6610
6611 $all_stat_statements{$data[2]}{$data[$id]}{calls} = ($data[$id+1] || 0);
6612 $all_stat_statements{$data[2]}{$data[$id]}{total_time} = ($data[$id+2] || 0);
6613 $all_stat_statements{$data[2]}{$data[$id]}{rows} = ($data[$id+3] || 0);
6614 if ($#data > 6) {
6615 $all_stat_statements{$data[2]}{$data[$id]}{shared_blks_hit} = $data[$id+4];
6616 $all_stat_statements{$data[2]}{$data[$id]}{shared_blks_read} = $data[$id+5];
6617 if ($#data < 18) {
6618 $all_stat_statements{$data[2]}{$data[$id]}{shared_blks_written} = $data[$id+6];
6619 $all_stat_statements{$data[2]}{$data[$id]}{local_blks_hit} = $data[$id+7];
6620 $all_stat_statements{$data[2]}{$data[$id]}{local_blks_read} = $data[$id+8];
6621 $all_stat_statements{$data[2]}{$data[$id]}{local_blks_written} = $data[$id+9];
6622 $all_stat_statements{$data[2]}{$data[$id]}{temp_blks_read} = $data[$id+10];
6623 $all_stat_statements{$data[2]}{$data[$id]}{temp_blks_written} = $data[$id+11];
6624 # This is just a flag, the total_time key is not used but must exists to not generate
6625 # error on use of unitialised value later. This is ugly but useful
6626 $all_stat_statements{$data[2]}{has_temp}{total_time} = 1;
6627 } else {
6628 $all_stat_statements{$data[2]}{$data[$id]}{shared_blks_dirtied} = ($data[$id+6]*8192);
6629 $all_stat_statements{$data[2]}{$data[$id]}{shared_blks_written} = $data[$id+7];
6630 $all_stat_statements{$data[2]}{$data[$id]}{local_blks_hit} = $data[$id+8];
6631 $all_stat_statements{$data[2]}{$data[$id]}{local_blks_read} = $data[$id+9];
6632 $all_stat_statements{$data[2]}{$data[$id]}{local_blks_dirtied} = $data[$id+10];
6633 $all_stat_statements{$data[2]}{$data[$id]}{local_blks_written} = $data[$id+11];
6634 $all_stat_statements{$data[2]}{$data[$id]}{temp_blks_read} = ($data[$id+12]*8192);
6635 $all_stat_statements{$data[2]}{$data[$id]}{temp_blks_written} = ($data[$id+13]*8192);
6636 $all_stat_statements{$data[2]}{$data[$id]}{blk_read_time} = $data[$id+14];
6637 $all_stat_statements{$data[2]}{$data[$id]}{blk_write_time} = $data[$id+15];
6638 # This is just a flag, the total_time key is not used but must exists to not generate
6639 # error on use of unitialised value later. This is ugly but useful
6640 $all_stat_statements{$data[2]}{has_temp}{total_time} = 2;
6641 if ($data[$id+14] || $data[$id+15]) {
6642 $all_stat_statements{$data[2]}{has_temp}{total_time} = 3;
6643 }
6644 }
6645 }
6646
6647 }
6648 $curfh->close();
6649 }
6650
6651 # Compute graphs of statements statistics
6652 sub pg_stat_statements_report
6653 {
6654 my ($src_base, $db, %data_info) = @_;
6655
6656 return if ( ($ACTION eq 'home') || ($ACTION eq 'database-info') );
6657
6658 return if (!$db);
6659
6660 my $id = &get_data_id('database-queries', %data_info);
6661 my $header = '';
6662 if (exists $all_stat_statements{$db}) {
6663 if (exists $all_stat_statements{$db}{has_temp}) {
6664 $header .= qq{<th>Temp blocks written</th>};
6665 }
6666 if ($all_stat_statements{$db}{has_temp}{total_time} >= 2) {
6667 $header .= qq{<th>Blocks read</th><th>Blocks hit</th><th>Blocks dirtied</th><th>Blocks written</th>};
6668 }
6669 if ($all_stat_statements{$db}{has_temp}{total_time} == 3) {
6670 $header .= qq{<th>I/O time</th>};
6671 }
6672 $header = qq{<th>Calls</th><th>Avg time</th><th>Total time</th><th>Rows</th>$header<th>Query</th>};
6673 } else {
6674 $header = qq{<td><div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div></td>};
6675 }
6676
6677 print qq{
6678 <li class="slide active-slide" id="database-queries-slide">
6679 <div id="database-queries"><br/><br/><br/><br/></div>
6680
6681 <div class="row">
6682 <div class="col-md-12">
6683 <div class="panel panel-default">
6684 <div class="panel-heading">
6685 <h2>$data_info{$id}{menu} on $db database</h2>
6686 <p>$data_info{$id}{description}</p>
6687 </div>
6688 <div class="panel-body">
6689 <div class="analysis-item row-fluid" id="$db-$data_info{$id}{name}">
6690 <div class="span11">
6691 <table class="table table-striped sortable" id="$db-$data_info{$id}{name}-table">
6692 <thead>
6693 <tr>
6694 $header
6695 </tr>
6696 </thead>
6697 <tbody>
6698 };
6699 foreach my $q (sort {$all_stat_statements{$db}{$b}{total_time} <=> $all_stat_statements{$db}{$a}{total_time}} keys %{$all_stat_statements{$db}}) {
6700 next if ($q eq 'has_temp');
6701 my $additional_cols = '';
6702 if (exists $all_stat_statements{$db}{has_temp}) {
6703 $additional_cols = "<td>" . &pretty_print_number($all_stat_statements{$db}{$q}{temp_blks_written}) . "</td>";
6704 }
6705 if ($all_stat_statements{$db}{has_temp}{total_time} == 2) {
6706 $additional_cols .= "<td>" . &pretty_print_number($all_stat_statements{$db}{$q}{shared_blks_read}) . "</td><td>" . &pretty_print_number($all_stat_statements{$db}{$q}{shared_blks_hit}) . "</td><td>" . &pretty_print_number($all_stat_statements{$db}{$q}{shared_blks_dirtied}) . "</td><td>" . &pretty_print_number($all_stat_statements{$db}{$q}{shared_blks_written}) . "</td>";
6707 }
6708 if ($all_stat_statements{$db}{has_temp}{total_time} == 3) {
6709 $additional_cols .= "<td>" . 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)) . "</td>";
6710 }
6711
6712 my $query = $q;
6713 $query =~ s/#SMCLN#/;/g;
6714 print "<tr><td>$all_stat_statements{$db}{$q}{calls}</td><td>" . &format_duration(int($all_stat_statements{$db}{$q}{total_time}/($all_stat_statements{$db}{$q}{calls}||1))) . "</td><td>" . &format_duration($all_stat_statements{$db}{$q}{total_time}) . "</td><td>$all_stat_statements{$db}{$q}{rows}</td>$additional_cols<th>$query</th></tr>\n";
6715 }
6716 print qq{
6717 </tbody>
6718 </table>
6719 </div>
6720 </div>
6721 </div>
6722 </div>
6723 </div>
6724 </div>
6725 </li>
6726 };
6727 %all_stat_statements = ();
6728
6729 }
6730
6731 sub normalize_line
6732 {
6733 my $data = shift;
6734
6735 # Get position of the database name
6736 my $pos = shift;
6737 $pos ||= 2;
6738
6739 return 0 if ($data->[0] !~ /^\d+/);
6740
6741 $data->[0] = &convert_time($data->[0]);
6742
6743 # Skip unwanted lines
6744 return 0 if ($BEGIN && ($data->[0] < $BEGIN));
6745 return 0 if ($END && ($data->[0] > $END));
6746
6747 chomp($data->[-1]);
6748 map { s/,/\./g; s/^$/0/; } @$data;
6749
6750 # Always skip default template database
6751 return 0 if ($data->[$pos] =~ /template/);
6752
6753 return 1;
6754 }
6755
6756 sub pretty_print_size
6757 {
6758 my $val = shift;
6759 return 0 if (!$val);
6760 return '-' if ($val eq '-');
6761
6762 if ($val >= 1125899906842624) {
6763 $val = ($val / 1125899906842624);
6764 $val = sprintf("%0.2f", $val) . " PB";
6765 } elsif ($val >= 1099511627776) {
6766 $val = ($val / 1099511627776);
6767 $val = sprintf("%0.2f", $val) . " TB";
6768 } elsif ($val >= 1073741824) {
6769 $val = ($val / 1073741824);
6770 $val = sprintf("%0.2f", $val) . " GB";
6771 } elsif ($val >= 1048576) {
6772 $val = ($val / 1048576);
6773 $val = sprintf("%0.2f", $val) . " MB";
6774 } elsif ($val >= 1024) {
6775 $val = ($val / 1024);
6776 $val = sprintf("%0.2f", $val) . " KB";
6777 } else {
6778 $val = $val . " B";
6779 }
6780
6781 return $val;
6782 }
6783
6784 sub pretty_print_number
6785 {
6786 my $val = shift;
6787 return 0 if (!$val);
6788 return '-' if ($val eq '-');
6789
6790 if ($val >= 1000000000000000) {
6791 $val = ($val / 1000000000000000);
6792 $val = sprintf("%0.2f", $val) . " P";
6793 } elsif ($val >= 1000000000000) {
6794 $val = ($val / 1000000000000);
6795 $val = sprintf("%0.2f", $val) . " T";
6796 } elsif ($val >= 1000000000) {
6797 $val = ($val / 1000000000);
6798 $val = sprintf("%0.2f", $val) . " G";
6799 } elsif ($val >= 1000000) {
6800 $val = ($val / 1000000);
6801 $val = sprintf("%0.2f", $val) . " M";
6802 } elsif ($val >= 1000) {
6803 $val = ($val / 1000);
6804 $val = sprintf("%0.2f", $val) . " K";
6805 }
6806
6807 return $val;
6808 }
6809
6810
6811 sub show_home
6812 {
6813 my $input_dir = shift();
6814
6815 # Compute global statistics for home page dashboard
6816 my %overall_stat_databases = ();
6817 if (exists $OVERALL_STATS{'cluster'}) {
6818 $OVERALL_STATS{'cluster'}{'blks_hit'} ||= 0;
6819 $OVERALL_STATS{'cluster'}{'blks_read'} ||= 0;
6820 $OVERALL_STATS{'cluster'}{'cache_ratio'} = sprintf("%3d", ($OVERALL_STATS{'cluster'}{'blks_hit'} * 100) / (($OVERALL_STATS{'cluster'}{'blks_read'} + $OVERALL_STATS{'cluster'}{'blks_hit'}) || 1)) . "%";
6821 $OVERALL_STATS{'cluster'}{'temp_bytes'} = &pretty_print_size($OVERALL_STATS{'cluster'}{'temp_bytes'});
6822 foreach my $db (keys %{$OVERALL_STATS{'database'}}) {
6823 next if ($db eq 'all');
6824 $OVERALL_STATS{'database'}{$db}{'blks_hit'} ||= 0;
6825 $OVERALL_STATS{'database'}{$db}{'blks_read'} ||= 0;
6826 $OVERALL_STATS{'database'}{$db}{'blks_hit'} ||= 0;
6827 $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));
6828 }
6829 foreach my $db (keys %{$OVERALL_STATS{'database'}}) {
6830 next if ($db eq 'all');
6831 $OVERALL_STATS{'cluster'}{'size'} += ($OVERALL_STATS{'database'}{$db}{'size'} || 0);
6832 next if (($#INCLUDE_DB >= 0) && !grep($db =~ /^$_$/, @INCLUDE_DB));
6833 if (exists $OVERALL_STATS{'database'}{$db}{'size'}) {
6834 if (!exists $overall_stat_databases{'size'} || $OVERALL_STATS{'database'}{$db}{'size'} > $overall_stat_databases{'size'}[1]) {
6835 @{$overall_stat_databases{'size'}} = ($db, $OVERALL_STATS{'database'}{$db}{'size'});
6836 }
6837 }
6838 if (exists $OVERALL_STATS{'database'}{$db}{'nbackend'}) {
6839 if (!exists $overall_stat_databases{'nbackend'} || $OVERALL_STATS{'database'}{$db}{'nbackend'} > $overall_stat_databases{'nbackend'}[1]) {
6840 @{$overall_stat_databases{'nbackend'}} = ($db, $OVERALL_STATS{'database'}{$db}{'nbackend'});
6841 }
6842 }
6843 if (exists $OVERALL_STATS{'database'}{$db}{'returned'}) {
6844 if (!exists $overall_stat_databases{'returned'} || $OVERALL_STATS{'database'}{$db}{'returned'} > $overall_stat_databases{'returned'}[1]) {
6845 @{$overall_stat_databases{'returned'}} = ($db, $OVERALL_STATS{'database'}{$db}{'returned'});
6846 }
6847 }
6848 if (exists $OVERALL_STATS{'database'}{$db}{'temp_files'}) {
6849 if (!exists $overall_stat_databases{'temp_files'} || $OVERALL_STATS{'database'}{$db} {'temp_files'} > $overall_stat_databases{'temp_files'}[1]) {
6850 @{$overall_stat_databases{'temp_files'}} = ($db, $OVERALL_STATS{'database'}{$db}{'temp_files'});
6851 }
6852 }
6853 if (exists $OVERALL_STATS{'database'}{$db}{'temp_bytes'}) {
6854 if (!exists $overall_stat_databases{'temp_bytes'} || $OVERALL_STATS{'database'}{$db}{'temp_bytes'} > $overall_stat_databases{'temp_bytes'}[1]) {
6855 @{$overall_stat_databases{'temp_bytes'}} = ($db, $OVERALL_STATS{'database'}{$db}{'temp_bytes'});
6856 }
6857 }
6858 if (exists $OVERALL_STATS{'database'}{$db}{'deadlocks'}) {
6859 if (!exists $overall_stat_databases{'deadlocks'} || $OVERALL_STATS{'database'}{$db}{'deadlocks'} > $overall_stat_databases{'deadlocks'}[1]) {
6860 @{$overall_stat_databases{'deadlocks'}} = ($db, $OVERALL_STATS{'database'}{$db}{'deadlocks'});
6861 }
6862 }
6863 if (exists $OVERALL_STATS{'database'}{$db}{'cache_ratio'}) {
6864 if (!exists $overall_stat_databases{'cache_ratio'} || $OVERALL_STATS{'database'}{$db}{'cache_ratio'} < $overall_stat_databases{'cache_ratio'}[1]) {
6865 @{$overall_stat_databases{'cache_ratio'}} = ($db, $OVERALL_STATS{'database'}{$db}{'cache_ratio'});
6866 }
6867 }
6868 }
6869 @{$overall_stat_databases{'size'}} = ('unknown', 0) if (!exists $overall_stat_databases{'size'});
6870 if (exists $overall_stat_databases{'size'}) {
6871 $overall_stat_databases{'size'}[1] = &pretty_print_size($overall_stat_databases{'size'}[1]);
6872 }
6873 if (exists $overall_stat_databases{'temp_bytes'}) {
6874 $overall_stat_databases{'temp_bytes'}[1] = &pretty_print_size($overall_stat_databases{'temp_bytes'}[1]);
6875 }
6876 }
6877
6878 my %overall_system_stats = ();
6879 if (!$DISABLE_SAR) {
6880
6881 if (!exists $OVERALL_STATS{'system'}{'cpu'}) {
6882 @{$OVERALL_STATS{'system'}{'cpu'}} = ('unknown', 0);
6883 } else {
6884 ${$OVERALL_STATS{'system'}{'cpu'}}[0] = localtime(${$OVERALL_STATS{'system'}{'cpu'}}[0]/1000);
6885 }
6886 if (!exists $OVERALL_STATS{'system'}{'load'}) {
6887 @{$OVERALL_STATS{'system'}{'load'}} = ('unknown', 0);
6888 } else {
6889 ${$OVERALL_STATS{'system'}{'load'}}[0] = localtime(${$OVERALL_STATS{'system'}{'load'}}[0]/1000);
6890 }
6891 if (!exists $OVERALL_STATS{'system'}{'blocked'}) {
6892 @{$OVERALL_STATS{'system'}{'blocked'}} = ('unknown', 0);
6893 } else {
6894 ${$OVERALL_STATS{'system'}{'blocked'}}[0] = localtime(${$OVERALL_STATS{'system'}{'blocked'}}[0]/1000);
6895 }
6896 if (!exists $OVERALL_STATS{'system'}{'kbcached'}) {
6897 @{$OVERALL_STATS{'system'}{'kbcached'}} = ('unknown', 0);
6898 } else {
6899 ${$OVERALL_STATS{'system'}{'kbcached'}}[0] = localtime(${$OVERALL_STATS{'system'}{'kbcached'}}[0]/1000);
6900 }
6901 if (!exists $OVERALL_STATS{'system'}{'kbdirty'}) {
6902 @{$OVERALL_STATS{'system'}{'kbdirty'}} = ('unknown', 0);
6903 } else {
6904 ${$OVERALL_STATS{'system'}{'kbdirty'}}[0] = localtime(${$OVERALL_STATS{'system'}{'kbdirty'}}[0]/1000);
6905 }
6906 if (!exists $OVERALL_STATS{'system'}{'bread'}) {
6907 @{$OVERALL_STATS{'system'}{'bread'}} = ('unknown', 0);
6908 } else {
6909 ${$OVERALL_STATS{'system'}{'bread'}}[0] = localtime(${$OVERALL_STATS{'system'}{'bread'}}[0]/1000);
6910 }
6911 if (!exists $OVERALL_STATS{'system'}{'bwrite'}) {
6912 @{$OVERALL_STATS{'system'}{'bwrite'}} = ('unknown', 0);
6913 } else {
6914 ${$OVERALL_STATS{'system'}{'bwrite'}}[0] = localtime(${$OVERALL_STATS{'system'}{'bwrite'}}[0]/1000);
6915 }
6916 if (!exists $OVERALL_STATS{'system'}{'svctm'}) {
6917 @{$OVERALL_STATS{'system'}{'svctm'}} = ('unknown', 0, 'unknown');
6918 } else {
6919 ${$OVERALL_STATS{'system'}{'svctm'}}[0] = localtime(${$OVERALL_STATS{'system'}{'svctm'}}[0]/1000);
6920 }
6921 if (exists $OVERALL_STATS{'system'}{'devices'}) {
6922 foreach my $d (sort keys %{$OVERALL_STATS{'system'}{'devices'}}) {
6923 if (! exists $overall_system_stats{read} || ($overall_system_stats{read}[1] < $OVERALL_STATS{'system'}{'devices'}{$d}{read})) {
6924 @{$overall_system_stats{read}} = ($d, $OVERALL_STATS{'system'}{'devices'}{$d}{read});
6925 }
6926 if (! exists $overall_system_stats{write} || ($overall_system_stats{write}[1] < $OVERALL_STATS{'system'}{'devices'}{$d}{write})) {
6927 @{$overall_system_stats{write}} = ($d, $OVERALL_STATS{'system'}{'devices'}{$d}{write});
6928 }
6929 if (! exists $overall_system_stats{tps} || ($overall_system_stats{tps}[1] < $OVERALL_STATS{'system'}{'devices'}{$d}{tps})) {
6930 @{$overall_system_stats{tps}} = ($d, $OVERALL_STATS{'system'}{'devices'}{$d}{tps});
6931 }
6932 }
6933 }
6934 if (exists $OVERALL_STATS{'system'}{'space'}) {
6935 foreach my $d (sort keys %{$OVERALL_STATS{'system'}{'space'}}) {
6936 if (! exists $overall_system_stats{'fsused'} || ($overall_system_stats{'fsused'}[1] < $OVERALL_STATS{'system'}{'space'}{$d}{'fsused'})) {
6937 @{$overall_system_stats{'fsused'}} = ($d, $OVERALL_STATS{'system'}{'space'}{$d}{'fsused'});
6938 }
6939 if (! exists $overall_system_stats{'iused'} || ($overall_system_stats{'iused'}[1] < $OVERALL_STATS{'system'}{'space'}{$d}{'iused'})) {
6940 @{$overall_system_stats{'iused'}} = ($d, $OVERALL_STATS{'system'}{'space'}{$d}{'iused'});
6941 }
6942 }
6943 }
6944
6945 if (!exists $overall_system_stats{read}) {
6946 @{$overall_system_stats{read}} = ('unknown', 0);
6947 }
6948 if (!exists $overall_system_stats{write}) {
6949 @{$overall_system_stats{write}} = ('unknown', 0);
6950 }
6951 if (!exists $overall_system_stats{tps}) {
6952 @{$overall_system_stats{tps}} = ('unknown', 0);
6953 }
6954 if (!exists $overall_system_stats{fsused}) {
6955 @{$overall_system_stats{fsused}} = ('unknown', 0);
6956 }
6957 if (!exists $overall_system_stats{iused}) {
6958 @{$overall_system_stats{iused}} = ('unknown', 0);
6959 }
6960
6961 $overall_system_stats{read}[1] = &pretty_print_size($overall_system_stats{read}[1]);
6962 $overall_system_stats{write}[1] = &pretty_print_size($overall_system_stats{write}[1]);
6963
6964 @{$overall_system_stats{kbcached}} = ($OVERALL_STATS{'system'}{'kbcached'}[0], &pretty_print_size($OVERALL_STATS{'system'}{'kbcached'}[1]));
6965 @{$overall_system_stats{kbdirty}} = ($OVERALL_STATS{'system'}{'kbdirty'}[0], &pretty_print_size($OVERALL_STATS{'system'}{'kbdirty'}[1]));
6966 @{$overall_system_stats{bread}} = ($OVERALL_STATS{'system'}{'bread'}[0], &pretty_print_size($OVERALL_STATS{'system'}{'bread'}[1]));
6967 @{$overall_system_stats{bwrite}} = ($OVERALL_STATS{'system'}{'bwrite'}[0], &pretty_print_size($OVERALL_STATS{'system'}{'bwrite'}[1]));
6968 }
6969
6970 my $numcol = 4;
6971 if ($DISABLE_SAR) {
6972 $numcol = 6;
6973 } elsif (!exists $OVERALL_STATS{'system'}) {
6974 $numcol = 12;
6975 }
6976
6977 print <<EOF;
6978 <ul id="slides">
6979 <li class="slide active-slide" id="home-slide">
6980 <div id="home"><br/><br/><br/><br/></div>
6981 EOF
6982 my $tz = ((0-$STATS_TIMEZONE)*3600);
6983 if (exists $OVERALL_STATS{'start_date'}) {
6984 $OVERALL_STATS{'start_date'} = ($OVERALL_STATS{'start_date'}/1000) + $tz;
6985 $OVERALL_STATS{'end_date'} = ($OVERALL_STATS{'end_date'}/1000) + $tz;
6986 }
6987 my $start_date = localtime($OVERALL_STATS{'start_date'}||0) || 'Unknown start date';
6988 my $end_date = localtime($OVERALL_STATS{'end_date'}||0) || 'Unknown end date';
6989 if (exists $OVERALL_STATS{'sar_start_date'}) {
6990 $OVERALL_STATS{'sar_start_date'} = ($OVERALL_STATS{'sar_start_date'}/1000);
6991 $OVERALL_STATS{'sar_end_date'} = ($OVERALL_STATS{'sar_end_date'}/1000);
6992 }
6993 my $sar_start_date = localtime($OVERALL_STATS{'sar_start_date'}||0) || 'Unknown start date';
6994 my $sar_end_date = localtime($OVERALL_STATS{'sar_end_date'}||0) || 'Unknown end date';
6995
6996 my $parts_info = '';
6997 if (exists $OVERALL_STATS{'cluster'}) {
6998 $OVERALL_STATS{'cluster'}{'size'} ||= 0;
6999 $OVERALL_STATS{'cluster'}{'nbackend'} ||= 0;
7000 $OVERALL_STATS{'cluster'}{'returned'} ||= 0;
7001 $OVERALL_STATS{'cluster'}{'cache_ratio'} ||= 0;
7002 $OVERALL_STATS{'cluster'}{'temp_files'} ||= 0;
7003 $OVERALL_STATS{'cluster'}{'temp_bytes'} ||= 0;
7004 $OVERALL_STATS{'cluster'}{'deadlocks'} ||= 0;
7005 my $temp_file_info = '';
7006 if ($OVERALL_STATS{'cluster'}{'temp_files'}) {
7007 $temp_file_info = qq{
7008 <li><span class="figure">$OVERALL_STATS{'cluster'}{'temp_files'}</span> <span class="figure-label">Temporary files</span></li>
7009 <li><span class="figure">$OVERALL_STATS{'cluster'}{'temp_bytes'}</span> <span class="figure-label">Temporary files size</span></li>
7010 };
7011 }
7012 my $deadlock_info = '';
7013 if ($OVERALL_STATS{'cluster'}{'deadlocks'}) {
7014 $deadlock_info = qq{
7015 <li><span class="figure">$OVERALL_STATS{'cluster'}{'deadlocks'}</span> <span class="figure-label">Deadlocks</span></li>
7016 };
7017 }
7018 my $extnum = $#{$OVERALL_STATS{'cluster'}{'extensions'}} + 1;
7019 my $extensions_info = '';
7020 if ($extnum) {
7021 my $extlist = join(', ', @{$OVERALL_STATS{'cluster'}{'extensions'}});
7022 $extensions_info = qq{<li><span class="figure">$extnum</span> <span class="figure-label">Extensions ($extlist)</span></li>};
7023 }
7024
7025 my $nparts = $#{$OVERALL_STATS{'cluster'}{'partitionned_tables'}} + 1;
7026 if ($nparts) {
7027 my %partitions = ();
7028 foreach my $pt (sort @{$OVERALL_STATS{'cluster'}{'partitionned_tables'}}) {
7029 $pt =~ s/^([^\.]+)\.//;
7030 $partitions{$1} .= "$pt;";
7031 }
7032 $parts_info = qq{<li><span class="figure">$nparts</span> <span class="figure-label">Partitioned tables</span></li><ul>};
7033 foreach my $t (keys %partitions) {
7034 $parts_info .= qq{<li><span class="figure">$t</span> <span class="figure-label">$partitions{$t}</span></li></ul>};
7035 }
7036 }
7037
7038 $sysinfo{PGVERSION}{'full_version'} ||= '';
7039 $sysinfo{PGVERSION}{'uptime'} ||= '';
7040 my $database_number = scalar keys %{$OVERALL_STATS{'database'}};
7041 $OVERALL_STATS{'cluster'}{'size'} ||= '-';
7042 $OVERALL_STATS{'cluster'}{'nbackend'} ||= '-';
7043 $OVERALL_STATS{'cluster'}{'returned'} ||= '-';
7044 $OVERALL_STATS{'cluster'}{'cache_ratio'} ||= '-';
7045 my $bgwriter_reset = '';
7046 if (exists $OVERALL_STATS{'bgwriter'}{stats_reset}) {
7047 $bgwriter_reset = "<li><span class=\"figure\"> $OVERALL_STATS{'bgwriter'}{stats_reset}</span> <span class=\"figure-label\">Last bgwriter stats reset</span></li>";
7048 }
7049 my $cluster_size = &pretty_print_size($OVERALL_STATS{'cluster'}{'size'});
7050 $OVERALL_STATS{'cluster'}{unlogged} ||= 0;
7051 my $unlogged_dblist = '';
7052 if (exists $OVERALL_STATS{'cluster'}{unlogged_db}) {
7053 $unlogged_dblist = ' (' . join(', ', @{$OVERALL_STATS{'cluster'}{unlogged_db}}) . ')';
7054 }
7055 $OVERALL_STATS{'cluster'}{invalid_indexes} ||= 0;
7056 my $invalid_dblist = '';
7057 if (exists $OVERALL_STATS{'cluster'}{invalid_indexes_db}) {
7058 $invalid_dblist = ' (' . join(', ', @{$OVERALL_STATS{'cluster'}{invalid_indexes_db}}) . ')';
7059 }
7060 $OVERALL_STATS{'cluster'}{hash_indexes} ||= 0;
7061 my $hash_dblist = '';
7062 if (exists $OVERALL_STATS{'cluster'}{hash_indexes_db}) {
7063 $hash_dblist = ' (' . join(', ', @{$OVERALL_STATS{'cluster'}{hash_indexes_db}}) . ')';
7064 }
7065 # On version prior to 9.3 this is not applicable
7066 $OVERALL_STATS{'cluster'}{'data_checksums'} ||= 'N/A';
7067 print <<EOF;
7068 <div class="row">
7069 <div class="col-md-$numcol">
7070 <div class="panel panel-default">
7071 <div class="panel-heading">
7072 <i class="glyphicon icon-cogs icon-2x pull-left"></i><h2>Cluster</h2>
7073 </div>
7074 <div class="panel-body panel-xlheight">
7075 <div class="key-figures">
7076 <span class="figure-date">$start_date to $end_date</span>
7077 <ul>
7078 <li></li>
7079 <li><span class="figure">$OVERALL_STATS{'cluster'}{'data_checksums'}</span> <span class="figure-label">Data checksums</span></li>
7080 <li><span class="figure">$cluster_size</span> <span class="figure-label">Cluster size</span></li>
7081 <li><span class="figure">$database_number</span> <span class="figure-label">Databases</span></li>
7082 <li><span class="figure">$OVERALL_STATS{'cluster'}{'nbackend'}</span> <span class="figure-label">Connections</span></li>
7083 <li><span class="figure">$OVERALL_STATS{'cluster'}{'returned'}</span> <span class="figure-label">Tuples returned</span></li>
7084 <li><span class="figure">$OVERALL_STATS{'cluster'}{'cache_ratio'}</span> <span class="figure-label">Hit cache ratio</span></li>
7085 <li><span class="figure">$OVERALL_STATS{'cluster'}{'unlogged'}</span> <span class="figure-label">Unlogged tables$unlogged_dblist</span></li>
7086 <li><span class="figure">$OVERALL_STATS{'cluster'}{'invalid_indexes'}</span> <span class="figure-label">Invalid indexes$invalid_dblist</span></li>
7087 <li><span class="figure">$OVERALL_STATS{'cluster'}{'hash_indexes'}</span> <span class="figure-label">Hash indexes$hash_dblist</span></li>
7088 $temp_file_info
7089 $deadlock_info
7090 $extensions_info
7091 $bgwriter_reset
7092 </ul>
7093 </div>
7094 </div>
7095 </div>
7096 </div><!--/span-->
7097
7098 <div class="col-md-$numcol">
7099 <div class="panel panel-default">
7100 <div class="panel-heading">
7101 <i class="glyphicon icon-th icon-2x pull-left"></i><h2>Databases</h2>
7102 </div>
7103 <div class="panel-body panel-xlheight">
7104 <div class="key-figures">
7105 <ul>
7106 <li></li>
7107 EOF
7108 if (exists $overall_stat_databases{'size'}) {
7109 print <<EOF;
7110 <li><span class="figure">$overall_stat_databases{'size'}[1]</span> <span class="figure-label">Largest database</span><br/><span class="figure-date">($overall_stat_databases{'size'}[0])</span></li>
7111 EOF
7112 }
7113 if (exists $overall_stat_databases{'nbackend'}) {
7114 print <<EOF;
7115 <li><span class="figure">$overall_stat_databases{'nbackend'}[1]</span> <span class="figure-label">Most connections</span><br/><span class="figure-date">($overall_stat_databases{'nbackend'}[0])</span></li>
7116 EOF
7117 }
7118 if (exists $overall_stat_databases{'returned'}) {
7119 print qq{<li><span class="figure">$overall_stat_databases{'returned'}[1]</span> <span class="figure-label">Most tuples returned</span><br/><span class="figure-date">($overall_stat_databases{'returned'}[0])</span></li>
7120 };
7121 }
7122 if (exists $overall_stat_databases{'cache_ratio'}) {
7123 push(@{$overall_stat_databases{'cache_ratio'}}, '-', '-') if ($#{$overall_stat_databases{'cache_ratio'}} < 0);
7124 print <<EOF;
7125 <li><span class="figure">$overall_stat_databases{'cache_ratio'}[1]%</span> <span class="figure-label">Worst cache utilization</span><br/><span class="figure-date">($overall_stat_databases{'cache_ratio'}[0])</span></li>
7126 EOF
7127 }
7128 if (exists $overall_stat_databases{'temp_files'} && $overall_stat_databases{'temp_files'}[1]) {
7129 print <<EOF;
7130 <li><span class="figure">$overall_stat_databases{'temp_files'}[1]</span> <span class="figure-label">Most temporary files</span><br/><span class="figure-date">($overall_stat_databases{'temp_files'}[0])</span></li>
7131 EOF
7132 }
7133 if (exists $overall_stat_databases{'temp_bytes'} && $overall_stat_databases{'temp_bytes'}[1]) {
7134 print <<EOF;
7135 <li><span class="figure">$overall_stat_databases{'temp_bytes'}[1]</span> <span class="figure-label">Most temporary bytes</span><br/><span class="figure-date">($overall_stat_databases{'temp_bytes'}[0])</span></li>
7136 EOF
7137 }
7138 if (exists $overall_stat_databases{'deadlocks'} && $overall_stat_databases{'deadlocks'}[1]) {
7139 print <<EOF;
7140 <li><span class="figure">$overall_stat_databases{'deadlocks'}[1]</span> <span class="figure-label">Most deadlocks</span><br/><span class="figure-date">($overall_stat_databases{'deadlocks'}[0])</span></li>
7141 EOF
7142 }
7143 print <<EOF;
7144 </ul>
7145 </div>
7146 </div>
7147 </div>
7148 </div><!--/span-->
7149 EOF
7150
7151 }
7152 if (!$DISABLE_SAR) {
7153 print <<EOF;
7154 <div class="col-md-$numcol">
7155 <div class="panel panel-default">
7156 <div class="panel-heading">
7157 <i class="glyphicon icon-desktop icon-2x pull-left"></i> <h2>System</h2>
7158 </div>
7159 <div class="panel-body panel-xlheight">
7160 <div class="key-figures">
7161 <span class="figure-date">$sar_start_date to $sar_end_date</span>
7162 <ul>
7163 <li></li>
7164 <li><span class="figure">$OVERALL_STATS{'system'}{'cpu'}[1]%</span> <span class="figure-label">Highest CPU utilization</span><br/><span class="figure-date">($OVERALL_STATS{'system'}{'cpu'}[0])</span></li>
7165 <li><span class="figure">$OVERALL_STATS{'system'}{'load'}[1]</span> <span class="figure-label">Highest system load</span><br/><span class="figure-date">($OVERALL_STATS{'system'}{'load'}[0])</span></li>
7166 <li><span class="figure">$OVERALL_STATS{'system'}{'blocked'}[1]</span> <span class="figure-label">Highest blocked processes</span><br/><span class="figure-date">($OVERALL_STATS{'system'}{'blocked'}[0])</span></li>
7167 <li><span class="figure">$OVERALL_STATS{'system'}{'svctm'}[1] ms</span> <span class="figure-label">Highest device service time</span><br/><span class="figure-date">($OVERALL_STATS{'system'}{'svctm'}[0] on device $OVERALL_STATS{'system'}{'svctm'}[2])</span></li>
7168 <li><span class="figure">$overall_system_stats{kbcached}[1]</span> <span class="figure-label">Lowest system cache</span><br/><span class="figure-date">($overall_system_stats{kbcached}[0])</span></li>
7169 <li><span class="figure">$overall_system_stats{kbdirty}[1]</span> <span class="figure-label">Highest dirty memory</span><br/><span class="figure-date">($overall_system_stats{kbdirty}[0])</span></li>
7170 <!-- li><span class="figure">$overall_system_stats{bread}[1]</span> <span class="figure-label">Highest block read</span><br/><span class="figure-date">($overall_system_stats{bread}[0])</span></li -->
7171 <!-- li><span class="figure">$overall_system_stats{bwrite}[1]</span> <span class="figure-label">Highest block write</span><br/><span class="figure-date">($overall_system_stats{bwrite}[0])</span> </li -->
7172 <li><span class="figure">$overall_system_stats{read}[1]</span> <span class="figure-label">Most read device</span><br/><span class="figure-date"> ($overall_system_stats{read}[0])</span></li>
7173 <li><span class="figure">$overall_system_stats{write}[1]</span> <span class="figure-label">Most written device</span><br/><span class="figure-date">($overall_system_stats{write}[0])</span></li>
7174 <li><span class="figure">$overall_system_stats{tps}[1]</span> <span class="figure-label">Highest tps on device</span><br/><span class="figure-date">($overall_system_stats{tps}[0])</span></li>
7175 </ul>
7176 </div>
7177 </div>
7178 </div>
7179 </div><!--/span-->
7180 EOF
7181 }
7182 print <<EOF;
7183 </div>
7184 EOF
7185
7186 if (exists $sysinfo{PGVERSION}) {
7187 my $cache_info = '';
7188 $cache_info = "<li><span class=\"figure-label\">Cache was last built on $sysinfo{CACHE}{last_run}</span></li>" if (exists $sysinfo{CACHE});
7189 my $uptime = '';
7190 $uptime = "<li><span class=\"figure-label\">Up since $sysinfo{PGVERSION}{'uptime'}</span></li>" if ($sysinfo{PGVERSION}{'uptime'});
7191 print <<EOF;
7192 <div class="col-md-12">
7193 <div class="panel panel-default">
7194 <div class="panel-body">
7195 <div class="key-figures">
7196 <ul>
7197 <li></li>
7198 $cache_info
7199 <li><span class="figure-label">$sysinfo{PGVERSION}{'full_version'}</span></li>
7200 $uptime
7201 </ul>
7202 </div>
7203 </div>
7204 </div>
7205 </div><!--/span-->
7206
7207 EOF
7208 }
7209
7210 if (exists $OVERALL_STATS{'archiver'}) {
7211 my $archiver_infos = '';
7212 if (exists $OVERALL_STATS{'archiver'}{last_archived_wal}) {
7213 $archiver_infos = qq{<li><span class="figure">$OVERALL_STATS{'archiver'}{last_archived_wal}</span> <span class="figure-label">Last archived wal</span></li>};
7214 $archiver_infos .= qq{<li><span class="figure">$OVERALL_STATS{'archiver'}{last_archived_time}</span> <span class="figure-label">Last archived time</span></li>};
7215 }
7216 if (exists $OVERALL_STATS{'archiver'}{last_failed_wal}) {
7217 $archiver_infos .= qq{<li><span class="figure">$OVERALL_STATS{'archiver'}{last_failed_wal}</span> <span class="figure-label">Last failed wal</span></li>};
7218 $archiver_infos .= qq{<li><span class="figure">$OVERALL_STATS{'archiver'}{last_failed_time}</span> <span class="figure-label">Last failed time</span></li>};
7219 }
7220 if (exists $OVERALL_STATS{'archiver'}{stats_reset}) {
7221 $archiver_infos .= qq{<li><span class="figure">$OVERALL_STATS{'archiver'}{stats_reset}</span> <span class="figure-label">Last stats reset</span></li>};
7222 }
7223
7224 print <<EOF;
7225 <div class="col-md-12">
7226 <div class="panel panel-default">
7227 <div class="panel-heading">
7228 <i class="glyphicon icon-th icon-2x pull-left icon-archive"></i><h2>Archiver</h2>
7229 </div>
7230 <div class="panel-body">
7231 <div class="key-figures">
7232 <ul>
7233 <li></li>
7234 $archiver_infos
7235 </ul>
7236 </div>
7237 </div>
7238 </div>
7239 </div><!--/span-->
7240 EOF
7241 }
7242
7243 if ($parts_info) {
7244 print <<EOF;
7245 <div class="row">
7246 <div class="col-md-12">
7247 <div class="panel panel-default">
7248 <div class="panel-heading">
7249 <i class="glyphicon icon-th icon-2x pull-left"></i><h2>Partitioning</h2>
7250 </div>
7251 <div class="panel-body">
7252 <div class="key-figures">
7253 <ul>
7254 <li></li>
7255 $parts_info
7256 </ul>
7257 </div>
7258 </div>
7259 </div>
7260 </div><!--/span-->
7261 </div>
7262 EOF
7263 }
7264
7265 if (exists $sysinfo{INSTALLATION}) {
7266 my $package_infos = join('', @{$sysinfo{INSTALLATION}});
7267 print <<EOF;
7268 <div class="row">
7269 <div class="col-md-12">
7270 <div class="panel panel-default">
7271 <div class="panel-heading">
7272 <i class="glyphicon icon-archive icon-2x pull-left"></i><h2>Packages</h2>
7273 </div>
7274 <div class="panel-body">
7275 <div class="key-figures">
7276 <ul>
7277 <li></li>
7278 <pre>$package_infos</pre>
7279 </ul>
7280 </div>
7281 </div>
7282 </div>
7283 </div><!--/span-->
7284 </div>
7285 EOF
7286 }
7287
7288
7289 if (exists $sysinfo{CRONTAB}) {
7290 my $cron_infos = join('', @{$sysinfo{CRONTAB}});
7291 print <<EOF;
7292 <div class="row">
7293 <div class="col-md-12">
7294 <div class="panel panel-default">
7295 <div class="panel-heading">
7296 <i class="glyphicon icon-coffee icon-2x pull-left"></i><h2>Crontab entries</h2>
7297 </div>
7298 <div class="panel-body">
7299 <div class="key-figures">
7300 <ul>
7301 <li></li>
7302 <pre>$cron_infos</pre>
7303 </ul>
7304 </div>
7305 </div>
7306 </div>
7307 </div><!--/span-->
7308 </div>
7309 EOF
7310 }
7311
7312
7313 print <<EOF;
7314 </li>
7315 </ul> <!-- end of slides -->
7316 EOF
7317
7318 }
7319
7320 sub wrong_date_selection
7321 {
7322 my $show_last_stats = shift;
7323 if ($show_last_stats) {
7324 $show_last_stats = &last_know_statistics();
7325 }
7326
7327 my $end_date = timelocal_nocheck(0, 0, 0, $o_day, $o_month - 1, $o_year - 1900) + 86400;
7328 $end_date = strftime("%Y-%m-%d %H:%M:00",localtime($end_date));
7329 print <<EOF;
7330 <ul id="slides">
7331 <li class="slide active-slide" id="wrong_date-slide">
7332
7333 <div id="wrong_date"><br/><br/><br/><br/><br/></div>
7334 <div class="jumbotron">
7335 <h1>No data found</h1>
7336 <p>$PROGRAM is not able to find any data relative to your date selection.</p>
7337 <ul>
7338 <li>Start: $o_year-$o_month-$o_day $o_hour:00:00</li>
7339 <li>End&nbsp;: $end_date</li>
7340 </ul>
7341 <p>Please choose more accurate dates or use time selector menu.</p>
7342 $show_last_stats
7343 </div>
7344 </li>
7345 </ul> <!-- end of slides -->
7346 EOF
7347
7348 }
7349
7350 sub last_know_statistics
7351 {
7352
7353 my $start_stats = '';
7354 my $end_stats = '';
7355
7356 # Search the path to last computed statistics
7357 # Search years / months / days / hours directories
7358 if (not opendir(DIR, "$INPUT_DIR")) {
7359 return "<p>FATAL: Can't open directory $INPUT_DIR: $!</p>\n";
7360 }
7361 my @years = grep { /^\d+$/ && -d "$INPUT_DIR/$_" } readdir(DIR);
7362 closedir(DIR);
7363 if ($#years >= 0) {
7364 foreach my $y (sort { $b <=> $a } @years) {
7365 if (not opendir(DIR, "$INPUT_DIR/$y")) {
7366 return "<p>FATAL: Can't open directory $INPUT_DIR/$y: $!</p>\n";
7367 }
7368 my @months = grep { /^\d+$/ && -d "$INPUT_DIR/$y/$_" } readdir(DIR);
7369 closedir(DIR);
7370 foreach my $m (sort { $b <=> $a } @months) {
7371 if (not opendir(DIR, "$INPUT_DIR/$y/$m")) {
7372 return "<p>FATAL: Can't open directory $INPUT_DIR/$y/$m: $!</p>\n";
7373 }
7374 my @days = grep { /^\d+$/ && -d "$INPUT_DIR/$y/$m/$_" } readdir(DIR);
7375 closedir(DIR);
7376 foreach my $d (sort { $b <=> $a } @days) {
7377 if (not opendir(DIR, "$INPUT_DIR/$y/$m/$d")) {
7378 return "<p>FATAL: Can't open directory $INPUT_DIR/$y/$m/$d: $!</p>\n";
7379 }
7380 $start_stats = "$y-$m-$d\%2000:00";
7381 $end_stats = timelocal_nocheck(0, 0, 0, $d, $m - 1, $y - 1900) + 86400;
7382 $end_stats = strftime("%Y-%m-%d%%2000:00",localtime($end_stats));
7383 # my @hours = grep { /^\d+$/ && -d "$INPUT_DIR/$y/$m/$d/$_" } readdir(DIR);
7384 # closedir(DIR);
7385 # if ($#hours == -1) {
7386 # $start_stats = "$y-$m-$d\%2000:00";
7387 # $end_stats = timelocal_nocheck(0, 0, 0, $d, $m - 1, $y - 1900) + 86400;
7388 # $end_stats = strftime("%Y-%m-%d%%20%H:%M",localtime($end_stats));
7389 # } else {
7390 # foreach my $h (sort { $b <=> $a } @hours) {
7391 # $start_stats = "$y-$m-$d\%20$h:00";
7392 # $end_stats = timegm_nocheck(0, 0, $h, $d, $m - 1, $y - 1900) + 3600;
7393 # $end_stats = strftime("%Y-%m-%d%%20%H:%M",localtime($end_stats));
7394 # last;
7395 # }
7396 # }
7397 last;
7398 }
7399 last;
7400 }
7401 last;
7402 }
7403 }
7404
7405 if ($start_stats) {
7406 return " <p><a href=\"\" onclick=\"document.location.href='$SCRIPT_NAME?action=home&end=$end_stats&start=$start_stats'; return false;\">Last known statistics</a></p>\n";
7407 }
7408
7409 return " <p>No statistics found</p>\n";
7410
7411 }
7412
7413 sub show_about
7414 {
7415 print <<EOF;
7416 <ul id="slides">
7417 <li class="slide active-slide" id="about-slide">
7418
7419 <div id="about"><br/><br/><br/><br/><br/></div>
7420 <div class="jumbotron">
7421 <h1>About $PROGRAM</h1>
7422 <p>$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.</p>
7423 </div>
7424 <div class="row">
7425 <div class="col-md-4">
7426 <div class="panel panel-default">
7427 <div class="panel-heading">
7428 <i class="glyphicon icon-link icon-2x pull-left"></i><h2>License</h2>
7429 </div>
7430 <div class="panel-body panel-height">
7431 <p>$PROGRAM is licenced under the PostgreSQL Licence a liberal Open Source license, similar to the BSD or MIT licenses.</p>
7432 <p>That mean that all parts of the program are open source and free of charge.</p>
7433 <p>This is the case for both, the collector and the grapher programs.</p>
7434 </div>
7435 </div>
7436 </div><!--/span-->
7437 <div class="col-md-4">
7438 <div class="panel panel-default">
7439 <div class="panel-heading">
7440 <i class="glyphicon icon-download-alt icon-2x pull-left"></i><h2>Download</h2>
7441 </div>
7442 <div class="panel-body panel-height">
7443 <p>Official releases at SourceForge:<br/>
7444 [ <a href="http://sourceforge.net/projects/pgcluu/">http://sourceforge.net/projects/pgcluu/</a> ].</p>
7445 <p>Source code at github:<br/>
7446 [ <a href="https://github.com/darold/pgcluu">https://github.com/darold/pgcluu</a> ].</p>
7447 <p>ChangeLog can be read on-line on GitHub repository <a href="https://github.com/darold/pgcluu/blob/master/ChangeLog">here</a>
7448 <p>Offical web site is hosted at <a href="http://pgcluu.darold.net/">pgcluu.darold.net</a>
7449 </div>
7450 </div>
7451 </div><!--/span-->
7452 <div class="col-md-4">
7453 <div class="panel panel-default">
7454 <div class="panel-heading">
7455 <i class="glyphicon icon-wrench icon-2x pull-left"></i><h2>Authors</h2>
7456 </div>
7457 <div class="panel-body panel-height">
7458 <p>$PROGRAM is an original development of <a href="http://www.darold.net/">Gilles Darold</a>.</p>
7459 <p>Some parts of the collector are taken from <a href="https://github.com/gleu/pgstats">pgstats</a> a C program writen by Guillaume Lelarge and especially the SQL queries including the compatibility with all PostgreSQL versions.</p>
7460 <p>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 <a href="http://sysusage.darold.net/">SysUsage</a></p>
7461 </div>
7462 </div>
7463 </div><!--/span-->
7464 </div>
7465 </li>
7466 </ul> <!-- end of slides -->
7467 EOF
7468
7469 }
7470
7471 sub show_sysinfo
7472 {
7473 my $input_dir = shift;
7474
7475 &read_sysinfo($input_dir);
7476
7477 $sysinfo{UPTIME}{'uptime'} = '-' if (!exists $sysinfo{UPTIME}{'uptime'});
7478
7479 my $release_version = '';
7480 if ($sysinfo{RELEASE}{'version'}) {
7481 $release_version = qq{<li><span class="figure">$sysinfo{RELEASE}{'version'}</span> <span class="figure-label">Version</span></li>};
7482 }
7483 my $sysctl_info = '';
7484 my $hugepage_info = '';
7485 foreach my $k (sort keys %{$sysinfo{SYSTEM}}) {
7486 next if ($k =~ /^kernel.*shm/);
7487 if ($k =~ /transparent_hugepage/) {
7488 my $k2 = $k;
7489 $k2 =~ s/\/sys\/kernel\/mm\/transparent_hugepage\///;
7490 $sysinfo{SYSTEM}{$k} =~ s/.*\[(.*)\].*/$1/;
7491 $hugepage_info .= <<EOF;
7492 <li><span class="figure-label" data-toggle="tooltip" data-placement="top" title="$k">$k2</span> <span class="figure">$sysinfo{SYSTEM}{$k}</span></li>
7493 EOF
7494 } else {
7495 my $lbl = $k;
7496 $lbl =~ s/kernel\.//;
7497 $sysctl_info .= "<li><span class=\"figure-label\">$lbl</span> <span class=\"figure\">$sysinfo{SYSTEM}{$k}</span></li>\n";
7498 }
7499 }
7500 my $core_info = '';
7501 if (exists $sysinfo{CPU}{'cpu cores'}) {
7502 my $nsockets = $sysinfo{CPU}{'processor'}/($sysinfo{CPU}{'cpu cores'}||1);
7503 $core_info = qq{
7504 <li><span class="figure">$nsockets</span> <span class="figure-label">Sockets</span></li>
7505 <li><span class="figure">$sysinfo{CPU}{'cpu cores'}</span> <span class="figure-label">Cores per CPU</span></li>
7506 };
7507 }
7508 if ($hugepage_info) {
7509 $hugepage_info = <<EOF;
7510 <span class="figure-label"><b>/sys/kernel/mm/transparent_hugepage/</b></span>
7511 <ul>
7512 <li></li>
7513 $hugepage_info
7514 </ul>
7515 EOF
7516 }
7517
7518 if (exists $sysinfo{KERNEL}{'kernel'} || exists $sysinfo{CPU}{'processor'}) {
7519 print <<EOF;
7520 <ul id="slides">
7521 <li class="slide active-slide" id="info-slide">
7522
7523 <div id="info"><br/><br/><br/></div>
7524 <div class="row">
7525 <div class="col-md-3">
7526 <div class="panel panel-default">
7527 <div class="panel-heading">
7528 <i class="glyphicon icon-desktop icon-2x pull-left"></i><h2>System</h2>
7529 </div>
7530 <div class="panel-body panel-xlheight">
7531 <div class="key-figures">
7532 <span class="figure-label"><b>OS information</b></span>
7533 <ul>
7534 <li></li>
7535 <li><span class="figure">$sysinfo{UPTIME}{'uptime'}</span> <span class="figure-label">Uptime</span></li>
7536 <li><span class="figure">$sysinfo{KERNEL}{'hostname'}</span> <span class="figure-label">Hostname</span></li>
7537 <li><span class="figure">$sysinfo{KERNEL}{'kernel'}</span> <span class="figure-label">Kernel</span></li>
7538 <li><span class="figure">$sysinfo{KERNEL}{'arch'}</span> <span class="figure-label">Arch</span></li>
7539 <li><span class="figure">$sysinfo{RELEASE}{'name'}</span> <span class="figure-label">Distribution</span></li>
7540 $release_version
7541 </ul>
7542 </div>
7543 </div>
7544 </div>
7545 </div><!--/span-->
7546
7547 <div class="col-md-3">
7548 <div class="panel panel-default">
7549 <div class="panel-heading">
7550 <i class="glyphicon icon-gear icon-2x pull-left"></i><h2>Kernel</h2>
7551 </div>
7552 <div class="panel-body panel-xlheight">
7553 <div class="key-figures">
7554 $hugepage_info
7555 <span class="figure-label"><b>sysctl parameters</b></span>
7556 <ul>
7557 <li></li>
7558 $sysctl_info
7559 </ul>
7560 </div>
7561 </div>
7562 </div>
7563 </div><!--/span-->
7564 <div class="col-md-3">
7565 <div class="panel panel-default">
7566 <div class="panel-heading">
7567 <i class="glyphicon icon-dashboard icon-2x pull-left"></i><h2>CPU</h2>
7568 </div>
7569 <div class="panel-body panel-xlheight">
7570 <div class="key-figures">
7571 <span class="figure-label"><b>CPUs information</b></span>
7572 <ul>
7573 <li></li>
7574 <li><span class="figure">$sysinfo{CPU}{'model name'}</span></li>
7575 <li><span class="figure">$sysinfo{CPU}{'cpu MHz'}</span> <span class="figure-label">Speed</span></li>
7576 <li><span class="figure">$sysinfo{CPU}{'cache size'}</span> <span class="figure-label">Cache</span></li>
7577 $core_info
7578 <li><span class="figure">$sysinfo{CPU}{'processor'}</span> <span class="figure-label">Cores</span></li>
7579 </ul>
7580 </div>
7581 </div>
7582 </div>
7583 </div><!--/span-->
7584 <div class="col-md-3">
7585 <div class="panel panel-default">
7586 <div class="panel-heading">
7587 <i class="glyphicon icon-tasks icon-2x pull-left"></i><h2>Memory</h2>
7588 </div>
7589 <div class="panel-body panel-xlheight">
7590 <div class="key-figures">
7591 <span class="figure-label"><b>Memory information</b></span>
7592 <ul>
7593 <li></li>
7594 <li><span class="figure">$sysinfo{MEMORY}{'memtotal'}</span> <span class="figure-label">Total memory</span></li>
7595 <li><span class="figure">$sysinfo{MEMORY}{'memfree'}</span> <span class="figure-label">Free memory</span></li>
7596 <li><span class="figure">$sysinfo{MEMORY}{'buffers'}</span> <span class="figure-label">Buffers</span></li>
7597 <li><span class="figure">$sysinfo{MEMORY}{'cached'}</span> <span class="figure-label">Cached</span></li>
7598 <li><span class="figure">$sysinfo{MEMORY}{'swaptotal'}</span> <span class="figure-label">Total swap</span></li>
7599 <li><span class="figure">$sysinfo{MEMORY}{'swapfree'}</span> <span class="figure-label">Free swap</span></li>
7600 <li><span class="figure">$sysinfo{MEMORY}{'pagetables'}</span> <span class="figure-label">Page Tables</span></li>
7601 EOF
7602 if (exists $sysinfo{MEMORY}{'shmem'}) {
7603 print <<EOF;
7604 <li><span class="figure">$sysinfo{MEMORY}{'shmem'}</span> <span class="figure-label">Shared memory</span></li>
7605 EOF
7606 }
7607 if (exists $sysinfo{MEMORY}{'commitlimit'}) {
7608 print <<EOF;
7609 <li><span class="figure">$sysinfo{MEMORY}{'commitlimit'}</span> <span class="figure-label">Commit limit</span></li>
7610 <li><span class="figure">$sysinfo{MEMORY}{'committed_as'}</span> <span class="figure-label">Committed</span></li>
7611 EOF
7612 }
7613 if (exists $sysinfo{SYSTEM}{'kernel.shmmax'} and exists $sysinfo{SYSTEM}{'kernel.shmall'}) {
7614 $sysinfo{SYSTEM}{'kernel.shmmax'} = pretty_print_size($sysinfo{SYSTEM}{'kernel.shmmax'});
7615 $sysinfo{SYSTEM}{'kernel.shmall'} = pretty_print_size($sysinfo{SYSTEM}{'kernel.shmall'} * 1024 * 4);
7616 print <<EOF;
7617 </ul>
7618 <span class="figure-label"><b>sysctl parameters</b></span>
7619 <ul>
7620 <li></li>
7621 <li><span class="figure">$sysinfo{SYSTEM}{'kernel.shmmax'}</span> <span class="figure-label">kernel.shmmax</span></li>
7622 <li><span class="figure">$sysinfo{SYSTEM}{'kernel.shmall'}</span> <span class="figure-label">kernel.shmall</span></li>
7623 EOF
7624 }
7625 } else {
7626 print <<EOF;
7627 <ul id="slides">
7628 <li class="slide active-slide" id="info-slide">
7629
7630 <div id="info"><br/><br/><br/></div>
7631 <div class="row">
7632 <div class="col-md-12">
7633 <div class="panel panel-default">
7634 <div class="panel-heading">
7635 <i class="glyphicon icon-desktop icon-2x pull-left"></i><h2>No System information available</h2>
7636 </div>
7637 <div class="key-figures">
7638 <ul>
7639 <li></li>
7640 </ul>
7641 </div>
7642 </div>
7643 </div>
7644 </div><!--/span-->
7645 </div>
7646 EOF
7647 }
7648 if (exists $sysinfo{DF} || exists $sysinfo{MOUNT}) {
7649 my @df_infos = ();
7650 push(@df_infos, @{$sysinfo{DF}}) if (exists $sysinfo{DF});
7651 my @mount_infos = ();
7652 push(@mount_infos, @{$sysinfo{MOUNT}}) if (exists $sysinfo{MOUNT});
7653 print <<EOF;
7654 </ul>
7655 </div>
7656 </div>
7657 </div>
7658 </div><!--/span-->
7659 </div>
7660
7661 <div class="row">
7662 <div class="col-md-12">
7663 <div class="panel panel-default">
7664 <div class="panel-heading">
7665 <i class="glyphicon icon-hdd icon-2x pull-left"></i><h2>Filesystem</h2>
7666 </div>
7667 <div class="panel-body panel-lheight">
7668 <div class="key-figures">
7669 <ul>
7670 <li></li>
7671 <li>
7672 <table>
7673 <tr><th>Filesystem</th><th>Size</th><th>Used</th><th>Free</th><th>Use%</th><th>Mount</th></tr>
7674 @df_infos
7675 </table>
7676 </li>
7677 <li>
7678 <table>
7679 <tr><th>Filesystem</th><th>Mount</th><th>type</th><th>Options</th></tr>
7680 @mount_infos
7681 </table>
7682 </li>
7683 </ul>
7684 </div>
7685 </div>
7686 </div>
7687 </div><!--/span-->
7688 </div>
7689 EOF
7690 }
7691 if (exists $sysinfo{PROCESS}) {
7692 print <<EOF;
7693 <div class="row">
7694 <div class="col-md-12">
7695 <div class="panel panel-default">
7696 <div class="panel-heading">
7697 <i class="glyphicon icon-list icon-2x pull-left"></i><h2>Process list</h2>
7698 </div>
7699 <div class="panel-body panel-lheight">
7700 <div class="key-figures">
7701 <ul>
7702 <li></li>
7703 <li>
7704 <table>
7705 <tr><th>USER</th><th>PID</th><th>%CPU</th><th>%MEM</th><th>VSZ</th><th>RSS</th><th>TTY</th><th>STAT</th><th>START</th><th>TIME</th><th>COMMAND</th></tr>
7706 @{$sysinfo{PROCESS}}
7707 </table>
7708 </li>
7709 </ul>
7710 </div>
7711 </div>
7712 </div>
7713 </div><!--/span-->
7714 </div>
7715
7716 </li>
7717 EOF
7718 }
7719 print <<EOF;
7720 </ul> <!-- end of slides -->
7721 EOF
7722
7723 }
7724
7725 sub html_header
7726 {
7727 my @db_list = @_;
7728
7729 my $pgcluu_ico =
7730 'data:image/png;base64,
7731 iVBORw0KGgoAAAANSUhEUgAAACAAAAAjCAYAAAD17ghaAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A
7732 /wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB98GCwcGIvGIhhwAAAOBSURBVFjD
7733 vZdZiI1hGMd/55gFM/Ylss4YGsuQLDP2C3uWGyVzI1mypOxSCAmFO2WJUJaoKReDIhcmSbYaaphG
7734 msgWMXZmmPnc/L96ejvfd86ZOeOp03e+733e9/m/z/5EaBxFgWFAgd6fAg+BBv4D9QBuAj8BT79f
7735 wG2gT3MK7gSs0y09PSt1+z8GzBagY6qFFwNvjZCfwEygNdAKmAJ8NOvvgOWpEFwAXDEH1wAngPQA
7736 vzjsALlu/CQp6gKcBr6bwy4A+Qns7QucNPt+AGeBrokIjgArgM/mgCpgcpx9LbTX0ljgsTnnG7Aa
7737 yAhTd7XZ8BfYKtW6NA7oad63yB9iAVsD1JpzXwDDXcZlhqEWOAfkhdx4krM+QsKCqJd8x4buGn+x
7738 P/BVH8uBIQG3bipFBPqeMclwhMQDKgK82/fwZMIqO05SqpDM9VEgRx/vyO5B6N843yaHAM4HRoUA
7739 KNczN2psVx+yoR4oNe9zgRvAfr2XKgf49AAoCTnP8520sbZeoudAmXA2sFL5I+mqlij1BLYBWUCd
7740 STo9DE8bIA2Yn0oAUfnAUWA3sA+4q7VvwC3DWyNfuggcSAWAlsBi3Wy0bFcInAEuSyOl8odF8qfB
7741 4lsBdIgHIC3Oegbw0omGzsobc8z3qXrmGAfLVP6vaYoGvqqi/XDU/gvoJjDdgXZae69MGgFeOeAb
7742 7QPZ0tRSYK1ufkz9QTXwGngO7BXQkbL/GAGNS4ektmMxKlqGOp4nxlyzTEfkOb+DCTr/WfEfiaeB
7743 PKCfwi1fTnXcJC3PPD2F34BU5oHnakrSJLxMNo8ap/TM/17A/URDMBEAtcAl4JNKboEERozwiDGd
7744 J5/ZCCxIFoAXwLNR9b/I4fUMCM/RBMCEBGqBl6YOFpXPaIyiVCPvznHUHolhBktVIZf2a8YHgIkq
7745 w3VqwVoEbLrmeP8LYDOwU+HmrzXIZO0DAGwAfmuWmOYe7insxscIyaEaRL6oNyg0azNMI9ugAcal
7746 IuCRkVNm+4kosMss1mv8cm+RrvTaOiBki6VRV3tXnelpR1AZGKUhs84wrwLaNqJnyFaB8s+pUydU
7747 GG9jujqeCrO5MsmecKGj7ipgngpUUrTTaaXLgUEh/Lmaku1UtKep7XRv4Lwzip9yzJIJHJFAn69E
7748 gFJG04FnRsAnYDuwyRlIq9UjNgu1Uof0OkYlfKMuKCuZA/8B+QsSxkN8YYwAAAAASUVORK5CYII=
7749 ';
7750 my $date = localtime(time);
7751 print qq{Content-Type: text/html; charset=$charset
7752
7753 <!DOCTYPE html>
7754 <html lang="en">
7755 <head>
7756 <meta charset="utf-8">
7757 <meta http-equiv="X-UA-Compatible" content="IE=edge">
7758 <meta name="viewport" content="width=device-width, initial-scale=1.0">
7759 <meta http-equiv="Content-Type" content="text/html; charset=$charset" />
7760 <meta name="robots" content="noindex,nofollow">
7761 <meta http-equiv="Expires" content="$date">
7762 <meta http-equiv="Generator" content="pgCluu v$VERSION">
7763 <meta http-equiv="Date" content="$date">
7764
7765 <meta name="description" content="">
7766 <meta name="author" content="">
7767 <link rel="shortcut icon" href="$pgcluu_ico" />
7768
7769 <title>$PROGRAM</title>
7770
7771 <link href="$RSC_BASE/jquery.jqplot.min.css" rel="stylesheet">
7772 <script type="text/javascript" src="$RSC_BASE/jquery.min.js"></script>
7773 <script type="text/javascript" src="$RSC_BASE/jquery.jqplot.min.js"></script>
7774 <script type="text/javascript" src="$RSC_BASE/jqplot.pieRenderer.min.js"></script>
7775 <script type="text/javascript" src="$RSC_BASE/jqplot.barRenderer.min.js"></script>
7776 <script type="text/javascript" src="$RSC_BASE/jqplot.dateAxisRenderer.min.js"></script>
7777 <script type="text/javascript" src="$RSC_BASE/jqplot.canvasTextRenderer.min.js"></script>
7778 <script type="text/javascript" src="$RSC_BASE/jqplot.categoryAxisRenderer.min.js"></script>
7779 <script type="text/javascript" src="$RSC_BASE/jqplot.canvasAxisTickRenderer.min.js"></script>
7780 <script type="text/javascript" src="$RSC_BASE/jqplot.canvasAxisLabelRenderer.min.js"></script>
7781 <script type="text/javascript" src="$RSC_BASE/jqplot.highlighter.min.js"></script>
7782 <script type="text/javascript" src="$RSC_BASE/jqplot.highlighter.min.js"></script>
7783 <script type="text/javascript" src="$RSC_BASE/jqplot.cursor.min.js"></script>
7784 <script type="text/javascript" src="$RSC_BASE/jqplot.pointLabels.min.js"></script>
7785 <script type="text/javascript" src="$RSC_BASE/bean.min.js"></script>
7786 <script type="text/javascript" src="$RSC_BASE/underscore.min.js"></script>
7787 <link href="$RSC_BASE/bootstrap.min.css" rel="stylesheet">
7788 <link href="$RSC_BASE/fontawesome.min.css" rel="stylesheet">
7789 <script type="text/javascript" src="$RSC_BASE/bootstrap.min.js"></script>
7790
7791 <link href="$RSC_BASE/pgcluu.min.css" rel="stylesheet">
7792 <link href="$RSC_BASE/bootstrap-datetimepicker.min.css" rel="stylesheet">
7793 <script src="$RSC_BASE/pgcluu.min.js"></script>
7794 <script src="$RSC_BASE/pgcluu_slide.min.js"></script>
7795 <script src="$RSC_BASE/sorttable.min.js"></script>
7796 <script src="$RSC_BASE/bootstrap-datetimepicker.min.js"></script>
7797
7798 </head>
7799
7800 <body>
7801
7802 <div class="container" id="main-container">
7803 };
7804
7805 }
7806
7807 sub html_footer
7808 {
7809 my $db = shift();
7810
7811 print qq{
7812 <hr>
7813 <footer>
7814 <p>&copy; Gilles Darold 2012-2024</p>
7815 <p>Report generated by <a href="http://pgcluu.darold.net/">$PROGRAM</a> $VERSION.</p>
7816 </footer>
7817
7818 <!-- Modal -->
7819 <div class="modal fade" id="pgcluuModal" role="dialog">
7820 <div class="modal-dialog">
7821
7822 <!-- Modal content-->
7823 <div class="modal-content">
7824 <div class="modal-header">
7825 <button type="button" class="close" data-dismiss="modal">&times;</button>
7826 <h4 class="modal-title">Right click + "Save image as ..." to save the graph as PNG image</h4>
7827 </div>
7828 <div class="modal-body">
7829 <img src="" />
7830 </div>
7831 <div class="modal-footer">
7832 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
7833 </div>
7834 </div>
7835
7836 </div>
7837 </div>
7838
7839 </div><!--/.container-->
7840 };
7841
7842 print &generate_menu();
7843 print qq{
7844 </body>
7845 </html>
7846 };
7847
7848 }
7849
7850 sub generate_menu
7851 {
7852 my $date = localtime(time);
7853
7854 my $pgcluu_logo =
7855 'data:image/png;base64,
7856 iVBORw0KGgoAAAANSUhEUgAAAJgAAAAsCAYAAACZmXFCAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A
7857 /wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB98GCwcUDSKty5YAABOVSURBVHja
7858 7Vx7lF1Vff6+fe5MJi8SQh4ESIDI+2nrQtQCihVRsFhZKmh9oKII6rJSq6uCj7ZSLK0Wn0trVSit
7859 BbUiRV0KUqlFRZRHKmCUdwpESEgCCTOTuXd/X/+Y3xl3DvfOI6Qugdlr3TV3zj1nn31++/t9v9fe
7860 B3icTdLY95wzbI/9X36fbk/Nxm290DbI0cs7nQ5TSgO255BMtgdTSoMkc/Pc6TYNsHFbzhkAUFVV
7861 DbQB288E8BIABwLoA3A/gO+QvILk+pLpUkrTUp9ukzaP+0g6V9L9kmzbxd9BSZfaPsL2QMl8NUin
7862 23Tr6mvZXizpTZKuk+T4PCzp6pzztyXdXYBtnaQP296/V3/T7SncSke90+nMsv1Hki6TtMWjLdv+
7863 L9tvyTkvzznvmHM+VtKFkjYWQLve9jsl7TYNtOkGSVuBK+d8hKTPSlpds5btm22fLWm/Lr7aTpJe
7864 Y/u7trfENUOSLpd0kqS50yCbZi3YPjTn/PeSbpXUCaA8KOlvbR8uaaB5XQ0Y25C0wvZbJV1bmNP7
7865 JH055/ySZvAw3Z46ftYM2++zfYukwdrU5Zz/RdIzcs6zukWY3djIdp+k3SW9W9LGYL+2pPttX5Rz
7866 XlaCdJrRxp+bJxzz28bIyEgJlMNyzt+X1C5YZ42kE3POA+vXr0cDEP0551Q8+GLbe3e5Twpwfl9S
7867 J0DbzjnfL+kU23yyM9p4yedev413ze+8nMoB5pwXSzrH9oMFsO6X9AlJyxvn1g+/QNIHcs77FwI5
7868 Led8Qi9Nsz075/w2STcU9xm0/XVJz3gy+mZNkISFmC9poaQdmsrVBI7tubb/xPYrbL9S0sk55wOf
7869 SBS8NOd8aTHhm2x/0fZh40247QFJz805L2ow2LwePl0J0mWS/tz26ohILelXpW/2RAZZ6YsWcjlZ
7870 0vk5569I+o7tqyR9U9IXcs5nSjqw0+mMAazuI+d8YM55cyjikKTBnPP7nyiCmCHpvQW4rpP0opGR
7871 kaoJjDCJrdIk9vLBymt6BQJxbE/bFxbR6bckrXgS+U9zbZ8i6ReScuHPupC5JWVJG3LO/yRpeUO2
7872 B0naVJ+bcx6U9KHf+YcPUOwi6eoY/E9zzvuNE1XOkHRczvnQyTBMocUzbS+S1Net3+Hh4UrS50L4
7873 d9h+8RMZVAUDLZb0sQJEGn3E3wCsBlzxWWf7pMYcHJRz3tRwKT74uy6HFLXBuQAWkATJH1ZVtao8
7874 qVGorgDsAWDX6AA555mSDpE0rxDsnHa7PVZ7tP0020eTnNvsd8uWLRgYGMgkPx+F8R0ALCn9ku3h
7875 90zF3HbxgaZ036qqkHNeAOBcAO8iaZKK30myTXKt7TW215DcWHSxBUD7ycDerZjQfgD9HpXi4ATX
7876 DAG4CMBwcezVAM4A8Mmqqi7IOR9D8uiU0iUAVoZQ15AcArC52WF/fz8KwcN2C6NFcwJwr0mcaIVG
7877 8/ca7OMV3ut+62J+r756sXVKCfEMle3TALxxtFs7noe2bwdwBYCfAHg0ju1K8tm2n0Vyju1qIhDX
7878 Y6rvO56yBOAf81zN8QfJTPiME8m/Tje14qQxAdhOEzyUAWwqju1t+1Tbvw/gyJzzNQDOt70fyR0B
7879 nA4AVVU9BOChbuCov5NkMIUnYpyYxD7bewJYYLsDoJVS2gTgFyQlaU/bB6eUFgYj3Gn7+pTScHNi
7880 bG81LtsH2N7X9jySm0jeTnJlXLcryaW2FcPeYvvulNLmuk9J+6aU3lo8D+PzI5IfJPnDULhy8i4C
7881 8CwAxwN4eDwGLeUXEz4gaS+Sc2OOKkmPAlhZVZVjDtDpdKqU0n4kF0rKJPtIrie5spBFZXt327uQ
7882 7JBsBfH8D8lOLafAyh62l9nOJCuSm2zfQnILALQm0vpJmIkdAcyNGy4i+YdhQgngkJxzq6qqTn1y
7883 u92eVP8kJ2PS5gN4u+0XxWT1214ZObWX234ryT0BzLItkg+RvErSuSml1QGEJrDm2H697dcBWE5y
7884 BoAR22skXUbyfADPt312CL1l+z6SZwG4vp4kkscBWF6Ci+Q9ts9JKX2vZITapKaU1gP4tqQf92Lu
7885 8bIAJM8GcCiADKAieSeAlwEYKcA4h+TbbR8bIJgB4Drbry5M+GwArwfw2njGftt3AzgJwIYCIzMB
7886 vArAacHE/bZXkTwNwL1jAJuI7mqtLEzMcpLn2b5b0pUkB0OoO0WfbZIDkvpJJklH2T4FwOerqvrx
7887 RAnFAOtk5NoPYHeSZVJ3Y0rp3bbfSXJhA7gLAOwNYHHO+fSqqh4sTYKkGQBOBfBhALNLmdheQnI/
7888 AAfbvhXAPsU9F9ieU8irn+RR8SwOXzIDuILkf5dmq5ZpznnMvKaUNpRmpqqqCWUSbs4KAPsVc9qS
7889 lBrnVQB2A7BnIes1je4qALuGctatL46XMqkALAGwrJDVcMwLxgBWD74XyIKCZ0rqD/NyakQ5q1NK
7890 v7S9Lk59EMCVts8BkEj+AsBOJD8M4EgAS22fQfKu7bHK1aNOW6f4TgD7AjiwLqYXAHJ8EoATSd5o
7891 +zySI4U5PtT2WSRn13m5WKFby2gAwEsBPAdAh2QrJr1TMg7JebafW1gEAtgY5nFTba62mtEuvtFU
7892 5BNA7jRciC0pJTdlBiAXjI2QYTl+A8gNi7KlyapxbW6MtePiwq0YbALWOJLkzpK+TvL4OH8hgNkA
7893 Pg7gHgCXpJR+Jek8APsD+EuS+9uuM86H2346gLu6Ca92Hqcg1LGxx3eF2STJywH8Rxx7QVB5LZCK
7894 5Nts/1u73b6jr68PJGcCeAuAhbWASKbwOy60vc72gSTfE1pbYHBrxziy9LNioupjDwK4c7IBymQi
7895 1YncmXAL2A20UwmSaj+yeX4vYir/34rBJqiTPUpyTTh2fXFufwj7SwD+MzQZJP8OQF+sGTs4Jgq2
7896 ZwBYIqmVUupM9HCtVmvSICvGSZLfInkygKGIjL5Ocp3td0giSdneGcDxrVbrU6MEplkk31QDJ8Z8
7897 h+3TSF4bzAcAK0n+awHCbmMqqxgplGeD7QemykyTcfK7BSm1MuWcNdVIsUyQF8rrbWHYVHZU+lld
7898 fLAfkrwypdQheXXBuCoipZbt/vh/iKRSShtJDkX/QyTXbty4sdPL1ysfrtPpTFqTQ1PrvN5Hwy90
7899 VVVOKW20fRnJB1JKiaMNkRaocs4k+bxamHEObF9M8oY4pqqqZPtySdeEC1BOQDmmHYuI23FshOTw
7900 tjLWZNimOKcGv7pZiXK8PRRkDA8FS7lXXnE869fqQoVdTVen00FVVTMiHP0MgINsD5G8NqV0ku2D
7901 AQwHS7UB3ATgKgA32b4EwPHBLNcsWLCga+5mWzS7FECkWX4N4K5mf3H8zmDc+roDAMwIs3l02U8k
7902 O2+vfbTifiMAVgE4ohn1Ft/XFoxSp15mRnT222h1PjH3yntN5Hd3K/H1yiuO199joshuKA0k72D7
7903 TyMv8jeSjk8ptaK6/w/xezmgDoDLAZy+du3ady1atOhTAO6NnFFPzZnqXsrSf4y/68okcBEBb7b9
7904 SD3pRVQ5g+Sg7V1KVo8+HurhTNfrlXrNzmABeIWZXBjVj1t/i9v43GUly4SgaMyBez1nk9K6+tUT
7905 TWyR13kOgLMBvM/2ISmloQiL32R7h7iZi0G1AJxg+4wlS5YgpXTHeODqBrbJbHEr+qqZog1AXbL3
7906 3aKnqhZelHJKf4bsMtDa9ZogJzVI8sH6+jA5C0g+baIcX1miKs8pv3czyz3mvq/LbzPrXV5TYbBu
7907 OdNIW8wajxTSFGz9orgJAfyBpHm23xshe23zWUdOYf9p+8RYxzS/rjtOdmHdZLW8Nm1x/sJIADbb
7908 bADzYnJqv+iROglp++4Alovzl3TDNIDFRTjfDWAbAfygeB5HVeOYnPPS8Zz00qSVQGyY+27gcBdZ
7909 zkgpseEvLSa5qARiD7m7YdX6euTeFtUy7TavaSIkF5pzW5SIqvAlTib5qlLQjURpnb0+yPanbH8k
7910 57xiYGBgXICVTv5kV2s2tHkpyaVdtH4hgGWNybgrWFXhL47ly0hWtg9qt9sDjdvNBfDM8dikr68v
7911 A/geAEU0Wv/4PAAn9grti4TvvpL2KFl8AjMG251wX8rzZ9TMU5SB9iS5x0SFAZK50dcs202QzcHo
7912 ZuueLs5jTGQThsUD/hzAN8OBvhtAXWdTUWcr7XX9v4O9TiP5Ztsze5m+icLnSWT/60j2dNuprK1F
7913 gnR55K7q+1xnuxPn/YzkMMlUMNPLqqp6Wb2qw/YSAGeT3L8oqzym8BzHryB5c2NsC0ieGdv3FnVR
7914 5n1t/xnJjwN4+hS9+g0ANjUYaamkI4r+dyX5mvA93UvmkkZqP7P4fRHJo8tcH4C3RUXDPVh1zK6O
7915 AaRbaBsXPhrrj3aJMsPTS0e3YDE3SiSO74nkQWHC/rdHIKFteWFK4bjXYH9lrLu6PEo0LwRwchEl
7916 JtsZwLfjLwA8bPszAM4stHgZgHNsH297cyyMPGo8v7VQyHttnwvgy8FitVxXAPgAgBfbvt32WpKz
7917 YvL3tH1opHiqqbgPJDfa3tBYlDCL5Eds/x6AIdvH2H5B03lvAqOqqmFJdxX+pqKi8X7be0naYPsI
7918 kicUc97NZUUrEm/DUdQkyfndlmbEQ9xu+14AJzRMoRtrt1zetHiAobLw2pyU4hUDbQBD9SqAKWSb
7919 STLbHghNPS7GMQ/AQPhpdTBwEYBba59H0paU0j8D+GMAK8JsKupxy+toMCb+HgBLo7jbjQFq/+kb
7920 JN8ftc1UMPoCkscAOJpkO/rtDxmmWEnh8aK/bgnRMMvHhb/nGP8hAPYKRZob/XfCQWcv98j2qkjT
7921 7FWDDMB+4Xd3ANRLilwr7XhO/gaMvrAEkQ86sqGNpT/EwndTwRojAB4AsL528GstCbOTSf6I5APd
7922 IqNYw//ueNh1AO6bDMAagqftayNB2gKwmOTiGlwhUAK4y/bHY2nPqKa1WiB5K8m/AvBIsE4qos2+
7923 WI7yjyQ/Ybu/nOyIUscUJpRz2Pb5GF1w2C5WVdTs0Re+zczyfrZbPVwVFlUXllFq/L3A9rWFOGrL
7924 NCeUrEPysyS/V4MrPt2CvVtIfhe/oaYahbOiUlEB+DGAL9RF8BhHKqPsFBq80fZXo1C5v6QLJJ0Z
7925 PkczZTAM4DuhZakA6ccAHEZyH9t/Wfdf+zwAfhQmayt2zDn3Szre9tdIvjR+vsH2zVM1lVEJaIVv
7926 8FHbGyXVZoCRm7sOwBskreySkW5LuhijiwSvClO+FsB9US46JfpeXESHXet0tbxSSo/a/jSAY0he
7927 HD7scCgDi0WWJvkAyWtIfgTA1Q0lzCQ3214LYC3JR8IibKVoKaXTbX8j/DEWlmW17Q+FeV4HYBPJ
7928 eiXtI8Uusbqfh0l+jOSFgQ8WgdsaAJ8G8HLbd0bw9+uo1z4i6TdsVJjBWZHjOquuY9m+nuSnAXy1
7929 XBwXC/2OCjqea/tG21+uqurhYtLeEuZhN9u32D61qqprG0ndw2y/B8Cx0Q9iIl9H8rZ2u42+vr7x
7930 2GsXAJ+sI7ManABemFJ6KBzcZ2N0zVoGcBvJK0NAY0tmuq1wzTnPJ7l7mJXNsXJkvaSZAC4k+Ypi
7931 lepK22+squqG8YrSOecZkQs7wPYyADuE9o+klO6XtArAr6qqWtfl2lkppWfGKgcGQO9OKd3TxaWZ
7932 D+DZUZwfkPQAyetJ3hTPug/JBUEoLZKPpJRuLqsrBQHMA3A4yYNIzpa0NqV0Pcmf5pwTyWUxD4o0
7933 1RBGF3yOjFm9Rgb+9bbvjR0u9YaEayQt7RKmYnBwsGstMf6fl3PePec8t5g4ttvt/tgIsanY8LAh
7934 5/y5ctfRRAsObe9i+98bmyZ+2i1CGy+hWRamJc3OOfePw5IHSGrHPRUbN75oe8eJ2HUqTNxtD+pk
7935 cofb+lbJ7b1z/DHjaABjhe0LbN8XW/ydcx6y/Q7byyS1xhtMt4HF6zXnS3qRpJ8XgNhg++pyF9FE
7936 Kzt6ASzn7Jzzz8YD2HhCk7RzbDL+C9sHSlpie358lkg6XNKNoXg5zP8WSW+c7OSOd8723APa7Gtb
7937 d4BvV+B1YaAX275E0v0555rNfmD7DbZ3v+KKKyY7cTtKOlbSlyRtKTb2ft/2GfXiwMkCqwSYpG1i
7938 sB7jXBJv/3GE6ZdL+nx8vmv70fitU9zz4nrT8fQ7NSbZSrTb3iHnfHK8E2wohDos6XLbJ5emoeko
7939 htCPtP0J2/cVIPiJpPfY3v3xaIWkXWxf2thTeMPjANjOti8rNgCP/a1bYy/jN+v9odNvB3qcbGZ7
7940 qaR3BEOMbRCNF809t8v1KySdFbuZy9c2nWf7kO1BucFglzU2sd4kafE2PvM8SX8t6V5JIz02xW7O
7941 Od8Ub21c8Xh9nyd742TYrCzA5pwPSSm90vabi3D9jog0vwZgg6TjUkonAXhO5FgE4GsAviTp6lar
7942 Ndyr/ykCbJbt50e5YiTySr8GcGm9NW2yyhTRF20vsb0vgL1J7kZyVp1QBLCZ5C8lrZL0876+vk55
7943 /XTbTk6jpBm2j7b9FdvDodlt26uCQcot7jdKeoPtnba3Q7t69eoaFMk22+0267zXVPvvdn6n0+mT
7944 NNP2rJzzY4q9vd6HNt22U2QSrx56re2rbA+XvkqYxg9Kelqn00nbO1L6//J5JmPqpkG1HU3keCal
7945 zh3ZXkrysHoJMkZXW1xH8rZyW9i0GZlu28QgnU4HtplzbknqyzmnRiQ6LbCnaPs/zGhC2bEgIrsA
7946 AAAASUVORK5CYII=';
7947
7948 my $menu_str = qq{
7949 <!-- Load navbar -->
7950 <div id="navigation">
7951 <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
7952 <a class="navbar-brand" href="" onclick="document.location.href='$SCRIPT_NAME?action=home'; return false;">
7953 <img src="$pgcluu_logo" title="$PROGRAM"></a>
7954 <div class="container mainmenu">
7955 <div class="navbar-header">
7956 <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
7957 <span class="icon-bar"></span>
7958 <span class="icon-bar"></span>
7959 <span class="icon-bar"></span>
7960 </button>
7961 </div>
7962
7963 <div class="navbar-inverse navbar-collapse collapse">
7964 <ul class="nav navbar-nav">
7965 <li id="menu-home" class="dropdown"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=home&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Home</a></li>
7966 };
7967 $menu_str .= qq{
7968 <li id="menu-info" class="dropdown"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=sysinfo&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">SysInfo</a></li>
7969 } if ($#DATABASE_LIST >= 0 || $#DEVICE_LIST >= 0);
7970
7971 if ($#DATABASE_LIST >= 0) {
7972
7973 $menu_str .= qq{
7974 <li id="menu-cluster" class="dropdown">
7975 <a href="#" class="dropdown-toggle" data-toggle="dropdown">Cluster <b class="caret"></b></a>
7976 <ul class="dropdown-menu">
7977 <li id="menu-cluster-size"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-size&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Databases sizes</a></li>
7978 <li id="menu-tablespace-size"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=tablespace-size&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Tablespaces sizes</a></li>
7979 };
7980 $menu_str .= qq{
7981 <li id="menu-connectionbackend" class="dropdown-submenu">
7982 <a href="#" tabindex="-1">Connections </a>
7983 <ul class="dropdown-menu">
7984 <li id="menu-cluster-backends"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-backends&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Connections</a></li>
7985 <li id="menu-cluster-connections"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-connections&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Connections by type</a></li>
7986 </ul>
7987 </li>
7988 };
7989 if (&backend_minimum_version(9.2)) {
7990 $menu_str .= qq{
7991 <li id="menu-cluster-deadlocks"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-deadlocks&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Deadlocks</a></li>
7992 };
7993 }
7994 $menu_str .= qq{
7995 <li class="divider"></li>
7996 <li id="menu-cluster-cache_ratio"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-cache_ratio&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Cache utilization</a></li>
7997 <li id="menu-pgbuffercache" class="dropdown-submenu">
7998 <a href="#" tabindex="-1">Shared buffers statistics </a>
7999 <ul class="dropdown-menu">
8000 <li id="menu-cluster-buffersused"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-buffersused&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Shared buffers utilization</a></li>
8001 <li id="menu-cluster-databaseloaded"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-databaseloaded&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Database in shared buffers</a></li>
8002 <li id="menu-cluster-usagecount"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-usagecount&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Usagecount in shared buffers</a></li>
8003 <li id="menu-cluster-isdirty"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-isdirty&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Usagecount in dirty buffers</a></li>
8004 </ul>
8005 </li>
8006 <li class="divider"></li>
8007 <li id="menu-backgroundwriter" class="dropdown-submenu">
8008 <a href="#" tabindex="-1">Background writer </a>
8009 <ul class="dropdown-menu">
8010 <li id="menu-cluster-bgwriter_write"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-bgwriter_write&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Bgwriter buffers written</a></li>
8011 <li id="menu-cluster-bgwriter_read"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-bgwriter_read&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Bgwriter buffers allocated</a></li>
8012 <li id="menu-cluster-bgwriter_count"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-bgwriter_count&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Bgwriter counters</a></li>
8013 </ul>
8014 </li>
8015 };
8016 if (&backend_minimum_version(9.2)) {
8017 $menu_str .= qq{
8018 <li id="menu-temporaryfiles" class="dropdown-submenu">
8019 <a href="#" tabindex="-1">Temporary files </a>
8020 <ul class="dropdown-menu">
8021 <li id="menu-cluster-temporary_files"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-temporary_files&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Temporary files</a></li>
8022 <li id="menu-cluster-temporary_bytes"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-temporary_bytes&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Temporary files size</a></li>
8023 </ul>
8024 </li>
8025 };
8026 }
8027 $menu_str .= qq{
8028 <li id="menu-walcheckpoint" class="dropdown-submenu">
8029 <a href="#" tabindex="-1">Wal / Checkpoint </a>
8030 <ul class="dropdown-menu">
8031 <li id="menu-cluster-xlog_files"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-xlog_files&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Wal files</a></li>
8032 <li id="menu-cluster-checkpoints"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-checkpoints&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Checkpoints counter</a></li>
8033 <li id="menu-cluster-checkpoints_time"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-checkpoints_time&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Checkpoints write time</a></li>
8034 <li id="menu-cluster-archive"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-archive&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Archiver stats</a></li>
8035 </ul>
8036 </li>
8037 <li id="menu-rw" class="dropdown-submenu">
8038 <a href="#" tabindex="-1">Queries Reads / Writes </a>
8039 <ul class="dropdown-menu">
8040 <li id="menu-cluster-read_ratio"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-read_ratio&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Read tuples</a></li>
8041 <li id="menu-cluster-write_ratio"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-write_ratio&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Write ratio</a></li>
8042 <li id="menu-cluster-read_write_query"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-read_write_query&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Read vs Write queries</a></li>
8043 <li id="menu-cluster-commits_rollbacks"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-commits_rollbacks&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Commits vs Rollbacks</a></li>
8044 </ul>
8045 </li>
8046 <li id="menu-cluster-transactions"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-transactions&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Transactions throughput</a></li>
8047 <li id="menu-cluster-canceled_queries"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-canceled_queries&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Canceled queries</a></li>
8048 <li class="divider"></li>
8049 <li id="menu-replication" class="dropdown-submenu">
8050 <a href="#" tabindex="-1">Replication statistics </a>
8051 <ul class="dropdown-menu">
8052 <li id="menu-cluster-xlog"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-xlog&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Wal bytes written</a></li>
8053 <li id="menu-cluster-replication"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-replication&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Replication lag</a></li>
8054 <li id="menu-cluster-conflicts"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-conflicts&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Conflicts</a></li>
8055 </ul>
8056 </li>
8057 };
8058 $menu_str .= qq{
8059 <li class="divider"></li>
8060 <li id="menu-configuration" class="dropdown-submenu">
8061 <a href="#" tabindex="-1">Configurations </a>
8062 <ul class="dropdown-menu">
8063 <li id="menu-cluster-pgconf"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-pgconf&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">PostgreSQL configuration</a></li>
8064 <li id="menu-cluster-settings"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-settings&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">PostgreSQL settings</a></li>
8065 <li id="menu-cluster-dbrolesetting"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-dbrolesetting&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Database/Roles settings</a></li>
8066 <li id="menu-cluster-alterconf"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-alterconf&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">PostgreSQL ALTER SYSTEM configuration</a></li>
8067 <li id="menu-cluster-recoveryconf"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-recoveryconf&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">PostgreSQL recovery configuration</a></li>
8068 <li id="menu-cluster-pghba"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-pghba&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">PostgreSQL authorization</a></li>
8069 <li id="menu-cluster-pgident"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-pgident&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">User Name Maps</a></li>
8070 <li id="menu-cluster-pgbouncer"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=all&action=cluster-pgbouncer&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Pgbouncer settings</a></li>
8071 </ul>
8072 </li>
8073 </ul>
8074 </li>
8075 };
8076 }
8077
8078 if ($#DATABASE_LIST >= 0) {
8079 $menu_str .= qq{
8080 <li id="menu-database" class="dropdown">
8081 <a href="#" class="dropdown-toggle" data-toggle="dropdown">Databases <b class="caret"></b></a>
8082 <ul class="dropdown-menu">
8083 };
8084 }
8085
8086 my $dbidx = 0;
8087 my $l = 0;
8088 foreach my $db (sort @DATABASE_LIST) {
8089 next if (($db eq 'all') || (($#INCLUDE_DB >= 0) && (!grep($db =~ /^$_$/, @INCLUDE_DB))));
8090 if ($#DATABASE_LIST >= 10) {
8091 my $md = $l % 10;
8092 if ($md == 0) {
8093 $dbidx++;
8094 if ($l > 0) {
8095 $menu_str .= qq{
8096 </ul>
8097 </li>
8098 };
8099 }
8100 my $lbl = '';
8101 $lbl = " (part $dbidx)" if ($#DATABASE_LIST >= 10);
8102 $menu_str .= qq{
8103 <li id="menu-device$dbidx" class="dropdown-submenu">
8104 <a href="#" tabindex="-1">Database $lbl</a>
8105 <ul class="dropdown-menu">
8106 };
8107 }
8108 $l++;
8109 }
8110
8111 $menu_str .= qq{
8112 <li id="menu-$db" class="dropdown-submenu">
8113 <a href="#" tabindex="-1">$db </a>
8114 <ul class="dropdown-menu">
8115 <li id="menu-database-info"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=database-info&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Database info</a></li>
8116 };
8117
8118 my %data_info = %{$DB_GRAPH_INFOS{'pg_stat_user_tables.csv'}};
8119 my $table_str = '';
8120 foreach my $id (sort {$a <=> $b} keys %data_info) {
8121 next if ($data_info{$id}{name} !~ /^table-/);
8122 $table_str .= qq{
8123 <li id="menu-$data_info{$id}{name}"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=$data_info{$id}{name}&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">$data_info{$id}{menu}</a></li>
8124 };
8125 }
8126 %data_info = %{$DB_GRAPH_INFOS{'pg_class_size.csv'}};
8127 foreach my $id (sort {$a <=> $b} keys %data_info) {
8128 next if ($data_info{$id}{name} !~ /^table-/);
8129 $table_str .= qq{
8130 <li id="menu-$data_info{$id}{name}"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=$data_info{$id}{name}&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">$data_info{$id}{menu}</a></li>
8131 };
8132 }
8133 %data_info = %{$DB_GRAPH_INFOS{'pg_stat_unlogged.csv'}};
8134 foreach my $id (sort {$a <=> $b} keys %data_info) {
8135 next if ($data_info{$id}{name} !~ /^table-/);
8136 $table_str .= qq{
8137 <li id="menu-$data_info{$id}{name}"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=$data_info{$id}{name}&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">$data_info{$id}{menu}</a></li>
8138 };
8139 }
8140 %data_info = %{$DB_GRAPH_INFOS{'pg_statio_user_tables.csv'}};
8141 foreach my $id (sort {$a <=> $b} keys %data_info) {
8142 next if ($data_info{$id}{name} !~ /^statio-/);
8143 $table_str .= qq{
8144 <li id="menu-$data_info{$id}{name}"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=$data_info{$id}{name}&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">$data_info{$id}{menu}</a></li>
8145 };
8146 }
8147 %data_info = %{$DB_GRAPH_INFOS{'pg_stat_ext.csv'}};
8148 foreach my $id (sort {$a <=> $b} keys %data_info) {
8149 next if ($data_info{$id}{name} !~ /^table-/);
8150 $table_str .= qq{
8151 <li id="menu-$data_info{$id}{name}"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=$data_info{$id}{name}&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">$data_info{$id}{menu}</a></li>
8152 };
8153 }
8154 my $disable_table = ' disabled';
8155 $disable_table = '' if ($table_str);
8156 $menu_str .= qq{
8157 <li id="menu-$db-table" class="dropdown-submenu $disable_table">
8158 <a href="#" tabindex="-1">Tables statistics </a>
8159 <ul class="dropdown-menu">
8160 $table_str
8161 </ul>
8162 </li>
8163 };
8164 $table_str = '';
8165
8166 my $idx_str = '';
8167 %data_info = %{$DB_GRAPH_INFOS{'pg_stat_user_indexes.csv'}};
8168 foreach my $id (sort {$a <=> $b} keys %data_info) {
8169 next if ($data_info{$id}{name} !~ /^index-/);
8170 $idx_str .= qq{
8171 <li id="menu-$data_info{$id}{name}"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=$data_info{$id}{name}&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">$data_info{$id}{menu}</a></li>
8172 };
8173 }
8174 %data_info = %{$DB_GRAPH_INFOS{'pg_class_size.csv'}};
8175 foreach my $id (sort {$a <=> $b} keys %data_info) {
8176 next if ($data_info{$id}{name} !~ /^index-/);
8177 $idx_str .= qq{
8178 <li id="menu-$data_info{$id}{name}"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=$data_info{$id}{name}&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">$data_info{$id}{menu}</a></li>
8179 };
8180 }
8181 %data_info = %{$DB_GRAPH_INFOS{'pg_stat_invalid_indexes.csv'}};
8182 foreach my $id (sort {$a <=> $b} keys %data_info) {
8183 next if ($data_info{$id}{name} !~ /^index-/);
8184 $idx_str .= qq{
8185 <li id="menu-$data_info{$id}{name}"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=$data_info{$id}{name}&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">$data_info{$id}{menu}</a></li>
8186 };
8187 }
8188 %data_info = %{$DB_GRAPH_INFOS{'pg_stat_hash_indexes.csv'}};
8189 foreach my $id (sort {$a <=> $b} keys %data_info) {
8190 next if ($data_info{$id}{name} !~ /^index-/);
8191 $idx_str .= qq{
8192 <li id="menu-$data_info{$id}{name}"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=$data_info{$id}{name}&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">$data_info{$id}{menu}</a></li>
8193 };
8194 }
8195 %data_info = %{$DB_GRAPH_INFOS{'pg_statio_user_indexes.csv'}};
8196 foreach my $id (sort {$a <=> $b} keys %data_info) {
8197 next if ($data_info{$id}{name} !~ /^statio-/);
8198 $idx_str .= qq{
8199 <li id="menu-$data_info{$id}{name}"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=$data_info{$id}{name}&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">$data_info{$id}{menu}</a></li>
8200 };
8201 }
8202 %data_info = %{$DB_GRAPH_INFOS{'pg_stat_unused_indexes.csv'}};
8203 foreach my $id (sort {$a <=> $b} keys %data_info) {
8204 $idx_str .= qq{
8205 <li id="menu-$data_info{$id}{name}"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=$data_info{$id}{name}&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">$data_info{$id}{menu}</a></li>
8206 };
8207 }
8208 %data_info = %{$DB_GRAPH_INFOS{'pg_stat_redundant_indexes.csv'}};
8209 foreach my $id (sort {$a <=> $b} keys %data_info) {
8210 $idx_str .= qq{
8211 <li id="menu-$data_info{$id}{name}"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=$data_info{$id}{name}&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">$data_info{$id}{menu}</a></li>
8212 };
8213 }
8214 %data_info = %{$DB_GRAPH_INFOS{'pg_stat_missing_fkindexes.csv'}};
8215 foreach my $id (sort {$a <=> $b} keys %data_info) {
8216 $idx_str .= qq{
8217 <li id="menu-$data_info{$id}{name}"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=$data_info{$id}{name}&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">$data_info{$id}{menu}</a></li>
8218 };
8219 }
8220 %data_info = %{$DB_GRAPH_INFOS{'pg_stat_count_indexes.csv'}};
8221 my $idx = &get_data_id('count-index', %data_info);
8222 $idx_str .= qq{
8223 <li id="menu-$data_info{$idx}{name}"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=$data_info{$idx}{name}&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Number of indexes</a></li>
8224 };
8225 my $disable_idx = ' disabled';
8226 $disable_idx = '' if ($idx_str);
8227 $menu_str .= qq{
8228 <li id="menu-$db-table" class="dropdown-submenu $disable_idx">
8229 <a href="#" tabindex="-1">Indexes statistics </a>
8230 <ul class="dropdown-menu">
8231 $idx_str
8232 </ul>
8233 </li>
8234 <li id="menu-database-functions"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=database-functions&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Functions statistics</a></li>
8235 };
8236
8237 %data_info = %{$DB_GRAPH_INFOS{'pg_relation_buffercache.csv'}};
8238 my $buffer_str = '';
8239 foreach my $id (sort {$a <=> $b} keys %data_info) {
8240 next if ($data_info{$id}{name} !~ /buffercache/);
8241 $buffer_str .= qq{
8242 <li id="menu-$data_info{$id}{name}"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=$data_info{$id}{name}&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">$data_info{$id}{menu}</a></li>
8243 };
8244 }
8245 my $disable_buffer = ' disabled';
8246 $disable_buffer = '' if ($buffer_str);
8247 $menu_str .= qq{
8248 <li id="menu-$db-buffercache-relation" class="dropdown-submenu $disable_buffer">
8249 <a href="#" tabindex="-1">Buffercache Statistics </a>
8250 <ul class="dropdown-menu">
8251 $buffer_str
8252 </ul>
8253 </li>
8254 };
8255 $buffer_str = '';
8256
8257 $menu_str .= qq{
8258 <li id="menu-database-queries"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=database-queries&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Statements statistics</a></li>
8259 };
8260
8261 $menu_str .= qq{
8262 <li class="divider"></li>
8263 <li id="menu-database-size"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=database-size&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Database size</a></li>
8264 <li id="menu-${db}_connections" class="dropdown-submenu">
8265 <a href="#" tabindex="-1">Connections </a>
8266 <ul class="dropdown-menu">
8267 <li id="menu-database-backends"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=database-backends&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Connections</a></li>
8268 <li id="menu-database-connections"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=database-connections&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Connections by type</a></li>
8269 </ul>
8270 </li>
8271 <li id="menu-database-cache_ratio"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=database-cache_ratio&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Cache utilization</a></li>
8272 <li class="divider"></li>
8273 <li id="menu-${db}_locks" class="dropdown-submenu">
8274 <a href="#" tabindex="-1">Locks </a>
8275 <ul class="dropdown-menu">
8276 <li id="menu-database-deadlocks"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=database-deadlocks&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Deadlocks</a></li>
8277 <li id="menu-database-lock-types"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=database-lock-types&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Locks per types</a></li>
8278 <li id="menu-database-lock-modes"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=database-lock-modes&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Locks per modes</a></li>
8279 <li id="menu-database-lock-granted"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=database-lock-granted&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Locks granted or not</a></li>
8280 </ul>
8281 </li>
8282 <li class="divider"></li>
8283 <li id="menu-${db}_temporaryfiles" class="dropdown-submenu">
8284 <a href="#" tabindex="-1">Temporary files </a>
8285 <ul class="dropdown-menu">
8286 <li id="menu-database-temporary_files"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=database-temporary_files&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Temporary files</a></li>
8287 <li id="menu-database-temporary_bytes"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=database-temporary_bytes&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Temporary files size</a></li>
8288 </ul>
8289 </li>
8290 <li id="menu-${db}_rw" class="dropdown-submenu">
8291 <a href="#" tabindex="-1">Queries Reads / Writes </a>
8292 <ul class="dropdown-menu">
8293 <li id="menu-database-read_ratio"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=database-read_ratio&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Read tuples</a></li>
8294 <li id="menu-database-write_ratio"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=database-write_ratio&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Write ratio</a></li>
8295 <li id="menu-database-read_write_query"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=database-read_write_query&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Read vs Write queries</a></li>
8296 <li id="menu-database-commits_rollbacks"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=database-commits_rollbacks&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Commits vs Rollbacks</a></li>
8297 </ul>
8298 </li>
8299 <li id="menu-database-transactions"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=database-transactions&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Transactions throughput</a></li>
8300 <li class="divider"></li>
8301 <li id="menu-database-canceled_queries"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=database-canceled_queries&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Canceled queries</a></li>
8302 <li id="menu-database-conflicts"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=database-conflicts&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Conflicts</a></li>
8303 </ul>
8304 </li>
8305 };
8306 }
8307 if ($#DATABASE_LIST >= 0) {
8308 if ($#DATABASE_LIST >= 10) {
8309 $menu_str .= qq{
8310 </ul>
8311 </li>
8312 };
8313 }
8314 $menu_str .= qq{
8315 </ul>
8316 </li>
8317 };
8318 }
8319
8320 my @pgbouncer_list = ();
8321 if ($#pgbouncer_list >= 0) {
8322 $menu_str .= qq{
8323 <li id="menu-database" class="dropdown">
8324 <a href="#" class="dropdown-toggle" data-toggle="dropdown">pgBouncer <b class="caret"></b></a>
8325 <ul class="dropdown-menu">
8326 };
8327 foreach my $db (sort @pgbouncer_list) {
8328 $menu_str .= qq{
8329 <li id="menu-$db" class="dropdown-submenu">
8330 <a href="#" tabindex="-1">$db </a>
8331 <ul class="dropdown-menu">
8332 <li id="menu-pgbouncer-connections"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=pgbouncer-connections&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Clients / servers connections</a></li>
8333 <li id="menu-pgbouncer-duration"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=pgbouncer-duration&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Average queries duration</a></li>
8334 <li id="menu-pgbouncer-number"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=pgbouncer-number&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Queries per second</a></li>
8335 <li id="menu-pgbouncer-wait-total"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=pgbouncer-wait-total&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Total wait time</a></li>
8336 <li id="menu-pgbouncer-wait-average"><a href="" onclick="document.location.href='$SCRIPT_NAME?db=$db&action=pgbouncer-wait-average&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Average of wait time per second</a></li>
8337 </ul>
8338 </li>
8339 };
8340 }
8341 $menu_str .= qq{
8342 </ul>
8343 </li>
8344 };
8345 }
8346
8347 if (!$DISABLE_SAR && $#DEVICE_LIST >= 0) {
8348 $menu_str .= qq{
8349 <li id="menu-system" class="dropdown">
8350 <a href="#" class="dropdown-toggle" data-toggle="dropdown">System <b class="caret"></b></a>
8351 <ul class="dropdown-menu">
8352 <li id="menu-system-cpu"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=system-cpu&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Cpu</a></li>
8353 <li class="divider"></li>
8354 <li id="menu-system-memory"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=system-memory&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Memory</a></li>
8355 <li id="menu-system-dirty"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=system-dirty&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Dirty memory</a></li>
8356 <li id="menu-system-swap"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=system-swap&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Swap</a></li>
8357 <li id="menu-system-swap"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=system-commit_memory&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Memory workload</a></li>
8358 <li class="divider"></li>
8359 <li id="menu-system-load"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=system-load&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Load</a></li>
8360 <li id="menu-system-process"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=system-process&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Task list</a></li>
8361 <li id="menu-system-runqueue"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=system-runqueue&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Run queue</a></li>
8362 <li id="menu-system-cswch"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=system-cswch&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Context switches</a></li>
8363 <li id="menu-system-pcrea"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=system-pcrea&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Tasks created per second</a></li>
8364 <li class="divider"></li>
8365 <li id="menu-system-block"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=system-block&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Blocks</a></li>
8366 <li id="menu-system-tps"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=system-tps&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Transfers per second</a></li>
8367 <li id="menu-system-pageall" class="dropdown-submenu">
8368 <a href="#" tabindex="-1">Pages</a>
8369 <ul class="dropdown-menu">
8370 <li id="menu-system-page"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=system-page&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Pages in/out</a></li>
8371 <li id="menu-system-fault"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=system-fault&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Pages faults</a></li>
8372 <li id="menu-system-scanpage"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=system-scanpage&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Pages scanned</a></li>
8373 </ul>
8374 </li>
8375 <li class="divider"></li>
8376 };
8377 my $idx = 0;
8378 @DEVICE_LIST = sort @DEVICE_LIST;
8379 for (my $i = 0; $i <= $#DEVICE_LIST; $i++) {
8380 next if (!&device_in_report($DEVICE_LIST[$i]));
8381 my $md = $i % 10;
8382 if ($md == 0) {
8383 $idx++;
8384 if ($i > 0) {
8385 $menu_str .= qq{
8386 </ul>
8387 </li>
8388 };
8389 }
8390 my $lbl = '';
8391 $lbl = " (part $idx)" if ($#DEVICE_LIST >= 10);
8392 $menu_str .= qq{
8393 <li id="menu-device$idx" class="dropdown-submenu">
8394 <a href="#" tabindex="-1">Devices $lbl</a>
8395 <ul class="dropdown-menu">
8396 };
8397 }
8398 $menu_str .= qq{
8399 <li id="menu-device$i" class="dropdown-submenu">
8400 <a href="#" tabindex="-1">$DEVICE_LIST[$i] </a>
8401 <ul class="dropdown-menu">
8402 <li id="menu-system-cpudevice"><a href="" onclick="document.location.href='$SCRIPT_NAME?dev=$DEVICE_LIST[$i]&action=system-cpudevice&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Cpu utilization</a></li>
8403 <li id="menu-system-rwdevice"><a href="" onclick="document.location.href='$SCRIPT_NAME?dev=$DEVICE_LIST[$i]&action=system-rwdevice&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Read/write bytes per second</a></li>
8404 <li id="menu-system-tpsdevice"><a href="" onclick="document.location.href='$SCRIPT_NAME?dev=$DEVICE_LIST[$i]&action=system-tpsdevice&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Transfert per second</a></li>
8405 <li id="menu-system-srvtime"><a href="" onclick="document.location.href='$SCRIPT_NAME?dev=$DEVICE_LIST[$i]&action=system-srvtime&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Average service time</a></li>
8406 </ul>
8407 </li>
8408 };
8409 }
8410 $menu_str .= qq{
8411 </ul>
8412 </li>
8413 } if ($#DEVICE_LIST >= 0);
8414
8415 $idx = 0;
8416 @DEVICE_SPACE_LIST = sort @DEVICE_SPACE_LIST;
8417 for (my $i = 0; $i <= $#DEVICE_SPACE_LIST; $i++) {
8418 my $md = $i % 10;
8419 if ($md == 0) {
8420 $idx++;
8421 if ($i > 0) {
8422 $menu_str .= qq{
8423 </ul>
8424 </li>
8425 };
8426 }
8427 my $lbl = '';
8428 $lbl = " (part $idx)" if ($#DEVICE_SPACE_LIST >= 10);
8429 $menu_str .= qq{
8430 <li id="menu-device-space-$idx" class="dropdown-submenu">
8431 <a href="#" tabindex="-1">Disk space utilization $lbl</a>
8432 <ul class="dropdown-menu">
8433 };
8434 }
8435 $menu_str .= qq{
8436 <li id="menu-system-space"><a href="" onclick="document.location.href='$SCRIPT_NAME?dev=$DEVICE_SPACE_LIST[$i]&action=system-space&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Device $DEVICE_SPACE_LIST[$i]</a></li>
8437 };
8438 }
8439 $menu_str .= qq{
8440 </ul>
8441 </li>
8442 } if ($#DEVICE_SPACE_LIST >= 0);
8443
8444 if ($#IFACE_LIST >= 0) {
8445 $menu_str .= qq{
8446 <li id="menu-network" class="dropdown-submenu">
8447 <a href="#" tabindex="-1">Network </a>
8448 <ul class="dropdown-menu">
8449 };
8450 @IFACE_LIST = sort @IFACE_LIST;
8451 for (my $i = 0; $i <= $#IFACE_LIST; $i++) {
8452 next if (!&interface_in_report($IFACE_LIST[$i]));
8453 $menu_str .= qq{
8454 <li id="menu-device$i" class="dropdown-submenu">
8455 <a href="#" tabindex="-1">$IFACE_LIST[$i] </a>
8456 <ul class="dropdown-menu">
8457 <li id="menu-network-utilization"><a href="" onclick="document.location.href='$SCRIPT_NAME?dev=$IFACE_LIST[$i]&action=network-utilization&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Network utilization</a></li>
8458 <li id="menu-network-error"><a href="" onclick="document.location.href='$SCRIPT_NAME?dev=$IFACE_LIST[$i]&action=network-error&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Network errors</a></li>
8459 </ul>
8460 </li>
8461 };
8462 }
8463 $menu_str .= qq{
8464 </ul>
8465 </li>
8466 };
8467 }
8468
8469 $menu_str .= qq{
8470 <li class="divider"></li>
8471 <li id="menu-postgres-stats" class="dropdown-submenu">
8472 <a href="#" tabindex="-1">PostgreSQL</a>
8473 <ul class="dropdown-menu">
8474 <li id="menu-postgres-cpu"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=pidstat-postgres-cpu&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">CPU</a></li>
8475 <li id="menu-postgres-cswch"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=pidstat-postgres-cswch&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Context switches</a></li>
8476 <li id="menu-postgres-memory"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=pidstat-postgres-memory&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Memory</a></li>
8477 <li id="menu-postgres-mempercent"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=pidstat-postgres-mempercent&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Percent Memory use</a></li>
8478 <li id="menu-postgres-fault"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=pidstat-postgres-fault&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Pages faults</a></li>
8479 <li id="menu-postgres-iodelay"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=pidstat-postgres-iodelay&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">I/O delay</a></li>
8480 <li id="menu-postgres-io"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=pidstat-postgres-io&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">Kb I/O</a></li>
8481 </ul>
8482 </li>
8483 };
8484
8485 $menu_str .= qq{
8486 </ul>
8487 </li>
8488 };
8489 }
8490
8491 my $begin_date = '';
8492 $begin_date = "$o_year-$o_month-$o_day $o_hour:$o_min" if ($BEGIN && $o_year);
8493 my $end_date = '';
8494 $end_date = "$e_year-$e_month-$e_day $e_hour:$e_min" if ($END && $e_year);
8495
8496 $menu_str .= qq{
8497 <!-- li id="menu-about" class="dropdown"><a href="" onclick="document.location.href='$SCRIPT_NAME?action=about&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;">About</a></li -->
8498 <li id="menu-time" class="dropdown">
8499 <a href="#" class="dropdown-toggle" data-toggle="dropdown">Time selector <b class="caret"></b></a>
8500 <ul class="dropdown-menu">
8501 <!-- li id="menu-time-year"><a href="" onclick="custom_date('year'); return false;">Year</a></li>
8502 <li id="menu-time-month"><a href="" onclick="custom_date('month'); return false;">Month</a></li -->
8503 <li id="menu-time-week"><a href="" onclick="custom_date('week'); return false;">Week</a></li>
8504 <li id="menu-time-day"><a href="" onclick="custom_date('day'); return false;">Day</a></li>
8505 <li id="menu-time-backward"><a href="" onclick="go_backward(); return false;">Backward</a></li>
8506 <li id="menu-time-forward"><a href="" onclick="go_forward(); return false;">Forward</a></li>
8507 </ul>
8508 </li>
8509 </ul>
8510 </div><!--/.nav-collapse -->
8511
8512 <div class="navbar-collapse collapse pull-right">
8513 <ul class="nav navbar-nav">
8514 <li id="menu-time" class="dropdown" style="color: #ffffff;">
8515 <table><tr><td>
8516 Start: <input size="16" type="text" value="$begin_date" id="start-date" readonly class="form_datepick">
8517 </td><td>&nbsp;
8518 End: <input size="16" type="text" value="$end_date" id="end-date" readonly class="form_datepick">
8519 </td><td>&nbsp;&nbsp;
8520 <a href="" onclick="document.location.href='$SCRIPT_NAME?db=$DATABASE&dev=$DEVICE&action=$ACTION&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value; return false;"><i class="glyphicon icon-refresh icon-2x" style="color: #ffffff; position: top;"></i></a>
8521 </td></tr></table>
8522 </li>
8523 </ul>
8524 </div><!--/.nav-collapse -->
8525 </div><!-- div navigation -->
8526
8527 <script type="text/javascript">
8528 \$(document).ready(function () {
8529 \$(".form_datepick").datetimepicker({
8530 format: "yyyy-mm-dd hh:ii",
8531 autoclose: true,
8532 todayBtn: true,
8533 pickerPosition: "bottom-left"
8534 });
8535 });
8536
8537 function custom_date( kind ) {
8538 var fromDate = new Date()
8539 var toDate = new Date();
8540
8541 switch(kind) {
8542 case 'year':
8543 // Display last year
8544 toDate = new Date(Date.now());
8545 fromDate.setYear(fromDate.getYear() + 1900 - 1);
8546 break;
8547 case 'month':
8548 // Display last month
8549 toDate = new Date(Date.now());
8550 fromDate.setMonth(toDate.getMonth() - 1);
8551 break;
8552 case 'week':
8553 // Display last 7 days
8554 toDate = new Date(Date.now());
8555 fromDate.setDate(toDate.getDate() - 7);
8556 break;
8557 case 'day':
8558 // Display last 24 hours
8559 toDate = new Date(Date.now());
8560 fromDate.setDate(toDate.getDate() - 1);
8561 break;
8562 }
8563
8564 var tzoffset = (new Date()).getTimezoneOffset() * 60000;
8565 document.getElementById('start-date').value = (new Date(fromDate - tzoffset)).toISOString().slice(0,16).replace(/T/g," ");
8566 document.getElementById('start-date').value = document.getElementById('start-date').value;
8567 document.getElementById('end-date').value = (new Date(toDate - tzoffset)).toISOString().slice(0,16).replace(/T/g," ");
8568 document.getElementById('end-date').value = document.getElementById('end-date').value;
8569 // Then submit immediately
8570 document.location.href='$SCRIPT_NAME?db=$DATABASE&dev=$DEVICE&action=$ACTION&end='+document.getElementById('end-date').value+'&start='+document.getElementById('start-date').value;
8571 }
8572
8573 function go_forward() {
8574 if ((document.getElementById('start-date').value == '')||(document.getElementById('end-date').value == '')) {
8575 custom_date( 'day' );
8576 }
8577 var fromDate = new Date(document.getElementById('start-date').value)/1;
8578 var toDate = new Date(document.getElementById('end-date').value)/1;
8579 var delta = toDate - fromDate;
8580 fromDate += delta - 3600000;
8581 toDate += delta - 3600000;
8582 document.getElementById('start-date').value = (new Date(fromDate)).toISOString().slice(0,16).replace(/T/g," ");
8583 document.getElementById('end-date').value = (new Date(toDate)).toISOString().slice(0,16).replace(/T/g," ");
8584 };
8585
8586 function go_backward() {
8587 if ((document.getElementById('start-date').value == '')||(document.getElementById('end-date').value == '')) {
8588 custom_date( 'day' );
8589 }
8590 var fromDate = new Date(document.getElementById('start-date').value)/1;
8591 var toDate = new Date(document.getElementById('end-date').value)/1;
8592 var delta = toDate - fromDate;
8593 fromDate -= delta - 3600000;
8594 toDate -= delta - 3600000;
8595 document.getElementById('start-date').value = (new Date(fromDate)).toISOString().slice(0,16).replace(/T/g," ");
8596 document.getElementById('end-date').value = (new Date(toDate)).toISOString().slice(0,16).replace(/T/g," ");
8597 };
8598
8599 </script>
8600
8601 };
8602
8603 return $menu_str;
8604 }
8605
8606 sub device_in_report
8607 {
8608 my $device = shift;
8609
8610 return 1 if ($#INCLUDE_DEV == -1);
8611
8612 foreach my $g (@INCLUDE_DEV) {
8613 return 1 if (grep(/^$g$/, $device));
8614 }
8615 return 0;
8616 }
8617
8618 sub interface_in_report
8619 {
8620 my $device = shift;
8621
8622 return 1 if ($#INCLUDE_IFACE == -1);
8623
8624 foreach my $g (@INCLUDE_IFACE) {
8625 return 1 if (grep(/^$g$/, $device));
8626 }
8627 return 0;
8628 }
8629
8630 sub compute_cpu_stat
8631 {
8632 my %ncpu = ();
8633 for (my $i = 0; $i <= $#_; $i++) {
8634 my @data = split(/;/, $_[$i]);
8635 next if ($data[2] !~ /^\d+/);
8636 # hostname;interval;timestamp;CPU;%user;%nice;%system;%iowait;%steal;%idle
8637 # hostname;interval;timestamp;CPU;%usr;%nice;%sys;%iowait;%steal;%irq;%soft;%guest;%idle
8638
8639 # Skip unwanted lines
8640 next if ($BEGIN && ($data[2] < $BEGIN));
8641 next if ($END && ($data[2] > $END));
8642
8643 map { s/,/\./ } @data ;
8644 # we only store all cpu statistics
8645 if ($data[3] eq 'all')
8646 {
8647 my $total_cpu = ($data[6]||0) + ($data[4]||0);
8648 if ($ACTION ne 'home') {
8649 $sar_cpu_stat{$data[2]}{$data[3]}{total} = $total_cpu;
8650 $sar_cpu_stat{$data[2]}{$data[3]}{system} = ($data[6]||0);
8651 $sar_cpu_stat{$data[2]}{$data[3]}{user} = ($data[4]||0);
8652 $sar_cpu_stat{$data[2]}{$data[3]}{iowait} = ($data[7]||0);
8653 $sar_cpu_stat{$data[2]}{$data[3]}{idle} = ($data[-1]||0);
8654 }
8655 if (!exists $OVERALL_STATS{'system'}{'cpu'} || ($OVERALL_STATS{'system'}{'cpu'}[1] < $total_cpu)) {
8656 @{$OVERALL_STATS{'system'}{'cpu'}} = ($data[2], $total_cpu);
8657 }
8658 $OVERALL_STATS{'sar_start_date'} = $data[2] if (!$OVERALL_STATS{'sar_start_date'} || ($OVERALL_STATS{'sar_start_date'} gt $data[2]));
8659 $OVERALL_STATS{'sar_end_date'} = $data[2] if (!$OVERALL_STATS{'sar_end_date'} || ($OVERALL_STATS{'sar_end_date'} lt $data[2]));
8660 } else {
8661 $ncpu{$data[3]} = '';
8662 }
8663 }
8664 $OVERALL_STATS{'system'}{'ncpu'} = (scalar keys %ncpu);
8665 }
8666
8667 sub compute_cpu_report
8668 {
8669 my $data_info = shift();
8670
8671 my %cpu_stat = ();
8672 foreach my $t (sort {$a <=> $b} keys %sar_cpu_stat)
8673 {
8674 foreach my $cpu (keys %{$sar_cpu_stat{$t}})
8675 {
8676 if ($cpu eq 'all') {
8677 $cpu_stat{$cpu}{total} .= '[' . $t . ',' . $sar_cpu_stat{$t}{$cpu}{total} . '],';
8678 $cpu_stat{$cpu}{system} .= '[' . $t . ',' . $sar_cpu_stat{$t}{$cpu}{system} . '],';
8679 $cpu_stat{$cpu}{user} .= '[' . $t . ',' . $sar_cpu_stat{$t}{$cpu}{user} . '],';
8680 $cpu_stat{$cpu}{iowait} .= '[' . $t . ',' . $sar_cpu_stat{$t}{$cpu}{iowait} . '],';
8681 $cpu_stat{$cpu}{idle} .= '[' . $t . ',' . $sar_cpu_stat{$t}{$cpu}{idle} . '],';
8682 }
8683 }
8684 }
8685 %sar_cpu_stat = ();
8686
8687 if (scalar keys %cpu_stat > 0)
8688 {
8689 $cpu_stat{'all'}{total} =~ s/,$//;
8690 $cpu_stat{'all'}{system} =~ s/,$//;
8691 $cpu_stat{'all'}{user} =~ s/,$//;
8692 $cpu_stat{'all'}{iowait} =~ s/,$//;
8693 $cpu_stat{'all'}{idle} =~ s/,$//;
8694
8695 print &jqplot_linegraph_array($IDX++, 'system-cpu', $data_info, 'all', $cpu_stat{'all'}{total}, $cpu_stat{'all'}{system}, $cpu_stat{'all'}{user}, $cpu_stat{'all'}{idle}, $cpu_stat{'all'}{iowait});
8696 }
8697
8698 }
8699
8700 sub compute_pidstatcpu_stat
8701 {
8702 for (my $i = 0; $i <= $#_; $i++)
8703 {
8704 my @data = split(/;/, $_[$i]);
8705 next if ($data[2] !~ /^\d+/);
8706 # hostname;interval;timestamp;USER;PID;%usr;%system;%guest;%CPU;CPU;Command
8707 # hostname;interval;timestamp;USER;PID;%usr;%system;%guest;%wait;%CPU;CPU;Command
8708 # Skip unwanted lines
8709 next if ($BEGIN && ($data[2] < $BEGIN));
8710 next if ($END && ($data[2] > $END));
8711
8712 map { s/,/\./ } @data ;
8713 # we only store all cpu statistics
8714 my $total_cpu = ($data[6]||0) + ($data[7]||0);
8715 my $ncpu = $data[9];
8716 $ncpu = $data[10] if ($#data > 10);
8717 $pidstat_cpu_stat{$data[2]}{$ncpu}{total} += $total_cpu;
8718 $pidstat_cpu_stat{$data[2]}{$ncpu}{user} += ($data[6]||0);
8719 $pidstat_cpu_stat{$data[2]}{$ncpu}{system} += ($data[7]||0);
8720
8721 $pidstat_cpu_stat{$data[2]}{'all'}{total} += $total_cpu;
8722 $pidstat_cpu_stat{$data[2]}{'all'}{user} += ($data[6]||0);
8723 $pidstat_cpu_stat{$data[2]}{'all'}{system} += ($data[7]||0);
8724
8725 if ($#data > 10)
8726 {
8727 $pidstat_cpu_stat{$data[2]}{$ncpu}{wait} += ($data[8]||0);
8728 $pidstat_cpu_stat{$data[2]}{$ncpu}{cpu} += ($data[9]||0);
8729 $pidstat_cpu_stat{$data[2]}{'all'}{wait} += ($data[8]||0);
8730 $pidstat_cpu_stat{$data[2]}{'all'}{cpu} += ($data[9]||0);
8731 }
8732 else
8733 {
8734 $pidstat_cpu_stat{$data[2]}{$ncpu}{cpu} += ($data[8]||0);
8735 $pidstat_cpu_stat{$data[2]}{'all'}{cpu} += ($data[8]||0);
8736 }
8737 }
8738 }
8739
8740 sub compute_pidstatcpu_report
8741 {
8742 my $data_info = shift();
8743
8744 my %pidstatcpu_stat = ();
8745 foreach my $t (sort {$a <=> $b} keys %pidstat_cpu_stat)
8746 {
8747 foreach my $cpu (keys %{$pidstat_cpu_stat{$t}})
8748 {
8749 # We only process values from total CPU
8750 next if ($cpu ne 'all');
8751 $pidstatcpu_stat{$cpu}{total} .= '[' . $t . ',' . $pidstat_cpu_stat{$t}{$cpu}{total} . '],';
8752 $pidstatcpu_stat{$cpu}{system} .= '[' . $t . ',' . $pidstat_cpu_stat{$t}{$cpu}{system} . '],';
8753 $pidstatcpu_stat{$cpu}{user} .= '[' . $t . ',' . $pidstat_cpu_stat{$t}{$cpu}{user} . '],';
8754 $pidstatcpu_stat{$cpu}{cpu} .= '[' . $t . ',' . $pidstat_cpu_stat{$t}{$cpu}{cpu} . '],';
8755 if (exists $pidstatcpu_stat{$cpu}{wait})
8756 {
8757 $pidstatcpu_stat{$cpu}{wait} .= '[' . $t . ',' . $pidstat_cpu_stat{$t}{$cpu}{wait} . '],';
8758 }
8759 }
8760 }
8761 %pidstat_cpu_stat = ();
8762
8763 if (scalar keys %pidstatcpu_stat > 0)
8764 {
8765 foreach my $cpu (keys %pidstatcpu_stat)
8766 {
8767 next if ($cpu ne 'all');
8768 $pidstatcpu_stat{$cpu}{total} =~ s/,$//;
8769 $pidstatcpu_stat{$cpu}{system} =~ s/,$//;
8770 $pidstatcpu_stat{$cpu}{user} =~ s/,$//;
8771 $pidstatcpu_stat{$cpu}{cpu} =~ s/,$//;
8772
8773 if (exists $pidstatcpu_stat{$cpu}{wait})
8774 {
8775 $pidstatcpu_stat{$cpu}{wait} =~ s/,$//;
8776 print &jqplot_linegraph_array($IDX++, 'postgres-cpu', $data_info, $cpu, $pidstatcpu_stat{$cpu}{total}, $pidstatcpu_stat{$cpu}{system}, $pidstatcpu_stat{$cpu}{user}, $pidstatcpu_stat{$cpu}{wait});
8777 }
8778 else
8779 {
8780 print &jqplot_linegraph_array($IDX++, 'postgres-cpu', $data_info, $cpu, $pidstatcpu_stat{$cpu}{total}, $pidstatcpu_stat{$cpu}{system}, $pidstatcpu_stat{$cpu}{user});
8781 }
8782 }
8783 }
8784 }
8785
8786 sub compute_load_stat
8787 {
8788 for (my $i = 0; $i <= $#_; $i++) {
8789 # hostname;interval;timestamp;runq-sz;plist-sz;ldavg-1;ldavg-5;ldavg-15;blocked
8790 my @data = split(/;/, $_[$i]);
8791 next if ($data[2] !~ /^\d+/);
8792
8793 # Skip unwanted lines
8794 next if ($BEGIN && ($data[2] < $BEGIN));
8795 next if ($END && ($data[2] > $END));
8796
8797 map { s/,/\./ } @data ;
8798 $data[5] ||= 0;
8799 if ($ACTION ne 'home') {
8800 $sar_load_stat{$data[2]}{'ldavg-1'} = $data[5];
8801 $sar_load_stat{$data[2]}{'ldavg-5'} = ($data[6]||0);
8802 $sar_load_stat{$data[2]}{'ldavg-15'} = ($data[7]||0);
8803 } else {
8804 if (!exists $OVERALL_STATS{'system'}{'load'} || ($OVERALL_STATS{'system'}{'load'}[1] < $data[5])) {
8805 @{$OVERALL_STATS{'system'}{'load'}} = ($data[2], $data[5]);
8806 }
8807 }
8808 }
8809 }
8810
8811 sub compute_load_report
8812 {
8813 my $data_info = shift();
8814
8815 my %load_stat = ();
8816 foreach my $t (sort { $a <=> $b } keys %sar_load_stat) {
8817 $load_stat{'ldavg-1'} .= '[' . $t . ',' . $sar_load_stat{$t}{'ldavg-1'} . '],';
8818 $load_stat{'ldavg-5'} .= '[' . $t . ',' . $sar_load_stat{$t}{'ldavg-5'} . '],';
8819 $load_stat{'ldavg-15'} .= '[' . $t . ',' . $sar_load_stat{$t}{'ldavg-15'} . '],';
8820 }
8821 %sar_load_stat = ();
8822
8823 if (scalar keys %load_stat > 0) {
8824 $load_stat{'ldavg-1'} =~ s/,$//;
8825 $load_stat{'ldavg-5'} =~ s/,$//;
8826 $load_stat{'ldavg-15'} =~ s/,$//;
8827 print &jqplot_linegraph_array($IDX++, 'system-load', $data_info, '', $load_stat{'ldavg-1'}, $load_stat{'ldavg-5'}, $load_stat{'ldavg-15'});
8828 }
8829 }
8830
8831 sub compute_process_stat
8832 {
8833
8834 for (my $i = 0; $i <= $#_; $i++) {
8835 # hostname;interval;timestamp;runq-sz;plist-sz;ldavg-1;ldavg-5;ldavg-15;blocked
8836 my @data = split(/;/, $_[$i]);
8837 next if ($data[2] !~ /^\d+/);
8838
8839 # Skip unwanted lines
8840 next if ($BEGIN && ($data[2] < $BEGIN));
8841 next if ($END && ($data[2] > $END));
8842
8843 map { s/,/\./ } @data ;
8844 $data[4] ||= 0;
8845 if ($ACTION ne 'home') {
8846 $sar_process_stat{$data[2]}{'plist-sz'}= $data[4];
8847 $sar_process_stat{$data[2]}{'runq-sz'} = ($data[3]||0);
8848 if ($#data > 7) {
8849 $sar_process_stat{$data[2]}{'blocked'} = ($data[8]||0);
8850 } else {
8851 $sar_process_stat{$data[2]}{'blocked'} = 0;
8852 }
8853 } else {
8854 if (!exists $OVERALL_STATS{'system'}{'process'} || ($OVERALL_STATS{'system'}{'process'}[1] < $data[4])) {
8855 @{$OVERALL_STATS{'system'}{'process'}} = ($data[2], $data[4]);
8856 }
8857 if (!exists $OVERALL_STATS{'system'}{'blocked'} || ($OVERALL_STATS{'system'}{'blocked'}[1] < $data[8])) {
8858 @{$OVERALL_STATS{'system'}{'blocked'}} = ($data[2], $data[8]||0);
8859 }
8860 }
8861 }
8862 }
8863
8864 sub compute_process_report
8865 {
8866 my $data_info = shift();
8867
8868 my %process_stat = ();
8869 foreach my $t (sort {$a <=> $b} keys %sar_process_stat) {
8870 $process_stat{'plist-sz'} .= '[' . $t . ',' . $sar_process_stat{$t}{'plist-sz'} . '],' if (exists $sar_process_stat{$t}{'plist-sz'});
8871 $process_stat{'runq-sz'} .= '[' . $t . ',' . $sar_process_stat{$t}{'runq-sz'} . '],' if (exists $sar_process_stat{$t}{'runq-sz'});
8872 $process_stat{'blocked'} .= '[' . $t . ',' . $sar_process_stat{$t}{'blocked'} . '],' if (exists $sar_process_stat{$t}{'blocked'});
8873 }
8874 if (scalar keys %process_stat > 0) {
8875 if ($data_info->{name} eq 'system-process') {
8876 $process_stat{'plist-sz'} =~ s/,$//;
8877 print &jqplot_linegraph_array($IDX++, 'system-process', $data_info, '', $process_stat{'plist-sz'});
8878 } elsif ($data_info->{name} eq 'system-runqueue') {
8879 $process_stat{'runq-sz'} =~ s/,$//;
8880 $process_stat{'blocked'} =~ s/,$//;
8881 print &jqplot_linegraph_array($IDX++, 'system-runqueue', $data_info, '', $process_stat{'runq-sz'}, $process_stat{'blocked'});
8882 }
8883 }
8884 }
8885
8886 sub compute_context_stat
8887 {
8888
8889 for (my $i = 0; $i <= $#_; $i++) {
8890 # hostname;interval;timestamp;proc;cswch
8891 my @data = split(/;/, $_[$i]);
8892 next if ($data[2] !~ /^\d+/);
8893
8894 # Skip unwanted lines
8895 next if ($BEGIN && ($data[2] < $BEGIN));
8896 next if ($END && ($data[2] > $END));
8897
8898 map { s/,/\./ } @data ;
8899 $data[4] ||= 0;
8900 if ($ACTION ne 'home') {
8901 $sar_context_stat{$data[2]}{'cswch'} = $data[4];
8902 $sar_context_stat{$data[2]}{'pcrea'} = ($data[3]||0);
8903 } else {
8904 if (!exists $OVERALL_STATS{'system'}{'cswch'} || ($OVERALL_STATS{'system'}{'cswch'}[1] < $data[4])) {
8905 @{$OVERALL_STATS{'system'}{'cswch'}} = ($data[2], $data[4]);
8906 }
8907 }
8908 }
8909 }
8910
8911 sub compute_context_report
8912 {
8913 my $data_info = shift();
8914
8915 my %context_stat = ();
8916 foreach my $t (sort {$a <=> $b} keys %sar_context_stat) {
8917 if ($data_info->{name} eq 'system-cswch') {
8918 $context_stat{'cswch'} .= '[' . $t . ',' . $sar_context_stat{$t}{'cswch'} . '],';
8919 } elsif ($data_info->{name} eq 'system-pcrea') {
8920 $context_stat{'pcrea'} .= '[' . $t . ',' . $sar_context_stat{$t}{'pcrea'} . '],';
8921 }
8922 }
8923 if (scalar keys %context_stat > 0) {
8924 if ($data_info->{name} eq 'system-cswch') {
8925 $context_stat{'cswch'} =~ s/,$//;
8926 print &jqplot_linegraph_array($IDX++, 'system-cswch', $data_info, '', $context_stat{'cswch'});
8927 } elsif ($data_info->{name} eq 'system-pcrea') {
8928 $context_stat{'pcrea'} =~ s/,$//;
8929 print &jqplot_linegraph_array($IDX++, 'system-pcrea', $data_info, '', $context_stat{'pcrea'});
8930 }
8931 }
8932 }
8933
8934 sub compute_pidstatcontext_stat
8935 {
8936
8937 for (my $i = 0; $i <= $#_; $i++)
8938 {
8939 # hostname;interval;timestamp;USER;PID;cswch/s;nvcswch/s;Command
8940 my @data = split(/;/, $_[$i]);
8941 next if ($data[2] !~ /^\d+/);
8942
8943 # Skip unwanted lines
8944 next if ($BEGIN && ($data[2] < $BEGIN));
8945 next if ($END && ($data[2] > $END));
8946
8947 map { s/,/\./ } @data ;
8948 $pidstat_context_stat{$data[2]}{'cswch'} = ($data[5]||0);
8949 $pidstat_context_stat{$data[2]}{'nvcswch'} = ($data[6]||0);
8950 }
8951 }
8952
8953 sub compute_pidstatcontext_report
8954 {
8955 my $data_info = shift();
8956 my %pidstatcontext_stat = ();
8957 foreach my $t (sort {$a <=> $b} keys %pidstat_context_stat)
8958 {
8959 if ($data_info->{name} eq 'postgres-cswch') {
8960 $pidstatcontext_stat{'cswch'} .= '[' . $t . ',' . $pidstat_context_stat{$t}{'cswch'} . '],';
8961 $pidstatcontext_stat{'nvcswch'} .= '[' . $t . ',' . $pidstat_context_stat{$t}{'nvcswch'} . '],';
8962 }
8963 }
8964 if (exists $pidstatcontext_stat{'cswch'} && exists $pidstatcontext_stat{'nvcswch'})
8965 {
8966 $pidstatcontext_stat{'cswch'} =~ s/,$//;
8967 $pidstatcontext_stat{'nvcswch'} =~ s/,$//;
8968 print &jqplot_linegraph_array($IDX++, 'postgres-cswch', $data_info, '', $pidstatcontext_stat{'cswch'}, $pidstatcontext_stat{'nvcswch'});
8969 }
8970 }
8971
8972 sub compute_memory_stat
8973 {
8974 for (my $i = 0; $i <= $#_; $i++) {
8975 # hostname;interval;timestamp;kbmemfree;kbmemused;%memused;kbbuffers;kbcached;kbcommit;%commit;kbactive;kbinact;kbdirty
8976 my @data = split(/;/, $_[$i]);
8977 next if ($data[2] !~ /^\d+/);
8978
8979 # Skip unwanted lines
8980 next if ($BEGIN && ($data[2] < $BEGIN));
8981 next if ($END && ($data[2] > $END));
8982
8983 map { s/,/\./ } @data ;
8984 my $kbcached = ($data[7]*1024) || 0;
8985 if ($ACTION ne 'home') {
8986 $sar_memory_stat{$data[2]}{'kbcached'} = $kbcached;
8987 $sar_memory_stat{$data[2]}{'kbbuffers'} = ($data[6]*1024)||0;
8988 $sar_memory_stat{$data[2]}{'kbmemfree'} = ($data[3]*1024)||0;
8989 } else {
8990 if (!exists $OVERALL_STATS{'system'}{'kbcached'} || ($OVERALL_STATS{'system'}{'kbcached'}[1] > $kbcached)) {
8991 @{$OVERALL_STATS{'system'}{'kbcached'}} = ($data[2], $kbcached);
8992 }
8993 }
8994 }
8995 }
8996
8997 sub compute_memory_report
8998 {
8999 my $data_info = shift();
9000
9001 my %memory_stat = ();
9002 foreach my $t (sort {$a <=> $b} keys %sar_memory_stat) {
9003 $memory_stat{'kbcached'} .= '[' . $t . ',' . $sar_memory_stat{$t}{'kbcached'} . '],';
9004 $memory_stat{'kbbuffers'} .= '[' . $t . ',' . $sar_memory_stat{$t}{'kbbuffers'} . '],';
9005 $memory_stat{'kbmemfree'} .= '[' . $t . ',' . $sar_memory_stat{$t}{'kbmemfree'} . '],';
9006 }
9007 %sar_memory_stat = ();
9008 if (scalar keys %memory_stat > 0) {
9009 $memory_stat{'kbcached'} =~ s/,$//;
9010 $memory_stat{'kbbuffers'} =~ s/,$//;
9011 $memory_stat{'kbmemfree'} =~ s/,$//;
9012 print &jqplot_linegraph_array($IDX++, 'system-memory', $data_info, '', $memory_stat{'kbcached'}, $memory_stat{'kbbuffers'}, $memory_stat{'kbmemfree'});
9013 }
9014 }
9015
9016 sub compute_pidstatmemory_stat
9017 {
9018 for (my $i = 0; $i <= $#_; $i++)
9019 {
9020 # hostname;interval;timestamp;USER;PID;minflt/s;majflt/s;VSZ;RSS;%MEM;Command
9021 my @data = split(/;/, $_[$i]);
9022 next if ($data[2] !~ /^\d+/);
9023 # Skip unwanted lines
9024 next if ($BEGIN && ($data[2] < $BEGIN));
9025 next if ($END && ($data[2] > $END));
9026
9027 map { s/,/\./ } @data ;
9028 $pidstat_memory_stat{$data[2]}{'minflt/s'} = ($data[5]||0);
9029 $pidstat_memory_stat{$data[2]}{'majflt/s'} = ($data[6]||0);
9030 $pidstat_memory_stat{$data[2]}{'VSZ'} = $data[7]||0;
9031 $pidstat_memory_stat{$data[2]}{'RSS'} = $data[8]||0;
9032 $pidstat_memory_stat{$data[2]}{'%MEM'} = $data[9]||0;
9033 }
9034 }
9035
9036 sub compute_pidstatmemory_report
9037 {
9038 my $data_info = shift();
9039
9040 my %pidstatmemory_stat = ();
9041 foreach my $t (sort {$a <=> $b} keys %pidstat_memory_stat)
9042 {
9043 $pidstatmemory_stat{'VSZ'} .= '[' . $t . ',' . $pidstat_memory_stat{$t}{'VSZ'} . '],';
9044 $pidstatmemory_stat{'RSS'} .= '[' . $t . ',' . $pidstat_memory_stat{$t}{'RSS'} . '],';
9045 $pidstatmemory_stat{'%MEM'} .= '[' . $t . ',' . $pidstat_memory_stat{$t}{'%MEM'} . '],';
9046 }
9047 if (scalar keys %pidstatmemory_stat > 0)
9048 {
9049 if ($data_info->{name} eq 'postgres-memory')
9050 {
9051 $pidstatmemory_stat{'VSZ'} =~ s/,$//;
9052 $pidstatmemory_stat{'RSS'} =~ s/,$//;
9053 print &jqplot_linegraph_array($IDX++, 'postgres-memory', $data_info, '', $pidstatmemory_stat{'VSZ'}, $pidstatmemory_stat{'RSS'});
9054 }
9055 elsif ($data_info->{name} eq 'postgres-mempercent')
9056 {
9057 $pidstatmemory_stat{'%MEM'} =~ s/,$//;
9058 print &jqplot_linegraph_array($IDX++, 'postgres-mempercent', $data_info, '', $pidstatmemory_stat{'%MEM'});
9059 }
9060 }
9061 }
9062
9063 sub compute_dirty_stat
9064 {
9065 for (my $i = 0; $i <= $#_; $i++) {
9066 # hostname;interval;timestamp;kbmemfree;kbmemused;%memused;kbbuffers;kbcached;kbcommit;%commit;kbactive;kbinact;kbdirty
9067 my @data = split(/;/, $_[$i]);
9068 next if ($data[2] !~ /^\d+/);
9069
9070 # New sar version has dirty dirty information: kbactive;kbinact;kbdirty
9071 next if ($#data <= 9);
9072
9073 # Skip unwanted lines
9074 next if ($BEGIN && ($data[2] < $BEGIN));
9075 next if ($END && ($data[2] > $END));
9076
9077 map { s/,/\./ } @data ;
9078 my $kbdirty = ($data[12]*1024) || 0;
9079 if ($ACTION ne 'home') {
9080 $sar_dirty_stat{$data[2]}{'kbactive'}= ($data[10]*1024)||0;
9081 $sar_dirty_stat{$data[2]}{'kbinact'} = ($data[11]*1024)||0;
9082 $sar_dirty_stat{$data[2]}{'kbdirty'} = ($data[12]*1024)||0;
9083 } else {
9084 if ($kbdirty && (!exists $OVERALL_STATS{'system'}{'kbdirty'} || ($OVERALL_STATS{'system'}{'kbdirty'}[1] < $kbdirty))) {
9085 @{$OVERALL_STATS{'system'}{'kbdirty'}} = ($data[2], $kbdirty);
9086 }
9087 }
9088 }
9089 }
9090
9091 sub compute_dirty_report
9092 {
9093 my $data_info = shift();
9094
9095 my %dirty_stat = ();
9096 foreach my $t (sort {$a <=> $b} keys %sar_dirty_stat) {
9097 $dirty_stat{'kbactive'}.= '[' . $t . ',' . $sar_dirty_stat{$t}{'kbactive'} . '],';
9098 $dirty_stat{'kbinact'} .= '[' . $t . ',' . $sar_dirty_stat{$t}{'kbinact'} . '],';
9099 $dirty_stat{'kbdirty'} .= '[' . $t . ',' . $sar_dirty_stat{$t}{'kbdirty'} . '],';
9100 }
9101 %sar_dirty_stat = ();
9102 if (scalar keys %dirty_stat > 0) {
9103 $dirty_stat{'kbactive'} =~ s/,$//;
9104 $dirty_stat{'kbinact'} =~ s/,$//;
9105 $dirty_stat{'kbdirty'} =~ s/,$//;
9106 print &jqplot_linegraph_array($IDX++, 'system-dirty', $data_info, '', $dirty_stat{'kbactive'}, $dirty_stat{'kbinact'}, $dirty_stat{'kbdirty'});
9107 }
9108 }
9109
9110 sub compute_swap_stat
9111 {
9112 for (my $i = 0; $i <= $#_; $i++) {
9113 # hostname;interval;timestamp;pswpin/s;pswpout/s
9114 my @data = split(/;/, $_[$i]);
9115 next if ($data[2] !~ /^\d+/);
9116
9117 # Skip unwanted lines
9118 next if ($BEGIN && ($data[2] < $BEGIN));
9119 next if ($END && ($data[2] > $END));
9120
9121 map { s/,/\./ } @data ;
9122 $data[3] ||= 0;
9123 $data[4] ||= 0;
9124 if ($ACTION ne 'home') {
9125 $sar_swap_stat{$data[2]}{'pswpin/s'} = $data[3];
9126 $sar_swap_stat{$data[2]}{'pswpout/s'} = $data[4];
9127 } else {
9128 if (!exists $OVERALL_STATS{'system'}{'pswpin'} || ($OVERALL_STATS{'system'}{'pswpin'}[1] < $data[3])) {
9129 @{$OVERALL_STATS{'system'}{'pswpin'}} = ($data[2], $data[3]);
9130 }
9131 if (!exists $OVERALL_STATS{'system'}{'pswpout'} || ($OVERALL_STATS{'system'}{'pswpout'}[1] < $data[4])) {
9132 @{$OVERALL_STATS{'system'}{'pswpout'}} = ($data[2], $data[4]);
9133 }
9134 }
9135 }
9136 }
9137
9138 sub compute_swap_report
9139 {
9140 my $data_info = shift();
9141
9142 my %swap_stat = ();
9143 foreach my $t (sort {$a <=> $b} keys %sar_swap_stat) {
9144 $swap_stat{'pswpin/s'} .= '[' . $t . ',' . $sar_swap_stat{$t}{'pswpin/s'} . '],';
9145 $swap_stat{'pswpout/s'} .= '[' . $t . ',' . $sar_swap_stat{$t}{'pswpout/s'} . '],';
9146 }
9147 %sar_swap_stat = ();
9148 if (scalar keys %swap_stat > 0) {
9149 $swap_stat{'pswpin/s'} =~ s/,$//;
9150 $swap_stat{'pswpout/s'} =~ s/,$//;
9151 print &jqplot_linegraph_array($IDX++, 'system-swap', $data_info, '', $swap_stat{'pswpin/s'}, $swap_stat{'pswpout/s'});
9152 }
9153 }
9154
9155 sub compute_page_stat
9156 {
9157 for (my $i = 0; $i <= $#_; $i++) {
9158 # hostname;interval;timestamp;pgpgin/s;pgpgout/s;fault/s;majflt/s;pgfree/s;pgscank/s;pgscand/s;pgsteal/s;%vmeff
9159 my @data = split(/;/, $_[$i]);
9160 next if ($data[2] !~ /^\d+/);
9161
9162 # Skip unwanted lines
9163 next if ($BEGIN && ($data[2] < $BEGIN));
9164 next if ($END && ($data[2] > $END));
9165
9166 map { s/,/\./ } @data ;
9167 $data[3] ||= 0;
9168 $data[4] ||= 0;
9169 if ($ACTION ne 'home') {
9170 $sar_pageswap_stat{$data[2]}{'pgpgin/s'} = $data[3];
9171 $sar_pageswap_stat{$data[2]}{'pgpgout/s'} = $data[4];
9172 } else {
9173 if (!exists $OVERALL_STATS{'system'}{'pgpgin'} || ($OVERALL_STATS{'system'}{'pgpgin'}[1] < $data[3])) {
9174 @{$OVERALL_STATS{'system'}{'pgpgin'}} = ($data[2], $data[3]);
9175 }
9176 if (!exists $OVERALL_STATS{'system'}{'pgpgout'} || ($OVERALL_STATS{'system'}{'pgpgout'}[1] < $data[4])) {
9177 @{$OVERALL_STATS{'system'}{'pgpgout'}} = ($data[2], $data[4]);
9178 }
9179 }
9180 }
9181 }
9182
9183 sub compute_fault_stat
9184 {
9185 for (my $i = 0; $i <= $#_; $i++) {
9186 # hostname;interval;timestamp;pgpgin/s;pgpgout/s;fault/s;majflt/s;pgfree/s;pgscank/s;pgscand/s;pgsteal/s;%vmeff
9187 my @data = split(/;/, $_[$i]);
9188 next if ($data[2] !~ /^\d+/);
9189
9190 # Skip unwanted lines
9191 next if ($BEGIN && ($data[2] < $BEGIN));
9192 next if ($END && ($data[2] > $END));
9193
9194 map { s/,/\./ } @data ;
9195 $data[5] ||= 0;
9196 $data[6] ||= 0;
9197 if ($ACTION ne 'home') {
9198 $sar_pageswap_stat{$data[2]}{'majflt/s'} = $data[6];
9199 $sar_pageswap_stat{$data[2]}{'minflt/s'} = ($data[5]-$data[6]);
9200 } else {
9201 if (!exists $OVERALL_STATS{'system'}{'majflt'} || ($OVERALL_STATS{'system'}{'majflt'}[1] < $data[6])) {
9202 @{$OVERALL_STATS{'system'}{'majflt'}} = ($data[2], $data[6]);
9203 }
9204 if (!exists $OVERALL_STATS{'system'}{'minflt'} || ($OVERALL_STATS{'system'}{'minflt'}[1] < ($data[5]-$data[6]))) {
9205 @{$OVERALL_STATS{'system'}{'minflt'}} = ($data[2], ($data[5]-$data[6]));
9206 }
9207 }
9208 }
9209 }
9210
9211 sub compute_scanpage_stat
9212 {
9213 for (my $i = 0; $i <= $#_; $i++) {
9214 # hostname;interval;timestamp;pgpgin/s;pgpgout/s;fault/s;majflt/s;pgfree/s;pgscank/s;pgscand/s;pgsteal/s;%vmeff
9215 my @data = split(/;/, $_[$i]);
9216 next if ($data[2] !~ /^\d+/);
9217
9218 # Skip unwanted lines
9219 next if ($BEGIN && ($data[2] < $BEGIN));
9220 next if ($END && ($data[2] > $END));
9221
9222 map { s/,/\./ } @data ;
9223 $data[7] ||= 0;
9224 $data[8] ||= 0;
9225 $data[9] ||= 0;
9226 $data[10] ||= 0;
9227 $data[11] ||= 0;
9228 if ($ACTION ne 'home') {
9229 $sar_pageswap_stat{$data[2]}{'pgfree/s'} = $data[7];
9230 $sar_pageswap_stat{$data[2]}{'pgscank/s'} = $data[8];
9231 $sar_pageswap_stat{$data[2]}{'pgscand/s'} = $data[9];
9232 $sar_pageswap_stat{$data[2]}{'pgsteal/s'} = $data[10];
9233 $sar_pageswap_stat{$data[2]}{'%vmeff'} = $data[11];
9234 } else {
9235 if (!exists $OVERALL_STATS{'system'}{'pgfree'} || ($OVERALL_STATS{'system'}{'pgfree'}[1] < $data[7])) {
9236 @{$OVERALL_STATS{'system'}{'pgfree'}} = ($data[2], $data[7]);
9237 }
9238 if (!exists $OVERALL_STATS{'system'}{'pgscank'} || ($OVERALL_STATS{'system'}{'pgscank'}[1] < $data[8])) {
9239 @{$OVERALL_STATS{'system'}{'pgscank'}} = ($data[2], $data[8]);
9240 }
9241 if (!exists $OVERALL_STATS{'system'}{'pgscand'} || ($OVERALL_STATS{'system'}{'pgscand'}[1] < $data[9])) {
9242 @{$OVERALL_STATS{'system'}{'pgscand'}} = ($data[2], $data[9]);
9243 }
9244 if (!exists $OVERALL_STATS{'system'}{'pgsteal'} || ($OVERALL_STATS{'system'}{'pgsteal'}[1] < $data[10])) {
9245 @{$OVERALL_STATS{'system'}{'pgsteal'}} = ($data[2], $data[10]);
9246 }
9247 if (!exists $OVERALL_STATS{'system'}{'vmeff'} || ($OVERALL_STATS{'system'}{'vmeff'}[1] < $data[11])) {
9248 @{$OVERALL_STATS{'system'}{'vmeff'}} = ($data[2], $data[11]);
9249 }
9250 }
9251 }
9252 }
9253
9254 sub compute_page_report
9255 {
9256 my $data_info = shift();
9257
9258 my %pageswap_stat = ();
9259 foreach my $t (sort {$a <=> $b} keys %sar_pageswap_stat) {
9260 $pageswap_stat{'pgpgin/s'} .= '[' . $t . ',' . $sar_pageswap_stat{$t}{'pgpgin/s'} . '],';
9261 $pageswap_stat{'pgpgout/s'} .= '[' . $t . ',' . $sar_pageswap_stat{$t}{'pgpgout/s'} . '],';
9262 }
9263 if (scalar keys %pageswap_stat > 0) {
9264 $pageswap_stat{'pgpgin/s'} =~ s/,$//;
9265 $pageswap_stat{'pgpgout/s'} =~ s/,$//;
9266 print &jqplot_linegraph_array($IDX++, 'system-page', $data_info, '', $pageswap_stat{'pgpgin/s'}, $pageswap_stat{'pgpgout/s'});
9267 }
9268 }
9269
9270 sub compute_fault_report
9271 {
9272 my $data_info = shift();
9273
9274 my %pageswap_stat = ();
9275 foreach my $t (sort {$a <=> $b} keys %sar_pageswap_stat) {
9276 $pageswap_stat{'majflt/s'} .= '[' . $t . ',' . $sar_pageswap_stat{$t}{'majflt/s'} . '],';
9277 $pageswap_stat{'minflt/s'} .= '[' . $t . ',' . $sar_pageswap_stat{$t}{'minflt/s'} . '],';
9278 }
9279 if (scalar keys %pageswap_stat > 0) {
9280 $pageswap_stat{'majflt/s'} =~ s/,$//;
9281 $pageswap_stat{'minflt/s'} =~ s/,$//;
9282 print &jqplot_linegraph_array($IDX++, 'system-fault', $data_info, '', $pageswap_stat{'majflt/s'}, $pageswap_stat{'minflt/s'});
9283 }
9284 }
9285
9286 sub compute_pidstatfault_report
9287 {
9288 my $data_info = shift();
9289
9290 my %pidstatfault_stat = ();
9291 foreach my $t (sort {$a <=> $b} keys %pidstat_memory_stat)
9292 {
9293 $pidstatfault_stat{'majflt/s'} .= '[' . $t . ',' . $pidstat_memory_stat{$t}{'majflt/s'} . '],';
9294 $pidstatfault_stat{'minflt/s'} .= '[' . $t . ',' . $pidstat_memory_stat{$t}{'minflt/s'} . '],';
9295 }
9296 if (scalar keys %pidstatfault_stat > 0)
9297 {
9298 $pidstatfault_stat{'majflt/s'} =~ s/,$//;
9299 $pidstatfault_stat{'minflt/s'} =~ s/,$//;
9300 print &jqplot_linegraph_array($IDX++, 'postgres-fault', $data_info, '', $pidstatfault_stat{'majflt/s'}, $pidstatfault_stat{'minflt/s'});
9301 %pidstat_memory_stat = ();
9302 }
9303 }
9304
9305 sub compute_scanpage_report
9306 {
9307 my $data_info = shift();
9308
9309 my %pageswap_stat = ();
9310 foreach my $t (sort {$a <=> $b} keys %sar_pageswap_stat) {
9311 $pageswap_stat{'pgfree/s'} .= '[' . $t . ',' . $sar_pageswap_stat{$t}{'pgfree/s'} . '],';
9312 $pageswap_stat{'pgscank/s'} .= '[' . $t . ',' . $sar_pageswap_stat{$t}{'pgscank/s'} . '],';
9313 $pageswap_stat{'pgscand/s'} .= '[' . $t . ',' . $sar_pageswap_stat{$t}{'pgscand/s'} . '],';
9314 $pageswap_stat{'pgsteal/s'} .= '[' . $t . ',' . $sar_pageswap_stat{$t}{'pgsteal/s'} . '],';
9315 $pageswap_stat{'%vmeff'} .= '[' . $t . ',' . $sar_pageswap_stat{$t}{'%vmeff'} . '],';
9316 }
9317 if (scalar keys %pageswap_stat > 0) {
9318 $pageswap_stat{'pgfree/s'} =~ s/,$//;
9319 $pageswap_stat{'pgscank/s'} =~ s/,$//;
9320 $pageswap_stat{'pgscand/s'} =~ s/,$//;
9321 $pageswap_stat{'pgsteal/s'} =~ s/,$//;
9322 $pageswap_stat{'%vmeff'} =~ s/,$//;
9323 print &jqplot_linegraph_array($IDX++, 'system-scanpage', $data_info, '', $pageswap_stat{'pgscank/s'}, $pageswap_stat{'pgscand/s'}, $pageswap_stat{'pgsteal/s'}, $pageswap_stat{'%vmeff'});
9324 }
9325 }
9326
9327
9328 sub compute_block_stat
9329 {
9330 for (my $i = 0; $i <= $#_; $i++) {
9331 # hostname;interval;timestamp;tps;rtps;wtps;bread/s;bwrtn/s
9332 my @data = split(/;/, $_[$i]);
9333 next if ($data[2] !~ /^\d+/);
9334
9335 # Skip unwanted lines
9336 next if ($BEGIN && ($data[2] < $BEGIN));
9337 next if ($END && ($data[2] > $END));
9338
9339 map { s/,/\./ } @data;
9340 $data[6] ||= 0;
9341 $data[7] ||= 0;
9342 if ($ACTION ne 'home') {
9343 $sar_block_stat{$data[2]}{'bread/s'} = $data[6];
9344 $sar_block_stat{$data[2]}{'bwrtn/s'} = $data[7];
9345 $sar_block_stat{$data[2]}{'tps'} = ($data[3]||0);
9346 $sar_block_stat{$data[2]}{'rtps'} = ($data[4]||0);
9347 $sar_block_stat{$data[2]}{'wtps'} = ($data[5]||0);
9348 } else {
9349 if (!exists $OVERALL_STATS{'system'}{'bread'} || ($OVERALL_STATS{'system'}{'bread'}[1] < $data[6])) {
9350 @{$OVERALL_STATS{'system'}{'bread'}} = ($data[2], $data[6]);
9351 }
9352 if (!exists $OVERALL_STATS{'system'}{'bwrite'} || ($OVERALL_STATS{'system'}{'bwrite'}[1] < $data[7])) {
9353 @{$OVERALL_STATS{'system'}{'bwrite'}} = ($data[2], $data[7]);
9354 }
9355 }
9356 }
9357 }
9358
9359 sub compute_block_report
9360 {
9361 my $data_info = shift();
9362
9363 my %block_stat = ();
9364 foreach my $t (sort {$a <=> $b} keys %sar_block_stat) {
9365 $block_stat{'bread/s'} .= '[' . $t . ',' . $sar_block_stat{$t}{'bread/s'} . '],';
9366 $block_stat{'bwrtn/s'} .= '[' . $t . ',' . $sar_block_stat{$t}{'bwrtn/s'} . '],';
9367 $block_stat{'tps'} .= '[' . $t . ',' . $sar_block_stat{$t}{'tps'} . '],';
9368 $block_stat{'rtps'} .= '[' . $t . ',' . $sar_block_stat{$t}{'rtps'} . '],';
9369 $block_stat{'wtps'} .= '[' . $t . ',' . $sar_block_stat{$t}{'wtps'} . '],';
9370 }
9371 if (scalar keys %block_stat > 0) {
9372 if ($data_info->{name} eq 'system-block') {
9373 %sar_block_stat = ();
9374 $block_stat{'bread/s'} =~ s/,$//;
9375 $block_stat{'bwrtn/s'} =~ s/,$//;
9376 print &jqplot_linegraph_array($IDX++, 'system-block', $data_info, '', $block_stat{'bread/s'}, $block_stat{'bwrtn/s'});
9377 } elsif ($data_info->{name} eq 'system-tps') {
9378 $block_stat{'tps'} =~ s/,$//;
9379 $block_stat{'rtps'} =~ s/,$//;
9380 $block_stat{'wtps'} =~ s/,$//;
9381 print &jqplot_linegraph_array($IDX++, 'system-tps', $data_info, '', $block_stat{'tps'}, $block_stat{'rtps'}, $block_stat{'wtps'});
9382 }
9383 }
9384 }
9385
9386 sub compute_pidstatio_stat
9387 {
9388 for (my $i = 0; $i <= $#_; $i++)
9389 {
9390 # hostname;interval;timestamp;USER;PID;kB_rd/s;kB_wr/s;kB_ccwr/s;Command
9391 # hostname;interval;timestamp;USER;PID;kB_rd/s;kB_wr/s;kB_ccwr/s;iodelay;Command
9392 my @data = split(/;/, $_[$i]);
9393 next if ($data[2] !~ /^\d+/);
9394
9395 # Skip unwanted lines
9396 next if ($BEGIN && ($data[2] < $BEGIN));
9397 next if ($END && ($data[2] > $END));
9398
9399 map { s/,/\./ } @data;
9400 $pidstat_io_stat{$data[2]}{'kB_rd/s'} = ($data[5] > 0) ? $data[5] : 0;
9401 $pidstat_io_stat{$data[2]}{'kB_wr/s'} = ($data[6] > 0) ? $data[6] : 0;
9402 $pidstat_io_stat{$data[2]}{'kB_ccwr/s'} = ($data[7] > 0) ? $data[7] : 0;
9403 if ($#data > 8)
9404 {
9405 $pidstat_io_stat{$data[2]}{'iodelay'} = ($data[8] > 0) ? $data[8] : 0;
9406 }
9407 }
9408 }
9409
9410 sub compute_pidstatio_report
9411 {
9412 my $data_info = shift();
9413
9414 my %pidstatio_stat = ();
9415 foreach my $t (sort {$a <=> $b} keys %pidstat_io_stat)
9416 {
9417 $pidstatio_stat{'kB_rd/s'} .= '[' . $t . ',' . $pidstat_io_stat{$t}{'kB_rd/s'} . '],';
9418 $pidstatio_stat{'kB_wr/s'} .= '[' . $t . ',' . $pidstat_io_stat{$t}{'kB_wr/s'} . '],';
9419 $pidstatio_stat{'kB_ccwr/s'} .= '[' . $t . ',' . $pidstat_io_stat{$t}{'kB_ccwr/s'} . '],';
9420 if (exists $pidstatio_stat{'iodelay'})
9421 {
9422 $pidstatio_stat{'iodelay'} .= '[' . $t . ',' . $pidstat_io_stat{$t}{'iodelay'} . '],';
9423 }
9424 }
9425 if (scalar keys %pidstatio_stat > 0)
9426 {
9427 if ($data_info->{name} eq 'postgres-io')
9428 {
9429 $pidstatio_stat{'kB_rd/s'} =~ s/,$//;
9430 $pidstatio_stat{'kB_wr/s'} =~ s/,$//;
9431 $pidstatio_stat{'kB_ccwr/s'} =~ s/,$//;
9432 print &jqplot_linegraph_array($IDX++, 'postgres-io', $data_info, '', $pidstatio_stat{'kB_rd/s'}, $pidstatio_stat{'kB_wr/s'}, $pidstatio_stat{'kB_ccwr/s'});
9433 }
9434 elsif ($data_info->{name} eq 'postgres-iodelay' && exists $pidstatio_stat{'iodelay'})
9435 {
9436 $pidstatio_stat{'iodelay'} =~ s/,$//;
9437 print &jqplot_linegraph_array($IDX++, 'postgres-iodelay', $data_info, '', $pidstatio_stat{'iodelay'});
9438 %pidstat_io_stat = ();
9439 }
9440 }
9441 }
9442
9443 sub compute_srvtime_stat
9444 {
9445
9446
9447 for (my $i = 0; $i <= $#_; $i++) {
9448 # hostname;interval;timestamp;DEV;tps;rd_sec/s;wr_sec/s;avgrq-sz;avgqu-sz;await;svctm;%util
9449 # sysstat version 11.5.7:
9450 # Replace "avgrq-sz" field (expressed in sectors) with "areq-sz" (expressed in kilobytes)
9451 # Rename "avgqu-sz" field to "aqu-sz"
9452 # "rd_sec/s" and "wr_sec/s" (expressed in sectors) fields have been replaced
9453 # with "rkB/s" and "wkB/s" (expressed in kilobytes)
9454 my @data = split(/;/, $_[$i]);
9455 next if ($data[2] !~ /^\d+/);
9456
9457 # Skip unwanted lines
9458 next if ($BEGIN && ($data[2] < $BEGIN));
9459 next if ($END && ($data[2] > $END));
9460 next if (!&device_in_report($data[3]));
9461
9462 next if ($DEVICE && ($data[3] ne $DEVICE));
9463
9464 map { s/,/\./ } @data ;
9465 $data[10] ||= 0;
9466 if ($ACTION ne 'home') {
9467 $sar_srvtime_stat{$data[2]}{$data[3]}{'await'} = ($data[9]||0);
9468 $sar_srvtime_stat{$data[2]}{$data[3]}{'svctm'} = $data[10];
9469 } else {
9470 if (!exists $OVERALL_STATS{'system'}{'svctm'} || ($OVERALL_STATS{'system'}{'svctm'}[1] < $data[10])) {
9471 @{$OVERALL_STATS{'system'}{'svctm'}} = ($data[2], $data[10], $data[3]);
9472 }
9473 }
9474 }
9475 }
9476
9477 sub compute_srvtime_report
9478 {
9479 my $data_info = shift();
9480 my $src_base = shift();
9481
9482 my %srvtime_stat = ();
9483 foreach my $t (sort {$a <=> $b} keys %sar_srvtime_stat) {
9484 foreach my $dev (sort keys %{$sar_srvtime_stat{$t}}) {
9485 $srvtime_stat{$dev}{'await'} .= '[' . $t . ',' . $sar_srvtime_stat{$t}{$dev}{'await'} . '],';
9486 $srvtime_stat{$dev}{'svctm'} .= '[' . $t . ',' . $sar_srvtime_stat{$t}{$dev}{'svctm'} . '],';
9487 }
9488 }
9489 %sar_srvtime_stat = ();
9490 if (scalar keys %srvtime_stat > 0) {
9491 foreach my $n (sort { $a cmp $b } keys %srvtime_stat) {
9492 $srvtime_stat{$n}{'await'} =~ s/,$//;
9493 $srvtime_stat{$n}{'svctm'} =~ s/,$//;
9494 print &jqplot_linegraph_array($IDX++, 'system-srvtime', $data_info, $n, $srvtime_stat{$n}{'await'}, $srvtime_stat{$n}{'svctm'});
9495 }
9496 }
9497 }
9498
9499 sub compute_rw_device_stat
9500 {
9501
9502 for (my $i = 0; $i <= $#_; $i++) {
9503 # hostname;interval;timestamp;DEV;tps;rd_sec/s;wr_sec/s;avgrq-sz;avgqu-sz;await;svctm;%util
9504 # sysstat version 11.5.7:
9505 # Replace "avgrq-sz" field (expressed in sectors) with "areq-sz" (expressed in kilobytes)
9506 # Rename "avgqu-sz" field to "aqu-sz"
9507 # "rd_sec/s" and "wr_sec/s" (expressed in sectors) fields have been replaced
9508 # with "rkB/s" and "wkB/s" (expressed in kilobytes)
9509 my @data = split(/;/, $_[$i]);
9510 next if ($data[2] !~ /^\d+/);
9511
9512 # Skip unwanted lines
9513 next if ($BEGIN && ($data[2] < $BEGIN));
9514 next if ($END && ($data[2] > $END));
9515 next if (!&device_in_report($data[3]));
9516
9517 next if ($DEVICE && ($data[3] ne $DEVICE));
9518 map { s/,/\./ } @data ;
9519 $data[4] ||= 0;
9520 $data[5] ||= 0;
9521 $data[6] ||= 0;
9522 my $sector = 512;
9523 $sector = 1024 if ($SAR_UPPER_11_5_6);
9524 if ($ACTION ne 'home') {
9525 $sar_rw_devices_stat{$data[2]}{$data[3]}{'rd_sec/s'} = ($data[5]*$sector);
9526 $sar_rw_devices_stat{$data[2]}{$data[3]}{'wr_sec/s'} = ($data[6]*$sector);
9527 $sar_rw_devices_stat{$data[2]}{$data[3]}{'tps'} = $data[4];
9528 } else {
9529 $OVERALL_STATS{'system'}{'devices'}{$data[3]}{read} += ($data[5]*$sector);
9530 $OVERALL_STATS{'system'}{'devices'}{$data[3]}{write} += ($data[6]*$sector);
9531 $OVERALL_STATS{'system'}{'devices'}{$data[3]}{tps} = $data[4] if (!$OVERALL_STATS{'system'}{'devices'}{$data[3]}{tps} || ($OVERALL_STATS{'system'}{'devices'}{$data[3]}{tps} < $data[4]))
9532 }
9533 }
9534 }
9535
9536 sub compute_rw_device_report
9537 {
9538 my $data_info = shift();
9539 my $src_base = shift();
9540
9541 my %devices_stat = ();
9542 foreach my $t (sort {$a <=> $b} keys %sar_rw_devices_stat) {
9543 foreach my $dev (keys %{$sar_rw_devices_stat{$t}}) {
9544 if ($data_info->{name} eq 'system-rwdevice') {
9545 $devices_stat{$dev}{'rd_sec/s'} .= '[' . $t . ',' . $sar_rw_devices_stat{$t}{$dev}{'rd_sec/s'} . '],';
9546 $devices_stat{$dev}{'wr_sec/s'} .= '[' . $t . ',' . $sar_rw_devices_stat{$t}{$dev}{'wr_sec/s'} . '],';
9547 } elsif ($data_info->{name} eq 'system-tpsdevice') {
9548 $devices_stat{$dev}{'tps'} .= '[' . $t . ',' . $sar_rw_devices_stat{$t}{$dev}{'tps'} . '],';
9549 }
9550 }
9551 }
9552
9553 if (scalar keys %devices_stat > 0) {
9554 foreach my $n (sort { $a cmp $b } keys %devices_stat) {
9555 if ($data_info->{name} eq 'system-rwdevice') {
9556 $devices_stat{$n}{'rd_sec/s'} =~ s/,$//;
9557 $devices_stat{$n}{'wr_sec/s'} =~ s/,$//;
9558 print &jqplot_linegraph_array($IDX++, 'system-rwdevice', $data_info, $n, $devices_stat{$n}{'rd_sec/s'}, $devices_stat{$n}{'wr_sec/s'});
9559 } elsif ($data_info->{name} eq 'system-tpsdevice') {
9560 $devices_stat{$n}{'tps'} =~ s/,$//;
9561 print &jqplot_linegraph_array($IDX++, 'system-tpsdevice', $data_info, $n, $devices_stat{$n}{'tps'});
9562 }
9563 }
9564 }
9565 }
9566
9567 sub compute_space_device_stat
9568 {
9569 for (my $i = 0; $i <= $#_; $i++) {
9570 # hostname;interval;timestamp;MBfsfree;MBfsused;%fsused;%ufsused;Ifree;Iused;%Iused;FILESYSTEM
9571 my @data = split(/;/, $_[$i]);
9572 next if ($data[2] !~ /^\d+/);
9573 $data[10] =~ s/.*\///;
9574 next if ($data[10] =~ /^(loop|tmpfs|udev)/);
9575
9576 # Skip unwanted lines
9577 next if ($BEGIN && ($data[2] < $BEGIN));
9578 next if ($END && ($data[2] > $END));
9579 next if (!&device_in_report($data[3]));
9580
9581 next if ($DEVICE && ($data[10] ne $DEVICE));
9582
9583 if ($ACTION ne 'home') {
9584 $sar_space_devices_stat{$data[2]}{$data[10]}{'%fsused'} = $data[5];
9585 $sar_space_devices_stat{$data[2]}{$data[10]}{'%iused'} = $data[9];
9586 } else {
9587 $OVERALL_STATS{'system'}{'space'}{$data[10]}{fsused} = $data[5] if (!exists $OVERALL_STATS{'system'}{'space'}{$data[10]}{fsused} || $data[5] > $OVERALL_STATS{'system'}{'space'}{$data[10]}{fsused});
9588 $OVERALL_STATS{'system'}{'space'}{$data[10]}{iused} = $data[9] if (!exists $OVERALL_STATS{'system'}{'space'}{$data[10]}{iused} || $data[9] > $OVERALL_STATS{'system'}{'space'}{$data[10]}{iused});
9589 }
9590 }
9591 }
9592
9593 sub compute_space_device_report
9594 {
9595 my $data_info = shift();
9596 my $src_base = shift();
9597
9598 my %devices_stat = ();
9599 foreach my $t (sort {$a <=> $b} keys %sar_space_devices_stat) {
9600 foreach my $dev (keys %{$sar_space_devices_stat{$t}}) {
9601 if ($data_info->{name} eq 'system-space') {
9602 $devices_stat{$dev}{'%fsused'} .= '[' . $t . ',' . $sar_space_devices_stat{$t}{$dev}{'%fsused'} . '],';
9603 $devices_stat{$dev}{'%iused'} .= '[' . $t . ',' . $sar_space_devices_stat{$t}{$dev}{'%iused'} . '],';
9604 }
9605 }
9606 }
9607
9608 if (scalar keys %devices_stat > 0) {
9609 foreach my $n (sort { $a cmp $b } keys %devices_stat) {
9610 if ($data_info->{name} eq 'system-space') {
9611 $devices_stat{$n}{'%fsused'} =~ s/,$//;
9612 $devices_stat{$n}{'%iused'} =~ s/,$//;
9613 print &jqplot_linegraph_array($IDX++, 'system-space', $data_info, $n, $devices_stat{$n}{'%fsused'}, $devices_stat{$n}{'%iused'});
9614 }
9615 }
9616 }
9617 }
9618
9619 sub compute_util_device_stat
9620 {
9621 for (my $i = 0; $i <= $#_; $i++) {
9622 # hostname;interval;timestamp;DEV;tps;rd_sec/s;wr_sec/s;avgrq-sz;avgqu-sz;await;svctm;%util
9623 # sysstat version 11.5.7:
9624 # Replace "avgrq-sz" field (expressed in sectors) with "areq-sz" (expressed in kilobytes)
9625 # Rename "avgqu-sz" field to "aqu-sz"
9626 # "rd_sec/s" and "wr_sec/s" (expressed in sectors) fields have been replaced
9627 # with "rkB/s" and "wkB/s" (expressed in kilobytes)
9628 my @data = split(/;/, $_[$i]);
9629 next if ($data[2] !~ /^\d+/);
9630
9631 # Skip unwanted lines
9632 next if ($BEGIN && ($data[2] < $BEGIN));
9633 next if ($END && ($data[2] > $END));
9634 next if (!&device_in_report($data[3]));
9635
9636 next if ($data[3] ne $DEVICE);
9637
9638 map { s/,/\./ } @data ;
9639 $sar_util_devices_stat{$data[2]}{$data[3]}{'%util'} = ($data[11]||0);
9640 }
9641 }
9642
9643 sub compute_util_device_report
9644 {
9645 my $data_info = shift();
9646 my $src_base = shift();
9647
9648 return if ($ACTION eq 'home');
9649
9650 my %devices_stat = ();
9651 foreach my $t (sort {$a <=> $b} keys %sar_util_devices_stat) {
9652 foreach my $dev (keys %{$sar_util_devices_stat{$t}}) {
9653 $devices_stat{$dev}{'%util'} .= '[' . $t . ',' . $sar_util_devices_stat{$t}{$dev}{'%util'} . '],';
9654 }
9655 }
9656 %sar_util_devices_stat = ();
9657 if (scalar keys %devices_stat > 0) {
9658 foreach my $n (sort { $a cmp $b } keys %devices_stat) {
9659 $devices_stat{$n}{'%util'} =~ s/,$//;
9660 print &jqplot_linegraph_array($IDX++, 'system-cpudevice', $data_info, $n, $devices_stat{$n}{'%util'});
9661 }
9662 }
9663 }
9664
9665 sub compute_network_stat
9666 {
9667 for (my $i = 0; $i <= $#_; $i++) {
9668 # hostname;interval;timestamp;IFACE;rxpck/s;txpck/s;rxkB/s;txkB/s;rxcmp/s;txcmp/s;rxmcst/s
9669 my @data = split(/;/, $_[$i]);
9670 next if ($data[2] !~ /^\d+/);
9671
9672 # Skip unwanted lines
9673 next if ($BEGIN && ($data[2] < $BEGIN));
9674 next if ($END && ($data[2] > $END));
9675 next if (!&interface_in_report($data[3]));
9676
9677 next if ($data[3] ne $DEVICE);
9678
9679 map { s/,/\./ } @data ;
9680 $sar_networks_stat{$data[2]}{$data[3]}{'rxkB/s'} = ($data[6]*1024);
9681 $sar_networks_stat{$data[2]}{$data[3]}{'txkB/s'} = ($data[7]*1024);
9682 }
9683 }
9684
9685 sub compute_network_report
9686 {
9687 my $data_info = shift();
9688 my $src_base = shift();
9689
9690 return if ($ACTION eq 'home');
9691
9692 my %networks_stat = ();
9693 foreach my $t (sort {$a <=> $b} keys %sar_networks_stat) {
9694 foreach my $dev (keys %{$sar_networks_stat{$t}}) {
9695 $networks_stat{$dev}{'rxkB/s'} .= '[' . $t . ',' . $sar_networks_stat{$t}{$dev}{'rxkB/s'} . '],';
9696 $networks_stat{$dev}{'txkB/s'} .= '[' . $t . ',' . $sar_networks_stat{$t}{$dev}{'txkB/s'} . '],';
9697 }
9698 }
9699 %sar_networks_stat = ();
9700
9701 if (scalar keys %networks_stat > 0) {
9702 foreach my $n (sort { $a cmp $b } keys %networks_stat) {
9703 $networks_stat{$n}{'rxkB/s'} =~ s/,$//;
9704 $networks_stat{$n}{'txkB/s'} =~ s/,$//;
9705 print &jqplot_linegraph_array($IDX++, 'network-utilization', $data_info, $n, $networks_stat{$n}{'rxkB/s'}, $networks_stat{$n}{'txkB/s'});
9706 }
9707 }
9708 }
9709
9710 sub compute_network_error_stat
9711 {
9712 for (my $i = 0; $i <= $#_; $i++) {
9713 # hostname;interval;timestamp;IFACE;rxerr/s;txerr/s;coll/s;rxdrop/s;txdrop/s;txcarr/s;rxfram/s;rxfifo/s;txfifo/s
9714 my @data = split(/;/, $_[$i]);
9715 next if ($data[2] !~ /^\d+/);
9716
9717 # Skip unwanted lines
9718 next if ($BEGIN && ($data[2] < $BEGIN));
9719 next if ($END && ($data[2] > $END));
9720 next if (!&interface_in_report($data[3]));
9721
9722 next if ($data[3] ne $DEVICE);
9723
9724 map { s/,/\./ } @data ;
9725 $sar_neterror_stat{$data[2]}{$data[3]}{'rxerr/s'} = $data[4] || 0;
9726 $sar_neterror_stat{$data[2]}{$data[3]}{'txerr/s'} = $data[5] || 0;
9727 $sar_neterror_stat{$data[2]}{$data[3]}{'coll/s'} = $data[6] || 0;
9728 }
9729 }
9730
9731 sub compute_network_error_report
9732 {
9733 my $data_info = shift();
9734 my $src_base = shift();
9735
9736 return if ($ACTION eq 'home');
9737
9738 my %errors_stat = ();
9739 foreach my $t (sort {$a <=> $b} keys %sar_networks_stat) {
9740 foreach my $dev (keys %{$sar_networks_stat{$t}}) {
9741 $errors_stat{$dev}{'rxerr/s'} .= '[' . $t . ',' . $sar_neterror_stat{$t}{$dev}{'rxerr/s'} . '],';
9742 $errors_stat{$dev}{'txerr/s'} .= '[' . $t . ',' . $sar_neterror_stat{$t}{$dev}{'txerr/s'} . '],';
9743 $errors_stat{$dev}{'coll/s'} .= '[' . $t . ',' . $sar_neterror_stat{$t}{$dev}{'coll/s'} . '],';
9744 }
9745 }
9746 if (scalar keys %errors_stat > 0) {
9747 foreach my $n (sort { $a cmp $b } keys %errors_stat) {
9748 $errors_stat{$n}{'rxerr/s'} =~ s/,$//;
9749 $errors_stat{$n}{'txerr/s'} =~ s/,$//;
9750 $errors_stat{$n}{'coll/s'} =~ s/,$//;
9751 print &jqplot_linegraph_array($IDX++, 'network-error', $data_info, $n, $errors_stat{$n}{'rxerr/s'}, $errors_stat{$n}{'txerr/s'}, $errors_stat{$n}{'coll/s'});
9752 }
9753 }
9754 }
9755
9756 sub compute_sarstat_stats
9757 {
9758 my ($file, %data_info) = @_;
9759
9760 ####
9761 # Get CPU utilization
9762 ####
9763 if ($data_info{name} eq 'system-cpu') {
9764 my $command = "$SADF_PROG -t -d ALL -D $file";
9765 print STDERR "DEBUG: running $command'\n" if ($DEBUG);
9766 # Load data from file
9767 if (!open(IN, "$command |")) {
9768 die "FATAL: can't read output from command ($command): $!\n";
9769 }
9770 my @content = <IN>;
9771 close(IN);
9772 chomp(@content);
9773
9774 # Compute cpu statistics
9775 &compute_cpu_stat(@content);
9776 }
9777
9778 ####
9779 # Get load average
9780 ####
9781 if ($data_info{name} eq 'system-load') {
9782 my $command = "$SADF_PROG -t -d $file -- -q";
9783 print STDERR "DEBUG: running $command'\n" if ($DEBUG);
9784 # Load data from file
9785 if (!open(IN, "$command |")) {
9786 die "FATAL: can't read output from command ($command): $!\n";
9787 }
9788 my @content = <IN>;
9789 close(IN);
9790 chomp(@content);
9791
9792 # Compute load statistics
9793 &compute_load_stat(@content);
9794 }
9795
9796 ####
9797 # Get process number
9798 ####
9799 if ($data_info{name} eq 'system-process') {
9800 my $command = "$SADF_PROG -t -d $file -- -q";
9801 print STDERR "DEBUG: running $command'\n" if ($DEBUG);
9802 # Load data from file
9803 if (!open(IN, "$command |")) {
9804 die "FATAL: can't read output from command ($command): $!\n";
9805 }
9806 my @content = <IN>;
9807 close(IN);
9808 chomp(@content);
9809
9810 # Compute process statistics
9811 &compute_process_stat(@content);
9812 }
9813
9814 ####
9815 # Get context swiches
9816 ####
9817 if ($data_info{name} eq 'system-cswch') {
9818 my $command = "$SADF_PROG -t -d $file -- -w";
9819 print STDERR "DEBUG: running $command'\n" if ($DEBUG);
9820 # Load data from file
9821 if (!open(IN, "$command |")) {
9822 die "FATAL: can't read output from command ($command): $!\n";
9823 }
9824 my @content = <IN>;
9825 close(IN);
9826 chomp(@content);
9827
9828 # Compute context switches statistics
9829 &compute_context_stat(@content);
9830 }
9831
9832 ####
9833 # Get memory utilization
9834 ####
9835 if ($data_info{name} eq 'system-memory') {
9836 my $command = "$SADF_PROG -t -d $file -- -r";
9837 print STDERR "DEBUG: running $command'\n" if ($DEBUG);
9838 # Load data from file
9839 if (!open(IN, "$command |")) {
9840 die "FATAL: can't read output from command ($command): $!\n";
9841 }
9842 my @content = <IN>;
9843 close(IN);
9844 chomp(@content);
9845
9846 # Compute graphs for memory statistics
9847 &compute_memory_stat(@content);
9848 }
9849
9850 ####
9851 # Get dirty memory utilization
9852 ####
9853 if ($data_info{name} eq 'system-dirty') {
9854 my $command = "$SADF_PROG -t -d $file -- -r";
9855 print STDERR "DEBUG: running $command'\n" if ($DEBUG);
9856 # Load data from file
9857 if (!open(IN, "$command |")) {
9858 die "FATAL: can't read output from command ($command): $!\n";
9859 }
9860 my @content = <IN>;
9861 close(IN);
9862 chomp(@content);
9863
9864 # Compute graphs for memory statistics
9865 &compute_dirty_stat(@content);
9866 }
9867
9868 ####
9869 # Get swap utilization
9870 ####
9871 if ($data_info{name} eq 'system-swap') {
9872 my $command = "$SADF_PROG -t -d $file -- -W";
9873 print STDERR "DEBUG: running $command'\n" if ($DEBUG);
9874 # Load data from file
9875 if (!open(IN, "$command |")) {
9876 die "FATAL: can't read output from command ($command): $!\n";
9877 }
9878 my @content = <IN>;
9879 close(IN);
9880 chomp(@content);
9881
9882 # Compute swap statistics
9883 &compute_swap_stat(@content);
9884 }
9885
9886 ####
9887 # Get page utilization
9888 ####
9889 if ($data_info{name} eq 'system-page') {
9890 my $command = "$SADF_PROG -t -d $file -- -B";
9891 print STDERR "DEBUG: running $command'\n" if ($DEBUG);
9892 # Load data from file
9893 if (!open(IN, "$command |")) {
9894 die "FATAL: can't read output from command ($command): $!\n";
9895 }
9896 my @content = <IN>;
9897 close(IN);
9898 chomp(@content);
9899
9900 # Compute page swap statistics
9901 &compute_page_stat(@content);
9902 }
9903 if ($data_info{name} eq 'system-fault') {
9904 my $command = "$SADF_PROG -t -d $file -- -B";
9905 print STDERR "DEBUG: running $command'\n" if ($DEBUG);
9906 # Load data from file
9907 if (!open(IN, "$command |")) {
9908 die "FATAL: can't read output from command ($command): $!\n";
9909 }
9910 my @content = <IN>;
9911 close(IN);
9912 chomp(@content);
9913
9914 # Compute page swap statistics
9915 &compute_fault_stat(@content);
9916 }
9917 if ($data_info{name} eq 'system-scanpage') {
9918 my $command = "$SADF_PROG -t -d $file -- -B";
9919 print STDERR "DEBUG: running $command'\n" if ($DEBUG);
9920 # Load data from file
9921 if (!open(IN, "$command |")) {
9922 die "FATAL: can't read output from command ($command): $!\n";
9923 }
9924 my @content = <IN>;
9925 close(IN);
9926 chomp(@content);
9927
9928 # Compute page swap statistics
9929 &compute_scanpage_stat(@content);
9930 }
9931
9932
9933 ####
9934 # Get block in/out
9935 ####
9936 if ($data_info{name} eq 'system-block') {
9937 my $command = "$SADF_PROG -t -d $file -- -b";
9938 print STDERR "DEBUG: running $command'\n" if ($DEBUG);
9939 # Load data from file
9940 if (!open(IN, "$command |")) {
9941 die "FATAL: can't read output from command ($command): $!\n";
9942 }
9943 my @content = <IN>;
9944 close(IN);
9945 chomp(@content);
9946
9947 # Compute block statistics
9948 &compute_block_stat(@content);
9949 }
9950
9951 ####
9952 # Get Device service time
9953 ####
9954 if ($data_info{name} eq 'system-srvtime') {
9955 my $command = "$SADF_PROG -t -P ALL -d $file -- -d -p";
9956 print STDERR "DEBUG: running $command'\n" if ($DEBUG);
9957 # Load data from file
9958 if (!open(IN, "$command |")) {
9959 die "FATAL: can't read output from command ($command): $!\n";
9960 }
9961 my @content = <IN>;
9962 close(IN);
9963 chomp(@content);
9964
9965 # Compute service time per devices statistics
9966 &compute_srvtime_stat(@content);
9967 }
9968
9969
9970 ####
9971 # Get Device block read/write utilization
9972 ####
9973 if ($data_info{name} eq 'system-rwdevice') {
9974 my $command = "$SADF_PROG -t -P ALL -d $file -- -d -p";
9975 print STDERR "DEBUG: running $command'\n" if ($DEBUG);
9976 # Load data from file
9977 if (!open(IN, "$command |")) {
9978 die "FATAL: can't read output from command ($command): $!\n";
9979 }
9980 my @content = <IN>;
9981 close(IN);
9982 chomp(@content);
9983
9984 # Compute I/O per devices statistics
9985 &compute_rw_device_stat(@content);
9986 }
9987
9988 ####
9989 # When we are on home report we just collect overall stats. The following
9990 # statistiques are not necessary so we can return immediatly from the function
9991 ####
9992 return if ($ACTION eq 'home');
9993
9994 ####
9995 # Get run queue length
9996 ####
9997 if ($data_info{name} eq 'system-runqueue') {
9998 my $command = "$SADF_PROG -t -d $file -- -q";
9999 print STDERR "DEBUG: running $command'\n" if ($DEBUG);
10000 # Load data from file
10001 if (!open(IN, "$command |")) {
10002 die "FATAL: can't read output from command ($command): $!\n";
10003 }
10004 my @content = <IN>;
10005 close(IN);
10006 chomp(@content);
10007
10008 # Compute runqueue statistics
10009 &compute_process_stat(@content);
10010 }
10011
10012
10013 ####
10014 # Get tasks created per second
10015 ####
10016 if ($data_info{name} eq 'system-pcrea') {
10017 my $command = "$SADF_PROG -t -d $file -- -w";
10018 print STDERR "DEBUG: running $command'\n" if ($DEBUG);
10019 # Load data from file
10020 if (!open(IN, "$command |")) {
10021 die "FATAL: can't read output from command ($command): $!\n";
10022 }
10023 my @content = <IN>;
10024 close(IN);
10025 chomp(@content);
10026
10027 # Compute process creation statistics
10028 &compute_context_stat(@content);
10029 }
10030
10031
10032 ####
10033 # Get TPS
10034 ####
10035 if ($data_info{name} eq 'system-tps') {
10036 my $command = "$SADF_PROG -t -d $file -- -b";
10037 print STDERR "DEBUG: running $command'\n" if ($DEBUG);
10038 # Load data from file
10039 if (!open(IN, "$command |")) {
10040 die "FATAL: can't read output from command ($command): $!\n";
10041 }
10042 my @content = <IN>;
10043 close(IN);
10044 chomp(@content);
10045
10046 # Compute block statistics
10047 &compute_block_stat(@content);
10048 }
10049
10050 ####
10051 # Get Device space utilization
10052 ####
10053 if ($data_info{name} eq 'system-space') {
10054 my $command = "$SADF_PROG -t -P ALL -d $file -- -F -p";
10055 print "DEBUG: running $command'\n" if ($DEBUG);
10056 # Load data from file
10057 if (!open(IN, "$command |")) {
10058 die "FATAL: can't read output from command ($command): $!\n";
10059 }
10060 my @content = <IN>;
10061 close(IN);
10062 chomp(@content);
10063
10064 # Compute disk space use per devices statistics
10065 &compute_space_device_stat(@content);
10066 }
10067
10068 ####
10069 # Get per device TPS utilization
10070 ####
10071 if ($data_info{name} eq 'system-tpsdevice') {
10072 my $command = "$SADF_PROG -t -P ALL -d $file -- -d -p";
10073 print STDERR "DEBUG: running $command'\n" if ($DEBUG);
10074 # Load data from file
10075 if (!open(IN, "$command |")) {
10076 die "FATAL: can't read output from command ($command): $!\n";
10077 }
10078 my @content = <IN>;
10079 close(IN);
10080 chomp(@content);
10081
10082 # Compute I/O per devices statistics
10083 &compute_rw_device_stat(@content);
10084 }
10085
10086 ####
10087 # Get Device utilization
10088 ####
10089 if ($data_info{name} eq 'system-cpudevice') {
10090 my $command = "$SADF_PROG -t -P ALL -d $file -- -d -p";
10091 print STDERR "DEBUG: running $command'\n" if ($DEBUG);
10092 # Load data from file
10093 if (!open(IN, "$command |")) {
10094 die "FATAL: can't read output from command ($command): $!\n";
10095 }
10096 my @content = <IN>;
10097 close(IN);
10098 chomp(@content);
10099
10100 # Compute cpu utilization per devices statistics
10101 &compute_util_device_stat(@content);
10102 }
10103
10104
10105 ####
10106 # Get network interface utilization
10107 ####
10108 if ($data_info{name} eq 'network-utilization') {
10109 my $command = "$SADF_PROG -t -P ALL -d $file -- -n DEV";
10110 print STDERR "DEBUG: running $command'\n" if ($DEBUG);
10111 # Load data from file
10112 if (!open(IN, "$command |")) {
10113 die "FATAL: can't read output from command ($command): $!\n";
10114 }
10115 my @content = <IN>;
10116 close(IN);
10117 chomp(@content);
10118
10119 # Compute network statistics
10120 &compute_network_stat(@content);
10121 }
10122
10123 ####
10124 # Get network errors utilization
10125 ####
10126 if ($data_info{name} eq 'network-error') {
10127 my $command = "$SADF_PROG -t -P ALL -d $file -- -n EDEV";
10128 print STDERR "DEBUG: running $command'\n" if ($DEBUG);
10129 # Load data from file
10130 if (!open(IN, "$command |")) {
10131 die "FATAL: can't read output from command ($command): $!\n";
10132 }
10133 my @content = <IN>;
10134 close(IN);
10135 chomp(@content);
10136
10137 # Compute network errors statistics
10138 &compute_network_error_stat(@content);
10139 }
10140 }
10141
10142 sub find_report_type
10143 {
10144 my $data = shift;
10145 my $type = '';
10146
10147 if ($data =~ m#nvcswch/s#) {
10148 $type = 'pcswch';
10149 } elsif ($data =~ m#cswch/s#) {
10150 $type = 'cswch';
10151 } elsif ($data =~ m#proc/s#) {
10152 $type = 'pcrea';
10153 } elsif ($data =~ m#CPU\s+i\d+#) {
10154 $type = 'ncpu';
10155 } elsif ($data =~ m#CPU\s+M#) {
10156 $type = 'scpu';
10157 } elsif ($data =~ m#CPU\s+w#) {
10158 $type = 'wcpu';
10159 } elsif ($data =~ m#CPU\s+t#) {
10160 $type = 'tcpu';
10161 } elsif ($data =~ m#CPU\s+\%#) {
10162 $type = 'cpu';
10163 } elsif ($data =~ m#CPU\s+C#) {
10164 $type = 'pcpu';
10165 } elsif ($data =~ m#INTR\s+#) {
10166 $type = 'intr';
10167 } elsif ($data =~ m#VSZ\s+RSS#) {
10168 $type = 'pmem';
10169 } elsif ($data =~ m#pgpgin/s\s+#) {
10170 $type = 'page';
10171 } elsif ($data =~ m#pswpin/s\s+#) {
10172 $type = 'pswap';
10173 } elsif ( ($data =~ m#tps\s+#) && ($data !~ m#DEV\s+#) ) {
10174 $type = 'io';
10175 } elsif ($data =~ m#kB_ccwr/s\s+#) {
10176 $type = 'pio';
10177 } elsif ($data =~ m#frmpg/s\s+#) {
10178 $type = 'mpage';
10179 } elsif ($data =~ m#TTY\s+#) {
10180 $type = 'tty';
10181 } elsif ($data =~ m#IFACE\s+rxpck/s\s+#) {
10182 $type = 'net';
10183 } elsif ($data =~ m#IFACE\s+rxerr/s\s+#) {
10184 $type = 'err';
10185 } elsif ($data =~ m#DEV\s+#) {
10186 $type = 'dev';
10187 } elsif ($data =~ m#kbmemfree\s+#) {
10188 $type = 'mem';
10189 # New in sysstat 8.1.5
10190 } elsif ($data =~ m#kbswpfree\s+#) {
10191 $type = 'swap';
10192 } elsif ($data =~ m#dentunusd\s+#) {
10193 $type = 'file';
10194 } elsif ($data =~ m#totsck\s+#) {
10195 $type = 'sock';
10196 } elsif ($data =~ m#runq-sz\s+#) {
10197 $type = 'load';
10198 # New in 8.1.7
10199 } elsif ($data =~ m#active\/s\s+#) {
10200 $type = 'tcp';
10201 # Since 11.1.4
10202 } elsif ($data =~ m#\%ufsused#) {
10203 $type = 'space';
10204 }
10205
10206 return $type;
10207 }
10208
10209
10210 sub load_sarfile_stats
10211 {
10212 my ($file) = @_;
10213
10214 my $interval = 0;
10215 my $hostname = 'unknown';
10216 my $has_changed = 0;
10217
10218 # Load data from file
10219 my @content = ();
10220 my $offset = (exists $global_infos{$file}) ? $global_infos{$file} : 0;
10221 my $curfh = open_filehdl($file);
10222 print STDERR "DEBUG: Starting to read $file from offset $offset\n" if ($DEBUG);
10223 $curfh->seek($offset,0);
10224 while (my $l = <$curfh>) {
10225 $offset += length($l);
10226 chomp($l);
10227 $l =~ s/\r//;
10228 # Prevent non relevant lines from being loaded into memory
10229 if ( ($l eq '') || ($l =~ /^\d+:\d+:\d+/) || ($l =~ /\d+[\-\/]\d+[\-\/]\d+/)) {
10230 push(@content, $l);
10231 }
10232 # Look is the format of systat have changed
10233 if (!$has_changed && $l =~ m#wkB/s#) {
10234 # Replace "rd_sec/s" and "wr_sec/s" fields with "rkB/s" and "wkB/s".
10235 # fields are now expressed in kilobytes instead of sectors. This also make
10236 # them consistent with iostat's output.
10237 # Replace "avgrq-sz" field with "areq-sz". This field is now expressed in
10238 # kilobytes instead of sectors and make it consistent with iostat's output.
10239 # Rename "avgqu-sz" field to "aqu-sz" to make it consistent with iostat's
10240 # output.
10241 $SAR_UPPER_11_5_6 = 1;
10242 $has_changed = 1; # we don't expect several sar version upgrade on a single file
10243 }
10244 }
10245 $curfh->close();
10246 $global_infos{$file} = $offset;
10247
10248 my $type = '';
10249 my @headers = ();
10250 my %fulldata = ();
10251 my $old_time = 0;
10252 my $orig_time = 0;
10253
10254 for (my $i = 0; $i <= $#content; $i++) {
10255
10256 # Empty line, maybe the end of a report
10257 if ($content[$i] eq '') {
10258 $type = '';
10259 @headers = ();
10260 $old_time = $orig_time if ($FROM_SA_FILE);
10261 next;
10262 }
10263 # look for kernel header to find the date
10264 if ( ($content[$i] !~ /^\d+:\d+:\d+/) && ($content[$i] =~ /\s+(\d+)([\-\/])(\d+)[\-\/](\d+)\s+/) ) {
10265 if ($2 eq '/') {
10266 $sar_month = $1;
10267 $sar_day = $3;
10268 $sar_year = $4;
10269 } else {
10270 $sar_month = $3;
10271 $sar_day = $4;
10272 $sar_year = $1;
10273 }
10274 if (length($sar_year) == 2) {
10275 $sar_year += 2000;
10276 }
10277 # mm/dd/yy format in sar file instead of dd/mm/yy (see configuration directive REVERT_DATE)
10278 if ($REVERT_DATE || ($sar_month > 12)) {
10279 my $tmp = $sar_day;
10280 $sar_day = $sar_month;
10281 $sar_month = $tmp;
10282 }
10283
10284 my $tz = ((0-$TIMEZONE)*3600);
10285 $orig_time = &timegm_nocheck(0, 0, 0, $sar_day, $sar_month - 1, $sar_year - 1900) + $tz;
10286
10287 $type = '';
10288 @headers = ();
10289 next;
10290 }
10291 # Remove average/summary header if any
10292 if ( ($content[$i] !~ /^\d+:\d+:\d+/) && ($content[$i] =~ /^\D+:\s+/) ) {
10293 $type = '';
10294 @headers = ();
10295 next;
10296 }
10297
10298 if ($#headers == -1) {
10299 push(@headers, split(m#\s+#, $content[$i]));
10300 shift(@headers);
10301 # Try to find the kind of report
10302 $type = &find_report_type($content[$i]);
10303 if (!$type) {
10304 @headers = ();
10305 } else {
10306 push(@{$fulldata{$type}}, "hostname;interval;timestamp;" . join(";", @headers));
10307 }
10308 next;
10309 }
10310
10311 # Remove AM|PM timestamp information
10312 my $am_pm = '';
10313 if ($content[$i] =~ s/^(\d+:\d+:\d+)\s(AM|PM)/$1/) {
10314 $am_pm = $2;
10315 shift(@headers) if ($headers[0] =~ /^(AM|PM)$/);
10316 }
10317 # Get all values reported
10318 my @values = ();
10319 push(@values, split(m#\s+#, $content[$i]));
10320 # Extract the timestamp of the line
10321 my $timestamp = shift(@values);
10322
10323 if ($#values != $#headers) {
10324 warn "ERROR: Parsing of sar output reports different values than headers allow. ($#values != $#headers)\n";
10325 warn "INFO: sar output file was $file\n";
10326 warn "INFO: Line was: $content[$i]\n";
10327 die "Header: " . join(';', @headers) . " | Values: " . join(';', @values) . "\n";
10328 }
10329 if ($timestamp =~ /(\d+:\d+:\d+)/) {
10330 $timestamp = &convert_sar_time($1, $old_time, $am_pm);
10331 $old_time = $timestamp;
10332 }
10333 if (!$timestamp) {
10334 print STDERR "ERROR: unkown time information from sar file.\n";
10335 print STDERR "HEADER: $timestamp ", join(" ", @headers), "\n";
10336 die "DATA: $content[$i]\n";
10337 }
10338
10339 # Change decimal character to perl
10340 map { s/,/\./; } @values;
10341 push(@{$fulldata{$type}}, "$hostname;$interval;$timestamp;" . join(";", @values));
10342 }
10343
10344 return %fulldata;
10345 }
10346
10347 sub load_pidstatfile_stats
10348 {
10349 my ($file) = @_;
10350
10351 my $interval = 0;
10352 my $hostname = 'unknown';
10353 my $has_changed = 0;
10354
10355 # Load data from file
10356 my @content = ();
10357 my $offset = 0;
10358 $offset = $global_infos{"$file"} if (exists $global_infos{"$file"});
10359
10360 my $curfh = open_filehdl("$file");
10361 $curfh->seek($offset,0);
10362 while (my $l = <$curfh>)
10363 {
10364 $offset += length($l);
10365 chomp($l);
10366 $l =~ s/\r//;
10367 # Prevent non relevant lines from being loaded into memory
10368 if ( ($l eq '') || ($l =~ /^\d+:\d+:\d+/) || ($l =~ /\d+[\-\/]\d+[\-\/]\d+/)) {
10369 push(@content, $l);
10370 }
10371 }
10372 $curfh->close();
10373 $global_infos{"$file"} = $offset;
10374
10375 my $type = '';
10376 my @headers = ();
10377 my $old_time = 0;
10378 my $orig_time = 0;
10379
10380 for (my $i = 0; $i <= $#content; $i++)
10381 {
10382 # Empty line, maybe the end of a report
10383 if ($content[$i] eq '')
10384 {
10385 $type = '';
10386 @headers = ();
10387 $old_time = $orig_time if ($FROM_SA_FILE);
10388 next;
10389 }
10390 # look for kernel header to find the date
10391 if ( ($content[$i] !~ /^\d+:\d+:\d+/)
10392 && ($content[$i] =~ /\s+(\d+)([\-\/])(\d+)[\-\/](\d+)\s+/) )
10393 {
10394 if ($2 eq '/') {
10395 $pidstat_month = $1;
10396 $pidstat_day = $3;
10397 $pidstat_year = $4;
10398 } else {
10399 $pidstat_month = $3;
10400 $pidstat_day = $4;
10401 $pidstat_year = $1;
10402 }
10403 if (length($pidstat_year) == 2) {
10404 $pidstat_year += 2000;
10405 }
10406 # mm/dd/yy format in pidstat file instead of dd/mm/yy (see option -r)
10407 if ($REVERT_DATE || ($pidstat_month > 12)) {
10408 my $tmp = $pidstat_day;
10409 $pidstat_day = $pidstat_month;
10410 $pidstat_month = $tmp;
10411 }
10412
10413 my $tz = ((0-$TIMEZONE)*3600);
10414 $orig_time = &timegm_nocheck(0, 0, 0, $pidstat_day, $pidstat_month - 1, $pidstat_year - 1900) + $tz;
10415
10416 $type = '';
10417 @headers = ();
10418 next;
10419 }
10420 # Remove average/summary header if any
10421 if ( ($content[$i] !~ /^\d+:\d+:\d+/) && ($content[$i] =~ /^\D+:\s+/) ) {
10422 $type = '';
10423 @headers = ();
10424 next;
10425 }
10426
10427 if ($#headers == -1)
10428 {
10429 push(@headers, split(m#\s+#, $content[$i]));
10430 shift(@headers);
10431 # Try to find the kind of report
10432 $type = &find_report_type($content[$i]);
10433 if (!$type) {
10434 @headers = ();
10435 } else {
10436 #push(@{$fulldata{$type}}, "hostname;interval;timestamp;" . join(";", @headers));
10437 }
10438 next;
10439 }
10440
10441 # Remove AM|PM timestamp information
10442 my $am_pm = '';
10443 if ($content[$i] =~ s/^(\d+:\d+:\d+)\s(AM|PM)/$1/) {
10444 $am_pm = $2;
10445 shift(@headers) if ($headers[0] =~ /^(AM|PM)$/);
10446 }
10447
10448 # Get all values reported
10449 my @values = ();
10450 push(@values, split(m#\s+#, $content[$i]));
10451 # Extract the timestamp of the line
10452 my $timestamp = shift(@values);
10453
10454 if ($#values != $#headers)
10455 {
10456 warn "ERROR: Parsing of pidstat output reports different values than headers allow. ($#values != $#headers)\n";
10457 warn "INFO: pidstat output file was $file\n";
10458 warn "INFO: Line was: $content[$i]\n";
10459 die "Header: " . join(';', @headers) . " | Values: " . join(';', @values) . "\n";
10460 }
10461 if ($timestamp =~ /(\d+:\d+:\d+)/)
10462 {
10463 $timestamp = &convert_pidstat_time($1, $old_time, $am_pm);
10464 $old_time = $timestamp;
10465 }
10466 if (!$timestamp)
10467 {
10468 print STDERR "ERROR: unkown time information from pidstat file.\n";
10469 print STDERR "HEADER: $timestamp ", join(" ", @headers), "\n";
10470 die "DATA: $content[$i]\n";
10471 }
10472
10473 # Change decimal character to perl
10474 map { s/,/\./; } @values;
10475 push(@{$fullpidstatdata{$type}}, "$hostname;$interval;$timestamp;" . join(";", @values));
10476 }
10477 }
10478
10479 sub load_fsuse_stats
10480 {
10481 my ($input_dir, $file) = @_;
10482
10483 my $interval = 0;
10484 my $hostname = 'unknown';
10485 my @fsdata = ();
10486
10487 # Load data from file
10488 my $offset = (exists $global_infos{"$input_dir/$file"}) ? $global_infos{"$input_dir/$file"} : 0;
10489 my $curfh = open_filehdl("$input_dir/$file");
10490 print STDERR "DEBUG: Starting to read $input_dir/$file from offset $offset\n" if ($DEBUG);
10491 $curfh->seek($offset,0);
10492 my $first = 0;
10493 while (my $l = <$curfh>) {
10494 $offset += length($l);
10495 chomp($l);
10496 $l =~ s/\r//;
10497 $l =~ s/,/\./g;
10498 # Add the header
10499 push(@fsdata, "hostname;interval;timestamp;MBfsfree;MBfsused;%fsused;%ufsused;Ifree;Iused;%Iused;FILESYSTEM") if (!$first);
10500 push(@fsdata, $l);
10501 $first++;
10502 }
10503 $curfh->close();
10504 $global_infos{"$input_dir/$file"} = $offset;
10505
10506 return @fsdata;
10507 }
10508
10509 sub load_commit_memory_stats
10510 {
10511 my ($in_dir, $file) = @_;
10512
10513 my $interval = 0;
10514 my $hostname = 'unknown';
10515 my @fsdata = ();
10516
10517 # Load data from file
10518 my $offset = (exists $global_infos{"$in_dir/$file"}) ? $global_infos{"$in_dir/$file"} : 0;
10519 my $curfh = open_filehdl("$in_dir/$file");
10520 print STDERR "DEBUG: Starting to read $in_dir/$file from offset $offset\n" if ($DEBUG);
10521 $curfh->seek($offset,0);
10522 my $first = 0;
10523 while (my $l = <$curfh>) {
10524 $offset += length($l);
10525 chomp($l);
10526 $l =~ s/\r//;
10527 $l =~ s/,/\./g;
10528 # Add the header
10529 push(@fsdata, "timestamp;CommitLimit;CommittedAs") if (!$first);
10530 push(@fsdata, $l);
10531 $first++;
10532 }
10533 $curfh->close();
10534 $global_infos{"$in_dir/$file"} = $offset;
10535
10536 return @fsdata;
10537 }
10538
10539 sub compute_commit_memory_stat
10540 {
10541 for (my $i = 0; $i <= $#_; $i++) {
10542 # epoch;commitLimit;committed_As
10543 my @data = split(/;/, $_[$i]);
10544 next if ($data[0] !~ /^\d+/);
10545
10546 # Skip unwanted lines
10547 next if ($BEGIN && ($data[0]*1000 < $BEGIN));
10548 next if ($END && ($data[0]*1000 > $END));
10549
10550 my $tz = ((0-$TIMEZONE)*3600);
10551 $data[0] -= $tz;
10552 map { s/,/\./ } @data ;
10553 $sar_commit_memory_stat{$data[0]}{'commit_limit'} = ($data[1]||0)*1000;
10554 $sar_commit_memory_stat{$data[0]}{'committed_as'} = ($data[2]||0)*1000;
10555 }
10556 }
10557
10558 sub compute_commit_memory_report
10559 {
10560 my $data_info = shift();
10561
10562 my %commit_memory_stat = ();
10563 foreach my $t (sort {$a <=> $b} keys %sar_commit_memory_stat) {
10564 if (!exists $OVERALL_STATS{'system'}{'committed_as'} || ($OVERALL_STATS{'system'}{'committed_as'}[1] < $sar_commit_memory_stat{$t}{'committed_as'})) {
10565 @{$OVERALL_STATS{'system'}{'committed_as'}} = ($t, $sar_commit_memory_stat{$t}{'committed_as'});
10566 }
10567 $commit_memory_stat{'commit_limit'} .= '[' . $t . ',' . $sar_commit_memory_stat{$t}{'commit_limit'} . '],';
10568 $commit_memory_stat{'committed_as'} .= '[' . $t . ',' . $sar_commit_memory_stat{$t}{'committed_as'} . '],';
10569 }
10570 %sar_commit_memory_stat = ();
10571 if (scalar keys %commit_memory_stat > 0) {
10572 $commit_memory_stat{'commit_limit'} =~ s/,$//;
10573 $commit_memory_stat{'committed_as'} =~ s/,$//;
10574 print &jqplot_linegraph_array($IDX++, 'system-commit_memory', $data_info, '', $commit_memory_stat{'commit_limit'}, $commit_memory_stat{'committed_as'});
10575 }
10576 }
10577
10578 sub compute_sarfile_stats
10579 {
10580 my ($file, $input_dir, $fulldata, %data_info) = @_;
10581
10582 $SAR_UPPER_11_5_6 = 0;
10583
10584 ####
10585 # Set CPU utilization
10586 ####
10587 if ($data_info{name} eq 'system-cpu') {
10588 # Compute cpu statistics
10589 &compute_cpu_stat(@{$fulldata->{cpu}});
10590
10591 }
10592
10593 ####
10594 # Set load average
10595 ####
10596 if ($data_info{name} eq 'system-load') {
10597
10598 # Compute load statistics
10599 &compute_load_stat(@{$fulldata->{load}});
10600
10601 }
10602
10603 ####
10604 # Set process number
10605 ####
10606 if ($data_info{name} eq 'system-process') {
10607
10608 # Compute process statistics
10609 &compute_process_stat(@{$fulldata->{load}});
10610
10611 }
10612
10613 ####
10614 # Set context switches
10615 ####
10616 if ($data_info{name} eq 'system-cswch') {
10617
10618 # Compute context switches statistics
10619 &compute_context_stat(@{$fulldata->{cswch}});
10620
10621 }
10622
10623 ####
10624 # Set memory utilization
10625 ####
10626 if ($data_info{name} eq 'system-memory') {
10627
10628 # Compute memory statistics
10629 &compute_memory_stat(@{$fulldata->{mem}});
10630
10631 }
10632
10633 ####
10634 # Set dirty memory utilization
10635 ####
10636 if ($data_info{name} eq 'system-dirty') {
10637
10638 # Compute dirty memory statistics
10639 &compute_dirty_stat(@{$fulldata->{mem}});
10640
10641 }
10642
10643 ####
10644 # Set swap utilization
10645 ####
10646 if ($data_info{name} eq 'system-swap') {
10647
10648 # Compute swap statistics
10649 &compute_swap_stat(@{$fulldata->{pswap}});
10650
10651 }
10652
10653 ####
10654 # Set commit memory utilization
10655 ####
10656 if ($data_info{name} eq 'system-commit_memory') {
10657
10658 # Compute disk space use per devices statistics
10659 &compute_commit_memory_stat(@{$fulldata->{'system-commit_memory'}});
10660
10661 }
10662
10663 ####
10664 # Set page utilization
10665 ####
10666 if ($data_info{name} eq 'system-page') {
10667
10668 # Compute page swap statistics
10669 &compute_page_stat(@{$fulldata->{page}});
10670
10671 }
10672 if ($data_info{name} eq 'system-fault') {
10673
10674 # Compute page swap statistics
10675 &compute_fault_stat(@{$fulldata->{page}});
10676
10677 }
10678 if ($data_info{name} eq 'system-scanpage') {
10679
10680 # Compute page swap statistics
10681 &compute_scanpage_stat(@{$fulldata->{page}});
10682
10683 }
10684
10685
10686 ####
10687 # Set block in/out
10688 ####
10689 if ($data_info{name} eq 'system-block') {
10690
10691 # Compute block statistics
10692 &compute_block_stat(@{$fulldata->{io}});
10693
10694 }
10695
10696 ####
10697 # Set Device service time
10698 ####
10699 if ($data_info{name} eq 'system-srvtime') {
10700
10701 # Compute service time per devices statistics
10702 &compute_srvtime_stat(@{$fulldata->{dev}});
10703
10704 }
10705
10706 ####
10707 # Set Device disk space utilization
10708 ####
10709 if ($data_info{name} eq 'system-space') {
10710
10711 # Compute disk space use per devices statistics
10712 &compute_space_device_stat(@{$fulldata->{space}});
10713
10714 }
10715
10716 ####
10717 # Set Device read/write utilization
10718 ####
10719 if ($data_info{name} eq 'system-rwdevice') {
10720
10721 # Compute I/O per devices statistics
10722 &compute_rw_device_stat(@{$fulldata->{dev}});
10723
10724 }
10725
10726 ####
10727 # Set Device throughput
10728 ####
10729 if ($data_info{name} eq 'system-tpsdevice') {
10730
10731 # Compute TPS per devices statistics
10732 &compute_rw_device_stat(@{$fulldata->{dev}});
10733
10734 }
10735
10736 ####
10737 # When we are on home report we just collect overall stats. The following
10738 # statistiques are not necessary so we can return immediatly from the function
10739 ####
10740 return if ($ACTION eq 'home');
10741
10742 ####
10743 # Set run queue length
10744 ####
10745 if ($data_info{name} eq 'system-runqueue') {
10746
10747 # Compute runqueue statistics
10748 &compute_process_stat(@{$fulldata->{load}});
10749
10750 }
10751
10752 ####
10753 # Set process created per second
10754 ####
10755 if ($data_info{name} eq 'system-pcrea') {
10756
10757 # Compute process created per second statistics
10758 &compute_context_stat(@{$fulldata->{cswch}});
10759
10760 }
10761
10762 ####
10763 # Set TPS
10764 ####
10765 if ($data_info{name} eq 'system-tps') {
10766
10767 # Compute block statistics
10768 &compute_block_stat(@{$fulldata->{io}});
10769
10770 }
10771
10772 ####
10773 # Set Device CPU utilization
10774 ####
10775 if ($data_info{name} eq 'system-cpudevice') {
10776
10777 # Compute cpu utilization per devices statistics
10778 &compute_util_device_stat(@{$fulldata->{dev}});
10779
10780 }
10781
10782 ####
10783 # Set network utilization
10784 ####
10785 if ($data_info{name} eq 'network-utilization') {
10786
10787 # Compute block statistics
10788 &compute_network_stat(@{$fulldata->{net}});
10789
10790 }
10791
10792 ####
10793 # Set network error utilization
10794 ####
10795 if ($data_info{name} eq 'network-error') {
10796
10797 # Compute network error statistics
10798 &compute_network_error_stat(@{$fulldata->{err}});
10799
10800 }
10801 }
10802
10803 sub compute_sar_graph
10804 {
10805 my ($src_base, %data_info) = @_;
10806
10807 ####
10808 # Show CPU utilization
10809 ####
10810 if ($data_info{name} eq 'system-cpu') {
10811
10812 # Compute graphs for cpu statistics
10813 &compute_cpu_report(\%data_info);
10814
10815 }
10816
10817 ####
10818 # Show load average
10819 ####
10820 if ($data_info{name} eq 'system-load') {
10821
10822 # Compute graphs for load statistics
10823 &compute_load_report(\%data_info);
10824
10825 }
10826
10827 ####
10828 # Show process number
10829 ####
10830 if ($data_info{name} eq 'system-process') {
10831
10832 # Compute graphs for process statistics
10833 &compute_process_report(\%data_info);
10834
10835 }
10836
10837 ####
10838 # Show run queue length
10839 ####
10840 if ($data_info{name} eq 'system-runqueue') {
10841
10842 # Compute graphs for runqueue statistics
10843 &compute_process_report(\%data_info);
10844
10845 }
10846
10847 ####
10848 # Show context switches
10849 ####
10850 if ($data_info{name} eq 'system-cswch') {
10851
10852 # Compute graphs for context switches statistics
10853 &compute_context_report(\%data_info);
10854
10855 }
10856
10857 ####
10858 # Show process created per second
10859 ####
10860 if ($data_info{name} eq 'system-pcrea') {
10861
10862 # Compute graphs for number of process created per second statistics
10863 &compute_context_report(\%data_info);
10864
10865 }
10866
10867 ####
10868 # Show memory utilization
10869 ####
10870 if ($data_info{name} eq 'system-memory') {
10871
10872 # Compute graphs for memory statistics
10873 &compute_memory_report(\%data_info);
10874
10875 }
10876
10877 ####
10878 # Show dirty memory utilization
10879 ####
10880 if ($data_info{name} eq 'system-dirty') {
10881
10882 # Compute graphs for memory statistics
10883 &compute_dirty_report(\%data_info);
10884
10885 }
10886
10887 ####
10888 # Show swap utilization
10889 ####
10890 if ($data_info{name} eq 'system-swap') {
10891
10892 # Compute graphs for swap statistics
10893 &compute_swap_report(\%data_info);
10894
10895 }
10896
10897 ####
10898 # Show commit memory utilization
10899 ####
10900 if ($data_info{name} eq 'system-commit_memory') {
10901
10902 # Compute graphs for I/O per devices statistics
10903 &compute_commit_memory_report(\%data_info, $src_base);
10904
10905 }
10906
10907 ####
10908 # Show page utilization
10909 ####
10910 if ($data_info{name} eq 'system-page') {
10911
10912 # Compute graphs for page swap statistics
10913 &compute_page_report(\%data_info);
10914
10915 }
10916 if ($data_info{name} eq 'system-fault') {
10917
10918 # Compute graphs for page swap statistics
10919 &compute_fault_report(\%data_info);
10920
10921 }
10922 if ($data_info{name} eq 'system-scanpage') {
10923
10924 # Compute graphs for page swap statistics
10925 &compute_scanpage_report(\%data_info);
10926
10927 }
10928
10929
10930 ####
10931 # Show block in/out
10932 ####
10933 if ($data_info{name} eq 'system-block') {
10934
10935 # Compute graphs for block statistics
10936 &compute_block_report(\%data_info);
10937
10938 }
10939
10940 ####
10941 # Show TPS
10942 ####
10943 if ($data_info{name} eq 'system-tps') {
10944
10945 # Compute graphs for block statistics
10946 &compute_block_report(\%data_info);
10947
10948 }
10949
10950
10951 ####
10952 # Show Device service time
10953 ####
10954 if ($data_info{name} eq 'system-srvtime') {
10955
10956 # Compute graphs for service time per device statistics
10957 &compute_srvtime_report(\%data_info, $src_base);
10958
10959 }
10960
10961 ####
10962 # Show Device space utilization
10963 ####
10964 if ($data_info{name} eq 'system-space') {
10965
10966 # Compute graphs for I/O per devices statistics
10967 &compute_space_device_report(\%data_info, $src_base);
10968
10969 }
10970
10971 ####
10972 # Show Device read/write utilization
10973 ####
10974 if ($data_info{name} eq 'system-rwdevice') {
10975
10976 # Compute graphs for I/O per devices statistics
10977 &compute_rw_device_report(\%data_info, $src_base);
10978
10979 }
10980
10981 ####
10982 # Show per device TPS utilization
10983 ####
10984 if ($data_info{name} eq 'system-tpsdevice') {
10985
10986 # Compute graphs for I/O per devices statistics
10987 &compute_rw_device_report(\%data_info, $src_base);
10988
10989 }
10990
10991 ####
10992 # Show Device utilization
10993 ####
10994 if ($data_info{name} eq 'system-cpudevice') {
10995
10996 # Compute graphs for cpu utilization per devices statistics
10997 &compute_util_device_report(\%data_info, $src_base);
10998
10999 }
11000
11001 ####
11002 # Show network utilization
11003 ####
11004 if ($data_info{name} eq 'network-utilization') {
11005
11006 # Compute graphs for network utilization statistics
11007 &compute_network_report(\%data_info, $src_base);
11008
11009 }
11010
11011 ####
11012 # Show network error utilization
11013 ####
11014 if ($data_info{name} eq 'network-error') {
11015
11016 # Compute graphs for network errors statistics
11017 &compute_network_error_report(\%data_info, $src_base);
11018
11019 }
11020
11021 }
11022
11023 sub compute_pidstatfile_stats
11024 {
11025 my ($file, $in_dir, %data_info) = @_;
11026
11027 $SAR_UPPER_11_5_6 = 0;
11028
11029 # Load sar statistics from file if not already done
11030 &load_pidstatfile_stats($file) if (scalar keys %fullpidstatdata == 0);
11031
11032 ####
11033 # Set CPU utilization
11034 ####
11035 if ($data_info{name} eq 'postgres-cpu')
11036 {
11037 # Compute cpu statistics
11038 &compute_pidstatcpu_stat(@{$fullpidstatdata{pcpu}});
11039 }
11040
11041 ####
11042 # Set context switches
11043 ####
11044 if ($data_info{name} eq 'postgres-cswch')
11045 {
11046 # Compute context switches statistics
11047 &compute_pidstatcontext_stat(@{$fullpidstatdata{pcswch}});
11048 }
11049
11050 ####
11051 # Set memory utilization
11052 ####
11053 if ($data_info{name} eq 'postgres-memory')
11054 {
11055 # Compute memory statistics
11056 &compute_pidstatmemory_stat(@{$fullpidstatdata{pmem}});
11057 }
11058
11059 if ($data_info{name} eq 'postgres-fault')
11060 {
11061 # Done above
11062 }
11063
11064 ####
11065 # Set Kb in/out
11066 ####
11067 if ($data_info{name} eq 'postgres-io')
11068 {
11069 # Compute block statistics
11070 &compute_pidstatio_stat(@{$fullpidstatdata{pio}});
11071 }
11072 }
11073
11074 sub compute_pidstat_graph
11075 {
11076 my ($src_base, %data_info) = @_;
11077
11078 ####
11079 # Show CPU utilization
11080 ####
11081 if ($data_info{name} eq 'postgres-cpu')
11082 {
11083 # Compute graphs for cpu statistics
11084 &compute_pidstatcpu_report(\%data_info);
11085 }
11086
11087 ####
11088 # Show context switches
11089 ####
11090 if ($data_info{name} eq 'postgres-cswch')
11091 {
11092 # Compute graphs for context switches statistics
11093 &compute_pidstatcontext_report(\%data_info);
11094 }
11095
11096 ####
11097 # Show memory utilization
11098 ####
11099 if ($data_info{name} eq 'postgres-memory')
11100 {
11101 # Compute graphs for memory statistics
11102 &compute_pidstatmemory_report(\%data_info);
11103 }
11104 if ($data_info{name} eq 'postgres-mempercent')
11105 {
11106 # Compute graphs for memory statistics
11107 &compute_pidstatmemory_report(\%data_info);
11108 }
11109
11110 ####
11111 # Show page utilization
11112 ####
11113 if ($data_info{name} eq 'postgres-fault')
11114 {
11115 # Compute graphs for page swap statistics
11116 &compute_pidstatfault_report(\%data_info);
11117 }
11118
11119 ####
11120 # Show in/out
11121 ####
11122 if ($data_info{name} eq 'postgres-io')
11123 {
11124 # Compute graphs for block statistics
11125 &compute_pidstatio_report(\%data_info);
11126 }
11127 if ($data_info{name} eq 'postgres-iodelay')
11128 {
11129 # Compute graphs for block statistics
11130 &compute_pidstatio_report(\%data_info);
11131 }
11132 }
11133
11134 sub convert_time
11135 {
11136 my $str = shift;
11137
11138 # 2012-07-16 12:35:29+02
11139 if ($str =~ /(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/) {
11140 return &timegm_nocheck($6, $5, $4, $3, $2 - 1, $1 - 1900) * 1000;
11141 } elsif ($str =~ /(\d+)-(\d+)-(\d+) (\d+):(\d+)/) {
11142 return &timegm_nocheck(0, $5, $4, $3, $2 - 1, $1 - 1900) * 1000;
11143 } elsif ($str =~ /(\d+):(\d+):(\d+)/) {
11144 return &timegm_nocheck($3, $2, $1, $o_day, $o_month - 1, $o_year - 1900) * 1000;
11145 } elsif ($str !~ /\D/) {
11146 return $str * 1000;
11147 }
11148
11149 return $str;
11150 }
11151
11152 sub convert_sar_time
11153 {
11154 my ($str, $old_timestamp, $am_pm) = @_;
11155
11156 my $curdate = '';
11157
11158 $old_timestamp ||= 0;
11159 $sar_day ||= $o_day;
11160 $sar_month ||= $o_month;
11161 $sar_year ||= $o_year;
11162
11163 if ($str =~ /(\d+):(\d+):(\d+)/) {
11164 my $h = $1;
11165 my $m = $2;
11166 my $s = $3;
11167 if ($am_pm && ($am_pm eq 'AM')) {
11168 $h = 0 if ($h == 12);
11169 } elsif ($am_pm && ($am_pm eq 'PM')) {
11170 $h += 12 if ($h < 12);
11171 }
11172
11173 my $time = ($h*3600)+($m*60)+$s;
11174
11175 my $tz = ((0-$TIMEZONE)*3600);
11176 $curdate = &timegm_nocheck(0, 0, 0, $sar_day, $sar_month - 1, $sar_year - 1900) + $tz;
11177 if (!$FROM_SA_FILE) {
11178 while ($old_timestamp > (($curdate+$time) * 1000)) {
11179 $curdate += 86399;
11180 my @tinf = gmtime($curdate - $tz);
11181 $sar_month = $tinf[4]+1;
11182 $sar_day = $tinf[3];
11183 $sar_year = $tinf[5]+1900;
11184 }
11185 }
11186
11187 return ($curdate + $time) * 1000;
11188 }
11189
11190 return 0;
11191 }
11192
11193 sub convert_pidstat_time
11194 {
11195 my ($str, $old_timestamp, $am_pm) = @_;
11196
11197 my $curdate = '';
11198
11199 $old_timestamp ||= 0;
11200 $pidstat_day ||= $o_day;
11201 $pidstat_month ||= $o_month;
11202 $pidstat_year ||= $o_year;
11203
11204 if ($str =~ /(\d+):(\d+):(\d+)/)
11205 {
11206 my $h = $1;
11207 my $m = $2;
11208 my $s = $3;
11209 if ($am_pm && ($am_pm eq 'AM')) {
11210 $h = 0 if ($h == 12);
11211 } elsif ($am_pm && ($am_pm eq 'PM')) {
11212 $h += 12 if ($h < 12);
11213 }
11214
11215 my $time = ($h*3600)+($m*60)+$s;
11216
11217 my $tz = ((0-$TIMEZONE)*3600);
11218 $curdate = &timegm_nocheck(0, 0, 0, $pidstat_day, $pidstat_month - 1, $pidstat_year - 1900) + $tz;
11219 if (!$FROM_SA_FILE) {
11220 while ($old_timestamp > (($curdate+$time) * 1000)) {
11221 $curdate += 86399;
11222 my @tinf = gmtime($curdate - $tz);
11223 $pidstat_month = $tinf[4]+1;
11224 $pidstat_day = $tinf[3];
11225 $pidstat_year = $tinf[5]+1900;
11226 }
11227 }
11228 return ($curdate + $time) * 1000;
11229 }
11230 return 0;
11231 }
11232
11233 sub jqplot_linegraph_array
11234 {
11235 my ($buttonid, $divid, $infos, $title, @data) = @_;
11236
11237 my @legend = ();
11238 my $description = $infos->{description} || '';
11239 $title ||= '';
11240
11241 for (my $i = 0; $i <= $#data; $i++) {
11242 push(@legend, $infos->{legends}[$i] || '');
11243 }
11244 if ($title eq 'all') {
11245 $title = $infos->{title};
11246 } else {
11247 $title = sprintf($infos->{title}, ($title || 'none'));
11248 }
11249
11250 return &jqplot_linegraph($buttonid, $divid, $infos, $title, $description, \@data, \@legend);
11251 }
11252
11253 sub jqplot_linegraph_hash
11254 {
11255 my ($buttonid, $divid, $infos, $title, %data_h) = @_;
11256
11257 my @legend = ();
11258 my @data = ();
11259 my $i = 1;
11260 my $description = $infos->{description} || '';
11261
11262 foreach my $id (sort keys %data_h) {
11263 $data_h{$id} ||= '';
11264 push(@data, $data_h{$id});
11265 push(@legend, $id);
11266 $i++;
11267 }
11268 $title = sprintf($infos->{title}, ($title || $infos->{title} || 'none'));
11269
11270 return &jqplot_linegraph($buttonid, $divid, $infos, $title, $description, \@data, \@legend);
11271 }
11272
11273 sub jqplot_linegraph
11274 {
11275 my ($buttonid, $divid, $infos, $title, $description, $data, $legend) = @_;
11276
11277 my $ylabel = $infos->{ylabel} || '';
11278 my $str = '';
11279 if (($divid !~ /\+$/) && ($divid !~ /^statio-/)) {
11280 $str = qq{
11281 <ul id="slides">
11282 <li class="slide active-slide" id="$divid-slide">
11283 <div id="$divid"><br/><br/><br/><br/></div>
11284 };
11285 } else {
11286 $divid =~ s/\+$//;
11287 }
11288
11289 $str .= qq{
11290 <div class="row">
11291 <div class="col-md-12">
11292 <div class="panel panel-default">
11293 <div class="panel-heading">
11294 <h2>$title</h2>
11295 <p>$description</p>
11296 </div>
11297 <div class="panel-body">
11298 };
11299 my $y2label = '';
11300 if (exists $infos->{y2label}) {
11301 $y2label = $infos->{y2label};
11302 }
11303
11304 my $dateTracker_dataopts = '';
11305 my $options_series = '';
11306 my $has_data = 0;
11307 if ($#{$data} >= 0) {
11308 for (my $i = 0; $i <= $#{$legend}; $i++) {
11309 next if (!$legend->[$i]);
11310 my $color = '';
11311 if ($#{$legend} <= $#GRAPH_COLORS) {
11312 $color = ", color: \"$GRAPH_COLORS[$i]\"";
11313 }
11314 if ($legend->[$i] =~ /label: "([^"]+)"/) {
11315 if (($i == $#{$legend}) && $infos->{y2label}) {
11316 $options_series .= "{ label: \"$1\"$color, yaxis: 'y2axis' },";
11317 } else {
11318 $options_series .= "{ label: \"$1\"$color },";
11319 }
11320 } else {
11321 if (($i == $#{$legend}) && $infos->{y2label}) {
11322 $options_series .= "{ label: \"$legend->[$i]\"$color, yaxis: 'y2axis' },";
11323 } else {
11324 $options_series .= "{ label: \"$legend->[$i]\"$color },";
11325 }
11326 }
11327 }
11328
11329 for (my $i = 0; $i <= $#{$data}; $i++) {
11330 next if (!$data->[$i]);
11331 $data->[$i] = "var graph_${buttonid}_d$i = [$data->[$i]];\n";
11332 $dateTracker_dataopts .= "graph_${buttonid}_d$i,";
11333 $has_data = 1;
11334 }
11335 $dateTracker_dataopts =~ s/,$//;
11336 $dateTracker_dataopts = "[$dateTracker_dataopts]";
11337 }
11338
11339 my $cssgraph = 'linegraph';
11340 if ($divid =~ /^table-/) {
11341 $cssgraph = 'smallgraph';
11342 }
11343 if ($has_data) {
11344 $str .= <<EOF;
11345 <div id="$divid$buttonid" class="jqplot-graph $cssgraph"></div>
11346 <script type="text/javascript">
11347 /* <![CDATA[ */
11348 @$data
11349 var series_arr = [ $options_series ];
11350
11351 create_download_button($buttonid, 'btn');
11352 var graph_${buttonid} = create_linegraph('$divid$buttonid', '$title', '$ylabel', series_arr, $dateTracker_dataopts, '$y2label');
11353 add_download_button_event($buttonid, '$divid$buttonid', graph_${buttonid});
11354 /* ]]> */
11355 </script>
11356 </div>
11357 </div>
11358 </div>
11359 </div>
11360 EOF
11361 } else {
11362 $str .= "<div class=\"jqplot-graph $cssgraph\"><blockquote><b>NO DATASET</b></blockquote></div>";
11363 }
11364
11365 if ($divid !~ /^(pgbouncer|tablespace|statio)/) {
11366 $str .= qq{
11367 </li>
11368 </ul>
11369 };
11370 }
11371
11372 return $str;
11373 }
11374
11375 sub jqplot_piegraph
11376 {
11377 my ($buttonid, $divid, $infos, $title, %data) = @_;
11378
11379 my $datadef = '';
11380 foreach my $k (sort keys %data) {
11381 $datadef .= "['$k', $data{$k}],";
11382 }
11383 if ($title ne '') {
11384 $title = sprintf($infos->{title}, $title);
11385 } else {
11386 $title = $infos->{title};
11387 }
11388 my $description = $infos->{description} || '';
11389 my $str = qq{
11390 <ul id="slides">
11391 <li class="slide active-slide" id="$divid-slide">
11392 <div id="$divid"><br/><br/><br/><br/></div>
11393 <div class="row">
11394 <div class="col-md-12">
11395 <div class="panel panel-default">
11396 <div class="panel-heading">
11397 <h2>$title</h2>
11398 <p>$description</p>
11399 </div>
11400 <div class="panel-body">
11401
11402 };
11403
11404 if ($datadef) {
11405 $str .= <<EOF;
11406 <div id="$divid$buttonid" class="jqplot-graph piegraph"></div>
11407 <script type="text/javascript">
11408 /* <![CDATA[ */
11409 var data_${buttonid} = [ $datadef ];
11410
11411 create_download_button($buttonid, 'btn');
11412 var graph_$buttonid = create_piechart('$divid$buttonid', '$title', data_${buttonid});
11413 add_download_button_event($buttonid, '$divid$buttonid', graph_$buttonid);
11414 /* ]]> */
11415 </script>
11416 EOF
11417 } else {
11418 $str .= '<div class="jqplot-graph piegraph"><blockquote><b>NO DATASET</b></blockquote></div>';
11419 }
11420 $str .= qq{
11421 </div>
11422 </div>
11423 </div><!--/span-->
11424 </div>
11425 </li>
11426 </ul>
11427 };
11428
11429 return $str;
11430 }
11431
11432 sub getNumericalOffset
11433 {
11434 my $stringofs = shift;
11435
11436 my @pieces = split /\//, $stringofs;
11437 die "Invalid offset: $stringofs" unless ($#pieces == 1);
11438
11439
11440 # First part is logid, second part is record offset
11441 return (hex("ffffffff") * hex($pieces[0])) + hex($pieces[1]);
11442 }
11443
11444 sub read_sysinfo
11445 {
11446 my $input_dir = shift;
11447
11448 # Empty arrays before filling them
11449 my @toclear = qw/DF MOUNT PROCESS PCI CRONTAB INSTALLATION EXTENSION SCHEMA JSON/;
11450 foreach my $s (@toclear) {
11451 delete $sysinfo{$s};
11452 }
11453
11454 print STDERR "DEBUG: Looking for system information in directory $input_dir\n" if ($DEBUG);
11455 if (-e "$input_dir/sys_cache.bin") {
11456 print STDERR "DEBUG: Loading system information from cache file $input_dir/sys_cache.bin\n" if ($DEBUG);
11457 &load_sysinfo_binary($input_dir, "sys_cache.bin");
11458 $sysinfo{CACHE}{last_run} = localtime((stat("$input_dir/sys_cache.bin"))[9]) || '';
11459 } elsif (-e "$input_dir/sysinfo.txt") {
11460 print STDERR "DEBUG: Loading system information from file $input_dir/sysinfo.txt\n" if ($DEBUG);
11461 %sysinfo = &read_sysinfo_file("$input_dir/sysinfo.txt");
11462 $sysinfo{RELEASE}{'name'} ||= 'unknown';
11463 } elsif (-e "$input_dir/sysinfo.txt.gz") {
11464 print STDERR "DEBUG: Loading system information from file $input_dir/sysinfo.txt.gz\n" if ($DEBUG);
11465 %sysinfo = &read_sysinfo_file("$input_dir/sysinfo.txt.gz");
11466 $sysinfo{RELEASE}{'name'} ||= 'unknown';
11467 }
11468
11469 # Get the list of database from registered extension and schema
11470 foreach my $db (keys %{$sysinfo{EXTENSION}}) {
11471 push(@DATABASE_LIST, $db) if (!grep(/^$db$/, @DATABASE_LIST));
11472 }
11473 foreach my $db (keys %{$sysinfo{SCHEMA}}) {
11474 push(@DATABASE_LIST, $db) if (!grep(/^$db$/, @DATABASE_LIST));
11475 }
11476
11477
11478 # Load global information from cache file
11479 if (-e "$input_dir/global_infos.bin")
11480 {
11481 &load_sar_binary($input_dir, 'global_infos');
11482
11483 # Look for disk device and network interface from global info
11484 if (exists $global_infos{DEVICE_LIST}) {
11485 foreach my $d (@{$global_infos{DEVICE_LIST}}) {
11486 push(@DEVICE_LIST, $d) if (!grep(/^$d$/, @DEVICE_LIST));
11487 }
11488 }
11489 if (exists $global_infos{IFACE_LIST}) {
11490 foreach my $d (@{$global_infos{IFACE_LIST}}) {
11491 push(@IFACE_LIST, $d) if (!grep(/^$d$/, @IFACE_LIST));
11492 }
11493 }
11494 if (exists $global_infos{DEVICE_SPACE_LIST}) {
11495 foreach my $d (@{$global_infos{DEVICE_SPACE_LIST}}) {
11496 push(@DEVICE_SPACE_LIST, $d) if (!grep(/^$d$/, @DEVICE_SPACE_LIST));
11497 }
11498 }
11499
11500 } else {
11501
11502 # Look for disk device and network interface from the sar file
11503 if (!$DISABLE_SAR && -e "$input_dir/sar_stats.dat") {
11504 &set_device_list("$input_dir/sar_stats.dat");
11505 }
11506 }
11507 }
11508
11509 sub read_sysinfo_file
11510 {
11511 my $file = shift;
11512
11513 if (!is_compressed($file)) {
11514 open(IN, $file) or die "ERROR: can't read file $file, $!\n";
11515 } else {
11516 open(IN, "$ZCAT_PROG $file |") or die "ERROR: can't read pipe on command: $ZCAT_PROG $file, $!\n";
11517 }
11518 my %sysinfo = ();
11519 my $section = '';
11520 while (my $l = <IN>) {
11521 chomp($l);
11522 if ($l =~ /^\[(.*)\]$/) {
11523 $section = $1;
11524 next;
11525 }
11526 if ($section eq 'CPU') {
11527 my ($key, $val) = split(/\s+:\s+/, $l);
11528 if ($key eq 'processor') {
11529 $sysinfo{$section}{$key} = $val + 1;
11530 } elsif ($key eq 'model name') {
11531 $val =~ s/\s+\@\s+(.*)$//;
11532 $sysinfo{$section}{'cpu MHz'} = $1;
11533 $sysinfo{$section}{$key} = $val;
11534 } else {
11535 $sysinfo{$section}{$key} = $val;
11536 }
11537 }
11538 elsif ($section eq 'KERNEL') {
11539 my @kinf = split(/\s+/, $l);
11540 $sysinfo{$section}{'hostname'} = $kinf[1];
11541 $sysinfo{$section}{'kernel'} = "$kinf[0] $kinf[2] $kinf[3] $kinf[4]";
11542 $sysinfo{$section}{'arch'} = "$kinf[-2] $kinf[-1]";
11543 }
11544 elsif ($section eq 'UPTIME') {
11545 $sysinfo{$section}{'all'} = $l;
11546 if ($l =~ /\s*([^,]+), (.*)/) {
11547 $sysinfo{$section}{'uptime'} = $1;
11548 $sysinfo{$section}{'infos'} = $2;
11549 }
11550 }
11551 elsif ($section eq 'RELEASE') {
11552 my ($key, $val) = split(/=/, $l);
11553 if ($val) {
11554 $val =~ s/"//g;
11555 $sysinfo{$section}{lc($key)} = $val;
11556 } else {
11557 $sysinfo{RELEASE}{'name'} = $key;
11558 $sysinfo{RELEASE}{'version'} = '';
11559 }
11560 }
11561 elsif ($section eq 'MEMORY') {
11562 my ($key, $val) = split(/:\s+/, $l);
11563 if ($val =~ s/ kB//) {
11564 $sysinfo{$section}{lc($key)} = &pretty_print_size($val*1000);
11565 } else {
11566 $sysinfo{$section}{lc($key)} = $val;
11567 }
11568 }
11569 elsif ($section eq 'DF') {
11570 next if ($l !~ /^[\s\/]/);
11571 if ($l =~ s/^\s+//) {
11572 $sysinfo{$section}[-1] =~ s/<\/tr>$/<td>/;
11573 $sysinfo{$section}[-1] .= join('</td><td>', split(/\s+/, $l)) . "</td></tr>";
11574 next;
11575 }
11576 push(@{$sysinfo{$section}}, '<tr><td>' . join('</td><td>', split(/\s+/, $l)) . "</td></tr>");
11577 }
11578 elsif ($section eq 'MOUNT') {
11579 next if ($l !~ /^\//);
11580 push(@{$sysinfo{$section}}, '<tr><td>' . join('</td><td>', split(/\s+on\s+|\s+type\s+|\s+/, $l)) . '</td></tr>');
11581 }
11582 elsif ($section eq 'SYSTEM') {
11583 my ($key, $val) = split(/\s*[=:]\s+/, $l);
11584 $sysinfo{$section}{$key} = $val if ($key && defined $val);
11585 }
11586 elsif ($section eq 'PGVERSION') {
11587 $sysinfo{$section}{full_version} = $l;
11588 if ($l =~ /^PostgreSQL (\d+)\.(\d+)\.(\d+)/) {
11589 $sysinfo{$section}{major} = "$1.$2";
11590 $sysinfo{$section}{minor} = "$1.$2.$3";
11591 } elsif ($l =~ /^PostgreSQL (\d+)\.(\d+)/) {
11592 $sysinfo{$section}{major} = "$1.$2";
11593 $sysinfo{$section}{minor} = "$1.$2.0";
11594 } elsif ($l =~ /^EnterpriseDB (\d+)\.(\d+)\.(\d+)/) {
11595 $sysinfo{$section}{major} = "$1.$2";
11596 $sysinfo{$section}{minor} = "$1.$2.$3";
11597 } elsif ($l =~ /(\d+)\.(\d+)\.(\d+)/) {
11598 $sysinfo{$section}{major} = "$1.$2";
11599 $sysinfo{$section}{minor} = "$1.$2.$3";
11600 } else {
11601 $sysinfo{$section}{major} = '';
11602 $sysinfo{$section}{minor} = '';
11603 }
11604 }
11605 elsif ($section eq 'PGUPTIME') {
11606 $sysinfo{PGVERSION}{uptime} = $l;
11607 }
11608 elsif ($section eq 'EXTENSION') {
11609 my ($db, @vals) = split(/[=,]+/, $l);
11610 foreach my $e (@vals) {
11611 push(@{$sysinfo{$section}{$db}}, $e) if (!grep(/^$e$/, @{$sysinfo{$section}{$db}}));
11612 push(@{$OVERALL_STATS{'cluster'}{'extensions'}}, $e) if (!grep(/^$e$/, @{$OVERALL_STATS{'cluster'}{'extensions'}}));
11613 }
11614
11615 }
11616 elsif ($section eq 'SCHEMA') {
11617 my ($db, @vals) = split(/[=,]+/, $l);
11618 foreach my $s (@vals) {
11619 push(@{$sysinfo{$section}{$db}}, $s) if (!grep(/^$s$/, @{$sysinfo{$section}{$db}}));
11620 }
11621 }
11622 elsif ($section eq 'JSON') {
11623 my ($db, @vals) = split(/[=,]+/, $l);
11624 foreach my $s (@vals) {
11625 push(@{$sysinfo{$section}{$db}}, $s) if (!grep(/^$s$/, @{$sysinfo{$section}{$db}}));
11626 }
11627 }
11628 elsif ($section eq 'PROCEDURE') {
11629 if ($l =~ /^([^=]+)=(\d+)$/) {
11630 $sysinfo{$section}{$1} = $2;
11631 } else {
11632 # Backward compatibility with version 2.4
11633 my ($db, @vals) = split(/[=,]+/, $l);
11634 $sysinfo{$section}{$db} = $#vals + 1;
11635 }
11636 }
11637 elsif ($section eq 'TRIGGER') {
11638 my ($db, $val) = split(/[=]+/, $l);
11639 $sysinfo{$section}{$db} = $val;
11640 }
11641 elsif ($section eq 'PROCESS') {
11642 my ($USER,$PID,$CPU,$MEM,$VSZ,$RSS,$TTY,$STAT,$START,$TIME,$COMMAND) = split(/\s+/, $l, 11);
11643 push(@{$sysinfo{$section}}, '<tr><td>' . join('</td><td>', $USER,$PID,$CPU,$MEM,$VSZ,$RSS,$TTY,$STAT,$START,$TIME,$COMMAND) . '</td></tr>') if ($l !~/^USER/);
11644 }
11645 elsif ($section eq 'PARTITIONNED_TABLE') {
11646 # limit split to 2 fields, check constraint can contains "="
11647 my ($db, $csv) = split(/[=]/, $l, 2);
11648
11649 if ($csv) {
11650 my ($oid, $parent, $child, $constraint, $kind, $nparts ) = split(/[;]+/, $csv);
11651 $sysinfo{$section}{$db}{$oid}{name} = $parent;
11652 $sysinfo{$section}{$db}{$oid}{child}{$child} = $constraint;
11653 $sysinfo{$section}{$db}{$oid}{kind} = $kind;
11654 $sysinfo{$section}{$db}{$oid}{nparts} = $nparts;
11655 push(@{$OVERALL_STATS{'cluster'}{'partitionned_tables'}}, "$db.$parent") if (!grep(/^$db.$parent/, @{$OVERALL_STATS{'cluster'}{'partitionned_tables'}}));
11656 }
11657 }
11658 elsif ($section =~ /PARTITION_IMPL (.*) (\d+)/) {
11659 $sysinfo{PARTITIONNED_TABLE}{$1}{$2}{implementation} .= "$l\n";
11660 }
11661 elsif ($section =~ /^(PCI|CRONTAB|INSTALLATION)$/) {
11662 push(@{$sysinfo{$section}}, "$l\n");
11663 }
11664 }
11665 close(IN);
11666
11667 return %sysinfo;
11668 }
11669
11670 # Format duration
11671 sub format_duration
11672 {
11673 my $time = shift;
11674
11675 return '0s' if (!$time);
11676
11677 my $days = int($time / 86400000);
11678 $time -= ($days * 86400000);
11679 my $hours = int($time / 3600000);
11680 $time -= ($hours * 3600000);
11681 my $minutes = int($time / 60000);
11682 $time -= ($minutes * 60000);
11683 my $seconds = sprintf("%0.3f", $time / 1000);
11684
11685 $days = $days < 1 ? '' : $days . 'd';
11686 $hours = $hours < 1 ? '' : $hours . 'h';
11687 $minutes = $minutes < 1 ? '' : $minutes . 'm';
11688 $seconds =~ s/\.\d+$// if ($minutes);
11689 $time = $days . $hours . $minutes . $seconds . 's';
11690
11691 return $time;
11692 }
11693
11694 sub get_data_directories
11695 {
11696 my @work_dirs = ();
11697
11698 my $local_max_render = $MAX_RENDERED_DAYS;
11699
11700 # Lookup for daily or hourly sub directories to scan
11701 # Search years / months / days / hours directories
11702 if (not opendir(DIR, "$INPUT_DIR")) {
11703 print STDERR "FATAL: Can't open directory $INPUT_DIR: $!\n";
11704 return;
11705 }
11706 my @years = grep { /^\d+$/ && -d "$INPUT_DIR/$_" } readdir(DIR);
11707 closedir(DIR);
11708 if ($#years >= 0) {
11709 foreach my $y (sort { $a <=> $b } @years) {
11710 next if ($o_year && ($y < $o_year));
11711 next if ($e_year && ($y > $e_year));
11712 if (not opendir(DIR, "$INPUT_DIR/$y")) {
11713 print STDERR "FATAL: Can't open directory $INPUT_DIR/$y: $!\n";
11714 return;
11715 }
11716 my @months = grep { /^\d+$/ && -d "$INPUT_DIR/$y/$_" } readdir(DIR);
11717 closedir(DIR);
11718 foreach my $m (sort { $a <=> $b } @months) {
11719 next if ($o_month && ("$y$m" lt "$o_year$o_month"));
11720 next if ($e_month && ("$y$m" gt "$e_year$e_month"));
11721 if (not opendir(DIR, "$INPUT_DIR/$y/$m")) {
11722 print STDERR "FATAL: Can't open directory $INPUT_DIR/$y/$m: $!\n";
11723 return;
11724 }
11725 my @days = grep { /^\d+$/ && -d "$INPUT_DIR/$y/$m/$_" } readdir(DIR);
11726 closedir(DIR);
11727 foreach my $d (sort { $a <=> $b } @days) {
11728 next if ($o_day && ("$y$m$d" lt "$o_year$o_month$o_day"));
11729 next if ($e_day && ("$y$m$d" gt "$e_year$e_month$e_day"));
11730 if (not opendir(DIR, "$INPUT_DIR/$y/$m/$d")) {
11731 print STDERR "FATAL: Can't open directory $INPUT_DIR/$y/$m/$d: $!\n";
11732 return;
11733 }
11734 my @hbin = grep { /^.*\.bin$/ } readdir(DIR);
11735 closedir(DIR);
11736 if (not opendir(DIR, "$INPUT_DIR/$y/$m/$d")) {
11737 print STDERR "FATAL: Can't open directory $INPUT_DIR/$y/$m/$d: $!\n";
11738 return;
11739 }
11740 my @hours = grep { /^\d+$/ && -d "$INPUT_DIR/$y/$m/$d/$_" } readdir(DIR);
11741 closedir(DIR);
11742 if ($#hours == -1 || $#hbin >= 0) {
11743 push(@work_dirs, "$y/$m/$d");
11744 } else {
11745 $local_max_render = $MAX_RENDERED_DAYS * 24;
11746 foreach my $h (sort { $a <=> $b } @hours) {
11747 next if ($o_hour && ("$y$m$d$h" lt "$o_year$o_month$o_day$o_hour"));
11748 next if ($e_hour && ("$y$m$d$h" gt "$e_year$e_month$e_day$e_hour"));
11749 push(@work_dirs, "$y/$m/$d/$h");
11750 }
11751 }
11752 }
11753 }
11754 }
11755
11756 if ($#work_dirs > $local_max_render) {
11757 $local_max_render--;
11758 splice(@work_dirs, 0, $local_max_render);
11759 }
11760 }
11761
11762 return @work_dirs;
11763 }
11764
11765 # Initialise global variables storing PostgreSQL statistics
11766 sub clear_db_stats
11767 {
11768 print STDERR "DEBUG: Cleaning memory from PostgreSQL statistics storages\n" if ($DEBUG);
11769
11770 foreach my $name (@pg_to_be_stored) {
11771 if (grep(/^$name$/, 'global_databases', 'global_tbspnames', )) {
11772 @{$name} = ();
11773 } else {
11774 %{$name} = ();
11775 }
11776 }
11777 }
11778
11779 # Initialise global variables storing statistics
11780 sub clear_stats
11781 {
11782 # Clean PostgreSQL statistics
11783 &clear_db_stats();
11784
11785 print STDERR "DEBUG: Cleaning memory from all statistics storages\n" if ($DEBUG);
11786 %OVERALL_STATS = ();
11787 %sysinfo = ();
11788 foreach my $name (@sar_to_be_stored) {
11789 %{$name} = ();
11790 }
11791 foreach my $name (@pidstat_to_be_stored) {
11792 %{$name} = ();
11793 }
11794
11795 }
11796
11797 # Load statistics from pg cache into memory
11798 sub load_pg_binary
11799 {
11800 my ($input_dir, $varname) = @_;
11801
11802 foreach my $name (@pg_to_be_stored)
11803 {
11804 next if ($varname ne 'home' && $name ne $varname && !grep($name, 'global_databases', 'global_tbspnames')); # Just load the right binary file
11805 next if ( !-e "$input_dir/$name.bin");
11806
11807 print STDERR "DEBUG: Loading PostgreSQL statistics from cache file $in_dir/$name.bin\n" if ($DEBUG);
11808
11809 my %stats = ();
11810 my $lfh = new IO::File "<$input_dir/$name.bin";
11811 if (not defined $lfh) {
11812 die "FATAL: can't read from $input_dir/$name.bin, $!\n";
11813 }
11814 %stats = %{ fd_retrieve($lfh) };
11815 $lfh->close();
11816
11817 if (!grep(/^$name$/, 'global_databases', 'global_tbspnames'))
11818 {
11819 # Setting global information
11820 if ($name eq 'global_infos') {
11821
11822 my %_global_infos = %{$stats{global_infos}} ;
11823 foreach my $inf (keys %_global_infos) {
11824 $_global_infos{$inf} //= 0;
11825 if ($_global_infos{$inf} =~ /ARRAY/) {
11826 push(@{$global_infos{$inf}}, @{$_global_infos{$inf}});
11827 } else {
11828 $global_infos{$inf} = $_global_infos{$inf};
11829 }
11830 }
11831 delete $stats{global_infos};
11832
11833 } else {
11834
11835 # Load other storages
11836 foreach my $m (keys %stats) {
11837 foreach my $t (keys %{$stats{$m}}) {
11838 if ($stats{$m}{$t} =~ /HASH/) {
11839 foreach my $d (keys %{$stats{$m}{$t}}) {
11840 if ($stats{$m}{$t}{$d} =~ /HASH/) {
11841 foreach my $k (keys %{$stats{$m}{$t}{$d}}) {
11842 ${$m}{$t}{$d}{$k} = $stats{$m}{$t}{$d}{$k};
11843 }
11844 } elsif ($stats{$m}{$t}{$d} =~ /ARRAY/) {
11845 push(@{${$m}{$t}{$d}}, @{$stats{$m}{$t}{$d}});
11846 } else {
11847 ${$m}{$t}{$d} = $stats{$m}{$t}{$d};
11848 }
11849 }
11850 } elsif ($stats{$m}{$t} =~ /ARRAY/) {
11851 push(@{${$m}{$t}}, @{$stats{$m}{$t}});
11852 } else {
11853 ${$m}{$t} = $stats{$m}{$t};
11854 }
11855 }
11856 }
11857 }
11858 }
11859 else
11860 {
11861 # Look for database and tablespace
11862 foreach my $d (@{$stats{$name}}) {
11863 push(@{$name}, $d) if (!grep(/^$d$/, @{$name}));
11864 }
11865 delete $stats{$name};
11866 }
11867 }
11868
11869 # Preserve backward compatibility with renaming of variable all_statio_all_indexes
11870 if (-e "$input_dir/all_statio_all_indexes.bin") {
11871
11872 my $lfh = new IO::File "<$input_dir/all_statio_all_indexes.bin";
11873 if (not defined $lfh) {
11874 die "FATAL: can't read from $input_dir/all_statio_all_indexes.bin, $!\n";
11875 }
11876 my %stats = %{ fd_retrieve($lfh) };
11877 $lfh->close();
11878
11879 foreach my $a (keys %{$stats{'all_statio_all_indexes'}}) {
11880 foreach my $b (keys %{$stats{'all_statio_all_indexes'}{$a}}) {
11881 foreach my $c (keys %{$stats{'all_statio_all_indexes'}{$a}{$b}}) {
11882 foreach my $k (keys %{$stats{'all_statio_all_indexes'}{$a}{$b}{$c}}) {
11883 $all_statio_user_indexes{$a}{$b}{$c}{$k} = $stats{'all_statio_all_indexes'}{$a}{$b}{$c}{$k};
11884 }
11885 }
11886 }
11887 }
11888 }
11889
11890 # Compute overall database statistics from binary file
11891 # as they are normally computed when reading data files.
11892 set_overall_database_stat_from_binary();
11893 }
11894
11895 # Load statistics from sar cache into memory
11896 sub load_sar_binary
11897 {
11898 my ($input_dir, $varname) = @_;
11899
11900 foreach my $name (@sar_to_be_stored)
11901 {
11902 next if ($varname ne 'home' && $name ne $varname); # Just load the right binary file
11903
11904 print STDERR "DEBUG: Loading Sar statistics from cache file $in_dir/$name.bin\n" if ($DEBUG);
11905 my %stats = ();
11906 if (-e "$input_dir/$name.bin")
11907 {
11908 my $lfh = new IO::File "<$input_dir/$name.bin";
11909 if (not defined $lfh) {
11910 die "FATAL: can't read from $input_dir/$name.bin, $!\n";
11911 }
11912 %stats = %{ fd_retrieve($lfh) };
11913 $lfh->close();
11914 }
11915
11916 # Setting global information
11917 if ($name eq 'global_infos')
11918 {
11919 # Setting global information
11920 if (exists $stats{global_infos})
11921 {
11922 my %_global_infos = %{$stats{global_infos}} ;
11923 foreach my $inf (keys %_global_infos) {
11924 $_global_infos{$inf} //= 0;
11925 if ($_global_infos{$inf} =~ /ARRAY/) {
11926 push(@{$global_infos{$inf}}, @{$_global_infos{$inf}});
11927 } else {
11928 $global_infos{$inf} = $_global_infos{$inf};
11929 }
11930 }
11931 delete $stats{global_infos};
11932 }
11933 }
11934 else
11935 {
11936
11937 # Load other sar storages
11938 foreach my $m (keys %stats) {
11939 foreach my $t (keys %{$stats{$m}}) {
11940 foreach my $d (keys %{$stats{$m}{$t}}) {
11941 if ($stats{$m}{$t}{$d} =~ /HASH/) {
11942 foreach my $k (keys %{$stats{$m}{$t}{$d}}) {
11943 ${$m}{$t}{$d}{$k} = $stats{$m}{$t}{$d}{$k};
11944 }
11945 } else {
11946 ${$m}{$t}{$d} = $stats{$m}{$t}{$d};
11947 }
11948 }
11949 }
11950 }
11951 }
11952 }
11953
11954 # Compute overall system statistics from binary file
11955 # as they are normally computed when reading data files.
11956 set_overall_system_stat_from_binary();
11957 }
11958
11959 # Load statistics from pidstat cache into memory
11960 sub load_pidstat_binary
11961 {
11962 my ($in_dir) = @_;
11963
11964 foreach my $name (@pidstat_to_be_stored)
11965 {
11966 next if (!-e "$in_dir/$name.bin");
11967 my $lfh = IO::File->new("$in_dir/$name.bin", 'r');
11968 if (not defined $lfh) {
11969 die "FATAL: can't read file $in_dir/$name.bin, $!\n";
11970 }
11971 my %stats = %{ fd_retrieve($lfh) };
11972 $lfh->close();
11973 # Load pidstat storages
11974 foreach my $m (keys %stats) {
11975 foreach my $t (keys %{$stats{$m}}) {
11976 foreach my $d (keys %{$stats{$m}{$t}}) {
11977 if ($stats{$m}{$t}{$d} =~ /HASH/) {
11978 foreach my $k (keys %{$stats{$m}{$t}{$d}}) {
11979 ${$m}{$t}{$d}{$k} = $stats{$m}{$t}{$d}{$k};
11980 }
11981 } else {
11982 ${$m}{$t}{$d} = $stats{$m}{$t}{$d};
11983 }
11984 }
11985 }
11986 }
11987 }
11988 }
11989
11990 # Load statistics from sysinfo cache into memory
11991 sub load_sysinfo_binary
11992 {
11993 my ($input_dir, $infile) = @_;
11994
11995 # Do not load empty file, Storable don't support it
11996 return if (-z "$input_dir/$infile");
11997
11998 my $lfh = new IO::File "<$input_dir/$infile";
11999 if (not defined $lfh) {
12000 die "FATAL: can't read from $input_dir/$infile, $!\n";
12001 }
12002 my %stats = %{ fd_retrieve($lfh) };
12003 $lfh->close();
12004 my %_sysinfo = %{$stats{sysinfo}};
12005
12006 # Empty arrays before filling them
12007 my @toclear = qw/DF MOUNT PROCESS PCI CRONTAB INSTALLATION EXTENSION SCHEMA JSON/;
12008 foreach my $s (@toclear) {
12009 delete $sysinfo{$s};
12010 }
12011
12012 # Load other storages
12013 foreach my $s (keys %_sysinfo) {
12014 if ($_sysinfo{$s} =~ /^HASH/) {
12015 foreach my $n (keys %{$_sysinfo{$s}}) {
12016 if ($_sysinfo{$s}{$n} =~ /^HASH/) {
12017 foreach my $k (keys %{$_sysinfo{$s}{$n}}) {
12018 if ($_sysinfo{$s}{$n}{$k} =~ /^HASH/) {
12019 foreach my $j (keys %{$_sysinfo{$s}{$n}{$k}}) {
12020 if ($_sysinfo{$s}{$n}{$k}{$j} =~ /^HASH/) {
12021 foreach my $i (keys %{$_sysinfo{$s}{$n}{$k}{$j}}) {
12022 $sysinfo{$s}{$n}{$k}{$j}{$i} = $_sysinfo{$s}{$n}{$k}{$j}{$i};
12023 }
12024 } else {
12025 $sysinfo{$s}{$n}{$k}{$j} = $_sysinfo{$s}{$n}{$k}{$j};
12026 }
12027 }
12028 } else {
12029 $sysinfo{$s}{$n}{$k} = $_sysinfo{$s}{$n}{$k};
12030 }
12031 }
12032 } elsif ($_sysinfo{$s}{$n} =~ /^ARRAY/) {
12033 push(@{$sysinfo{$s}{$n}}, @{$_sysinfo{$s}{$n}});
12034 } else {
12035 $sysinfo{$s}{$n} = $_sysinfo{$s}{$n};
12036 }
12037 }
12038 } elsif ($_sysinfo{$s} =~ /^ARRAY/) {
12039 push(@{$sysinfo{$s}}, @{$_sysinfo{$s}});
12040 }
12041 }
12042
12043 }
12044
12045 sub empty_dataset
12046 {
12047 my ($divid, $infos, $title) = @_;
12048
12049 my $description = $infos->{description} || '';
12050 if ($title ne '') {
12051 $title = sprintf($infos->{title}, $title);
12052 } else {
12053 $title = $infos->{title};
12054 }
12055
12056 my $str = qq{
12057 <ul id="slides">
12058 <li class="slide active-slide" id="$divid-slide">
12059 <div id="$divid"><br/><br/><br/><br/></div>
12060 <div class="row">
12061 <div class="col-md-12">
12062 <div class="panel panel-default">
12063 <div class="panel-heading">
12064 <h2>$title</h2>
12065 <p>$description</p>
12066 </div>
12067 <div class="panel-body">
12068 <div class="flotr-graph"><blockquote><b>NO DATASET</b></blockquote></div>
12069 </div>
12070 </div>
12071 </div><!--/span-->
12072 </div>
12073 </li>
12074 </ul>
12075 };
12076 return $str;
12077 }
12078
12079 # Compare given version numbers to the server's version
12080 sub backend_minimum_version
12081 {
12082 my ($numver) = @_;
12083
12084 return 0 if (!$numver);
12085
12086 return 1 if (!exists $sysinfo{PGVERSION}{'major'} || ($sysinfo{PGVERSION}{'major'} >= $numver));
12087
12088 return 0;
12089 }
12090