master
go 231 lines 5.41 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package postgres
4
5 import "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/oldmetrix"
6
7 type pgMetrics struct {
8 srvMetrics
9 dbs map[string]*dbMetrics
10 tables map[string]*tableMetrics
11 indexes map[string]*indexMetrics
12 replApps map[string]*replStandbyAppMetrics
13 replSlots map[string]*replSlotMetrics
14 }
15
16 type srvMetrics struct {
17 xactTimeHist oldmetrix.Histogram
18 queryTimeHist oldmetrix.Histogram
19
20 maxConnections int64
21 maxLocksHeld int64
22
23 uptime int64
24
25 relkindOrdinaryTable int64
26 relkindIndex int64
27 relkindSequence int64
28 relkindTOASTTable int64
29 relkindView int64
30 relkindMatView int64
31 relkindCompositeType int64
32 relkindForeignTable int64
33 relkindPartitionedTable int64
34 relkindPartitionedIndex int64
35 relkindOrdinaryTableSize int64
36 relkindIndexSize int64
37 relkindSequenceSize int64
38 relkindTOASTTableSize int64
39 relkindViewSize int64
40 relkindMatViewSize int64
41 relkindCompositeTypeSize int64
42 relkindForeignTableSize int64
43 relkindPartitionedTableSize int64
44 relkindPartitionedIndexSize int64
45
46 connUsed int64
47 connStateActive int64
48 connStateIdle int64
49 connStateIdleInTrans int64
50 connStateIdleInTransAborted int64
51 connStateFastpathFunctionCall int64
52 connStateDisabled int64
53
54 checkpointsTimed int64
55 checkpointsReq int64
56 checkpointWriteTime int64
57 checkpointSyncTime int64
58 buffersCheckpoint int64
59 buffersClean int64
60 maxwrittenClean int64
61 buffersBackend int64
62 buffersBackendFsync int64
63 buffersAlloc int64
64
65 oldestXID int64
66 percentTowardsWraparound int64
67 percentTowardsEmergencyAutovacuum int64
68
69 walWrites int64
70 walRecycledFiles int64
71 walWrittenFiles int64
72 walArchiveFilesReady int64
73 walArchiveFilesDone int64
74
75 autovacuumWorkersAnalyze int64
76 autovacuumWorkersVacuumAnalyze int64
77 autovacuumWorkersVacuum int64
78 autovacuumWorkersVacuumFreeze int64
79 autovacuumWorkersBrinSummarize int64
80 }
81
82 type dbMetrics struct {
83 name string
84
85 updated bool
86 hasCharts bool
87
88 numBackends int64
89 datConnLimit int64
90 xactCommit int64
91 xactRollback int64
92 blksRead incDelta
93 blksHit incDelta
94 tupReturned incDelta
95 tupFetched incDelta
96 tupInserted int64
97 tupUpdated int64
98 tupDeleted int64
99 conflicts int64
100 tempFiles int64
101 tempBytes int64
102 deadlocks int64
103
104 size *int64 // need 'connect' privilege for pg_database_size()
105
106 conflTablespace int64
107 conflLock int64
108 conflSnapshot int64
109 conflBufferpin int64
110 conflDeadlock int64
111
112 accessShareLockHeld int64
113 rowShareLockHeld int64
114 rowExclusiveLockHeld int64
115 shareUpdateExclusiveLockHeld int64
116 shareLockHeld int64
117 shareRowExclusiveLockHeld int64
118 exclusiveLockHeld int64
119 accessExclusiveLockHeld int64
120 accessShareLockAwaited int64
121 rowShareLockAwaited int64
122 rowExclusiveLockAwaited int64
123 shareUpdateExclusiveLockAwaited int64
124 shareLockAwaited int64
125 shareRowExclusiveLockAwaited int64
126 exclusiveLockAwaited int64
127 accessExclusiveLockAwaited int64
128 }
129
130 type replStandbyAppMetrics struct {
131 name string
132
133 updated bool
134 hasCharts bool
135
136 walSentDelta int64
137 walWriteDelta int64
138 walFlushDelta int64
139 walReplayDelta int64
140
141 walWriteLag int64
142 walFlushLag int64
143 walReplayLag int64
144 }
145
146 type replSlotMetrics struct {
147 name string
148
149 updated bool
150 hasCharts bool
151
152 walKeep int64
153 files int64
154 }
155
156 type tableMetrics struct {
157 name string
158 parentName string
159 db string
160 schema string
161
162 updated bool
163 hasCharts bool
164 hasLastAutoVacuumChart bool
165 hasLastVacuumChart bool
166 hasLastAutoAnalyzeChart bool
167 hasLastAnalyzeChart bool
168 hasTableIOCharts bool
169 hasTableIdxIOCharts bool
170 hasTableTOASTIOCharts bool
171 hasTableTOASTIdxIOCharts bool
172
173 // pg_stat_user_tables
174 seqScan int64
175 seqTupRead int64
176 idxScan int64
177 idxTupFetch int64
178 nTupIns int64
179 nTupUpd incDelta
180 nTupDel int64
181 nTupHotUpd incDelta
182 nLiveTup int64
183 nDeadTup int64
184 lastVacuumAgo int64
185 lastAutoVacuumAgo int64
186 lastAnalyzeAgo int64
187 lastAutoAnalyzeAgo int64
188 vacuumCount int64
189 autovacuumCount int64
190 analyzeCount int64
191 autoAnalyzeCount int64
192
193 // pg_statio_user_tables
194 heapBlksRead incDelta
195 heapBlksHit incDelta
196 idxBlksRead incDelta
197 idxBlksHit incDelta
198 toastBlksRead incDelta
199 toastBlksHit incDelta
200 tidxBlksRead incDelta
201 tidxBlksHit incDelta
202
203 totalSize int64
204
205 bloatSize *int64 // need 'SELECT' access to the table
206 bloatSizePerc *int64 // need 'SELECT' access to the table
207 nullColumns *int64 // need 'SELECT' access to the table
208 }
209
210 type indexMetrics struct {
211 name string
212 db string
213 schema string
214 table string
215 parentTable string
216
217 updated bool
218 hasCharts bool
219
220 idxScan int64
221 idxTupRead int64
222 idxTupFetch int64
223
224 size int64
225
226 bloatSize *int64 // need 'SELECT' access to the table
227 bloatSizePerc *int64 // need 'SELECT' access to the table
228 }
229 type incDelta struct{ prev, last int64 }
230
231 func (pc *incDelta) delta() int64 { return pc.last - pc.prev }