Projet

Général

Profil

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

root / plugins / oracle / oracle_sysstat_ @ fe8908c3

Historique | Voir | Annoter | Télécharger (21,8 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 -S -L}"
468
sqlplus_variables="
469
    set pagesize 0
470
    set feed off
471
    set head off
472
    set linesize 256
473
    set numwidth 20
474
"
475

    
476
# functions 
477

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

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

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

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

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

    
511
    echo graph_order "${fields[@]}"
512
}
513

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
873
exit 0