-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathResmonOracle.class.php
154 lines (136 loc) · 4.19 KB
/
ResmonOracle.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/**
* Resmon PHP class for pulling Oracle metrics
*
* Extension of the base Resmon class. Currently supports following
* metric types:
*
* - contents of the (G)V$SYSSTAT view
*
*
* See the Resmon project website for further info on the format:
* https://labs.omniti.com/labs/resmon
*
* Copyright (c) 2011 Michal Taborsky
* See LICENSE file for licensing info
*
* @author Michal Taborsky <[email protected]>
*
*/
class ResmonOracle extends Resmon {
protected $db;
protected $RAC = false;
protected $viewPrefix = 'V$';
protected $semaphore = array ();
/**
* Class constructor
*
* @param string $username Oracle user to connect as, must have privileges to querid tables
* @param string $password Oracle password
* @param string $connectString Oracle connec string (TNS name prefferably)
* @param boolean $isRAC Set to true if this is a RAC environment (default: false)
*/
public function __construct($username, $password, $connectString, $isRAC = false) {
$tstart = microtime ( true );
$this->db = @oci_connect ( $username, $password, $connectString );
$tconnected = microtime ( true );
$this->setModule ( 'Oracle::Core' );
$this->setService ( 'local' );
if ($this->db) {
$this->addMetric ( 'connect_time', ($tconnected - $tstart) * 1000, self::TYPE_UNSIGNED_INT );
$this->setState ( self::STATE_OK );
} else {
$this->setState ( self::STATE_BAD );
}
$this->RAC = $isRAC;
if ($isRAC) {
$this->viewPrefix = 'GV$';
} else {
$this->viewPrefix = 'V$';
}
}
/**
* Collect metrics from (G)V$SYSSTAT view
*
* @return boolean True on success, false on failure
*/
public function getSysStat() {
if (! $this->db) {
return false;
}
$tstart = microtime ( true );
$sql = "SELECT * FROM {$this->viewPrefix}SYSSTAT";
$stm = oci_parse ( $this->db, $sql );
$result = oci_execute ( $stm );
$tsysstat = microtime ( true );
$this->setModule ( 'Oracle::SysStat' );
$ok = false;
if ($result) {
$this->setService ( 'local' );
while ( $row = oci_fetch_assoc ( $stm ) ) {
if ($this->RAC) {
$this->setService ( 'Inst_' . $row ['INST_ID'] );
}
$this->addMetric ( $row ['NAME'], $row ['VALUE'], self::TYPE_LONGINT );
$this->setState ( self::STATE_OK );
$instances [$row ['INST_ID']] = true;
}
}
oci_free_statement ( $stm );
$this->setModule ( 'Oracle::Core' );
$this->setService ( 'local' );
$this->addMetric ( "sysstat_time", ($tsysstat - $tstart) * 1000, self::TYPE_UNSIGNED_INT );
if (empty ( $this->semaphore ['instances'] )) {
$this->addMetric ( "instances", count ( $instances ), Resmon::TYPE_INT );
$this->semaphore ['instances'] = true;
}
return true;
}
/**
* Collect metrics from DRCP pool stats
*
* @return boolean True on success, false on failure
*/
public function getDRCPStats() {
if (! $this->db) {
return false;
}
$tstart = microtime ( true );
$sql = "SELECT * FROM {$this->viewPrefix}CPOOL_STATS";
$stm = oci_parse ( $this->db, $sql );
$result = @oci_execute ( $stm );
$tend = microtime ( true );
$this->setModule ( 'Oracle::DRCP' );
$ok = false;
if ($result) {
$this->setService ( 'local' );
while ( $row = oci_fetch_assoc ( $stm ) ) {
if ($this->RAC) {
$this->setService ( 'Inst_' . $row ['INST_ID'] );
}
foreach ( $row as $col => $val ) {
if ($col != 'POOL_NAME' && $col != 'INST_ID' && ! is_numeric ( $col )) {
$this->addMetric ( $col, $val, self::TYPE_LONGINT );
}
}
$ok = true;
$this->setState ( self::STATE_OK );
$instances [$row ['INST_ID']] = true;
}
$this->setModule ( 'Oracle::Core' );
$this->setService ( 'local' );
$this->addMetric ( "drcp_time", ($tend - $tstart) * 1000, self::TYPE_UNSIGNED_INT );
if (empty ( $this->semaphore ['instances'] )) {
$this->addMetric ( "instances", count ( $instances ), Resmon::TYPE_INT );
$this->semaphore ['instances'] = true;
}
}
oci_free_statement ( $stm );
return true;
}
public function __destruct() {
if ($this->db) {
oci_close ( $this->db );
}
}
}