| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | //go:build cgo |
| 4 | |
| 5 | package as400 |
| 6 | |
| 7 | // diskMetrics holds metrics for an individual disk |
| 8 | type diskMetrics struct { |
| 9 | unit string |
| 10 | typeField string // HDD, SSD, etc. |
| 11 | model string |
| 12 | busyPercent int64 |
| 13 | readRequests int64 |
| 14 | writeRequests int64 |
| 15 | readBytes int64 |
| 16 | writeBytes int64 |
| 17 | averageTime int64 |
| 18 | ssdLifeRemaining int64 // -1 if not SSD |
| 19 | ssdPowerOnDays int64 // -1 if not SSD |
| 20 | hardwareStatus string // Hardware status from SYSDISKSTAT |
| 21 | diskModel string // Disk model from SYSDISKSTAT |
| 22 | serialNumber string // Serial number from SYSDISKSTAT |
| 23 | } |
| 24 | |
| 25 | // subsystemMetrics holds metrics for an individual subsystem |
| 26 | type subsystemMetrics struct { |
| 27 | name string |
| 28 | library string |
| 29 | status string |
| 30 | jobsActive int64 |
| 31 | jobsHeld int64 |
| 32 | storageUsed int64 // KB |
| 33 | poolID int64 |
| 34 | maxJobs int64 |
| 35 | currentJobs int64 |
| 36 | } |
| 37 | |
| 38 | // jobQueueMetrics holds metrics for an individual job queue |
| 39 | type jobQueueMetrics struct { |
| 40 | name string |
| 41 | library string |
| 42 | status string |
| 43 | jobsWaiting int64 |
| 44 | jobsHeld int64 |
| 45 | jobsScheduled int64 |
| 46 | maxJobs int64 |
| 47 | priority int64 |
| 48 | } |
| 49 | |
| 50 | // messageQueueMetrics holds metrics for an individual message queue |
| 51 | type messageQueueMetrics struct { |
| 52 | name string |
| 53 | library string |
| 54 | } |
| 55 | |
| 56 | type outputQueueMetrics struct { |
| 57 | name string |
| 58 | library string |
| 59 | status string |
| 60 | } |
| 61 | |
| 62 | // tempStorageMetrics holds metrics for a named temporary storage bucket |
| 63 | type tempStorageMetrics struct { |
| 64 | name string |
| 65 | currentSize int64 |
| 66 | peakSize int64 |
| 67 | } |
| 68 | |
| 69 | // activeJobMetrics holds metrics for an individual active job |
| 70 | type activeJobMetrics struct { |
| 71 | qualifiedName string |
| 72 | jobNumber string |
| 73 | jobUser string |
| 74 | jobName string |
| 75 | jobStatus string |
| 76 | subsystem string |
| 77 | jobType string |
| 78 | runPriority int64 |
| 79 | elapsedCPUTime int64 // seconds |
| 80 | elapsedTime int64 // seconds |
| 81 | temporaryStorage int64 // MB |
| 82 | cpuPercentage int64 // percentage * precision |
| 83 | interactiveTransactions int64 |
| 84 | diskIO int64 |
| 85 | threadCount int64 |
| 86 | } |
| 87 | |
| 88 | type networkInterfaceMetrics struct { |
| 89 | name string |
| 90 | interfaceType string // INTERFACE_LINE_TYPE |
| 91 | interfaceStatus string // INTERFACE_STATUS |
| 92 | connectionType string // CONNECTION_TYPE |
| 93 | internetAddress string // INTERNET_ADDRESS |
| 94 | networkAddress string // NETWORK_ADDRESS |
| 95 | subnetMask string // INTERFACE_SUBNET_MASK |
| 96 | mtu int64 // MAXIMUM_TRANSMISSION_UNIT |
| 97 | } |
| 98 | |
| 99 | type httpServerMetrics struct { |
| 100 | serverName string |
| 101 | httpFunction string |
| 102 | } |
| 103 | |
| 104 | type planCacheMetrics struct { |
| 105 | heading string |
| 106 | } |
| 107 | |
| 108 | // Per-instance metric methods |
| 109 | func (a *Collector) getDiskMetrics(unit string) *diskMetrics { |
| 110 | if _, ok := a.disks[unit]; !ok { |
| 111 | a.disks[unit] = &diskMetrics{ |
| 112 | unit: unit, |
| 113 | typeField: "UNKNOWN", // Default for disk type when not specified |
| 114 | ssdLifeRemaining: -1, // Default to -1 (not SSD) |
| 115 | ssdPowerOnDays: -1, // Default to -1 (not SSD) |
| 116 | hardwareStatus: "UNKNOWN", // Default for hardware status |
| 117 | diskModel: "UNKNOWN", // Default for disk model |
| 118 | serialNumber: "UNKNOWN", // Default for serial number |
| 119 | } |
| 120 | } |
| 121 | return a.disks[unit] |
| 122 | } |
| 123 | |
| 124 | func (a *Collector) getSubsystemMetrics(name string) *subsystemMetrics { |
| 125 | if _, ok := a.subsystems[name]; !ok { |
| 126 | a.subsystems[name] = &subsystemMetrics{name: name} |
| 127 | } |
| 128 | return a.subsystems[name] |
| 129 | } |
| 130 | |
| 131 | func (a *Collector) getJobQueueMetrics(key string) *jobQueueMetrics { |
| 132 | if _, ok := a.jobQueues[key]; !ok { |
| 133 | a.jobQueues[key] = &jobQueueMetrics{} |
| 134 | } |
| 135 | return a.jobQueues[key] |
| 136 | } |
| 137 | |
| 138 | func (a *Collector) getMessageQueueMetrics(key string) *messageQueueMetrics { |
| 139 | if _, ok := a.messageQueues[key]; !ok { |
| 140 | a.messageQueues[key] = &messageQueueMetrics{} |
| 141 | } |
| 142 | return a.messageQueues[key] |
| 143 | } |
| 144 | |
| 145 | func (a *Collector) getOutputQueueMetrics(key string) *outputQueueMetrics { |
| 146 | if _, ok := a.outputQueues[key]; !ok { |
| 147 | a.outputQueues[key] = &outputQueueMetrics{} |
| 148 | } |
| 149 | return a.outputQueues[key] |
| 150 | } |
| 151 | |
| 152 | func (a *Collector) getTempStorageMetrics(name string) *tempStorageMetrics { |
| 153 | if _, ok := a.tempStorageNamed[name]; !ok { |
| 154 | a.tempStorageNamed[name] = &tempStorageMetrics{name: name} |
| 155 | } |
| 156 | return a.tempStorageNamed[name] |
| 157 | } |
| 158 | |
| 159 | func (a *Collector) getActiveJobMetrics(jobName string) *activeJobMetrics { |
| 160 | if _, ok := a.activeJobs[jobName]; !ok { |
| 161 | a.activeJobs[jobName] = &activeJobMetrics{ |
| 162 | qualifiedName: jobName, |
| 163 | jobName: jobName, |
| 164 | } |
| 165 | } |
| 166 | return a.activeJobs[jobName] |
| 167 | } |
| 168 | |
| 169 | func (a *Collector) getNetworkInterfaceMetrics(name string) *networkInterfaceMetrics { |
| 170 | if _, ok := a.networkInterfaces[name]; !ok { |
| 171 | a.networkInterfaces[name] = &networkInterfaceMetrics{name: name} |
| 172 | } |
| 173 | return a.networkInterfaces[name] |
| 174 | } |
| 175 | |
| 176 | func (a *Collector) getHTTPServerMetrics(serverName, function string) *httpServerMetrics { |
| 177 | key := httpServerKey(serverName, function) |
| 178 | if _, ok := a.httpServers[key]; !ok { |
| 179 | a.httpServers[key] = &httpServerMetrics{ |
| 180 | serverName: serverName, |
| 181 | httpFunction: function, |
| 182 | } |
| 183 | } else { |
| 184 | m := a.httpServers[key] |
| 185 | m.serverName = serverName |
| 186 | m.httpFunction = function |
| 187 | } |
| 188 | return a.httpServers[key] |
| 189 | } |
| 190 | |
| 191 | func (a *Collector) getPlanCacheMetrics(key, heading string) *planCacheMetrics { |
| 192 | if key == "" { |
| 193 | return nil |
| 194 | } |
| 195 | if _, ok := a.planCache[key]; !ok { |
| 196 | a.planCache[key] = &planCacheMetrics{heading: heading} |
| 197 | } else if heading != "" { |
| 198 | a.planCache[key].heading = heading |
| 199 | } |
| 200 | return a.planCache[key] |
| 201 | } |
| 202 | |
| 203 | func httpServerKey(serverName, function string) string { |
| 204 | return serverName + "|" + function |
| 205 | } |