-
Notifications
You must be signed in to change notification settings - Fork 11
/
postgres_stats.h
182 lines (170 loc) · 4.4 KB
/
postgres_stats.h
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#ifndef _POSTGRES_STATS_H_
#define _POSTGRES_STATS_H_
typedef enum PgBackendType
{
PG_UNDEFINED = -1,
PG_UNKNOWN = 0,
PG_AUTOVAC_LAUNCHER,
PG_AUTOVAC_WORKER,
PG_BACKEND,
PG_BG_WORKER,
PG_BG_WRITER,
PG_CHECKPOINTER,
PG_STARTUP,
PG_WAL_RECEIVER,
PG_WAL_SENDER,
PG_WAL_WRITER,
PG_ARCHIVER,
PG_STATS_COLLECTOR,
PG_LOGGER,
PG_STANDALONE_BACKEND,
PG_SLOTSYNC_WORKER,
PG_WAL_SUMMARIZER,
PG_PARALLEL_WORKER,
PG_LOGICAL_LAUNCHER,
PG_LOGICAL_TABLESYNC_WORKER,
PG_LOGICAL_APPLY_WORKER,
PG_LOGICAL_PARALLEL_WORKER
} PgBackendType;
#define UNKNOWN_NAME "not initialized"
#define AUTOVAC_LAUNCHER_PROC_NAME "autovacuum launcher"
#define AUTOVAC_WORKER_PROC_NAME "autovacuum worker"
#define BACKEND_PROC_NAME "backend"
#define STANDALONE_BACKEND_PROC_NAME "standalone backend"
#define SLOTSYNC_WORKER_PROC_NAME "slotsync worker"
#define WAL_SUMMARIZER_PROC_NAME "walsummarizer"
#define BG_WRITER_NAME "bgwriter"
#define CHECKPOINTER_PROC_NAME "checkpointer"
#define STARTUP_PROC_NAME "startup"
#define WAL_RECEIVER_NAME "walreceiver"
#define WAL_SENDER_NAME "walsender"
#define WAL_WRITER_NAME "walwriter"
#define ARCHIVER_PROC_NAME "archiver"
#define LOGGER_PROC_NAME "logger"
#define STATS_COLLECTOR_PROC_NAME "stats collector"
#define PARALLEL_WORKER_NAME "parallel worker"
#define LOGICAL_LAUNCHER_NAME "logical replication launcher"
#define LOGICAL_TABLESYNC_WORKER_NAME "logical replication tablesync worker"
#define LOGICAL_APPLY_WORKER_NAME "logical replication apply worker"
#define LOGICAL_PARALLEL_WORKER_NAME "logical replication parallel worker"
typedef struct {
bool available;
unsigned long long read_bytes;
unsigned long read_diff;
unsigned long long write_bytes;
unsigned long write_diff;
unsigned long long cancelled_write_bytes;
unsigned long cancelled_write_diff;
} proc_io;
typedef struct {
int fields;
pid_t pid; // (1)
char state; // (3)
pid_t ppid; // (4)
unsigned long utime; // (14)
double utime_diff;
unsigned long stime; // (15)
double stime_diff;
long priority; // (18)
unsigned long long start_time; // (22)
unsigned long vsize; // (23)
long rss; // (24)
unsigned long long delayacct_blkio_ticks; // (42)
unsigned long delayacct_blkio_ticks_diff;
unsigned long gtime; // (43)
double gtime_diff;
unsigned long long uss;
char *cmdline;
bool free_cmdline;
proc_io io;
} proc_stat;
typedef struct {
pid_t pid;
Oid databaseid;
Oid userid;
char *datname;
char *usename;
double age;
double idle_in_transaction_age;
PgBackendType type;
BackendState state;
bool is_blocker;
uintptr_t blockers;
uint32 num_blockers;
pid_t parent_pid;
uint32 raw_wait_event;
char *query;
proc_stat ps;
} pg_stat_activity;
typedef struct {
bool is_wal_replay_paused;
TimestampTz last_xact_replay_timestamp;
XLogRecPtr last_wal_replay_lsn;
XLogRecPtr current_wal_lsn;
XLogRecPtr last_wal_receive_lsn;
int64 current_diff;
int64 receive_diff;
int64 replay_diff;
} wal_metrics;
typedef struct {
pg_stat_activity *values;
size_t size;
size_t pos;
int total_connections;
int active_connections;
int idle_in_transaction_connections;
} pg_stat_activity_list;
typedef struct {
Oid databaseid;
char *datname;
int64 n_xact_commit;
int64 n_xact_commit_diff;
int64 n_xact_rollback;
int64 n_xact_rollback_diff;
int64 n_blocks_fetched;
int64 n_blocks_fetched_diff;
int64 n_blocks_hit;
int64 n_blocks_hit_diff;
int64 n_tuples_returned;
int64 n_tuples_returned_diff;
int64 n_tuples_fetched;
int64 n_tuples_fetched_diff;
int64 n_tuples_updated;
int64 n_tuples_updated_diff;
int64 n_tuples_inserted;
int64 n_tuples_inserted_diff;
int64 n_tuples_deleted;
int64 n_tuples_deleted_diff;
int64 n_conflict_tablespace;
int64 n_conflict_lock;
int64 n_conflict_snapshot;
int64 n_conflict_bufferpin;
int64 n_conflict_startup_deadlock;
int64 n_temp_files;
int64 n_temp_files_diff;
int64 n_temp_bytes;
int64 n_temp_bytes_diff;
int64 n_deadlocks;
int64 n_checksum_failures;
TimestampTz last_checksum_failure;
int64 n_block_read_time; /* times in microseconds */
double n_block_read_time_diff;
int64 n_block_write_time;
double n_block_write_time_diff;
} db_stat;
typedef struct {
db_stat *values;
size_t size;
size_t pos;
bool track_io_timing;
} db_stat_list;
typedef struct {
unsigned long long uptime;
bool recovery_in_progress;
pg_stat_activity_list activity;
db_stat_list db;
wal_metrics wal_metrics;
} pg_stat;
void postgres_stats_init(void);
pg_stat get_postgres_stats(void);
#endif /* _POSTGRES_STATS_H_ */