Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / oracle / oracle_sysstat @ fa208cb6

Historique | Voir | Annoter | Télécharger (31,4 ko)

1
#!/bin/bash
2
# -*- sh -*-
3

    
4
: << =cut
5

    
6
=head1 NAME
7

    
8
  oracle_sysstat - Munin multi-graph plugin to monitor Oracle Statistics
9

    
10
  These modules are implemented:
11
    execute                 - To monitor Oracle Sysstat SQL Execute Count
12
    parse                   - To monitor Oracle Sysstat SQL Parse Count
13
    tablefetch              - To monitor Oracle Sysstat SQL Table Fetch Rows
14
    tablescan               - To monitor Oracle Sysstat SQL Table Scans
15
    transaction             - To monitor Oracle Sysstat SQL Transactions
16
    sort                    - To monitor Oracle Sysstat SQL Sorts
17
    logon                   - To monitor Oracle Sysstat User Logons
18
    cursor                  - To monitor Oracle Sysstat User Opened Cursors
19
    enqueue                 - To monitor Oracle Sysstat Enqueues
20
    redolog                 - To monitor Oracle Sysstat Redo Entries
21
    redosize                - To monitor Oracle Sysstat Redo Size
22
    physicaliops            - To monitor Oracle Sysstat I/O Physical Requests
23
    physicalrw              - To monitor Oracle Sysstat I/O Physical Bytes
24
    blockrw                 - To monitor Oracle Sysstat I/O Blocks
25
    netrw                   - To monitor Oracle Sysstat I/O Network Bytes
26
    sgainfo                 - To monitor Oracle Memory SGA
27
    pgastat                 - To monitor Oracle Memory PGA
28
    cputime                 - To monitor Oracle CPU Time
29
    cachehit                - To monitor Oracle Cache Hit Ratio
30
    sessionuser             - To monitor Oracle Session Users
31
    sessionwait             - To monitor Oracle Session Wait
32
    eventwait               - To monitor Oracle Wait Events
33
    eventwaitapplication    - To monitor Oracle Wait Events Application
34
    eventwaitnetwork        - To monitor Oracle Wait Events Network
35
    eventwaitconcurrency    - To monitor Oracle Wait Events Concurrency
36
    eventwaituserio         - To monitor Oracle Wait Events User I/O
37
    eventwaitsystemio       - To monitor Oracle Wait Events System I/O
38
    eventwaitcluster        - To monitor Oracle Wait Events Cluster
39
    eventwaitadministrative - To monitor Oracle Wait Events Administrative
40
    eventwaitconfiguration  - To monitor Oracle Wait Events Configuration
41
    tablespace              - To monitor Oracle Table Space Usage
42
    asmusage                - To monitor Oracle ASM Disk Group Usage
43

    
44
=head1 CONFIGURATION
45

    
46
  Make symlink:
47
    cd /path/to/munin/etc/plugins
48
    ln -s /path/to/munin/lib/plugins/oracle_sysstat .
49
    ln -s /path/to/munin/lib/plugins/oracle_sysstat oracle_sysstat_asmusage # if necessary
50
    ...
51

    
52
  The following shows example settings for this plugin:
53

    
54
    [oracle_sysstat]
55
      user  oracle
56
      env.ORACLE_SID   ORCL
57
      env.ORACLE_HOME  /path/to/oracle/home
58
      env.oracle_auth  / as SYSDBA
59

    
60
    [oracle_sysstat_asmusage]
61
      user  grid
62
      env.ORACLE_SID     +ASM
63
      env.ORACLE_HOME    /path/to/grid/home
64
      env.oracle_auth    / as SYSASM
65
      env.include_module asmusage
66
      env.plugin_name    oracle_sysstat
67

    
68
=head1 ENVIRONMENT VARIABLES
69

    
70
  env.ORACLE_SID:
71
    example:  env.ORACLE_SID  SOMESID
72
    default:  ORCL
73

    
74
  env.ORACLE_HOME:
75
    example:  env.ORACLE_HOME  /opt/oracle/...
76
    default:  Try to find from oratab file
77

    
78
  env.oracle_auth:
79
    example:  env.oracle_auth user/pass as SYSDBA
80
    default:  / as SYSDBA
81

    
82
  env.exclude_module:
83
    example:  env.exclude_module  asmusage tablespace
84
    default:  asmusage
85

    
86
    Module name(s) to exclude seperated by white-space.
87
    By default, asmusage module is excluded because another privilege 
88
    is necessary to connect ASM instance.
89

    
90
  env.include_module:
91
    example:  env.include_module  asmusage
92
    default:  none
93

    
94
    Module name(s) to include seperated by white-space.
95
    If both include_module and exclude_module are set, exclude will be 
96
    ignored.
97

    
98
  env.plugin_name: 
99
    example:  env.plugin_name  oracle_sysstat_2
100
    default:  program name (usually oracle_sysstat)
101

    
102
    Used for internal graph name. 
103
    It will be useful to monitor multi-instance databases.
104

    
105
  env.db_name: 
106
    example:  env.db_name  dbname
107
    default:  none
108

    
109
    Used for graph title. 
110
    It will be useful to monitor multi-instance databases.
111

    
112
=head1 NOTES
113

    
114
  Uses the command "sqlplus".
115
  Tested with Oracle Database 12c R1.
116

    
117
=head1 AUTHOR
118

    
119
  K.Cima https://github.com/shakemid
120

    
121
=head1 LICENSE
122

    
123
  GPLv2
124

    
125
=head1 MAGIC MARKERS
126

    
127
  #%# family=contrib
128
  #%# capabilities=autoconf
129

    
130
=cut
131

    
132
# Include plugin.sh
133
. "${MUNIN_LIBDIR:-}/plugins/plugin.sh"
134
is_multigraph "$@"
135

    
136
# Like perl 'use strict;' 
137
set -o nounset
138

    
139
# Global variables
140
: "${ORACLE_SID:=ORCL}"
141
: "${ORACLE_HOME:=$( cat /etc/oratab /var/opt/oracle/oratab \
142
    | awk -F: '$1 == "'$ORACLE_SID'" { print $2 }' 2>/dev/null )}"
143
: "${oracle_auth:=/ as SYSDBA}"
144
: "${exclude_module:=asmusage}"
145
: "${include_module:=}"
146
: "${plugin_name:=${0##*/}}"
147
[ -n "${db_name:=}" ] && db_name=" ($db_name)"
148

    
149
PATH=$PATH:$ORACLE_HOME/bin
150
export PATH ORACLE_HOME ORACLE_SID
151

    
152
# Graph settings
153
declare -A global_attrs  # required
154
declare -A data_attrs    # required (format: field type draw label)
155
declare -A getfield_func # optional
156
declare -A getvalue_func # required
157

    
158
# Note: Bash 4 (or above) is required to use hash.
159

    
160
key=execute
161
global_attrs[$key]="
162
    graph_title Oracle$db_name Sysstat SQL Execute Count
163
    graph_category db
164
    graph_args --base 1000 --lower-limit 0 --rigid
165
    graph_vlabel count per second
166
    graph_info Oracle Sysstat SQL Execute Count
167
"
168
data_attrs[$key]="
169
    execute_count   DERIVE LINE execute count
170
    user_calls      DERIVE LINE user calls
171
    recursive_calls DERIVE LINE recursive calls
172
"
173
getvalue_func[$key]=getvalue_sysstat
174

    
175
key=parse
176
global_attrs[$key]="
177
    graph_title Oracle$db_name Sysstat SQL Parse Count
178
    graph_category db
179
    graph_args --base 1000 --lower-limit 0 --rigid
180
    graph_vlabel count per second
181
    graph_info Oracle Sysstat SQL Parse Count
182
"
183
data_attrs[$key]="
184
    parse_count_total    DERIVE LINE parse count (total)
185
    parse_count_hard     DERIVE LINE parse count (hard)
186
    parse_count_describe DERIVE LINE parse count (describe)
187
    parse_count_failures DERIVE LINE parse count (failures)
188
"
189
getvalue_func[$key]=getvalue_sysstat
190

    
191
key=tablefetch
192
global_attrs[$key]="
193
    graph_title Oracle$db_name Sysstat SQL Table Fetch Rows
194
    graph_category db
195
    graph_args --base 1000 --lower-limit 0 --rigid
196
    graph_vlabel count per second
197
    graph_info Oracle Sysstat SQL Table Fetch Rows
198
"
199
data_attrs[$key]="
200
    table_fetch_by_rowid      DERIVE LINE table fetch by rowid
201
    table_scan_rows_gotten    DERIVE LINE table scan rows gotten
202
    table_fetch_continued_row DERIVE LINE table fetch continued row
203
"
204
getvalue_func[$key]=getvalue_sysstat
205

    
206
key=tablescan
207
global_attrs[$key]="
208
    graph_title Oracle$db_name Sysstat SQL Table Scans
209
    graph_category db
210
    graph_args --base 1000 --lower-limit 0 --rigid
211
    graph_vlabel count per second
212
    graph_info Oracle Sysstat SQL Table Scans
213
"
214
data_attrs[$key]="
215
    table_scans_short_tables DERIVE LINE table scans (short tables)
216
    table_scans_long_tables  DERIVE LINE table scans (long tables)
217
"
218
getvalue_func[$key]=getvalue_sysstat
219

    
220
key=transaction
221
global_attrs[$key]="
222
    graph_title Oracle$db_name Sysstat SQL Transactions
223
    graph_category db
224
    graph_args --base 1000 --lower-limit 0 --rigid
225
    graph_vlabel count per second
226
    graph_info Oracle Sysstat SQL Transactions
227
"
228
data_attrs[$key]="
229
    user_commits   DERIVE LINE user commits
230
    user_rollbacks DERIVE LINE user rollbacks
231
"
232
getvalue_func[$key]=getvalue_sysstat
233

    
234
key=sort
235
global_attrs[$key]="
236
    graph_title Oracle$db_name Sysstat SQL Sorts
237
    graph_category db
238
    graph_args --base 1000 --lower-limit 0 --rigid
239
    graph_vlabel count per second
240
    graph_info Oracle Sysstat SQL Sorts
241
"
242
data_attrs[$key]="
243
    sorts_memory DERIVE LINE sorts (memory)
244
    sorts_disk   DERIVE LINE sorts (disk)
245
"
246
getvalue_func[$key]=getvalue_sysstat
247

    
248
key=logon
249
global_attrs[$key]="
250
    graph_title Oracle$db_name Sysstat User Logons
251
    graph_category db
252
    graph_args --base 1000 --lower-limit 0 --rigid
253
    graph_vlabel count per second
254
    graph_info Oracle Sysstat User Logons
255
"
256
data_attrs[$key]="
257
    logon DERIVE LINE logons cumulative
258
"
259
getvalue_func[$key]=getvalue_sysstat
260

    
261
key=cursor
262
global_attrs[$key]="
263
    graph_title Oracle$db_name Sysstat User Opened Cursors
264
    graph_category db
265
    graph_args --base 1000 --lower-limit 0 --rigid
266
    graph_vlabel count
267
    graph_info Oracle Sysstat User Opened Cursors
268
"
269
data_attrs[$key]="
270
    open_cursor GAUGE LINE opened cursors current
271
"
272
getvalue_func[$key]=getvalue_sysstat
273

    
274
key=enqueue
275
global_attrs[$key]="
276
    graph_title Oracle$db_name Sysstat Enqueues
277
    graph_category db
278
    graph_args --base 1000 --lower-limit 0 --rigid
279
    graph_vlabel count per second
280
    graph_info Oracle Sysstat Enqueues
281
"
282
data_attrs[$key]="
283
    enqueue_requests    DERIVE LINE enqueue requests
284
    enqueue_releases    DERIVE LINE enqueue releases
285
    enqueue_conversions DERIVE LINE enqueue conversions
286
    enqueue_waits       DERIVE LINE enqueue waits
287
    enqueue_timeouts    DERIVE LINE enqueue timeouts
288
    enqueue_deadlocks   DERIVE LINE enqueue deadlocks
289
"
290
getvalue_func[$key]=getvalue_sysstat
291

    
292
key=redolog
293
global_attrs[$key]="
294
    graph_title Oracle$db_name Sysstat Redo Entries
295
    graph_category db
296
    graph_args --base 1000 --lower-limit 0 --rigid
297
    graph_vlabel count per second
298
    graph_info Oracle Sysstat Redo Entries
299
"
300
data_attrs[$key]="
301
    redo_entries                   DERIVE LINE redo entries
302
    redo_writes                    DERIVE LINE redo writes
303
    redo_synch_writes              DERIVE LINE redo synch writes
304
    redo_buffer_allocation_retries DERIVE LINE redo buffer allocation retries
305
    redo_log_space_requests        DERIVE LINE redo log space requests
306
"
307
getvalue_func[$key]=getvalue_sysstat
308

    
309
key=redosize
310
global_attrs[$key]="
311
    graph_title Oracle$db_name Sysstat Redo Size
312
    graph_category db
313
    graph_args --base 1024 --lower-limit 0 --rigid
314
    graph_vlabel bytes per second
315
    graph_info Oracle Sysstat Redo Size
316
"
317
data_attrs[$key]="
318
    redo_size    DERIVE LINE redo size
319
    redo_wastage DERIVE LINE redo wastage
320
"
321
getvalue_func[$key]=getvalue_sysstat
322

    
323
key=physicaliops
324
global_attrs[$key]="
325
    graph_title Oracle$db_name Sysstat I/O Physical Requests
326
    graph_category db
327
    graph_args --base 1000 --lower-limit 0 --rigid
328
    graph_vlabel iops
329
    graph_info Oracle Sysstat I/O Physical Requests
330
"
331
data_attrs[$key]="
332
    physical_read_total        DERIVE LINE2 physical read total IO requests
333
    physical_read              DERIVE LINE  physical read IO requests
334
    physical_read_total_multi  DERIVE LINE  physical read total multi block requests
335
    physical_write_total       DERIVE LINE2 physical write total IO requests
336
    physical_write             DERIVE LINE  physical write IO requests
337
    physical_write_total_multi DERIVE LINE  physical write total multi block requests
338
"
339
getvalue_func[$key]=getvalue_sysstat
340

    
341
key=physicalrw
342
global_attrs[$key]="
343
    graph_title Oracle$db_name Sysstat I/O Physical Bytes
344
    graph_category db
345
    graph_args --base 1024 --lower-limit 0 --rigid
346
    graph_vlabel bytes per second
347
    graph_info Oracle Sysstat I/O Physical Bytes
348
"
349
data_attrs[$key]="
350
    physical_read_total  DERIVE LINE2 physical read total bytes
351
    physical_read        DERIVE LINE  physical read bytes
352
    physical_write_total DERIVE LINE2 physical write total bytes
353
    physical_write       DERIVE LINE  physical write bytes
354
"
355
getvalue_func[$key]=getvalue_sysstat
356

    
357
key=blockrw
358
global_attrs[$key]="
359
    graph_title Oracle$db_name Sysstat I/O Blocks
360
    graph_category db
361
    graph_args --base 1000 --lower-limit 0 --rigid
362
    graph_vlabel blocks per second
363
    graph_info Oracle Sysstat I/O Blocks
364
"
365
data_attrs[$key]="
366
    db_block_gets      DERIVE LINE db block gets
367
    db_block_changes   DERIVE LINE db block changes
368
    consistent_gets    DERIVE LINE consistent gets
369
    consistent_changes DERIVE LINE consistent changes
370
    physical_reads     DERIVE LINE physical reads
371
    physical_writes    DERIVE LINE physical writes
372
"
373
getvalue_func[$key]=getvalue_sysstat
374

    
375

    
376
key=netrw
377
global_attrs[$key]="
378
    graph_title Oracle$db_name Sysstat I/O Network Bytes
379
    graph_category db
380
    graph_args --base 1024 --lower-limit 0 --rigid
381
    graph_vlabel bytes per second
382
    graph_info Oracle Sysstat I/O Network Bytes
383
"
384
data_attrs[$key]="
385
    bytes_sent_via_sql_net_to_client       DERIVE LINE bytes sent via SQL*Net to client
386
    bytes_received_via_sql_net_from_client DERIVE LINE bytes received via SQL*Net from client
387
    bytes_sent_via_sql_net_to_dblink       DERIVE LINE bytes sent via SQL*Net to dblink
388
    bytes_received_via_sql_net_from_dblink DERIVE LINE bytes received via SQL*Net from dblink
389
"
390
getvalue_func[$key]=getvalue_sysstat
391

    
392
key=sgainfo
393
global_attrs[$key]="
394
    graph_title Oracle$db_name Memory SGA
395
    graph_category db
396
    graph_args --base 1024 --lower-limit 0 --rigid
397
    graph_vlabel bytes
398
    graph_info Oracle Memory SGA
399
"
400
data_attrs[$key]="
401
    fixed_sga_size      GAUGE AREASTACK Fixed SGA Size
402
    redo_buffers        GAUGE AREASTACK Redo Buffers
403
    shared_pool_size    GAUGE AREASTACK Shared Pool Size
404
    large_pool_size     GAUGE AREASTACK Large Pool Size
405
    java_pool_size      GAUGE AREASTACK Java Pool Size
406
    streams_pool_size   GAUGE AREASTACK Streams Pool Size
407
    shared_io_pool_size GAUGE AREASTACK Shared IO Pool Size
408
    buffer_cache_size   GAUGE AREASTACK Buffer Cache Size
409
    in_memory_area_size GAUGE AREASTACK In-Memory Area Size
410
    maximum_sga_size    GAUGE LINE      Maximum SGA Size
411
"
412
getvalue_func[$key]=getvalue_sgainfo
413

    
414
key=pgastat
415
global_attrs[$key]="
416
    graph_title Oracle$db_name Memory PGA
417
    graph_category db
418
    graph_args --base 1024 --lower-limit 0 --rigid
419
    graph_vlabel bytes
420
    graph_info Oracle Memory PGA
421
"
422
data_attrs[$key]="
423
    pga_inuse        GAUGE AREA total PGA inuse
424
    pga_allocated    GAUGE LINE total PGA allocated
425
    pga_target       GAUGE LINE aggregate PGA target parameter
426
    pga_auto_target  GAUGE LINE aggregate PGA auto target
427
"
428
getvalue_func[$key]=getvalue_pgastat
429

    
430
key=cputime
431
global_attrs[$key]="
432
    graph_title Oracle$db_name CPU Time
433
    graph_category db
434
    graph_args --base 1000 --lower-limit 0 --rigid
435
    graph_vlabel seconds
436
    graph_info Oracle CPU Time
437
"
438
data_attrs[$key]="
439
    db_time                                        DERIVE LINE2 DB time
440
    db_cpu                                         DERIVE LINE2 DB CPU
441
    background_elapsed_time                        DERIVE LINE2 background elapsed time
442
    background_cpu_time                            DERIVE LINE2 background cpu time
443
    connection_management_call_elapsed_time        DERIVE LINE  connection management call elapsed time
444
    sequence_load_elapsed_time                     DERIVE LINE  sequence load elapsed time
445
    sql_execute_elapsed_time                       DERIVE LINE  sql execute elapsed time
446
    parse_time_elapsed                             DERIVE LINE  parse time elapsed
447
    hard_parse_elapsed_time                        DERIVE LINE  hard parse elapsed time
448
    hard_parse_sharing_criteria_elapsed_time       DERIVE LINE  hard parse (sharing criteria) elapsed time
449
    hard_parse_bind_mismatch_elapsed_time          DERIVE LINE  hard parse (bind mismatch) elapsed time
450
    failed_parse_elapsed_time                      DERIVE LINE  failed parse elapsed time
451
    failed_parse_out_of_shared_memory_elapsed_time DERIVE LINE  failed parse (out of shared memory) elapsed time
452
    pl_sql_execution_elapsed_time                  DERIVE LINE  PL/SQL execution elapsed time
453
    inbound_pl_sql_rpc_elapsed_time                DERIVE LINE  inbound PL/SQL rpc elapsed time
454
    pl_sql_compilation_elapsed_time                DERIVE LINE  PL/SQL compilation elapsed time
455
    java_execution_elapsed_time                    DERIVE LINE  Java execution elapsed time
456
    repeated_bind_elapsed_time                     DERIVE LINE  repeated bind elapsed time
457
    rman_cpu_time_backup_restore                   DERIVE LINE  RMAN cpu time (backup/restore)
458
"
459
getvalue_func[$key]=getvalue_cputime
460

    
461
key=cachehit
462
# buf_hitratio = 1 - physical_reads / ( db_block_gets + consistent_gets )
463
# lib_hitratio = 1 - reloads / pins
464
# dict_hitratio = ( gets - misses ) / gets
465
field_info=$( for field in buf_physical buf_logical lib_pins lib_reloads dict_gets dict_getmisses
466
   do
467
       echo "${field}.graph no"
468
       echo "${field}.type DERIVE"
469
       echo "${field}.min 0"
470
       echo "${field}.label ${field}"
471
   done
472
)
473
global_attrs[$key]="
474
    graph_title Oracle$db_name Cache Hit Ratio
475
    graph_category db
476
    graph_args --base 1000 --lower-limit 0 --upper-limit 100 --rigid
477
    graph_vlabel %
478
    graph_info Oracle Cache Hit Ratio - The graph shows cache hit ratio between munin-update intervals (5 minutes in most cases).
479
    graph_scale no
480

    
481
    ${field_info}
482
    buf_hitratio.cdef 100,1,buf_physical,buf_logical,/,-,*
483
    lib_hitratio.cdef 100,1,lib_reloads,lib_pins,/,-,*
484
    dict_hitratio.cdef 100,dict_gets,dict_getmisses,-,dict_gets,/,*
485
"
486
data_attrs[$key]="
487
    buf_hitratio GAUGE LINE Buffer Cache Hit Ratio
488
    lib_hitratio GAUGE LINE Library Cache Hit Ratio
489
    dict_hitratio GAUGE LINE Dictionary Cache Hit Ratio
490
"
491
getvalue_func[$key]=getvalue_cachehit
492

    
493
key=sessionuser
494
global_attrs[$key]="
495
    graph_title Oracle$db_name Session Users
496
    graph_category db
497
    graph_args --base 1000 --lower-limit 0 --rigid
498
    graph_vlabel count
499
    graph_info Oracle Session Users
500
"
501
data_attrs[$key]=""
502
getfield_func[$key]=getfield_sessionuser
503
getvalue_func[$key]=getvalue_sessionuser
504

    
505
key=sessionwait
506
global_attrs[$key]="
507
    graph_title Oracle$db_name Session Wait
508
    graph_category db
509
    graph_args --base 1000 --lower-limit 0 --rigid
510
    graph_vlabel count
511
    graph_info Oracle Session Wait
512
"
513
data_attrs[$key]=""
514
getfield_func[$key]=getfield_sessionwait
515
getvalue_func[$key]=getvalue_sessionwait
516

    
517
key=eventwait
518
global_attrs[$key]="
519
    graph_title Oracle$db_name Wait Events
520
    graph_category db
521
    graph_args --base 1000 --lower-limit 0 --rigid
522
    graph_vlabel microseconds
523
    graph_info Oracle Wait Events - It may look wierd that Y-axis indicates 'microseconds per second'. Although number of times of wait event looks easier to understand, in many cases the number of events does not matter, but wait time become more important to analyze bottle necks.
524
"
525
data_attrs[$key]=""
526
getfield_func[$key]=getfield_eventwait
527
getvalue_func[$key]=getvalue_eventwait
528

    
529
key=eventwaitapplication
530
global_attrs[$key]="
531
    graph_title Oracle$db_name Wait Events Application
532
    graph_category db
533
    graph_args --base 1000 --lower-limit 0 --rigid
534
    graph_vlabel microseconds
535
    graph_info Oracle Wait Events Application
536
"
537
data_attrs[$key]=""
538
getfield_func[$key]="getfield_eventwait2 Application"
539
getvalue_func[$key]="getvalue_eventwait2 Application"
540

    
541
key=eventwaitnetwork
542
global_attrs[$key]="
543
    graph_title Oracle$db_name Wait Events Network
544
    graph_category db
545
    graph_args --base 1000 --lower-limit 0 --rigid
546
    graph_vlabel microseconds
547
    graph_info Oracle Wait Events Network
548
"
549
data_attrs[$key]=""
550
getfield_func[$key]="getfield_eventwait2 Network"
551
getvalue_func[$key]="getvalue_eventwait2 Network"
552

    
553
key=eventwaitconcurrency
554
global_attrs[$key]="
555
    graph_title Oracle$db_name Wait Events Concurrency
556
    graph_category db
557
    graph_args --base 1000 --lower-limit 0 --rigid
558
    graph_vlabel microseconds
559
    graph_info Oracle Wait Events Concurrency
560
"
561
data_attrs[$key]=" "
562
getfield_func[$key]="getfield_eventwait2 Concurrency"
563
getvalue_func[$key]="getvalue_eventwait2 Concurrency"
564

    
565
key=eventwaituserio
566
global_attrs[$key]="
567
    graph_title Oracle$db_name Wait Events User I/O
568
    graph_category db
569
    graph_args --base 1000 --lower-limit 0 --rigid
570
    graph_vlabel microseconds
571
    graph_info Oracle Wait Events User I/O
572
"
573
data_attrs[$key]=""
574
getfield_func[$key]="getfield_eventwait2 User I/O"
575
getvalue_func[$key]="getvalue_eventwait2 User I/O"
576

    
577
key=eventwaitsystemio
578
global_attrs[$key]="
579
    graph_title Oracle$db_name Wait Events System I/O
580
    graph_category db
581
    graph_args --base 1000 --lower-limit 0 --rigid
582
    graph_vlabel microseconds
583
    graph_info Oracle Wait Events System I/O
584
"
585
data_attrs[$key]="
586
"
587
getfield_func[$key]="getfield_eventwait2 System I/O"
588
getvalue_func[$key]="getvalue_eventwait2 System I/O"
589

    
590
key=eventwaitcluster
591
global_attrs[$key]="
592
    graph_title Oracle$db_name Wait Events Cluster
593
    graph_category db
594
    graph_args --base 1000 --lower-limit 0 --rigid
595
    graph_vlabel microseconds
596
    graph_info Oracle Wait Events Cluster
597
"
598
data_attrs[$key]=" "
599
getfield_func[$key]="getfield_eventwait2 Cluster"
600
getvalue_func[$key]="getvalue_eventwait2 Cluster"
601

    
602
key=eventwaitadministrative
603
global_attrs[$key]="
604
    graph_title Oracle$db_name Wait Events Administrative
605
    graph_category db
606
    graph_args --base 1000 --lower-limit 0 --rigid
607
    graph_vlabel microseconds
608
    graph_info Oracle Wait Events Administrative
609
"
610
data_attrs[$key]=" "
611
getfield_func[$key]="getfield_eventwait2 Administrative"
612
getvalue_func[$key]="getvalue_eventwait2 Administrative"
613

    
614
key=eventwaitconfiguration
615
global_attrs[$key]="
616
    graph_title Oracle$db_name Wait Events Configuration
617
    graph_category db
618
    graph_args --base 1000 --lower-limit 0 --rigid
619
    graph_vlabel microseconds
620
    graph_info Oracle Wait Events Configuration
621
"
622
data_attrs[$key]=" "
623
getfield_func[$key]="getfield_eventwait2 Configuration"
624
getvalue_func[$key]="getvalue_eventwait2 Configuration"
625

    
626
key=tablespace
627
global_attrs[$key]="
628
    graph_title Oracle$db_name Table Space Usage
629
    graph_category db
630
    graph_args --base 1000 --lower-limit 0 --upper-limit 100 --rigid
631
    graph_vlabel %
632
    graph_info Oracle Table Space Usage
633
    warning ${warning:=92}
634
    critical ${critical:=98}
635
"
636
data_attrs[$key]=""
637
getfield_func[$key]=getfield_tablespace
638
getvalue_func[$key]=getvalue_tablespace
639

    
640
key=asmusage
641
global_attrs[$key]="
642
    graph_title Oracle$db_name ASM Disk Group Usage
643
    graph_category db
644
    graph_args --base 1000 --lower-limit 0 --upper-limit 100 --rigid
645
    graph_vlabel %
646
    graph_info Oracle ASM Disk Group Usage
647
    warning ${warning:=92}
648
    critical ${critical:=98}
649
"
650
data_attrs[$key]=""
651
getfield_func[$key]=getfield_asmusage
652
getvalue_func[$key]=getvalue_asmusage
653

    
654
# End of Graph Settings
655

    
656
# sqlplus options
657
: "${sqlplus:=sqlplus -S -L}"
658
sqlplus_variables="
659
    whenever sqlerror exit sql.sqlcode
660
    set pagesize 0
661
    set feed off
662
    set head off
663
    set linesize 256
664
    set numwidth 30
665
"
666

    
667
# Functions 
668

    
669
autoconf() {
670
    if [ -x "$( which "${sqlplus}" )" ]; then
671
        echo yes
672
    else
673
        echo "no (failed to find executable 'sqlplus')"
674
    fi
675
}
676

    
677
config() {
678
    for module in $( module_list )
679
    do
680
        do_config
681
    done
682
}
683

    
684
fetch() {
685
    for module in $( module_list )
686
    do
687
        do_fetch
688
    done
689
}
690

    
691
do_config() {
692
    local label_max_length=45
693

    
694
    getfield
695
    echo "multigraph ${plugin_name}_${module}"
696

    
697
    # print global attributes
698
    sed -e 's/^  *//' -e '/^$/d' <<< "${global_attrs[$module]}"
699

    
700
    # print data source attributes
701
    # split line into field,type,draw,label 
702
    local fields field type draw label
703
    fields=
704
    while read -r field type draw label
705
    do
706
        [ -z "$field" ] && continue
707
        fields="${fields} ${field}"
708

    
709
        echo "${field}.type ${type}"
710
        echo "${field}.draw ${draw}"
711
        echo "${field}.label ${label:0:${label_max_length}}"
712
        if [ "${type}" = DERIVE ]; then
713
            echo "${field}.min 0"
714
        fi
715
    done <<< "${data_attrs[$module]}"
716

    
717
    echo graph_order "$fields"
718
    echo
719
}
720

    
721
do_fetch() {
722
    echo "multigraph ${plugin_name}_${module}"
723
    getvalue
724
    echo
725
}
726

    
727
module_list() {
728
    local i
729

    
730
    if [ -n "$include_module" ]; then
731
        echo "$include_module"
732
    else
733
        for i in $exclude_module
734
        do 
735
            # remove excluded modules
736
            unset -v "global_attrs[$i]"
737
        done
738

    
739
        # print hash keys as available module names
740
        echo "${!global_attrs[@]}"
741
    fi
742
}
743

    
744
# wrapper for getfield_*
745
getfield() {
746
    local func arg
747
    if [ -n "${getfield_func[$module]:-}" ]; then
748
        # call getfield_* function with argument if necessary
749
        read -r func arg <<< "${getfield_func[$module]}"
750
        $func "$arg"
751
    fi
752
}
753

    
754
# wrapper for getvalue_*
755
getvalue() {
756
    local func arg
757
    # call getvalue_* function with argument if necessary
758
    read -r func arg <<< "${getvalue_func[$module]}"
759
    $func "$arg"
760
}
761

    
762
getvalue_sysstat() {
763
    local field type draw label
764
    while read -r field type draw label
765
    do
766
        [ -z "$field" ] && continue
767

    
768
        echo "${sqlplus_variables}
769
          VAR vf VARCHAR2(64)
770
          VAR vl VARCHAR2(64)
771
          EXEC :vf := '${field}' 
772
          EXEC :vl := '${label}' 
773
          SELECT
774
            :vf || '.value ' || value
775
          FROM
776
            v\$sysstat
777
          WHERE
778
            name = :vl;
779
        "
780
    done <<< "${data_attrs[$module]}" | ${sqlplus} "${oracle_auth}"
781
}
782

    
783
getvalue_sgainfo() {
784
    local field type draw label
785
    while read -r field type draw label
786
    do
787
        [ -z "$field" ] && continue
788

    
789
        echo "${sqlplus_variables}
790
          VAR vf VARCHAR2(64)
791
          VAR vl VARCHAR2(64)
792
          EXEC :vf := '${field}' 
793
          EXEC :vl := '${label}' 
794
          SELECT
795
            :vf || '.value ' || bytes
796
          FROM
797
            v\$sgainfo
798
          WHERE
799
            name = :vl;
800
        "
801
    done <<< "${data_attrs[$module]}" | ${sqlplus} "${oracle_auth}"
802
}
803

    
804
getvalue_pgastat() {
805
    local field type draw label
806
    while read -r field type draw label
807
    do
808
        [ -z "$field" ] && continue
809

    
810
        echo "${sqlplus_variables}
811
          VAR vf VARCHAR2(64)
812
          VAR vl VARCHAR2(64)
813
          EXEC :vf := '${field}' 
814
          EXEC :vl := '${label}' 
815
          SELECT
816
            :vf || '.value ' || value
817
          FROM
818
            v\$pgastat
819
          WHERE
820
            name = :vl;
821
        "
822
    done <<< "${data_attrs[$module]}" | ${sqlplus} "${oracle_auth}"
823
}
824

    
825
getvalue_cputime() {
826
    local field type draw label
827
    while read -r field type draw label
828
    do
829
        [ -z "$field" ] && continue
830

    
831
        echo "${sqlplus_variables}
832
          VAR vf VARCHAR2(64)
833
          VAR vl VARCHAR2(64)
834
          EXEC :vf := '${field}' 
835
          EXEC :vl := '${label}' 
836
          SELECT
837
            :vf || '.value ' || ROUND( value / 1000000 )
838
          FROM
839
            v\$sys_time_model
840
          WHERE
841
            stat_name = :vl;
842
        "
843
    done <<< "${data_attrs[$module]}" | ${sqlplus} "${oracle_auth}"
844
}
845

    
846
getvalue_cachehit() {
847
    ${sqlplus} "${oracle_auth}" <<EOF
848
${sqlplus_variables}
849
SELECT
850
  'buf_physical.value ' || value
851
FROM
852
  v\$sysstat
853
WHERE
854
  name = 'physical reads cache'
855
;
856
SELECT 
857
  'buf_logical.value ' || ( sd.value + sc.value )
858
FROM 
859
  v\$sysstat sd, v\$sysstat sc 
860
WHERE 
861
  sd.name = 'db block gets from cache' AND sc.name = 'consistent gets from cache'
862
;
863
SELECT 'lib_pins.value '    || SUM(pins)    FROM v\$librarycache;
864
SELECT 'lib_reloads.value ' || SUM(reloads) FROM v\$librarycache;
865
SELECT 'dict_gets.value '      || SUM(gets)      FROM v\$rowcache;
866
SELECT 'dict_getmisses.value ' || SUM(getmisses) FROM v\$rowcache;
867
SELECT 'buf_hitratio.value 0' FROM dual;
868
SELECT 'lib_hitratio.value 0' FROM dual;
869
SELECT 'dict_hitratio.value 0' FROM dual;
870
EOF
871
}
872

    
873
getfield_sessionuser() {
874
    data_attrs[$module]=$( ${sqlplus} "${oracle_auth}" <<EOF
875
${sqlplus_variables}
876
SELECT
877
  REGEXP_REPLACE( username, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) ||
878
  ' GAUGE LINE ' ||  username
879
FROM
880
  dba_users
881
WHERE
882
  account_status = 'OPEN'
883
ORDER BY
884
  username;
885
EOF
886
)
887
}
888

    
889
getvalue_sessionuser() {
890
    ${sqlplus} "${oracle_auth}" <<EOF
891
${sqlplus_variables}
892
SELECT
893
  REGEXP_REPLACE( du.username, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) || '.value ' ||
894
  count(vs.username)
895
FROM 
896
  ( SELECT
897
      username
898
    FROM
899
      dba_users
900
    WHERE
901
      account_status = 'OPEN'
902
  ) du
903
  LEFT JOIN v\$session vs
904
ON
905
  du.username = vs.username
906
GROUP BY
907
  du.username;
908
EOF
909
}
910

    
911
getfield_sessionwait() {
912
    data_attrs[$module]=$( ${sqlplus} "${oracle_auth}" <<EOF
913
${sqlplus_variables}
914
SELECT 'CPU GAUGE AREASTACK CPU' from dual;
915
SELECT
916
  REGEXP_REPLACE( wait_class, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) ||
917
  ' GAUGE AREASTACK ' || wait_class
918
FROM
919
  v\$event_name
920
WHERE
921
  wait_class NOT IN ( 'Other', 'Idle' )
922
GROUP BY
923
  wait_class
924
ORDER BY
925
  wait_class;
926
SELECT 'Other GAUGE AREASTACK Other' from dual;
927
SELECT 'Idle  GAUGE AREASTACK Idle' from dual;
928
EOF
929
)
930
}
931

    
932
getvalue_sessionwait() {
933
    ${sqlplus} "${oracle_auth}" <<EOF
934
${sqlplus_variables}
935
SELECT
936
  'CPU.value ' || count(wait_class)
937
FROM
938
  v\$session
939
WHERE
940
  wait_time != 0
941
;
942
SELECT
943
  REGEXP_REPLACE( en.wait_class, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) || '.value ' ||
944
  count(se.wait_class)
945
FROM
946
  ( SELECT
947
      wait_class
948
    FROM
949
      v\$event_name
950
    GROUP BY
951
      wait_class
952
  ) en
953
  LEFT JOIN v\$session se
954
ON
955
  en.wait_class = se.wait_class AND 
956
  se.username is not null AND
957
  se.wait_time = 0
958
GROUP BY
959
  en.wait_class
960
;
961
EOF
962
}
963

    
964
getfield_eventwait() {
965
    data_attrs[$module]=$( ${sqlplus} "${oracle_auth}" <<EOF
966
${sqlplus_variables}
967
SELECT
968
  REGEXP_REPLACE( wait_class, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) ||
969
  ' DERIVE LINE ' || wait_class
970
FROM
971
  v\$event_name
972
WHERE
973
  wait_class NOT IN ( 'Other', 'Idle' )
974
GROUP BY
975
  wait_class
976
ORDER BY
977
  wait_class;
978
SELECT 'Other DERIVE LINE Other' from dual;
979
EOF
980
)
981
}
982

    
983
getvalue_eventwait() {
984
    ${sqlplus} "${oracle_auth}" <<EOF
985
${sqlplus_variables}
986
SELECT
987
  REGEXP_REPLACE( en.wait_class, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) || '.value ' ||
988
  NVL( SUM(se.time_waited_micro), 0 )
989
FROM
990
  ( SELECT
991
      wait_class
992
    FROM
993
      v\$event_name
994
    WHERE
995
      wait_class NOT IN ( 'Idle' )
996
    GROUP BY
997
      wait_class
998
  ) en
999
  LEFT JOIN v\$system_event se
1000
ON
1001
  en.wait_class = se.wait_class
1002
GROUP BY
1003
  en.wait_class;
1004
EOF
1005
}
1006

    
1007
getfield_eventwait2() {
1008
    local waitclass="$1"
1009

    
1010
    data_attrs[$module]=$( ${sqlplus} "${oracle_auth}" <<EOF
1011
${sqlplus_variables}
1012
VAR vl VARCHAR2(64)
1013
EXEC :vl := '${waitclass}' 
1014
SELECT
1015
  REGEXP_REPLACE( name, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) ||
1016
  ' DERIVE LINE ' || name
1017
FROM
1018
  v\$event_name 
1019
WHERE
1020
  wait_class = :vl
1021
ORDER BY
1022
  name;
1023
EOF
1024
)
1025
}
1026

    
1027
getvalue_eventwait2() {
1028
    local waitclass="$1"
1029

    
1030
    ${sqlplus} "${oracle_auth}" <<EOF
1031
${sqlplus_variables}
1032
VAR vl VARCHAR2(64)
1033
EXEC :vl := '${waitclass}' 
1034
SELECT
1035
  REGEXP_REPLACE( en.name, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) || '.value ' || 
1036
  NVL( se.time_waited_micro, 0 )
1037
FROM
1038
  v\$event_name en LEFT JOIN v\$system_event se
1039
ON
1040
  en.name = se.event
1041
WHERE
1042
  en.wait_class = :vl;
1043
EOF
1044
}
1045

    
1046
getfield_tablespace() {
1047
    data_attrs[$module]=$( ${sqlplus} "${oracle_auth}" <<EOF
1048
${sqlplus_variables}
1049
SELECT
1050
  REGEXP_REPLACE( tablespace_name, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) ||
1051
  ' GAUGE LINE ' || tablespace_name
1052
FROM
1053
  dba_data_files
1054
ORDER BY
1055
  tablespace_name;
1056
EOF
1057
)
1058
}
1059

    
1060
getvalue_tablespace() {
1061
    ${sqlplus} "${oracle_auth}" <<EOF
1062
${sqlplus_variables}
1063
SELECT
1064
  REGEXP_REPLACE( tablespace_name, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) || '.value ' ||
1065
  ROUND( (total_bytes - free_total_bytes) / total_bytes * 100, 0 )
1066
FROM
1067
  ( SELECT
1068
      tablespace_name,
1069
      SUM(bytes) total_bytes
1070
    FROM
1071
      dba_data_files
1072
    GROUP BY
1073
      tablespace_name
1074
  ),
1075
  ( SELECT
1076
      tablespace_name free_tablespace_name,
1077
      SUM(bytes) free_total_bytes
1078
    FROM
1079
      dba_free_space
1080
    GROUP BY
1081
      tablespace_name
1082
  )
1083
WHERE
1084
  tablespace_name = free_tablespace_name;
1085
EOF
1086
}
1087

    
1088
getfield_asmusage() {
1089
    data_attrs[$module]=$( ${sqlplus} "${oracle_auth}" <<EOF
1090
${sqlplus_variables}
1091
SELECT
1092
  REGEXP_REPLACE( name, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) ||
1093
  ' GAUGE LINE ' || name
1094
FROM
1095
  v\$asm_diskgroup
1096
ORDER BY
1097
  name;
1098
EOF
1099
)
1100
}
1101

    
1102
getvalue_asmusage() {
1103
    ${sqlplus} "${oracle_auth}" <<EOF
1104
${sqlplus_variables}
1105
SELECT
1106
  REGEXP_REPLACE( name, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) || '.value ' ||
1107
  ROUND( ( total_mb - free_mb ) / total_mb * 100 )
1108
FROM
1109
  v\$asm_diskgroup
1110
ORDER BY
1111
  name;
1112
EOF
1113
}
1114

    
1115
# Main
1116
case ${1:-} in
1117
autoconf)
1118
    autoconf
1119
    ;;
1120
config)
1121
    config
1122
    [ "${MUNIN_CAP_DIRTYCONFIG:-}" = "1" ] && fetch
1123
    ;;
1124
*)
1125
    fetch
1126
    ;;
1127
esac
1128

    
1129
exit 0