Projet

Général

Profil

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

root / plugins / oracle / oracle_sysstat_ @ ca01c6e3

Historique | Voir | Annoter | Télécharger (28,6 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
# dic_hitratio = ( gets - misses ) / gets
415
global_attrs[$key]="
416
    graph_title Oracle Cache Hit Ratio
417
    graph_category db
418
    graph_args --base 1000 --lower-limit 0 --upper-limit 100 --rigid
419
    graph_vlabel %
420
    graph_info Oracle Cache Hit Ratio - The graph shows cache hit ratio between munin-update intervals (5 minutes in most cases).
421
    graph_scale no
422

    
423
    $( for field in buf_physical buf_logical lib_pins lib_reloads dic_gets dic_getmisses
424
       do
425
           echo "${field}.graph no"
426
           echo "${field}.type DERIVE"
427
           echo "${field}.min 0"
428
           echo "${field}.label ${field}"
429
       done
430
    )
431

    
432
    buf_hitratio.cdef 100,1,buf_physical,buf_logical,/,-,*,FLOOR
433
    lib_hitratio.cdef 100,1,lib_reloads,lib_pins,/,-,*,FLOOR
434
    dic_hitratio.cdef 100,dic_gets,dic_getmisses,-,dic_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
    dic_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 looks 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
    while read -r field type draw label
642
    do
643
        [ -z "${field:-}" ] && continue
644
        fields="${fields:-} ${field}"
645

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

    
654
    echo graph_order "$fields"
655
}
656

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
921
getfield_eventwait2() {
922
    local waitclass="$1"
923

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

    
941
getvalue_eventwait2() {
942
    local waitclass="$1"
943

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

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

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

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

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

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

    
1046
exit 0