-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbstatus.pike
21 lines (21 loc) · 971 Bytes
/
dbstatus.pike
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//Reformat raw output from psql into a nice database status display
//See: ./dbctl stat
int main() {
string data = Stdio.stdin->read();
sscanf(data, "%s\n%s\n%s\n%s", string readonly, string active, string replpid, string clients);
int ro = readonly == "on";
write("* Database is %s\n", ro ? "\e[1;34mread-only\e[0m" : "\e[1;32mread/write\e[0m");
write("* Active bot is on \e[1;36m%s\e[0m\n", active);
write("* Incoming replication %sactive\e[0m\n", (int)replpid ? "" : "\e[1;31min");
foreach (clients / "\n", string cli) {
if (cli == "") continue;
[string client_addr, string application_name, string xact_start, string state] = cli / "|";
string lbl = ([
"multihome": "Outgoing replication",
"stillebot": ro ? "\e[1;31m!! Active bot !!\e[0m" : "Active bot",
"stillebot-ro": "Read-only bot",
"stillebot-stat": "Gathering stats",
])[application_name] || application_name;
write("%14s %s [%s] %s\n", client_addr, lbl, state, xact_start);
}
}