-
Notifications
You must be signed in to change notification settings - Fork 13
/
nodeStatus.php
138 lines (117 loc) · 4.75 KB
/
nodeStatus.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
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Node status of pgpool
*
* PHP versions 4 and 5
*
* LICENSE: Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that copyright notice and this permission
* notice appear in supporting documentation, and that the name of the
* author not be used in advertising or publicity pertaining to
* distribution of the software without specific, written prior
* permission. The author makes no representations about the
* suitability of this software for any purpose. It is provided "as
* is" without express or implied warranty.
*
* @author Ryuma Ando <ando@ecomas.co.jp>
* @copyright 2003-2013 PgPool Global Development Group
* @version SVN: $Id$
*/
require_once('common.php');
require_once('command.php');
/* --------------------------------------------------------------------- */
/* nodeStatus.php */
/* --------------------------------------------------------------------- */
// Check login status
if (!isset($_SESSION[SESSION_LOGIN_USER])) {
exit();
}
// select buttons to each nodes depending on their status
$isParallelMode = isParallelMode();
$isReplicationMode = isReplicationMode();
$isMasterSlaveMode = isMasterSlaveMode();
$configValue = readConfigParams(array('backend_hostname', 'backend_port'));
if (!isset($configValue['backend_hostname'])) { return; }
$backends_in_conf = $configValue['backend_hostname'];
// Get nodes' status
$nodeCount = NULL;
$is_pgpool_running = DoesPgpoolPidExist();
if ($is_pgpool_running) {
$nodeCount = getNodeCount();
}
$has_not_loaded_node = FALSE;
// Merge backends in pgpool.conf and them in pgpool
// ex) when remove a backend but not reload yet
if (count($backends_in_conf) < $nodeCount) {
for ($i = 0; $i < $nodeCount; $i++) {
$backends_in_conf[$i] = array();
}
}
$nodeInfo = array();
foreach ($backends_in_conf as $i => $backend) {
// Set buttons
$nodeInfo[$i]['return'] = FALSE;
$nodeInfo[$i]['disconnect'] = FALSE;
$nodeInfo[$i]['promote'] = FALSE;
$nodeInfo[$i]['recovery'] = FALSE;
// The flag if postgres is active or sleeping
$nodeInfo[$i]['is_active'] = NodeActive($i);
// nodes recognized by pgpool
if ($nodeCount != NULL/* && $i < $nodeCount*/) {
// Get info by pcp_node_info
$nodeInfo[$i] += getNodeInfo($i);
// Get the result of "SELECT pg_is_in_recovery()" as integer(0, 1, -1)
// (If pgpool don't act in Master/Slave & SR mode, this value will be ignored.)
$nodeInfo[$i]['is_standby'] = NodeStandby($i);
switch($nodeInfo[$i]['status']) {
case NODE_ACTIVE_NO_CONNECT:
case NODE_ACTIVE_CONNECTED:
if ($isReplicationMode || $isMasterSlaveMode) {
if ($nodeInfo[$i]['is_active']) {
$nodeInfo[$i]['disconnect'] = TRUE;
}
}
// pcp_promote_node exists after V3.1
if (hasPcpPromote() && useStreaming()) {
$nodeInfo[$i]['promote'] = TRUE;
}
break;
case NODE_DOWN:
if ($isReplicationMode || $isMasterSlaveMode) {
if ($nodeInfo[$i]['is_active']) {
$nodeInfo[$i]['return'] = TRUE;
} else {
$nodeInfo[$i]['recovery'] = TRUE;
}
}
break;
}
// nodes not working as backend (just written in pgpool.conf)
} else {
$has_not_loaded_node = TRUE;
$nodeInfo[$i]['hostname'] = $configValue['backend_hostname'][$i];
$nodeInfo[$i]['port'] = $configValue['backend_port'][$i];
$nodeInfo[$i]['weight'] = 0;
$nodeInfo[$i]['status'] = NODE_NOT_LOADED;
$nodeInfo[$i]['is_standby'] = NULL;
}
}
// Set vars
$tpl->assign('help', basename( __FILE__, '.php'));
$tpl->assign('refreshTime', _PGPOOL2_STATUS_REFRESH_TIME * 1000);
$tpl->assign('nodeInfo', $nodeInfo);
$tpl->assign('parallelMode', $isParallelMode);
$tpl->assign('msgStopPgpool', $message['msgStopPgpool']);
$tpl->assign('nodeCount', $nodeCount);
$tpl->assign('has_not_loaded_node', $has_not_loaded_node);
$tpl->assign('pgpoolIsRunning', $is_pgpool_running);
$tpl->assign('is_superuser', (isset($_SESSION[SESSION_IS_SUPER_USER])) ?
$_SESSION[SESSION_IS_SUPER_USER] : isSuperUser($_SESSION[SESSION_LOGIN_USER]));
// Set params
$configValue = readConfigParams('recovery_1st_stage');
$tpl->assign('params', $configValue);
// Display
$tpl->display('nodeStatus.tpl');