Projet

Général

Profil

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

root / plugins / oracle / oracle_sysstat_ @ 827c75fb

Historique | Voir | Annoter | Télécharger (29 ko)

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

    
4
: << =cut
5

    
6
=head1 NAME
7

    
8
  oracle_sysstat_* - Munin plugin to monitor Oracle Statistics
9

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

    
43
=head1 CONFIGURATION
44

    
45
  To get a list of symlinks that can be created, run:   
46

    
47
    ./oracle_sysstat_ suggest
48

    
49
  Make symlinks:
50

    
51
    munin-node-configure --families=contrib --suggest --shell
52
    ...
53

    
54
  The following shows example settings for this plugin:
55

    
56
    [oracle_sysstat_*]
57
      user  oracle
58
      env.oracle_auth  / as SYSDBA
59
      env.ORACLE_HOME  /path/to/oracle/product/version
60
      env.ORACLE_SID   SOMESID
61

    
62
    [oracle_sysstat_asmusage]
63
      user  grid
64
      env.oracle_auth  / as SYSASM
65
      env.ORACLE_HOME  /path/to/grid/home/version
66
      env.ORACLE_SID   SOMESID
67

    
68
=head1 NOTES
69

    
70
  Uses the command "sqlplus".
71
  Tested with Oracle Database 12c R1.
72

    
73
=head1 AUTHOR
74

    
75
  K.Cima https://github.com/shakemid
76

    
77
=head1 LICENSE
78

    
79
  GPLv2
80

    
81
=cut
82

    
83
# Magic markers
84
#%# family=contrib
85
#%# capabilities=autoconf suggest
86

    
87
# Like perl 'use strict;' 
88
set -o nounset
89

    
90
# Include plugin.sh
91
. "${MUNIN_LIBDIR:-}/plugins/plugin.sh"
92

    
93
# Environments
94
: "${ORACLE_HOME:=$( echo /opt/oracle/product/* )}"
95
: "${ORACLE_SID:=orcl}"
96
: "${oracle_auth:=/ as SYSDBA}"
97

    
98
PATH=$PATH:$ORACLE_HOME/bin
99
export PATH ORACLE_HOME ORACLE_SID
100

    
101
# Module name
102
module=$( basename "$0" | sed -e 's/^.*_//' )
103

    
104
# Graph settings
105
declare -A global_attrs  # required
106
declare -A data_attrs    # required (format: field type draw label)
107
declare -A getfield_func # optional
108
declare -A getvalue_func # required
109

    
110
key=execute
111
global_attrs[$key]="
112
    graph_title Oracle Sysstat SQL Execute Count
113
    graph_category db
114
    graph_args --base 1000 --lower-limit 0 --rigid
115
    graph_vlabel count per second
116
    graph_info Oracle Sysstat SQL Execute Count
117
"
118
data_attrs[$key]="
119
    execute_count   DERIVE LINE execute count
120
    user_calls      DERIVE LINE user calls
121
    recursive_calls DERIVE LINE recursive calls
122
"
123
getvalue_func[$key]=getvalue_sysstat
124

    
125
key=parse
126
global_attrs[$key]="
127
    graph_title Oracle Sysstat SQL Parse Count
128
    graph_category db
129
    graph_args --base 1000 --lower-limit 0 --rigid
130
    graph_vlabel count per second
131
    graph_info Oracle Sysstat SQL Parse Count
132
"
133
data_attrs[$key]="
134
    parse_count_total    DERIVE LINE parse count (total)
135
    parse_count_hard     DERIVE LINE parse count (hard)
136
    parse_count_describe DERIVE LINE parse count (describe)
137
    parse_count_failures DERIVE LINE parse count (failures)
138
"
139
getvalue_func[$key]=getvalue_sysstat
140

    
141
key=tablefetch
142
global_attrs[$key]="
143
    graph_title Oracle Sysstat SQL Table Fetch Rows
144
    graph_category db
145
    graph_args --base 1000 --lower-limit 0 --rigid
146
    graph_vlabel count per second
147
    graph_info Oracle Sysstat SQL Table Fetch Rows
148
"
149
data_attrs[$key]="
150
    table_fetch_by_rowid      DERIVE LINE table fetch by rowid
151
    table_scan_rows_gotten    DERIVE LINE table scan rows gotten
152
    table_fetch_continued_row DERIVE LINE table fetch continued row
153
"
154
getvalue_func[$key]=getvalue_sysstat
155

    
156
key=tablescan
157
global_attrs[$key]="
158
    graph_title Oracle Sysstat SQL Table Scans
159
    graph_category db
160
    graph_args --base 1000 --lower-limit 0 --rigid
161
    graph_vlabel count per second
162
    graph_info Oracle Sysstat SQL Table Scans
163
"
164
data_attrs[$key]="
165
    table_scans_short_tables DERIVE LINE table scans (short tables)
166
    table_scans_long_tables  DERIVE LINE table scans (long tables)
167
"
168
getvalue_func[$key]=getvalue_sysstat
169

    
170
key=transaction
171
global_attrs[$key]="
172
    graph_title Oracle Sysstat SQL Transactions
173
    graph_category db
174
    graph_args --base 1000 --lower-limit 0 --rigid
175
    graph_vlabel count per second
176
    graph_info Oracle Sysstat SQL Transactions
177
"
178
data_attrs[$key]="
179
    user_commits   DERIVE LINE user commits
180
    user_rollbacks DERIVE LINE user rollbacks
181
"
182
getvalue_func[$key]=getvalue_sysstat
183

    
184
key=sort
185
global_attrs[$key]="
186
    graph_title Oracle Sysstat SQL Sorts
187
    graph_category db
188
    graph_args --base 1000 --lower-limit 0 --rigid
189
    graph_vlabel count per second
190
    graph_info Oracle Sysstat SQL Sorts
191
"
192
data_attrs[$key]="
193
    sorts_memory DERIVE LINE sorts (memory)
194
    sorts_disk   DERIVE LINE sorts (disk)
195
"
196
getvalue_func[$key]=getvalue_sysstat
197

    
198
key=logon
199
global_attrs[$key]="
200
    graph_title Oracle Sysstat User Logons
201
    graph_category db
202
    graph_args --base 1000 --lower-limit 0 --rigid
203
    graph_vlabel count per second
204
    graph_info Oracle Sysstat User Logons
205
"
206
data_attrs[$key]="
207
    logon DERIVE LINE logons cumulative
208
"
209
getvalue_func[$key]=getvalue_sysstat
210

    
211
key=cursor
212
global_attrs[$key]="
213
    graph_title Oracle Sysstat User Opened Cursors
214
    graph_category db
215
    graph_args --base 1000 --lower-limit 0 --rigid
216
    graph_vlabel count
217
    graph_info Oracle Sysstat User Opened Cursors
218
"
219
data_attrs[$key]="
220
    open_cursor GAUGE LINE opened cursors current
221
"
222
getvalue_func[$key]=getvalue_sysstat
223

    
224
key=enqueue
225
global_attrs[$key]="
226
    graph_title Oracle Sysstat Enqueues
227
    graph_category db
228
    graph_args --base 1000 --lower-limit 0 --rigid
229
    graph_vlabel count per second
230
    graph_info Oracle Sysstat Enqueues
231
"
232
data_attrs[$key]="
233
    enqueue_requests    DERIVE LINE enqueue requests
234
    enqueue_releases    DERIVE LINE enqueue releases
235
    enqueue_conversions DERIVE LINE enqueue conversions
236
    enqueue_waits       DERIVE LINE enqueue waits
237
    enqueue_timeouts    DERIVE LINE enqueue timeouts
238
    enqueue_deadlocks   DERIVE LINE enqueue deadlocks
239
"
240
getvalue_func[$key]=getvalue_sysstat
241

    
242
key=redolog
243
global_attrs[$key]="
244
    graph_title Oracle Sysstat Redo Entries
245
    graph_category db
246
    graph_args --base 1000 --lower-limit 0 --rigid
247
    graph_vlabel count per second
248
    graph_info Oracle Sysstat Redo Entries
249
"
250
data_attrs[$key]="
251
    redo_entries                   DERIVE LINE redo entries
252
    redo_writes                    DERIVE LINE redo writes
253
    redo_synch_writes              DERIVE LINE redo synch writes
254
    redo_buffer_allocation_retries DERIVE LINE redo buffer allocation retries
255
    redo_log_space_requests        DERIVE LINE redo log space requests
256
"
257
getvalue_func[$key]=getvalue_sysstat
258

    
259
key=redosize
260
global_attrs[$key]="
261
    graph_title Oracle Sysstat Redo Size
262
    graph_category db
263
    graph_args --base 1024 --lower-limit 0 --rigid
264
    graph_vlabel bytes per second
265
    graph_info Oracle Sysstat Redo Size
266
"
267
data_attrs[$key]="
268
    redo_size    DERIVE LINE redo size
269
    redo_wastage DERIVE LINE redo wastage
270
"
271
getvalue_func[$key]=getvalue_sysstat
272

    
273
key=physicaliops
274
global_attrs[$key]="
275
    graph_title Oracle Sysstat I/O Physical Requests
276
    graph_category db
277
    graph_args --base 1000 --lower-limit 0 --rigid
278
    graph_vlabel iops
279
    graph_info Oracle Sysstat I/O Physical Requests
280
"
281
data_attrs[$key]="
282
    physical_read_total        DERIVE LINE2 physical read total IO requests
283
    physical_read              DERIVE LINE  physical read IO requests
284
    physical_read_total_multi  DERIVE LINE  physical read total multi block requests
285
    physical_write_total       DERIVE LINE2 physical write total IO requests
286
    physical_write             DERIVE LINE  physical write IO requests
287
    physical_write_total_multi DERIVE LINE  physical write total multi block requests
288
"
289
getvalue_func[$key]=getvalue_sysstat
290

    
291
key=physicalrw
292
global_attrs[$key]="
293
    graph_title Oracle Sysstat I/O Physical Bytes
294
    graph_category db
295
    graph_args --base 1024 --lower-limit 0 --rigid
296
    graph_vlabel bytes per second
297
    graph_info Oracle Sysstat I/O Physical Bytes
298
"
299
data_attrs[$key]="
300
    physical_read_total  DERIVE LINE2 physical read total bytes
301
    physical_read        DERIVE LINE  physical read bytes
302
    physical_write_total DERIVE LINE2 physical write total bytes
303
    physical_write       DERIVE LINE  physical write bytes
304
"
305
getvalue_func[$key]=getvalue_sysstat
306

    
307
key=blockrw
308
global_attrs[$key]="
309
    graph_title Oracle Sysstat I/O Blocks
310
    graph_category db
311
    graph_args --base 1000 --lower-limit 0 --rigid
312
    graph_vlabel blocks per second
313
    graph_info Oracle Sysstat I/O Blocks
314
"
315
data_attrs[$key]="
316
    db_block_gets      DERIVE LINE db block gets
317
    db_block_changes   DERIVE LINE db block changes
318
    consistent_gets    DERIVE LINE consistent gets
319
    consistent_changes DERIVE LINE consistent changes
320
    physical_reads     DERIVE LINE physical reads
321
    physical_writes    DERIVE LINE physical writes
322
"
323
getvalue_func[$key]=getvalue_sysstat
324

    
325

    
326
key=netrw
327
global_attrs[$key]="
328
    graph_title Oracle Sysstat I/O Network Bytes
329
    graph_category db
330
    graph_args --base 1024 --lower-limit 0 --rigid
331
    graph_vlabel bytes per second
332
    graph_info Oracle Sysstat I/O Network Bytes
333
"
334
data_attrs[$key]="
335
    bytes_sent_via_sql_net_to_client       DERIVE LINE bytes sent via SQL*Net to client
336
    bytes_received_via_sql_net_from_client DERIVE LINE bytes received via SQL*Net from client
337
    bytes_sent_via_sql_net_to_dblink       DERIVE LINE bytes sent via SQL*Net to dblink
338
    bytes_received_via_sql_net_from_dblink DERIVE LINE bytes received via SQL*Net from dblink
339
"
340
getvalue_func[$key]=getvalue_sysstat
341

    
342
key=sgainfo
343
global_attrs[$key]="
344
    graph_title Oracle Memory SGA
345
    graph_category db
346
    graph_args --base 1024 --lower-limit 0 --rigid
347
    graph_vlabel bytes
348
    graph_info Oracle Memory SGA
349
"
350
data_attrs[$key]="
351
    maximum_sga_size    GAUGE LINE      Maximum SGA Size
352
    fixed_sga_size      GAUGE AREASTACK Fixed SGA Size
353
    redo_buffers        GAUGE AREASTACK Redo Buffers
354
    shared_pool_size    GAUGE AREASTACK Shared Pool Size
355
    large_pool_size     GAUGE AREASTACK Large Pool Size
356
    java_pool_size      GAUGE AREASTACK Java Pool Size
357
    streams_pool_size   GAUGE AREASTACK Streams Pool Size
358
    shared_io_pool_size GAUGE AREASTACK Shared IO Pool Size
359
    buffer_cache_size   GAUGE AREASTACK Buffer Cache Size
360
    in_memory_area_size GAUGE AREASTACK In-Memory Area Size
361
"
362
getvalue_func[$key]=getvalue_sgainfo
363

    
364
key=pgastat
365
global_attrs[$key]="
366
    graph_title Oracle Memory PGA
367
    graph_category db
368
    graph_args --base 1024 --lower-limit 0 --rigid
369
    graph_vlabel bytes
370
    graph_info Oracle Memory PGA
371
"
372
data_attrs[$key]="
373
    pga_target       GAUGE LINE aggregate PGA target parameter
374
    pga_auto_target  GAUGE LINE aggregate PGA auto target
375
    pga_allocated    GAUGE LINE total PGA allocated
376
    pga_inuse        GAUGE AREA total PGA inuse
377
"
378
getvalue_func[$key]=getvalue_pgastat
379

    
380
key=cputime
381
global_attrs[$key]="
382
    graph_title Oracle CPU Time
383
    graph_category db
384
    graph_args --base 1000 --lower-limit 0 --rigid
385
    graph_vlabel seconds
386
    graph_info Oracle CPU Time
387
"
388
data_attrs[$key]="
389
    db_time                                        DERIVE LINE2 DB time
390
    db_cpu                                         DERIVE LINE2 DB CPU
391
    background_elapsed_time                        DERIVE LINE2 background elapsed time
392
    background_cpu_time                            DERIVE LINE2 background cpu time
393
    connection_management_call_elapsed_time        DERIVE LINE  connection management call elapsed time
394
    sequence_load_elapsed_time                     DERIVE LINE  sequence load elapsed time
395
    sql_execute_elapsed_time                       DERIVE LINE  sql execute elapsed time
396
    parse_time_elapsed                             DERIVE LINE  parse time elapsed
397
    hard_parse_elapsed_time                        DERIVE LINE  hard parse elapsed time
398
    hard_parse_sharing_criteria_elapsed_time       DERIVE LINE  hard parse (sharing criteria) elapsed time
399
    hard_parse_bind_mismatch_elapsed_time          DERIVE LINE  hard parse (bind mismatch) elapsed time
400
    failed_parse_elapsed_time                      DERIVE LINE  failed parse elapsed time
401
    failed_parse_out_of_shared_memory_elapsed_time DERIVE LINE  failed parse (out of shared memory) elapsed time
402
    pl_sql_execution_elapsed_time                  DERIVE LINE  PL/SQL execution elapsed time
403
    inbound_pl_sql_rpc_elapsed_time                DERIVE LINE  inbound PL/SQL rpc elapsed time
404
    pl_sql_compilation_elapsed_time                DERIVE LINE  PL/SQL compilation elapsed time
405
    java_execution_elapsed_time                    DERIVE LINE  Java execution elapsed time
406
    repeated_bind_elapsed_time                     DERIVE LINE  repeated bind elapsed time
407
    rman_cpu_time_backup_restore                   DERIVE LINE  RMAN cpu time (backup/restore)
408
"
409
getvalue_func[$key]=getvalue_cputime
410

    
411
key=cachehit
412
# buf_hitratio = 1 - physical_reads / ( db_block_gets + consistent_gets )
413
# lib_hitratio = 1 - reloads / pins
414
# dict_hitratio = ( gets - misses ) / gets
415
field_info=$( for field in buf_physical buf_logical lib_pins lib_reloads dict_gets dict_getmisses
416
   do
417
       echo "${field}.graph no"
418
       echo "${field}.type DERIVE"
419
       echo "${field}.min 0"
420
       echo "${field}.label ${field}"
421
   done
422
)
423
global_attrs[$key]="
424
    graph_title Oracle Cache Hit Ratio
425
    graph_category db
426
    graph_args --base 1000 --lower-limit 0 --upper-limit 100 --rigid
427
    graph_vlabel %
428
    graph_info Oracle Cache Hit Ratio - The graph shows cache hit ratio between munin-update intervals (5 minutes in most cases).
429
    graph_scale no
430

    
431
    ${field_info}
432
    buf_hitratio.cdef 100,1,buf_physical,buf_logical,/,-,*,FLOOR
433
    lib_hitratio.cdef 100,1,lib_reloads,lib_pins,/,-,*,FLOOR
434
    dict_hitratio.cdef 100,dict_gets,dict_getmisses,-,dict_gets,/,*,FLOOR
435
"
436
data_attrs[$key]="
437
    buf_hitratio GAUGE LINE Buffer Cache Hit Ratio
438
    lib_hitratio GAUGE LINE Library Cache Hit Ratio
439
    dict_hitratio GAUGE LINE Dictionary Cache Hit Ratio
440
"
441
getvalue_func[$key]=getvalue_cachehit
442

    
443
key=sessionuser
444
global_attrs[$key]="
445
    graph_title Oracle Session Users
446
    graph_category db
447
    graph_args --base 1000 --lower-limit 0 --rigid
448
    graph_vlabel count
449
    graph_info Oracle Session Users
450
"
451
data_attrs[$key]=""
452
getfield_func[$key]=getfield_sessionuser
453
getvalue_func[$key]=getvalue_sessionuser
454

    
455
key=sessionwait
456
global_attrs[$key]="
457
    graph_title Oracle Session Wait
458
    graph_category db
459
    graph_args --base 1000 --lower-limit 0 --rigid
460
    graph_vlabel count
461
    graph_info Oracle Session Wait
462
"
463
data_attrs[$key]=""
464
getfield_func[$key]=getfield_sessionwait
465
getvalue_func[$key]=getvalue_sessionwait
466

    
467
key=eventwait
468
global_attrs[$key]="
469
    graph_title Oracle Wait Events
470
    graph_category db
471
    graph_args --base 1000 --lower-limit 0 --rigid
472
    graph_vlabel microseconds
473
    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.
474
"
475
data_attrs[$key]=""
476
getfield_func[$key]=getfield_eventwait
477
getvalue_func[$key]=getvalue_eventwait
478

    
479
key=eventwaitapplication
480
global_attrs[$key]="
481
    graph_title Oracle Wait Events Application
482
    graph_category db
483
    graph_args --base 1000 --lower-limit 0 --rigid
484
    graph_vlabel microseconds
485
    graph_info Oracle Wait Events Application
486
"
487
data_attrs[$key]=""
488
getfield_func[$key]="getfield_eventwait2 Application"
489
getvalue_func[$key]="getvalue_eventwait2 Application"
490

    
491
key=eventwaitnetwork
492
global_attrs[$key]="
493
    graph_title Oracle Wait Events Network
494
    graph_category db
495
    graph_args --base 1000 --lower-limit 0 --rigid
496
    graph_vlabel microseconds
497
    graph_info Oracle Wait Events Network
498
"
499
data_attrs[$key]=""
500
getfield_func[$key]="getfield_eventwait2 Network"
501
getvalue_func[$key]="getvalue_eventwait2 Network"
502

    
503
key=eventwaitconcurrency
504
global_attrs[$key]="
505
    graph_title Oracle Wait Events Concurrency
506
    graph_category db
507
    graph_args --base 1000 --lower-limit 0 --rigid
508
    graph_vlabel microseconds
509
    graph_info Oracle Wait Events Concurrency
510
"
511
data_attrs[$key]=" "
512
getfield_func[$key]="getfield_eventwait2 Concurrency"
513
getvalue_func[$key]="getvalue_eventwait2 Concurrency"
514

    
515
key=eventwaituserio
516
global_attrs[$key]="
517
    graph_title Oracle Wait Events User I/O
518
    graph_category db
519
    graph_args --base 1000 --lower-limit 0 --rigid
520
    graph_vlabel microseconds
521
    graph_info Oracle Wait Events User I/O
522
"
523
data_attrs[$key]=""
524
getfield_func[$key]="getfield_eventwait2 User I/O"
525
getvalue_func[$key]="getvalue_eventwait2 User I/O"
526

    
527
key=eventwaitsystemio
528
global_attrs[$key]="
529
    graph_title Oracle Wait Events System I/O
530
    graph_category db
531
    graph_args --base 1000 --lower-limit 0 --rigid
532
    graph_vlabel microseconds
533
    graph_info Oracle Wait Events System I/O
534
"
535
data_attrs[$key]="
536
"
537
getfield_func[$key]="getfield_eventwait2 System I/O"
538
getvalue_func[$key]="getvalue_eventwait2 System I/O"
539

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

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

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

    
576
key=tablespace
577
global_attrs[$key]="
578
    graph_title Oracle Table Space Usage
579
    graph_category db
580
    graph_args --base 1000 --lower-limit 0 --upper-limit 100 --rigid
581
    graph_vlabel %
582
    graph_info Oracle Table Space Usage
583
    warning ${warning:=92}
584
    critical ${critical:=98}
585
"
586
data_attrs[$key]=""
587
getfield_func[$key]=getfield_tablespace
588
getvalue_func[$key]=getvalue_tablespace
589

    
590
key=asmusage
591
global_attrs[$key]="
592
    graph_title Oracle ASM Disk Group Usage
593
    graph_category db
594
    graph_args --base 1000 --lower-limit 0 --upper-limit 100 --rigid
595
    graph_vlabel %
596
    graph_info Oracle ASM Disk Group Usage
597
    warning ${warning:=92}
598
    critical ${critical:=98}
599
"
600
data_attrs[$key]=""
601
getfield_func[$key]=getfield_asmusage
602
getvalue_func[$key]=getvalue_asmusage
603

    
604
# End of Graph Settings
605

    
606
# sqlplus options
607
: "${sqlplus:=sqlplus -S -L}"
608
sqlplus_variables="
609
    whenever sqlerror exit sql.sqlcode
610
    set pagesize 0
611
    set feed off
612
    set head off
613
    set linesize 256
614
    set numwidth 20
615
"
616

    
617
# functions 
618

    
619
autoconf() {
620
    if [ -x "$( which "${sqlplus}" )" ]; then
621
        echo yes
622
    else
623
        echo "no (failed to find executable 'sqlplus')"
624
    fi
625
}
626

    
627
suggest() {
628
    # print hash keys as available module names
629
    echo "${!global_attrs[@]}" | tr ' ' '\n' | sort
630
}
631

    
632
config() {
633
    local label_max_length=45
634

    
635
    # print global attributes
636
    sed -e 's/^  *//' -e '/^$/d' <<< "${global_attrs[$module]}"
637

    
638
    # print data source attributes
639
    # split line into field,type,draw,label 
640
    local fields field type draw label
641
    fields=
642
    while read -r field type draw label
643
    do
644
        [ -z "$field" ] && continue
645
        fields="${fields} ${field}"
646

    
647
        echo "${field}.type ${type}"
648
        echo "${field}.draw ${draw}"
649
        echo "${field}.label ${label:0:${label_max_length}}"
650
        if [ "${type}" = DERIVE ]; then
651
            echo "${field}.min 0"
652
        fi
653
    done <<< "${data_attrs[$module]}"
654

    
655
    echo graph_order "$fields"
656
}
657

    
658
# wrapper for getfield_*
659
getfield() {
660
    local func arg
661
    if [ -n "${getfield_func[$module]:-}" ]; then
662
        # call getfield_* function with argument if necessary
663
        read -r func arg <<< "${getfield_func[$module]}"
664
        $func "$arg"
665
    fi
666
}
667

    
668
# wrapper for getvalue_*
669
getvalue() {
670
    local func arg
671
    # call getvalue_* function with argument if necessary
672
    read -r func arg <<< "${getvalue_func[$module]}"
673
    $func "$arg"
674
}
675

    
676
getvalue_sysstat() {
677
    local field type draw label
678
    while read -r field type draw label
679
    do
680
        [ -z "$field" ] && continue
681

    
682
        echo "${sqlplus_variables}
683
          VAR vf VARCHAR2(64)
684
          VAR vl VARCHAR2(64)
685
          EXEC :vf := '${field}' 
686
          EXEC :vl := '${label}' 
687
          SELECT
688
            :vf || '.value ' || value
689
          FROM
690
            v\$sysstat
691
          WHERE
692
            name = :vl;
693
        "
694
    done <<< "${data_attrs[$module]}" | ${sqlplus} "${oracle_auth}"
695
}
696

    
697
getvalue_sgainfo() {
698
    local field type draw label
699
    while read -r field type draw label
700
    do
701
        [ -z "$field" ] && continue
702

    
703
        echo "${sqlplus_variables}
704
          VAR vf VARCHAR2(64)
705
          VAR vl VARCHAR2(64)
706
          EXEC :vf := '${field}' 
707
          EXEC :vl := '${label}' 
708
          SELECT
709
            :vf || '.value ' || bytes
710
          FROM
711
            v\$sgainfo
712
          WHERE
713
            name = :vl;
714
        "
715
    done <<< "${data_attrs[$module]}" | ${sqlplus} "${oracle_auth}"
716
}
717

    
718
getvalue_pgastat() {
719
    local field type draw label
720
    while read -r field type draw label
721
    do
722
        [ -z "$field" ] && continue
723

    
724
        echo "${sqlplus_variables}
725
          VAR vf VARCHAR2(64)
726
          VAR vl VARCHAR2(64)
727
          EXEC :vf := '${field}' 
728
          EXEC :vl := '${label}' 
729
          SELECT
730
            :vf || '.value ' || value
731
          FROM
732
            v\$pgastat
733
          WHERE
734
            name = :vl;
735
        "
736
    done <<< "${data_attrs[$module]}" | ${sqlplus} "${oracle_auth}"
737
}
738

    
739
getvalue_cputime() {
740
    local field type draw label
741
    while read -r field type draw label
742
    do
743
        [ -z "$field" ] && continue
744

    
745
        echo "${sqlplus_variables}
746
          VAR vf VARCHAR2(64)
747
          VAR vl VARCHAR2(64)
748
          EXEC :vf := '${field}' 
749
          EXEC :vl := '${label}' 
750
          SELECT
751
            :vf || '.value ' || ROUND( value / 1000000 )
752
          FROM
753
            v\$sys_time_model
754
          WHERE
755
            stat_name = :vl;
756
        "
757
    done <<< "${data_attrs[$module]}" | ${sqlplus} "${oracle_auth}"
758
}
759

    
760
getvalue_cachehit() {
761
    ${sqlplus} "${oracle_auth}" <<EOF
762
${sqlplus_variables}
763
SELECT
764
  'buf_physical.value ' || value
765
FROM
766
  v\$sysstat
767
WHERE
768
  name = 'physical reads cache'
769
;
770
SELECT 
771
  'buf_logical.value ' || ( sd.value + sc.value )
772
FROM 
773
  v\$sysstat sd, v\$sysstat sc 
774
WHERE 
775
  sd.name = 'db block gets from cache' AND sc.name = 'consistent gets from cache'
776
;
777
SELECT 'lib_pins.value '    || SUM(pins)    FROM v\$librarycache;
778
SELECT 'lib_reloads.value ' || SUM(reloads) FROM v\$librarycache;
779
SELECT 'dict_gets.value '      || SUM(gets)      FROM v\$rowcache;
780
SELECT 'dict_getmisses.value ' || SUM(getmisses) FROM v\$rowcache;
781
EOF
782
}
783

    
784
getfield_sessionuser() {
785
    data_attrs[$module]=$( ${sqlplus} "${oracle_auth}" <<EOF
786
${sqlplus_variables}
787
SELECT
788
  REGEXP_REPLACE( username, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) ||
789
  ' GAUGE LINE ' ||  username
790
FROM
791
  dba_users
792
WHERE
793
  account_status = 'OPEN'
794
ORDER BY
795
  username;
796
EOF
797
)
798
}
799

    
800
getvalue_sessionuser() {
801
    ${sqlplus} "${oracle_auth}" <<EOF
802
${sqlplus_variables}
803
SELECT
804
  REGEXP_REPLACE( du.username, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) || '.value ' ||
805
  count(vs.username)
806
FROM 
807
  ( SELECT
808
      username
809
    FROM
810
      dba_users
811
    WHERE
812
      account_status = 'OPEN'
813
  ) du
814
  LEFT JOIN v\$session vs
815
ON
816
  du.username = vs.username
817
GROUP BY
818
  du.username;
819
EOF
820
}
821

    
822
getfield_sessionwait() {
823
    data_attrs[$module]=$( ${sqlplus} "${oracle_auth}" <<EOF
824
${sqlplus_variables}
825
SELECT 'CPU GAUGE AREASTACK CPU' from dual;
826
SELECT
827
  REGEXP_REPLACE( wait_class, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) ||
828
  ' GAUGE AREASTACK ' || wait_class
829
FROM
830
  v\$event_name
831
WHERE
832
  wait_class NOT IN ( 'Other', 'Idle' )
833
GROUP BY
834
  wait_class
835
ORDER BY
836
  wait_class;
837
SELECT 'Other GAUGE AREASTACK Other' from dual;
838
SELECT 'Idle  GAUGE AREASTACK Idle' from dual;
839
EOF
840
)
841
}
842

    
843
getvalue_sessionwait() {
844
    ${sqlplus} "${oracle_auth}" <<EOF
845
${sqlplus_variables}
846
SELECT
847
  'CPU.value ' || count(wait_class)
848
FROM
849
  v\$session
850
WHERE
851
  wait_time != 0
852
;
853
SELECT
854
  REGEXP_REPLACE( en.wait_class, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) || '.value ' ||
855
  count(se.wait_class)
856
FROM
857
  ( SELECT
858
      wait_class
859
    FROM
860
      v\$event_name
861
    GROUP BY
862
      wait_class
863
  ) en
864
  LEFT JOIN v\$session se
865
ON
866
  en.wait_class = se.wait_class AND 
867
  se.username is not null AND
868
  se.wait_time = 0
869
GROUP BY
870
  en.wait_class
871
;
872
EOF
873
}
874

    
875
getfield_eventwait() {
876
    data_attrs[$module]=$( ${sqlplus} "${oracle_auth}" <<EOF
877
${sqlplus_variables}
878
SELECT
879
  REGEXP_REPLACE( wait_class, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) ||
880
  ' DERIVE LINE ' || wait_class
881
FROM
882
  v\$event_name
883
WHERE
884
  wait_class NOT IN ( 'Other', 'Idle' )
885
GROUP BY
886
  wait_class
887
ORDER BY
888
  wait_class;
889
SELECT 'Other DERIVE LINE Other' from dual;
890
EOF
891
)
892
}
893

    
894
getvalue_eventwait() {
895
    ${sqlplus} "${oracle_auth}" <<EOF
896
${sqlplus_variables}
897
SELECT
898
  REGEXP_REPLACE( en.wait_class, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) || '.value ' ||
899
  NVL( SUM(se.time_waited_micro), 0 )
900
FROM
901
  ( SELECT
902
      wait_class
903
    FROM
904
      v\$event_name
905
    WHERE
906
      wait_class NOT IN ( 'Idle' )
907
    GROUP BY
908
      wait_class
909
  ) en
910
  LEFT JOIN v\$system_event se
911
ON
912
  en.wait_class = se.wait_class
913
GROUP BY
914
  en.wait_class;
915
EOF
916
}
917

    
918
getfield_eventwait2() {
919
    local waitclass="$1"
920

    
921
    data_attrs[$module]=$( ${sqlplus} "${oracle_auth}" <<EOF
922
${sqlplus_variables}
923
VAR vl VARCHAR2(64)
924
EXEC :vl := '${waitclass}' 
925
SELECT
926
  REGEXP_REPLACE( name, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) ||
927
  ' DERIVE LINE ' || name
928
FROM
929
  v\$event_name 
930
WHERE
931
  wait_class = :vl
932
ORDER BY
933
  name;
934
EOF
935
)
936
}
937

    
938
getvalue_eventwait2() {
939
    local waitclass="$1"
940

    
941
    ${sqlplus} "${oracle_auth}" <<EOF
942
${sqlplus_variables}
943
VAR vl VARCHAR2(64)
944
EXEC :vl := '${waitclass}' 
945
SELECT
946
  REGEXP_REPLACE( en.name, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) || '.value ' || 
947
  NVL( se.time_waited_micro, 0 )
948
FROM
949
  v\$event_name en LEFT JOIN v\$system_event se
950
ON
951
  en.name = se.event
952
WHERE
953
  en.wait_class = :vl;
954
EOF
955
}
956

    
957
getfield_tablespace() {
958
    data_attrs[$module]=$( ${sqlplus} "${oracle_auth}" <<EOF
959
${sqlplus_variables}
960
SELECT
961
  REGEXP_REPLACE( tablespace_name, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) ||
962
  ' GAUGE LINE ' || tablespace_name
963
FROM
964
  dba_data_files
965
ORDER BY
966
  tablespace_name;
967
EOF
968
)
969
}
970

    
971
getvalue_tablespace() {
972
    ${sqlplus} "${oracle_auth}" <<EOF
973
${sqlplus_variables}
974
SELECT
975
  REGEXP_REPLACE( tablespace_name, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) || '.value ' ||
976
  ROUND( (total_bytes - free_total_bytes) / total_bytes * 100, 0 )
977
FROM
978
  ( SELECT
979
      tablespace_name,
980
      SUM(bytes) total_bytes
981
    FROM
982
      dba_data_files
983
    GROUP BY
984
      tablespace_name
985
  ),
986
  ( SELECT
987
      tablespace_name free_tablespace_name,
988
      SUM(bytes) free_total_bytes
989
    FROM
990
      dba_free_space
991
    GROUP BY
992
      tablespace_name
993
  )
994
WHERE
995
  tablespace_name = free_tablespace_name;
996
EOF
997
}
998

    
999
getfield_asmusage() {
1000
    data_attrs[$module]=$( ${sqlplus} "${oracle_auth}" <<EOF
1001
${sqlplus_variables}
1002
SELECT
1003
  REGEXP_REPLACE( name, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) ||
1004
  ' GAUGE LINE ' || name
1005
FROM
1006
  v\$asm_diskgroup
1007
ORDER BY
1008
  name;
1009
EOF
1010
)
1011
}
1012

    
1013
getvalue_asmusage() {
1014
    ${sqlplus} "${oracle_auth}" <<EOF
1015
${sqlplus_variables}
1016
SELECT
1017
  REGEXP_REPLACE( name, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) || '.value ' ||
1018
  ROUND( ( total_mb - free_mb ) / total_mb * 100 )
1019
FROM
1020
  v\$asm_diskgroup
1021
ORDER BY
1022
  name;
1023
EOF
1024
}
1025

    
1026
# main
1027
case ${1:-} in
1028
autoconf)
1029
    autoconf
1030
    ;;
1031
suggest)
1032
    suggest
1033
    ;;
1034
config)
1035
    getfield
1036
    config
1037
    ;;
1038
*)
1039
    getvalue
1040
    ;;
1041
esac
1042

    
1043
exit 0