master
go 321 lines 11.5 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 //go:build cgo
4
5 package db2
6
7 type metricsData struct {
8 // Database Overview metrics (Screen 01)
9 DatabaseStatusActive int64 `stm:"database_status_active"`
10 DatabaseStatusInactive int64 `stm:"database_status_inactive"`
11 DatabaseCountActive int64 `stm:"database_count_active"`
12 DatabaseCountInactive int64 `stm:"database_count_inactive"`
13 CPUUser int64 `stm:"cpu_user"`
14 CPUSystem int64 `stm:"cpu_system"`
15 CPUIdle int64 `stm:"cpu_idle"`
16 CPUIowait int64 `stm:"cpu_iowait"`
17 ConnectionsActive int64 `stm:"connections_active"`
18 ConnectionsTotal int64 `stm:"connections_total"`
19 MemoryDatabaseCommitted int64 `stm:"memory_database_committed"`
20 MemoryInstanceCommitted int64 `stm:"memory_instance_committed"`
21 MemoryBufferpoolUsed int64 `stm:"memory_bufferpool_used"`
22 MemorySharedSortUsed int64 `stm:"memory_shared_sort_used"`
23 OpsSelectStmts int64 `stm:"ops_select_stmts"`
24 OpsUIDStmts int64 `stm:"ops_uid_stmts"`
25 OpsTransactions int64 `stm:"ops_transactions"`
26 OpsActivitiesAborted int64 `stm:"ops_activities_aborted"`
27 TimeAvgDirectRead int64 `stm:"time_avg_direct_read"`
28 TimeAvgDirectWrite int64 `stm:"time_avg_direct_write"`
29 TimeAvgPoolRead int64 `stm:"time_avg_pool_read"`
30 TimeAvgPoolWrite int64 `stm:"time_avg_pool_write"`
31
32 // Enhanced logging metrics (Screen 18)
33 LogCommits int64 `stm:"log_commits"`
34 LogRollbacks int64 `stm:"log_rollbacks"`
35 LogBufferFullEvents int64 `stm:"log_buffer_full_events"`
36 LogAvgCommitTime int64 `stm:"log_avg_commit_time"`
37 LogAvgReadTime int64 `stm:"log_avg_read_time"`
38 LogAvgWriteTime int64 `stm:"log_avg_write_time"`
39
40 // Federation metrics (Screen 32)
41 FedConnectionsActive int64 `stm:"fed_connections_active"`
42 FedConnectionsIdle int64 `stm:"fed_connections_idle"`
43 FedRowsRead int64 `stm:"fed_rows_read"`
44 FedSelectStmts int64 `stm:"fed_select_stmts"`
45 FedWaitsTotal int64 `stm:"fed_waits_total"`
46
47 // Connection metrics
48 ConnTotal int64 `stm:"conn_total"`
49 ConnActive int64 `stm:"conn_active"`
50 ConnExecuting int64 `stm:"conn_executing"`
51 ConnIdle int64 `stm:"conn_idle"`
52 ConnMax int64 `stm:"conn_max"`
53
54 // Lock metrics
55 LockWaits int64 `stm:"lock_waits"`
56 LockTimeouts int64 `stm:"lock_timeouts"`
57 Deadlocks int64 `stm:"deadlocks"`
58 LockEscalations int64 `stm:"lock_escalations"`
59 LockActive int64 `stm:"lock_active"`
60 LockWaitTime int64 `stm:"lock_wait_time"`
61 LockWaitingAgents int64 `stm:"lock_waiting_agents"`
62 LockMemoryPages int64 `stm:"lock_memory_pages"`
63
64 // Sort metrics
65 TotalSorts int64 `stm:"total_sorts"`
66 SortOverflows int64 `stm:"sort_overflows"`
67
68 // Row metrics
69 RowsRead int64 `stm:"rows_read"`
70 RowsModified int64 `stm:"rows_modified"`
71 RowsReturned int64 `stm:"rows_returned"`
72
73 // Buffer pool hit/miss metrics for percentage-of-incremental-row
74 BufferpoolHits int64 `stm:"bufferpool_hits"`
75 BufferpoolMisses int64 `stm:"bufferpool_misses"`
76 BufferpoolDataHits int64 `stm:"bufferpool_data_hits"`
77 BufferpoolDataMisses int64 `stm:"bufferpool_data_misses"`
78 BufferpoolIndexHits int64 `stm:"bufferpool_index_hits"`
79 BufferpoolIndexMisses int64 `stm:"bufferpool_index_misses"`
80 BufferpoolXDAHits int64 `stm:"bufferpool_xda_hits"`
81 BufferpoolXDAMisses int64 `stm:"bufferpool_xda_misses"`
82 BufferpoolColumnHits int64 `stm:"bufferpool_column_hits"`
83 BufferpoolColumnMisses int64 `stm:"bufferpool_column_misses"`
84 BufferpoolLogicalReads int64 `stm:"bufferpool_logical_reads"`
85 BufferpoolPhysicalReads int64 `stm:"bufferpool_physical_reads"`
86 BufferpoolTotalReads int64 // No stm tag - calculated field
87
88 // Detailed buffer pool read metrics
89 BufferpoolDataLogicalReads int64 `stm:"bufferpool_data_logical_reads"`
90 BufferpoolDataPhysicalReads int64 `stm:"bufferpool_data_physical_reads"`
91 BufferpoolDataTotalReads int64 // No stm tag - calculated field
92 BufferpoolIndexLogicalReads int64 `stm:"bufferpool_index_logical_reads"`
93 BufferpoolIndexPhysicalReads int64 `stm:"bufferpool_index_physical_reads"`
94 BufferpoolIndexTotalReads int64 // No stm tag - calculated field
95 BufferpoolXDALogicalReads int64 `stm:"bufferpool_xda_logical_reads"`
96 BufferpoolXDAPhysicalReads int64 `stm:"bufferpool_xda_physical_reads"`
97 BufferpoolXDATotalReads int64 // No stm tag - calculated field
98 BufferpoolColumnLogicalReads int64 `stm:"bufferpool_column_logical_reads"`
99 BufferpoolColumnPhysicalReads int64 `stm:"bufferpool_column_physical_reads"`
100 BufferpoolColumnTotalReads int64 // No stm tag - calculated field
101
102 // Write metrics
103 BufferpoolWrites int64 `stm:"bufferpool_writes"`
104
105 // Log metrics
106 LogUsedSpace int64 `stm:"log_used_space"`
107 LogAvailableSpace int64 `stm:"log_available_space"`
108 LogUtilization int64 `stm:"log_utilization"`
109 LogIOReads int64 `stm:"log_io_reads"`
110 LogIOWrites int64 `stm:"log_io_writes"`
111 LogOpReads int64 `stm:"log_op_reads"`
112 LogOpWrites int64 `stm:"log_op_writes"`
113
114 // Query metrics
115 LongRunningQueries int64 `stm:"long_running_queries"`
116 LongRunningQueriesWarning int64 `stm:"long_running_queries_warning"`
117 LongRunningQueriesCritical int64 `stm:"long_running_queries_critical"`
118
119 // Backup metrics
120 LastBackupStatus int64 `stm:"last_backup_status"`
121 LastFullBackupAge int64 `stm:"last_full_backup_age"`
122 LastIncrementalBackupAge int64 `stm:"last_incremental_backup_age"`
123
124 // Service health checks
125 CanConnect int64 `stm:"can_connect"`
126 DatabaseStatus int64 `stm:"database_status"`
127
128 databases map[string]databaseInstanceMetrics
129 bufferpools map[string]bufferpoolInstanceMetrics
130 tablespaces map[string]tablespaceInstanceMetrics
131 connections map[string]connectionInstanceMetrics
132 tables map[string]tableInstanceMetrics
133 indexes map[string]indexInstanceMetrics
134 memoryPools map[string]memoryPoolInstanceMetrics
135 tableIOs map[string]tableIOInstanceMetrics
136 memorySets map[string]memorySetInstanceMetrics
137 prefetchers map[string]prefetcherInstanceMetrics
138 }
139
140 type databaseMetrics struct {
141 name string
142 status string
143 applications int64
144 }
145
146 type bufferpoolMetrics struct {
147 name string
148 pageSize int64
149 }
150
151 type tablespaceMetrics struct {
152 name string
153 tbspType string
154 contentType string
155 state string
156 }
157
158 type connectionMetrics struct {
159 applicationID string
160 applicationName string
161 clientHostname string
162 clientIP string
163 clientUser string
164 connectionState string
165 }
166
167 type tableMetrics struct {
168 name string
169 ioUpdated bool
170 }
171
172 type indexMetrics struct {
173 name string
174 }
175
176 type memoryPoolMetrics struct {
177 poolType string
178 updated bool
179 }
180
181 func (c *Collector) getTableMetrics(name string) *tableMetrics {
182 if _, ok := c.tables[name]; !ok {
183 c.tables[name] = &tableMetrics{name: name}
184 }
185 return c.tables[name]
186 }
187
188 func (c *Collector) getIndexMetrics(name string) *indexMetrics {
189 if _, ok := c.indexes[name]; !ok {
190 c.indexes[name] = &indexMetrics{name: name}
191 }
192 return c.indexes[name]
193 }
194
195 type databaseInstanceMetrics struct {
196 Status int64 `stm:"status"`
197 Applications int64 `stm:"applications"`
198 }
199
200 type bufferpoolInstanceMetrics struct {
201 // Basic metrics
202 PageSize int64 // No stm tag - used for labels only
203 TotalPages int64 `stm:"total_pages"`
204 UsedPages int64 `stm:"used_pages"`
205
206 // Hit/miss metrics for percentage-of-incremental-row
207 Hits int64 `stm:"hits"`
208 Misses int64 `stm:"misses"`
209 DataHits int64 `stm:"data_hits"`
210 DataMisses int64 `stm:"data_misses"`
211 IndexHits int64 `stm:"index_hits"`
212 IndexMisses int64 `stm:"index_misses"`
213 XDAHits int64 `stm:"xda_hits"`
214 XDAMisses int64 `stm:"xda_misses"`
215 ColumnHits int64 `stm:"column_hits"`
216 ColumnMisses int64 `stm:"column_misses"`
217
218 // Read metrics
219 LogicalReads int64 `stm:"logical_reads"`
220 PhysicalReads int64 `stm:"physical_reads"`
221 TotalReads int64 // No stm tag - calculated field
222 DataLogicalReads int64 `stm:"data_logical_reads"`
223 DataPhysicalReads int64 `stm:"data_physical_reads"`
224 IndexLogicalReads int64 `stm:"index_logical_reads"`
225 IndexPhysicalReads int64 `stm:"index_physical_reads"`
226 XDALogicalReads int64 `stm:"xda_logical_reads"`
227 XDAPhysicalReads int64 `stm:"xda_physical_reads"`
228 ColumnLogicalReads int64 `stm:"column_logical_reads"`
229 ColumnPhysicalReads int64 `stm:"column_physical_reads"`
230
231 // Write metrics
232 Writes int64 `stm:"writes"`
233 }
234
235 type tablespaceInstanceMetrics struct {
236 State int64 `stm:"state"`
237 TotalSize int64 `stm:"total_size"`
238 UsedSize int64 `stm:"used_size"`
239 FreeSize int64 `stm:"free_size"`
240 UsableSize int64 `stm:"usable_size"`
241 UsedPercent int64 `stm:"used_percent"`
242 PageSize int64 // No stm tag - used for labels only
243 }
244
245 type connectionInstanceMetrics struct {
246 State int64 `stm:"state"`
247 ExecutingQueries int64 `stm:"executing_queries"`
248 RowsRead int64 `stm:"rows_read"`
249 RowsWritten int64 `stm:"rows_written"`
250 TotalCPUTime int64 `stm:"total_cpu_time"`
251
252 // Wait time metrics (DB2 9.7+ LUW with MON_GET_CONNECTION)
253 // TotalWaitTime is not charted but collected for reference
254 TotalWaitTime int64 // No stm tag - not sent to netdata
255 LockWaitTime int64 `stm:"lock_wait_time"`
256 LogDiskWaitTime int64 `stm:"log_disk_wait_time"`
257 LogBufferWaitTime int64 `stm:"log_buffer_wait_time"`
258 PoolReadTime int64 `stm:"pool_read_time"`
259 PoolWriteTime int64 `stm:"pool_write_time"`
260 DirectReadTime int64 `stm:"direct_read_time"`
261 DirectWriteTime int64 `stm:"direct_write_time"`
262 FCMRecvWaitTime int64 `stm:"fcm_recv_wait_time"`
263 FCMSendWaitTime int64 `stm:"fcm_send_wait_time"`
264 TotalRoutineTime int64 `stm:"total_routine_time"`
265 TotalCompileTime int64 `stm:"total_compile_time"`
266 TotalSectionTime int64 `stm:"total_section_time"`
267 TotalCommitTime int64 `stm:"total_commit_time"`
268 TotalRollbackTime int64 `stm:"total_rollback_time"`
269 }
270
271 type tableInstanceMetrics struct {
272 DataSize int64 `stm:"data_size"`
273 IndexSize int64 `stm:"index_size"`
274 LongObjSize int64 `stm:"long_obj_size"`
275 RowsRead int64 `stm:"rows_read"`
276 RowsWritten int64 `stm:"rows_written"`
277 }
278
279 type indexInstanceMetrics struct {
280 LeafNodes int64 `stm:"leaf_nodes"`
281 IndexScans int64 `stm:"index_scans"`
282 FullScans int64 `stm:"full_scans"`
283 }
284
285 type memoryPoolInstanceMetrics struct {
286 PoolUsed int64 `stm:"used"`
287 PoolUsedHWM int64 `stm:"hwm"`
288 }
289
290 type tableIOInstanceMetrics struct {
291 TableScans int64 `stm:"scans"`
292 RowsRead int64 `stm:"read"`
293 RowsInserted int64 `stm:"inserts"`
294 RowsUpdated int64 `stm:"updates"`
295 RowsDeleted int64 `stm:"deletes"`
296 OverflowAccesses int64 `stm:"overflow_accesses"`
297 }
298
299 type memorySetInstanceMetrics struct {
300 // Screen 26: Instance Memory Sets metrics
301 Used int64 `stm:"used"` // MEMORY_SET_USED
302 Committed int64 `stm:"committed"` // MEMORY_SET_COMMITTED
303 HighWaterMark int64 `stm:"high_water_mark"` // MEMORY_SET_USED_HWM
304 AdditionalCommitted int64 `stm:"additional_committed"` // MEMORY_SET_COMMITTED - MEMORY_SET_USED
305 PercentUsedHWM int64 `stm:"percent_used_hwm"` // (MEMORY_SET_USED * 100) / MEMORY_SET_USED_HWM
306
307 // Metadata
308 hostName string
309 dbName string
310 setType string
311 member int64
312 }
313
314 type prefetcherInstanceMetrics struct {
315 PrefetchRatio int64 `stm:"prefetch_ratio"`
316 CleanerRatio int64 `stm:"cleaner_ratio"`
317 PhysicalReads int64 `stm:"physical_reads"`
318 AsyncReads int64 `stm:"async_reads"`
319 UnreadPages int64 `stm:"unread_pages"`
320 AvgWaitTime int64 `stm:"avg_wait_time"`
321 }