| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | //go:build cgo |
| 4 | |
| 5 | package as400 |
| 6 | |
| 7 | type metricsData struct { |
| 8 | // CPU metrics from SYSTEM_STATUS() |
| 9 | CPUPercentage int64 `stm:"cpu_percentage"` // AVERAGE_CPU_UTILIZATION |
| 10 | CurrentCPUCapacity int64 `stm:"current_cpu_capacity"` // CURRENT_CPU_CAPACITY |
| 11 | ConfiguredCPUs int64 `stm:"configured_cpus"` // CONFIGURED_CPUS |
| 12 | EntitledCPUPercentage int64 `stm:"entitled_cpu_percentage"` |
| 13 | |
| 14 | // Memory metrics from SYSTEM_STATUS() |
| 15 | MainStorageSize int64 `stm:"main_storage_size"` // MAIN_STORAGE_SIZE (KB) |
| 16 | CurrentTemporaryStorage int64 `stm:"current_temporary_storage"` // CURRENT_TEMPORARY_STORAGE (MB) |
| 17 | MaximumTemporaryStorageUsed int64 `stm:"maximum_temporary_storage_used"` // MAXIMUM_TEMPORARY_STORAGE_USED (MB) |
| 18 | |
| 19 | // Job metrics from SYSTEM_STATUS() |
| 20 | TotalJobsInSystem int64 `stm:"total_jobs_in_system"` // TOTAL_JOBS_IN_SYSTEM |
| 21 | ActiveJobsInSystem int64 `stm:"active_jobs_in_system"` // ACTIVE_JOBS_IN_SYSTEM |
| 22 | InteractiveJobsInSystem int64 `stm:"interactive_jobs_in_system"` // INTERACTIVE_JOBS_IN_SYSTEM |
| 23 | BatchJobsRunning int64 `stm:"batch_jobs_running"` // BATCH_RUNNING |
| 24 | JobQueueLength int64 `stm:"job_queue_length"` // From JOB_INFO query |
| 25 | |
| 26 | // Storage metrics from SYSTEM_STATUS() |
| 27 | SystemASPUsed int64 `stm:"system_asp_used"` // SYSTEM_ASP_USED (percentage) |
| 28 | SystemASPStorage int64 `stm:"system_asp_storage"` // SYSTEM_ASP_STORAGE (MB) |
| 29 | TotalAuxiliaryStorage int64 `stm:"total_auxiliary_storage"` // TOTAL_AUXILIARY_STORAGE (MB) |
| 30 | |
| 31 | // Thread metrics from SYSTEM_STATUS() |
| 32 | ActiveThreadsInSystem int64 `stm:"active_threads_in_system"` // ACTIVE_THREADS_IN_SYSTEM |
| 33 | ThreadsPerProcessor int64 `stm:"threads_per_processor"` // THREADS_PER_PROCESSOR |
| 34 | |
| 35 | // Legacy job type breakdown (removed - no corresponding charts) |
| 36 | |
| 37 | // Memory pool metrics from MEMORY_POOL() |
| 38 | MachinePoolSize int64 `stm:"machine_pool_size"` |
| 39 | BasePoolSize int64 `stm:"base_pool_size"` |
| 40 | InteractivePoolSize int64 `stm:"interactive_pool_size"` |
| 41 | SpoolPoolSize int64 `stm:"spool_pool_size"` |
| 42 | |
| 43 | MachinePoolDefinedSize int64 `stm:"machine_pool_defined_size"` |
| 44 | MachinePoolReservedSize int64 `stm:"machine_pool_reserved_size"` |
| 45 | BasePoolDefinedSize int64 `stm:"base_pool_defined_size"` |
| 46 | BasePoolReservedSize int64 `stm:"base_pool_reserved_size"` |
| 47 | |
| 48 | // Memory pool thread metrics (if available) |
| 49 | MachinePoolThreads int64 `stm:"machine_pool_threads"` // CURRENT_THREADS |
| 50 | MachinePoolMaxThreads int64 `stm:"machine_pool_max_threads"` // MAXIMUM_ACTIVE_THREADS |
| 51 | BasePoolThreads int64 `stm:"base_pool_threads"` |
| 52 | BasePoolMaxThreads int64 `stm:"base_pool_max_threads"` |
| 53 | |
| 54 | // Aggregate disk metrics |
| 55 | DiskBusyPercentage int64 `stm:"disk_busy_percentage"` |
| 56 | |
| 57 | // Network metrics from NETSTAT_INFO |
| 58 | RemoteConnections int64 `stm:"remote_connections"` // Count of established remote connections |
| 59 | TotalConnections int64 `stm:"total_connections"` // Total TCP connections |
| 60 | ListenConnections int64 `stm:"listen_connections"` // Connections in LISTEN state |
| 61 | CloseWaitConnections int64 `stm:"closewait_connections"` // Connections in CLOSE_WAIT state |
| 62 | |
| 63 | // Temporary storage from SYSTMPSTG |
| 64 | TempStorageCurrentTotal int64 `stm:"temp_storage_current_total"` // Total current temp storage |
| 65 | TempStoragePeakTotal int64 `stm:"temp_storage_peak_total"` // Total peak temp storage |
| 66 | |
| 67 | // Per-instance metrics (not included in stm) |
| 68 | disks map[string]diskInstanceMetrics |
| 69 | subsystems map[string]subsystemInstanceMetrics |
| 70 | jobQueues map[string]jobQueueInstanceMetrics |
| 71 | messageQueues map[string]messageQueueInstanceMetrics |
| 72 | outputQueues map[string]outputQueueInstanceMetrics |
| 73 | tempStorageNamed map[string]tempStorageInstanceMetrics |
| 74 | activeJobs map[string]activeJobInstanceMetrics |
| 75 | networkInterfaces map[string]networkInterfaceInstanceMetrics |
| 76 | httpServers map[string]httpServerInstanceMetrics |
| 77 | planCache map[string]planCacheInstanceMetrics |
| 78 | systemActivity systemActivityMetrics |
| 79 | |
| 80 | queryLatencies map[string]int64 `stm:"-"` |
| 81 | } |
| 82 | |
| 83 | // Per-instance metric structures for stm conversion |
| 84 | type diskInstanceMetrics struct { |
| 85 | BusyPercent int64 `stm:"busy_percent"` |
| 86 | ReadRequests int64 `stm:"read_requests"` |
| 87 | WriteRequests int64 `stm:"write_requests"` |
| 88 | PercentUsed int64 `stm:"percent_used"` // PERCENT_USED |
| 89 | AvailableGB int64 `stm:"available_gb"` // UNIT_SPACE_AVAILABLE_GB |
| 90 | CapacityGB int64 // UNIT_STORAGE_CAPACITY - used only for calculation |
| 91 | UsedGB int64 `stm:"used_gb"` // Calculated: CapacityGB - AvailableGB |
| 92 | BlocksRead int64 `stm:"blocks_read"` // TOTAL_BLOCKS_READ |
| 93 | BlocksWritten int64 `stm:"blocks_written"` // TOTAL_BLOCKS_WRITTEN |
| 94 | SSDLifeRemaining int64 // SSD_LIFE_REMAINING - manually added to map when > 0 |
| 95 | SSDPowerOnDays int64 // SSD_POWER_ON_DAYS - manually added to map when > 0 |
| 96 | HardwareStatus string // HARDWARE_STATUS - for labels only |
| 97 | DiskModel string // DISK_MODEL - for labels only |
| 98 | SerialNumber string // SERIAL_NUMBER - for labels only |
| 99 | } |
| 100 | |
| 101 | type subsystemInstanceMetrics struct { |
| 102 | CurrentActiveJobs int64 `stm:"current_active_jobs"` // CURRENT_ACTIVE_JOBS |
| 103 | MaximumActiveJobs int64 `stm:"maximum_active_jobs"` // MAXIMUM_ACTIVE_JOBS |
| 104 | // Note: HELD_JOB_COUNT and STORAGE_USED_KB removed - columns don't exist in SUBSYSTEM_INFO table |
| 105 | } |
| 106 | |
| 107 | type jobQueueInstanceMetrics struct { |
| 108 | NumberOfJobs int64 `stm:"number_of_jobs"` // NUMBER_OF_JOBS |
| 109 | // Note: HELD_JOB_COUNT removed - column doesn't exist in JOB_QUEUE_INFO table |
| 110 | } |
| 111 | |
| 112 | type messageQueueInstanceMetrics struct { |
| 113 | Total int64 `stm:"total"` |
| 114 | Informational int64 `stm:"informational"` |
| 115 | Inquiry int64 `stm:"inquiry"` |
| 116 | Diagnostic int64 `stm:"diagnostic"` |
| 117 | Escape int64 `stm:"escape"` |
| 118 | Notify int64 `stm:"notify"` |
| 119 | SenderCopy int64 `stm:"sender_copy"` |
| 120 | MaxSeverity int64 `stm:"max_severity"` |
| 121 | } |
| 122 | |
| 123 | type outputQueueInstanceMetrics struct { |
| 124 | Files int64 `stm:"files"` |
| 125 | Writers int64 `stm:"writers"` |
| 126 | Released int64 `stm:"released"` |
| 127 | } |
| 128 | |
| 129 | type tempStorageInstanceMetrics struct { |
| 130 | CurrentSize int64 `stm:"current_size"` // BUCKET_CURRENT_SIZE |
| 131 | PeakSize int64 `stm:"peak_size"` // BUCKET_PEAK_SIZE |
| 132 | } |
| 133 | |
| 134 | type activeJobInstanceMetrics struct { |
| 135 | CPUPercentage int64 `stm:"cpu_percentage"` // CPU_PERCENTAGE |
| 136 | ElapsedCPUTime int64 `stm:"elapsed_cpu_time"` // ELAPSED_CPU_TIME (seconds) |
| 137 | ElapsedTime int64 `stm:"elapsed_time"` // ELAPSED_TIME (seconds) |
| 138 | TemporaryStorage int64 `stm:"temporary_storage"` // TEMPORARY_STORAGE (MB) |
| 139 | ThreadCount int64 `stm:"thread_count"` // THREAD_COUNT |
| 140 | ElapsedDiskIO int64 `stm:"elapsed_disk_io"` // ELAPSED_TOTAL_DISK_IO_COUNT |
| 141 | ElapsedInteractiveTransactions int64 `stm:"elapsed_interactive_transactions"` // ELAPSED_INTERACTIVE_TRANSACTIONS |
| 142 | } |
| 143 | |
| 144 | type networkInterfaceInstanceMetrics struct { |
| 145 | InterfaceStatus int64 `stm:"interface_status"` // 1 if ACTIVE, 0 if not |
| 146 | MTU int64 `stm:"mtu"` // MAXIMUM_TRANSMISSION_UNIT |
| 147 | InterfaceType string // INTERFACE_LINE_TYPE - for labels only |
| 148 | ConnectionType string // CONNECTION_TYPE - for labels only |
| 149 | InternetAddress string // INTERNET_ADDRESS - for labels only |
| 150 | NetworkAddress string // NETWORK_ADDRESS - for labels only |
| 151 | SubnetMask string // INTERFACE_SUBNET_MASK - for labels only |
| 152 | } |
| 153 | |
| 154 | type systemActivityMetrics struct { |
| 155 | AverageCPURate int64 `stm:"average_cpu_rate"` // AVERAGE_CPU_RATE (percentage with precision) |
| 156 | AverageCPUUtilization int64 `stm:"average_cpu_utilization"` // AVERAGE_CPU_UTILIZATION (percentage with precision) |
| 157 | MinimumCPUUtilization int64 `stm:"minimum_cpu_utilization"` // MINIMUM_CPU_UTILIZATION (percentage with precision) |
| 158 | MaximumCPUUtilization int64 `stm:"maximum_cpu_utilization"` // MAXIMUM_CPU_UTILIZATION (percentage with precision) |
| 159 | } |
| 160 | |
| 161 | type httpServerInstanceMetrics struct { |
| 162 | NormalConnections int64 `stm:"normal_connections"` |
| 163 | SSLConnections int64 `stm:"ssl_connections"` |
| 164 | ActiveThreads int64 `stm:"active_threads"` |
| 165 | IdleThreads int64 `stm:"idle_threads"` |
| 166 | TotalRequests int64 `stm:"total_requests"` |
| 167 | TotalResponses int64 `stm:"total_responses"` |
| 168 | TotalRequestsRejected int64 `stm:"total_requests_rejected"` |
| 169 | BytesReceived int64 `stm:"bytes_received"` |
| 170 | BytesSent int64 `stm:"bytes_sent"` |
| 171 | } |
| 172 | |
| 173 | type planCacheInstanceMetrics struct { |
| 174 | Value int64 `stm:"value"` |
| 175 | } |