Projet

Général

Profil

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

root / plugins / oracle / oracle_sysstat_ @ 3e4a48ab

Historique | Voir | Annoter | Télécharger (22 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 Execute Count
11
    parse                - To monitor Oracle Sysstat Parse Count
12
    tablefetch           - To monitor Oracle Sysstat Table Fetch Rows
13
    tablescan            - To monitor Oracle Sysstat Table Scans
14
    transaction          - To monitor Oracle Sysstat Transactions
15
    sort                 - To monitor Oracle Sysstat Sorts
16
    cursor               - To monitor Oracle Sysstat Open Cursor
17
    enqueue              - To monitor Oracle Sysstat Enqueues
18
    redolog              - To monitor Oracle Sysstat Redo Log
19
    physicaliops         - To monitor Oracle Sysstat Physical I/O Requests
20
    physicalrw           - To monitor Oracle Sysstat Physical Read/Write Bytes
21
    netrw                - To monitor Oracle Sysstat Network Send/Receive Bytes
22
    sgainfo              - To monitor Oracle Memory SGA
23
    pgastat              - To monitor Oracle Memory PGA
24
    cachehit             - To monitor Oracle Cache Hit Ratio
25
    sessionuser          - To monitor Oracle Session Users
26
    sessionwait          - To monitor Oracle Session Wait
27
    eventwait            - To monitor Oracle Wait Events
28
    eventwaitapplication - To monitor Oracle Wait Events Application
29
    eventwaitconcurrency - To monitor Oracle Wait Events Concurrency
30
    eventwaituserio      - To monitor Oracle Wait Events User I/O
31
    eventwaitsystemio    - To monitor Oracle Wait Events System I/O
32
    eventwaitcluster     - To monitor Oracle Wait Events Cluster
33
    tablespace           - To monitor Oracle Table Space Usage
34
    asmusage             - To monitor Oracle ASM Disk Group Usage
35

    
36
=head1 CONFIGURATION
37

    
38
  To get a list of symlinks that can be created, run:   
39

    
40
    ./oracle_sysstat_ suggest
41

    
42
  Make symlinks:
43

    
44
    munin-node-configure --families=contrib --suggest --shell
45
    ...
46

    
47
  The following shows example settings for this plugin:
48

    
49
    [oracle_sysstat_*]
50
      user  oracle
51
      env.oracle_auth  / as SYSDBA
52
      env.ORACLE_HOME  /path/to/oracle/product/version
53
      env.ORACLE_SID   SOMESID
54

    
55
    [oracle_sysstat_asmusage]
56
      user  grid
57
      env.oracle_auth  / as SYSASM
58
      env.ORACLE_HOME  /path/to/grid/home/version
59
      env.ORACLE_SID   SOMESID
60

    
61
=head1 NOTES
62

    
63
  Uses the command "sqlplus".
64
  Tested with Oracle Database 12c R1.
65

    
66
=head1 AUTHOR
67

    
68
  K.Cima https://github.com/shakemid
69

    
70
=head1 LICENSE
71

    
72
  GPLv2
73

    
74
=cut
75

    
76
# Magic markers
77
#%# family=contrib
78
#%# capabilities=autoconf suggest
79

    
80
# Include plugin.sh
81
. $MUNIN_LIBDIR/plugins/plugin.sh
82

    
83
# Like perl 'use strict;' 
84
#set -o nounset
85

    
86
# Environments
87
: ${ORACLE_HOME:=$( echo /opt/oracle/product/* )}
88
: ${ORACLE_SID:=orcl}
89
: ${oracle_auth:=/ as SYSDBA}
90

    
91
PATH=$PATH:$ORACLE_HOME/bin
92
export PATH ORACLE_HOME ORACLE_SID
93

    
94
# Module name
95
module=$( basename $0 | sed -e 's/^.*_//' )
96

    
97
# Graph settings
98
declare -A global_attrs  # required
99
declare -A data_attrs    # required (format: field type draw 'label')
100
declare -A getfield_func # optional
101
declare -A getvalue_func # required
102

    
103
key=execute
104
global_attrs[$key]="
105
    graph_title Oracle Sysstat Execute Count
106
    graph_category db
107
    graph_args --base 1000 --lower-limit 0 --rigid
108
    graph_vlabel count per second
109
    graph_info Oracle Sysstat Execute Count
110
"
111
data_attrs[$key]="
112
    execute_count    DERIVE LINE 'execute count'
113
    user_calls       DERIVE LINE 'user calls'
114
    recursive_calls  DERIVE LINE 'recursive calls'
115
"
116
getvalue_func[$key]=getvalue_sysstat
117

    
118
key=parse
119
global_attrs[$key]="
120
    graph_title Oracle Sysstat Parse Count
121
    graph_category db
122
    graph_args --base 1000 --lower-limit 0 --rigid
123
    graph_vlabel count per second
124
    graph_info Oracle Sysstat Parse Count
125
"
126
data_attrs[$key]="
127
    parse_count_total     DERIVE LINE 'parse count (total)'
128
    parse_count_hard      DERIVE LINE 'parse count (hard)'
129
    parse_count_failures  DERIVE LINE 'parse count (failures)'
130
    parse_count_describe  DERIVE LINE 'parse count (describe)'
131
"
132
getvalue_func[$key]=getvalue_sysstat
133

    
134
key=tablefetch
135
global_attrs[$key]="
136
    graph_title Oracle Sysstat Table Fetch Rows
137
    graph_category db
138
    graph_args --base 1000 --lower-limit 0 --rigid
139
    graph_vlabel count per second
140
    graph_info Oracle Sysstat Table Scans
141
"
142
data_attrs[$key]="
143
    table_fetch_by_rowid   DERIVE LINE 'table fetch by rowid'
144
    table_scan_rows_gotten DERIVE LINE 'table scan rows gotten'
145
"
146
getvalue_func[$key]=getvalue_sysstat
147

    
148
key=tablescan
149
global_attrs[$key]="
150
    graph_title Oracle Sysstat Table Scans
151
    graph_category db
152
    graph_args --base 1000 --lower-limit 0 --rigid
153
    graph_vlabel count per second
154
    graph_info Oracle Sysstat Table Scans
155
"
156
data_attrs[$key]="
157
    table_scans_short_tables DERIVE LINE 'table scans (short tables)'
158
    table_scans_long_tables  DERIVE LINE 'table scans (long tables)'
159
"
160
getvalue_func[$key]=getvalue_sysstat
161

    
162
key=transaction
163
global_attrs[$key]="
164
    graph_title Oracle Sysstat Transactions
165
    graph_category db
166
    graph_args --base 1000 --lower-limit 0 --rigid
167
    graph_vlabel count per second
168
    graph_info Oracle Sysstat Transactions
169
"
170
data_attrs[$key]="
171
    user_commits   DERIVE LINE 'user commits'
172
    user_rollbacks DERIVE LINE 'user rollbacks'
173
"
174
getvalue_func[$key]=getvalue_sysstat
175

    
176
key=sort
177
global_attrs[$key]="
178
    graph_title Oracle Sysstat Sorts
179
    graph_category db
180
    graph_args --base 1000 --lower-limit 0 --rigid
181
    graph_vlabel count per second
182
    graph_info Oracle Sysstat - Sorts
183
"
184
data_attrs[$key]="
185
    sorts_memory DERIVE LINE 'sorts (memory)'
186
    sorts_disk   DERIVE LINE 'sorts (disk)'
187
"
188
getvalue_func[$key]=getvalue_sysstat
189

    
190
key=cursor
191
global_attrs[$key]="
192
    graph_title Oracle Sysstat Open Cursors
193
    graph_category db
194
    graph_args --base 1000 --lower-limit 0 --rigid
195
    graph_vlabel count
196
    graph_info Oracle Sysstat Open Cursors
197
"
198
data_attrs[$key]="
199
    open_cursor GAUGE LINE 'opened cursors current'
200
"
201
getvalue_func[$key]=getvalue_sysstat
202

    
203
key=enqueue
204
global_attrs[$key]="
205
    graph_title Oracle Sysstat Enqueues
206
    graph_category db
207
    graph_args --base 1000 --lower-limit 0 --rigid
208
    graph_vlabel count per second
209
    graph_info Oracle Sysstat Enqueues
210
"
211
data_attrs[$key]="
212
    enqueue_requests    DERIVE LINE 'enqueue requests'
213
    enqueue_releases    DERIVE LINE 'enqueue releases'
214
    enqueue_conversions DERIVE LINE 'enqueue conversions'
215
    enqueue_waits       DERIVE LINE 'enqueue waits'
216
    enqueue_timeouts    DERIVE LINE 'enqueue timeouts'
217
    enqueue_deadlocks   DERIVE LINE 'enqueue deadlocks'
218
"
219
getvalue_func[$key]=getvalue_sysstat
220

    
221
key=redolog
222
global_attrs[$key]="
223
    graph_title Oracle Sysstat Redo Log
224
    graph_category db
225
    graph_args --base 1000 --lower-limit 0 --rigid
226
    graph_vlabel count per second
227
    graph_info Oracle Sysstat Redo Log
228
"
229
data_attrs[$key]="
230
    redo_entries                   DERIVE LINE 'redo entries'
231
    redo_buffer_allocation_retries DERIVE LINE 'redo buffer allocation retries'
232
    redo_log_space_requests        DERIVE LINE 'redo log space requests'
233
"
234
getvalue_func[$key]=getvalue_sysstat
235

    
236
key=physicaliops
237
global_attrs[$key]="
238
    graph_title Oracle Sysstat Physical I/O Requests
239
    graph_category db
240
    graph_args --base 1000 --lower-limit 0 --rigid
241
    graph_vlabel iops
242
    graph_info Oracle Sysstat Physical I/O Requests
243
"
244
data_attrs[$key]="
245
    physical_read_total        DERIVE LINE2 'physical read total IO requests'
246
    physical_read              DERIVE LINE  'physical read IO requests'
247
    physical_read_total_multi  DERIVE LINE  'physical read total multi block requests'
248
    physical_write_total       DERIVE LINE2 'physical write total IO requests'
249
    physical_write             DERIVE LINE  'physical write IO requests'
250
    physical_write_total_multi DERIVE LINE  'physical write total multi block requests'
251
"
252
getvalue_func[$key]=getvalue_sysstat
253

    
254
key=physicalrw
255
global_attrs[$key]="
256
    graph_title Oracle Sysstat Physical Read/Write Bytes
257
    graph_category db
258
    graph_args --base 1024 --lower-limit 0 --rigid
259
    graph_vlabel bytes per second
260
    graph_info Oracle Sysstat Physical Read/Write Bytes
261
"
262
data_attrs[$key]="
263
    physical_read_total  DERIVE LINE2 'physical read total bytes'
264
    physical_read        DERIVE LINE  'physical read bytes'
265
    physical_write_total DERIVE LINE2 'physical write total bytes'
266
    physical_write       DERIVE LINE  'physical write bytes'
267
"
268
getvalue_func[$key]=getvalue_sysstat
269

    
270
key=netrw
271
global_attrs[$key]="
272
    graph_title Oracle Sysstat Network Send/Receive Bytes
273
    graph_category db
274
    graph_args --base 1024 --lower-limit 0 --rigid
275
    graph_vlabel bytes per second
276
    graph_info Oracle Sysstat Network Send/Receive Bytes
277
"
278
data_attrs[$key]="
279
    bytes_sent_via_sql_net_to_client       DERIVE LINE 'bytes sent via SQL*Net to client'
280
    bytes_received_via_sql_net_from_client DERIVE LINE 'bytes received via SQL*Net from client'
281
    bytes_sent_via_sql_net_to_dblink       DERIVE LINE 'bytes sent via SQL*Net to dblink'
282
    bytes_received_via_sql_net_from_dblink DERIVE LINE 'bytes received via SQL*Net from dblink'
283
"
284
getvalue_func[$key]=getvalue_sysstat
285

    
286
key=sgainfo
287
global_attrs[$key]="
288
    graph_title Oracle Memory SGA
289
    graph_category db
290
    graph_args --base 1024 --lower-limit 0 --rigid
291
    graph_vlabel bytes
292
    graph_info Oracle Memory SGA
293
"
294
data_attrs[$key]="
295
    maximum_sga_size    GAUGE LINE      'Maximum SGA Size'
296
    fixed_sga_size      GAUGE AREASTACK 'Fixed SGA Size'
297
    redo_buffers        GAUGE AREASTACK 'Redo Buffers'
298
    shared_pool_size    GAUGE AREASTACK 'Shared Pool Size'
299
    large_pool_size     GAUGE AREASTACK 'Large Pool Size'
300
    java_pool_size      GAUGE AREASTACK 'Java Pool Size'
301
    streams_pool_size   GAUGE AREASTACK 'Streams Pool Size'
302
    shared_io_pool_size GAUGE AREASTACK 'Shared IO Pool Size'
303
    buffer_cache_size   GAUGE AREASTACK 'Buffer Cache Size'
304
    in_memory_area_size GAUGE AREASTACK 'In-Memory Area Size'
305
"
306
getvalue_func[$key]=getvalue_sgainfo
307

    
308
key=pgastat
309
global_attrs[$key]="
310
    graph_title Oracle Memory PGA
311
    graph_category db
312
    graph_args --base 1024 --lower-limit 0 --rigid
313
    graph_vlabel bytes
314
    graph_info Oracle Memory PGA
315
"
316
data_attrs[$key]="
317
    pga_target    GAUGE LINE 'aggregate PGA auto target'
318
    pga_allocated GAUGE LINE 'total PGA allocated'
319
    pga_inuse     GAUGE AREA 'total PGA inuse'
320
"
321
getvalue_func[$key]=getvalue_pgastat
322

    
323
key=cachehit
324
global_attrs[$key]="
325
    graph_title Oracle Cache Hit Ratio
326
    graph_category db
327
    graph_args --base 1000 --lower-limit 0 --upper-limit 100 --rigid
328
    graph_vlabel %
329
    graph_info Oracle Cache Hit Ratio
330
    graph_scale no
331
"
332
data_attrs[$key]="
333
    buf_hitratio  GAUGE LINE 'Buffer Cache Hit Ratio'
334
    lib_hitratio  GAUGE LINE 'Library Cache Hit Ratio'
335
    dict_hitratio GAUGE LINE 'Dictionary Cache Hit Ratio'
336
"
337
getvalue_func[$key]=getvalue_cachehit
338

    
339
key=sessionuser
340
global_attrs[$key]="
341
    graph_title Oracle Session Users
342
    graph_category db
343
    graph_args --base 1000 --lower-limit 0 --rigid
344
    graph_vlabel count
345
    graph_info Oracle Session Users
346
"
347
data_attrs[$key]=""
348
getfield_func[$key]=getfield_sessionuser
349
getvalue_func[$key]=getvalue_sessionuser
350

    
351
key=sessionwait
352
global_attrs[$key]="
353
    graph_title Oracle Session Wait
354
    graph_category db
355
    graph_args --base 1000 --lower-limit 0 --rigid
356
    graph_vlabel count
357
    graph_info Oracle Session Wait
358
"
359
data_attrs[$key]=""
360
getfield_func[$key]=getfield_sessionwait
361
getvalue_func[$key]=getvalue_sessionwait
362

    
363
key=eventwait
364
global_attrs[$key]="
365
    graph_title Oracle Wait Events
366
    graph_category db
367
    graph_args --base 1000 --lower-limit 0 --rigid
368
    graph_vlabel microseconds
369
    graph_info Oracle Wait Events
370
"
371
data_attrs[$key]=""
372
getfield_func[$key]=getfield_eventwait
373
getvalue_func[$key]=getvalue_eventwait
374

    
375
key=eventwaitapplication
376
global_attrs[$key]="
377
    graph_title Oracle Wait Events Application
378
    graph_category db
379
    graph_args --base 1000 --lower-limit 0 --rigid
380
    graph_vlabel microseconds
381
    graph_info Oracle Wait Events Application
382
"
383
data_attrs[$key]=""
384
getfield_func[$key]='getfield_eventwait2 Application'
385
getvalue_func[$key]='getvalue_eventwait2 Application'
386

    
387
key=eventwaitconcurrency
388
global_attrs[$key]="
389
    graph_title Oracle Wait Events Concurrency
390
    graph_category db
391
    graph_args --base 1000 --lower-limit 0 --rigid
392
    graph_vlabel microseconds
393
    graph_info Oracle Wait Events Concurrency
394
"
395
data_attrs[$key]=" "
396
getfield_func[$key]='getfield_eventwait2 Concurrency'
397
getvalue_func[$key]='getvalue_eventwait2 Concurrency'
398

    
399
key=eventwaituserio
400
global_attrs[$key]="
401
    graph_title Oracle Wait Events User I/O
402
    graph_category db
403
    graph_args --base 1000 --lower-limit 0 --rigid
404
    graph_vlabel microseconds
405
    graph_info Oracle Wait Events User I/O
406
"
407
data_attrs[$key]=""
408
getfield_func[$key]='getfield_eventwait2 "User I/O"'
409
getvalue_func[$key]='getvalue_eventwait2 "User I/O"'
410

    
411
key=eventwaitsystemio
412
global_attrs[$key]="
413
    graph_title Oracle Wait Events System I/O
414
    graph_category db
415
    graph_args --base 1000 --lower-limit 0 --rigid
416
    graph_vlabel microseconds
417
    graph_info Oracle Wait Events System I/O
418
"
419
data_attrs[$key]="
420
"
421
getfield_func[$key]='getfield_eventwait2 "System I/O"'
422
getvalue_func[$key]='getvalue_eventwait2 "System I/O"'
423

    
424
key=eventwaitcluster
425
global_attrs[$key]="
426
    graph_title Oracle Wait Events Cluster
427
    graph_category db
428
    graph_args --base 1000 --lower-limit 0 --rigid
429
    graph_vlabel microseconds
430
    graph_info Oracle Wait Events Cluster
431
"
432
data_attrs[$key]=" "
433
getfield_func[$key]='getfield_eventwait2 Cluster'
434
getvalue_func[$key]='getvalue_eventwait2 Cluster'
435

    
436
key=tablespace
437
global_attrs[$key]="
438
    graph_title Oracle Table Space Usage
439
    graph_category db
440
    graph_args --base 1000 --lower-limit 0 --upper-limit 100 --rigid
441
    graph_vlabel %
442
    graph_info Oracle Table Space Usage
443
    warning ${warning:=92}
444
    critical ${critical:=98}
445
"
446
data_attrs[$key]=""
447
getfield_func[$key]=getfield_tablespace
448
getvalue_func[$key]=getvalue_tablespace
449

    
450
key=asmusage
451
global_attrs[$key]="
452
    graph_title Oracle ASM Disk Group Usage
453
    graph_category db
454
    graph_args --base 1000 --lower-limit 0 --upper-limit 100 --rigid
455
    graph_vlabel %
456
    graph_info Oracle ASM Disk Group Usage
457
    warning ${warning:=92}
458
    critical ${critical:=98}
459
"
460
data_attrs[$key]=""
461
getfield_func[$key]=getfield_asmusage
462
getvalue_func[$key]=getvalue_asmusage
463

    
464
# End of Graph Settings
465

    
466
# sqlplus options
467
: ${sqlplus:=sqlplus}
468
: ${sqlplus_opts:=-S -L}
469
sqlplus_variables="
470
    set pagesize 0
471
    set feed off
472
    set head off
473
    set linesize 256
474
    set numwidth 20
475
"
476

    
477
# functions 
478

    
479
autoconf() {
480
    if [ -x "$( which ${sqlplus} )" ]; then
481
        echo yes
482
    else
483
        echo "no (failed to find executable 'sqlplus')"
484
    fi
485
}
486

    
487
suggest() {
488
    echo ${!global_attrs[@]} | tr ' ' '\n' | sort
489
}
490

    
491
config() {
492
    # print global attributes
493
    sed -e 's/^  *//' -e '/^$/d' <<< "${global_attrs[$module]}"
494

    
495
    # print data source attributes
496
    local line t fields field type draw label
497
    while IFS= read -r line
498
    do
499
        eval 't=(' "$line" ')'
500
        field="${t[0]}"
501
        [ -z "$field" ] && continue
502
        fields+=( $field )
503
        type="${t[1]}"
504
        draw="${t[2]}"
505
        label="${t[3]}"
506

    
507
        echo ${field}.type  ${type}
508
        echo ${field}.draw  ${draw}
509
        echo ${field}.label ${label}
510
    done <<< "${data_attrs[$module]}"
511

    
512
    echo graph_order ${fields[@]}
513
}
514

    
515
getfield() {
516
    if [ -n "${getfield_func[$module]:-}" ]; then
517
        eval "${getfield_func[$module]}"
518
    fi
519
}
520

    
521
getvalue() {
522
    eval "${getvalue_func[$module]}"
523
}
524

    
525
getvalue_sysstat() {
526
    local line t field label
527
    while IFS= read -r line
528
    do
529
        eval 't=(' "$line" ')'
530
        field="${t[0]}"
531
        [ -z "$field" ] && continue
532
        label="${t[3]}"
533

    
534
        ${sqlplus} ${sqlplus_opts} "${oracle_auth}" <<EOF
535
${sqlplus_variables}
536
VAR vf VARCHAR2(64)
537
VAR vl VARCHAR2(64)
538
EXEC :vf := '${field}' 
539
EXEC :vl := '${label}' 
540
SELECT
541
  :vf || '.value ' || value
542
FROM
543
  v\$sysstat
544
WHERE
545
  name = :vl;
546
EOF
547
    done <<< "${data_attrs[$module]}"
548
}
549

    
550
getvalue_sgainfo() {
551
    local line t field label
552
    while IFS= read -r line
553
    do
554
        eval 't=(' "$line" ')'
555
        field="${t[0]}"
556
        [ -z "$field" ] && continue
557
        label="${t[3]}"
558

    
559
        ${sqlplus} ${sqlplus_opts} "${oracle_auth}" <<EOF
560
${sqlplus_variables}
561
VAR vf VARCHAR2(64)
562
VAR vl VARCHAR2(64)
563
EXEC :vf := '${field}' 
564
EXEC :vl := '${label}' 
565
SELECT
566
  :vf || '.value ' || bytes
567
FROM
568
  v\$sgainfo
569
WHERE
570
  name = :vl;
571
EOF
572
    done <<< "${data_attrs[$module]}"
573
}
574

    
575
getvalue_pgastat() {
576
    local line t field label
577
    while IFS= read -r line
578
    do
579
        eval 't=(' "$line" ')'
580
        field="${t[0]}"
581
        [ -z "$field" ] && continue
582
        label="${t[3]}"
583

    
584
        ${sqlplus} ${sqlplus_opts} "${oracle_auth}" <<EOF
585
${sqlplus_variables}
586
VAR vf VARCHAR2(64)
587
VAR vl VARCHAR2(64)
588
EXEC :vf := '${field}' 
589
EXEC :vl := '${label}' 
590
SELECT
591
  :vf || '.value ' || value
592
FROM
593
  v\$pgastat
594
WHERE
595
  name = :vl;
596
EOF
597
    done <<< "${data_attrs[$module]}"
598
}
599

    
600
getvalue_cachehit() {
601
    ${sqlplus} ${sqlplus_opts} "${oracle_auth}" <<EOF
602
${sqlplus_variables}
603
SELECT
604
  'buf_hitratio.value ' || ROUND( ( 1 - a.value / ( b.value + c.value ) ) * 100 )
605
FROM
606
  v\$sysstat a, v\$sysstat b, v\$sysstat c
607
WHERE
608
  a.name = 'physical reads' AND
609
  b.name = 'db block gets' AND
610
  c.name = 'consistent gets'
611
;
612
SELECT
613
  'lib_hitratio.value ' || ROUND( SUM(pins) / ( SUM(pins) + SUM(reloads) ) * 100 )
614
FROM
615
  v\$librarycache
616
;
617
SELECT
618
  'dict_hitratio.value ' || ROUND( ( 1 - SUM(getmisses) / SUM(gets) ) * 100 )
619
FROM
620
  v\$rowcache
621
;
622
EOF
623
}
624

    
625
getfield_sessionuser() {
626
    data_attrs[$module]="$( ${sqlplus} ${sqlplus_opts} "${oracle_auth}" <<EOF
627
${sqlplus_variables}
628
SELECT
629
  REGEXP_REPLACE( username, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) ||
630
  ' GAUGE LINE ' || '''' || username || ''''
631
FROM
632
  dba_users
633
WHERE
634
  account_status = 'OPEN'
635
ORDER BY
636
  username;
637
EOF
638
)"
639
}
640

    
641
getvalue_sessionuser() {
642
    ${sqlplus} ${sqlplus_opts} "${oracle_auth}" <<EOF
643
${sqlplus_variables}
644
SELECT
645
  REGEXP_REPLACE( du.username, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) || '.value ' ||
646
  count(vs.username)
647
FROM 
648
  ( SELECT
649
      username
650
    FROM
651
      dba_users
652
    WHERE
653
      account_status = 'OPEN'
654
  ) du
655
  LEFT JOIN v\$session vs
656
ON
657
  du.username = vs.username
658
GROUP BY
659
  du.username;
660
EOF
661
}
662

    
663
getfield_sessionwait() {
664
    data_attrs[$module]="$( ${sqlplus} ${sqlplus_opts} "${oracle_auth}" <<EOF
665
${sqlplus_variables}
666
SELECT
667
  REGEXP_REPLACE( wait_class, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) ||
668
  ' GAUGE AREASTACK ' || '''' || wait_class || ''''
669
FROM
670
  v\$event_name
671
WHERE
672
  wait_class NOT IN ( 'Other', 'Idle' )
673
GROUP BY
674
  wait_class
675
ORDER BY
676
  wait_class;
677
SELECT 'Other GAUGE AREASTACK Other' from dual;
678
SELECT 'Idle  GAUGE AREASTACK Idle' from dual;
679
EOF
680
)"
681
}
682

    
683
getvalue_sessionwait() {
684
    ${sqlplus} ${sqlplus_opts} "${oracle_auth}" <<EOF
685
${sqlplus_variables}
686
SELECT
687
  REGEXP_REPLACE( en.wait_class, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) || '.value ' ||
688
  count(se.wait_class)
689
FROM
690
  ( SELECT
691
      wait_class
692
    FROM
693
      v\$event_name
694
    GROUP BY
695
      wait_class
696
  ) en
697
  LEFT JOIN v\$session se
698
ON
699
  en.wait_class = se.wait_class AND 
700
  se.username is not null
701
GROUP BY
702
  en.wait_class;
703
EOF
704
}
705

    
706
getfield_eventwait() {
707
    data_attrs[$module]="$( ${sqlplus} ${sqlplus_opts} "${oracle_auth}" <<EOF
708
${sqlplus_variables}
709
SELECT
710
  REGEXP_REPLACE( wait_class, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) ||
711
  ' DERIVE LINE ' || '''' || wait_class || ''''
712
FROM
713
  v\$event_name
714
WHERE
715
  wait_class NOT IN ( 'Other', 'Idle' )
716
GROUP BY
717
  wait_class
718
ORDER BY
719
  wait_class;
720
SELECT 'Other DERIVE LINE Other' from dual;
721
EOF
722
)"
723
}
724

    
725
getvalue_eventwait() {
726
    ${sqlplus} ${sqlplus_opts} "${oracle_auth}" <<EOF
727
${sqlplus_variables}
728
SELECT
729
  REGEXP_REPLACE( en.wait_class, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) || '.value ' ||
730
  NVL( SUM(se.time_waited_micro), 0 )
731
FROM
732
  ( SELECT
733
      wait_class
734
    FROM
735
      v\$event_name
736
    WHERE
737
      wait_class NOT IN ( 'Idle' )
738
    GROUP BY
739
      wait_class
740
  ) en
741
  LEFT JOIN v\$system_event se
742
ON
743
  en.wait_class = se.wait_class
744
GROUP BY
745
  en.wait_class;
746
EOF
747
}
748

    
749
getfield_eventwait2() {
750
    local waitclass="$1"
751

    
752
    data_attrs[$module]="$( ${sqlplus} ${sqlplus_opts} "${oracle_auth}" <<EOF
753
${sqlplus_variables}
754
VAR vl VARCHAR2(64)
755
EXEC :vl := '${waitclass}' 
756
SELECT
757
  REGEXP_REPLACE( name, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) ||
758
  ' DERIVE LINE ' || '''' || SUBSTR( name, 1, 45 ) || ''''
759
FROM
760
  v\$event_name 
761
WHERE
762
  wait_class = :vl
763
ORDER BY
764
  name;
765
EOF
766
)"
767
}
768

    
769
getvalue_eventwait2() {
770
    local waitclass="$1"
771

    
772
    ${sqlplus} ${sqlplus_opts} "${oracle_auth}" <<EOF
773
${sqlplus_variables}
774
VAR vl VARCHAR2(64)
775
EXEC :vl := '${waitclass}' 
776
SELECT
777
  REGEXP_REPLACE( en.name, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) || '.value ' || 
778
  NVL( se.time_waited_micro, 0 )
779
FROM
780
  v\$event_name en LEFT JOIN v\$system_event se
781
ON
782
  en.name = se.event
783
WHERE
784
  en.wait_class = :vl;
785
EOF
786
}
787

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

    
802
getvalue_tablespace() {
803
    ${sqlplus} ${sqlplus_opts} "${oracle_auth}" <<EOF
804
${sqlplus_variables}
805
SELECT
806
  REGEXP_REPLACE( tablespace_name, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) || '.value ' ||
807
  ROUND( (total_bytes - free_total_bytes) / total_bytes * 100, 0 )
808
FROM
809
  ( SELECT
810
      tablespace_name,
811
      SUM(bytes) total_bytes
812
    FROM
813
      dba_data_files
814
    GROUP BY
815
      tablespace_name
816
  ),
817
  ( SELECT
818
      tablespace_name free_tablespace_name,
819
      SUM(bytes) free_total_bytes
820
    FROM
821
      dba_free_space
822
    GROUP BY
823
      tablespace_name
824
  )
825
WHERE
826
  tablespace_name = free_tablespace_name;
827
EOF
828
}
829

    
830
getfield_asmusage() {
831
    data_attrs[$module]="$( ${sqlplus} ${sqlplus_opts} "${oracle_auth}" <<EOF
832
${sqlplus_variables}
833
SELECT
834
  REGEXP_REPLACE( name, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) ||
835
  ' GAUGE LINE ' || '''' || name || ''''
836
FROM
837
  v\$asm_diskgroup
838
ORDER BY
839
  name;
840
EOF
841
)"
842
}
843

    
844
getvalue_asmusage() {
845
    ${sqlplus} ${sqlplus_opts} "${oracle_auth}" <<EOF
846
${sqlplus_variables}
847
SELECT
848
  REGEXP_REPLACE( name, '^[^A-Za-z_]|[^A-Za-z0-9_]', '_' ) || '.value ' ||
849
  ROUND( ( total_mb - free_mb ) / total_mb * 100 )
850
FROM
851
  v\$asm_diskgroup
852
ORDER BY
853
  name;
854
EOF
855
}
856

    
857
# main
858
case ${1:-} in
859
autoconf)
860
    autoconf
861
    ;;
862
suggest)
863
    suggest
864
    ;;
865
config)
866
    getfield
867
    config
868
    ;;
869
*)
870
    getvalue
871
    ;;
872
esac
873

    
874
exit 0