master
go 555 lines 13.2 KB
Raw
1 //go:build !cgo || !ibm_mq
2
3 package pcf
4
5 import (
6 "errors"
7 "github.com/netdata/netdata/go/plugins/plugin/ibm.d/framework"
8 "math"
9 "time"
10 )
11
12 // AttributeValue represents a configuration attribute value
13 type AttributeValue int64
14
15 // Special value indicating an attribute was not collected/available
16 const NotCollected AttributeValue = math.MinInt64
17
18 // IsCollected returns true if the attribute was successfully collected
19 func (a AttributeValue) IsCollected() bool {
20 return a != NotCollected
21 }
22
23 // Int64 returns the int64 value, should only be called when IsCollected() is true
24 func (a AttributeValue) Int64() int64 {
25 return int64(a)
26 }
27
28 // ChannelType represents the type of MQ channel
29 type ChannelType int32
30
31 func (t ChannelType) String() string {
32 return "unknown"
33 }
34
35 // ChannelStatus represents the status of MQ channel
36 type ChannelStatus int32
37
38 const (
39 ChannelStatusInactive ChannelStatus = 0
40 ChannelStatusBinding ChannelStatus = 1
41 ChannelStatusStarting ChannelStatus = 2
42 ChannelStatusRunning ChannelStatus = 3
43 ChannelStatusStopping ChannelStatus = 4
44 ChannelStatusRetrying ChannelStatus = 5
45 ChannelStatusStopped ChannelStatus = 6
46 ChannelStatusRequesting ChannelStatus = 7
47 ChannelStatusPaused ChannelStatus = 8
48 ChannelStatusDisconnected ChannelStatus = 9
49 ChannelStatusInitializing ChannelStatus = 13
50 ChannelStatusSwitching ChannelStatus = 14
51 )
52
53 func (s ChannelStatus) String() string {
54 return "unknown"
55 }
56
57 // ListenerStatus represents the status of MQ listener
58 type ListenerStatus int32
59
60 const (
61 ListenerStatusStopped ListenerStatus = 0
62 ListenerStatusStarting ListenerStatus = 1
63 ListenerStatusRunning ListenerStatus = 2
64 ListenerStatusStopping ListenerStatus = 3
65 ListenerStatusRetrying ListenerStatus = 4
66 )
67
68 // Stub implementations for when CGO is disabled
69
70 type Config struct {
71 QueueManager string
72 Channel string
73 Host string
74 Port int
75 User string
76 Password string
77 }
78
79 type Client struct {
80 state *framework.CollectorState
81 config Config
82 }
83
84 type ResourceStatus int
85
86 const (
87 ResourceStatusDisabled ResourceStatus = 0
88 ResourceStatusEnabled ResourceStatus = 1
89 ResourceStatusFailed ResourceStatus = 2
90 )
91
92 func NewClient(config Config, state *framework.CollectorState) *Client {
93 return &Client{
94 config: config,
95 state: state,
96 }
97 }
98
99 func (c *Client) Connect() error {
100 return errors.New("PCF protocol requires CGO support for IBM MQ library")
101 }
102
103 func (c *Client) IsConnected() bool {
104 return false
105 }
106
107 func (c *Client) Disconnect() error {
108 return nil
109 }
110
111 func (c *Client) GetQueueManagerInfo() (*QueueManagerInfo, error) {
112 return nil, errors.New("PCF protocol requires CGO support")
113 }
114
115 type QueueManagerMetrics struct {
116 Status int64
117 ConnectionCount AttributeValue
118 StartDate AttributeValue
119 StartTime AttributeValue
120 Uptime AttributeValue
121 }
122
123 func (c *Client) GetQueueManagerStatus() (*QueueManagerMetrics, error) {
124 return nil, errors.New("PCF protocol requires CGO support")
125 }
126
127 func (c *Client) GetConnectionInfo() (version, edition, endpoint string, err error) {
128 return "", "", "", errors.New("PCF protocol requires CGO support")
129 }
130
131 func (c *Client) GetQueues(collectConfig, collectMetrics, collectReset bool, maxQueues int, selector string, collectSystem bool) (*QueueCollectionResult, error) {
132 return nil, errors.New("PCF protocol requires CGO support")
133 }
134
135 func (c *Client) GetChannels(collectConfig, collectMetrics bool, maxChannels int, selector string, collectSystem bool) (*ChannelCollectionResult, error) {
136 return nil, errors.New("PCF protocol requires CGO support")
137 }
138
139 func (c *Client) GetListeners(collectConfig bool, maxListeners int, selector string, collectSystem bool) (*ListenerCollectionResult, error) {
140 return nil, errors.New("PCF protocol requires CGO support")
141 }
142
143 func (c *Client) GetTopics(collectMetrics bool, maxTopics int, selector string, collectSystem bool) (*TopicCollectionResult, error) {
144 return nil, errors.New("PCF protocol requires CGO support")
145 }
146
147 func (c *Client) GetSubscriptions(maxSubscriptions int, selector string) (*SubscriptionCollectionResult, error) {
148 return nil, errors.New("PCF protocol requires CGO support")
149 }
150
151 func (c *Client) ResetQueueStatistics(pattern string) error {
152 return errors.New("PCF protocol requires CGO support")
153 }
154
155 func (c *Client) CollectStatistics() (*StatisticsCollectionResult, error) {
156 return nil, errors.New("PCF protocol requires CGO support")
157 }
158
159 func (c *Client) GetQueueStatistics(name string) (*QueueStatistics, error) {
160 return nil, errors.New("PCF protocol requires CGO support")
161 }
162
163 func (c *Client) GetStatisticsQueue() (*StatisticsCollectionResult, error) {
164 return nil, errors.New("PCF protocol requires CGO support")
165 }
166
167 func (c *Client) GetStatisticsInterval() int {
168 return 0
169 }
170
171 // Resource Monitor Methods (IBM $SYS topics)
172 func (c *Client) IsResourceMonitoringSupported() bool {
173 return false
174 }
175
176 func (c *Client) GetResourceStatus() ResourceStatus {
177 return ResourceStatusDisabled
178 }
179
180 func (c *Client) EnableResourceMonitoring() error {
181 return errors.New("PCF protocol requires CGO support")
182 }
183
184 type ResourcePublicationsResult struct {
185 Stats CollectionStats
186 UserCPUPercent AttributeValue
187 SystemCPUPercent AttributeValue
188 AvailableMemory AttributeValue
189 UsedMemory AttributeValue
190 MemoryUsedMB AttributeValue
191 LogUsedBytes AttributeValue
192 LogMaxBytes AttributeValue
193 }
194
195 func (c *Client) GetResourcePublications() (*ResourcePublicationsResult, error) {
196 return nil, errors.New("PCF protocol requires CGO support")
197 }
198
199 func (c *Client) GetResourceMonitorData() (map[string]any, error) {
200 return nil, errors.New("PCF protocol requires CGO support")
201 }
202
203 // ParseMQDateTime stub
204 func ParseMQDateTime(dateStr, timeStr string) (time.Time, error) {
205 return time.Time{}, errors.New("PCF protocol requires CGO support")
206 }
207
208 // QueueTypeString returns a string representation of queue type
209 func QueueTypeString(t int32) string {
210 return "unknown"
211 }
212
213 // Stub type definitions
214 type ConnectionConfig struct {
215 QueueManager string
216 Host string
217 Port int
218 Channel string
219 User string
220 Password string
221 }
222
223 type QueueManagerInfo struct {
224 Name string
225 Status int32
226 Connections int32
227 StartDate string
228 StartTime string
229 Platform string
230 CommandLevel int32
231 IsBroker bool
232 }
233
234 type QueueInfo struct {
235 Name string
236 Type string
237 Usage string
238 }
239
240 type QueueMetrics struct {
241 Name string
242 Type AttributeValue
243 CurrentDepth int64
244 MaxDepth int64
245 DepthPercentage float64
246 OpenInputCount AttributeValue
247 OpenOutputCount AttributeValue
248 EnqueueCount int64
249 DequeueCount int64
250 HighDepth int64
251 TimeSinceReset int64
252 OldestMsgAge AttributeValue
253 UncommittedMsgs AttributeValue
254 LastGetDate AttributeValue
255 LastGetTime AttributeValue
256 LastPutDate AttributeValue
257 LastPutTime AttributeValue
258 HasStatusMetrics bool
259 HasResetStats bool
260 CurrentFileSize AttributeValue
261 CurrentMaxFileSize AttributeValue
262 QTimeShort AttributeValue
263 QTimeLong AttributeValue
264 InhibitGet AttributeValue
265 InhibitPut AttributeValue
266 BackoutThreshold AttributeValue
267 TriggerDepth AttributeValue
268 TriggerType AttributeValue
269 MaxMsgLength AttributeValue
270 DefPriority AttributeValue
271 ServiceInterval AttributeValue
272 RetentionInterval AttributeValue
273 Scope AttributeValue
274 Usage AttributeValue
275 MsgDeliverySequence AttributeValue
276 HardenGetBackout AttributeValue
277 DefPersistence AttributeValue
278 }
279
280 type ChannelInfo struct {
281 Name string
282 Type string
283 ConnectionName string
284 }
285
286 type ChannelMetrics struct {
287 Name string
288 Type ChannelType
289 Status ChannelStatus
290
291 // Message metrics (only for message channels)
292 Messages *int64
293 Bytes *int64
294 Batches *int64
295
296 // Current connections (only for SVRCONN)
297 Connections *int64
298
299 // Buffer metrics (only for sender/receiver channels)
300 BuffersUsed *int64
301 BuffersMax *int64
302
303 // Configuration metrics (populated when collectConfig is true)
304 BatchSize AttributeValue
305 BatchInterval AttributeValue
306 DiscInterval AttributeValue
307 HbInterval AttributeValue
308 KeepAliveInterval AttributeValue
309 ShortRetry AttributeValue
310 LongRetry AttributeValue
311 MaxMsgLength AttributeValue
312 SharingConversations AttributeValue
313 NetworkPriority AttributeValue
314
315 // Extended status metrics
316 BuffersSent AttributeValue
317 BuffersReceived AttributeValue
318 CurrentMessages AttributeValue
319 XmitQueueTime AttributeValue
320 MCAStatus AttributeValue
321 InDoubtStatus AttributeValue
322 SSLKeyResets AttributeValue
323 NPMSpeed AttributeValue
324 CurrentSharingConvs AttributeValue
325 ConnectionName string
326 }
327
328 type ListenerInfo struct {
329 Name string
330 Port int32
331 IPAddress string
332 }
333
334 type ListenerMetrics struct {
335 Name string
336 Status ListenerStatus
337 Port int64
338 Backlog AttributeValue
339 IPAddress string
340 Description string
341 StartDate string
342 StartTime string
343 Uptime int64
344 }
345
346 type TopicInfo struct {
347 Name string
348 Type string
349 }
350
351 type TopicMetrics struct {
352 Name string
353 TopicString string
354
355 Publishers int64
356 Subscribers int64
357
358 PublishMsgCount int64
359
360 LastPubDate AttributeValue
361 LastPubTime AttributeValue
362 }
363
364 type QueueResetStats struct {
365 GetCount int64
366 PutCount int64
367 }
368
369 type QueueType int32
370
371 type QueueStatistics struct {
372 Name string
373 Type QueueType
374
375 MinDepth AttributeValue
376 MaxDepth AttributeValue
377
378 AvgQTimeNonPersistent AttributeValue
379 AvgQTimePersistent AttributeValue
380
381 // Put operations
382 PutsCount AttributeValue
383 PutsNonPersistent AttributeValue
384 PutsPersistent AttributeValue
385 PutBytesNonPersistent AttributeValue
386 PutBytesPersistent AttributeValue
387 Put1Count AttributeValue
388 PutsFailed AttributeValue
389 Put1sFailed AttributeValue
390
391 // Get operations
392 GetsCount AttributeValue
393 GetsNonPersistent AttributeValue
394 GetsPersistent AttributeValue
395 GetBytesNonPersistent AttributeValue
396 GetBytesPersistent AttributeValue
397 GetsFailed AttributeValue
398
399 // Browse operations
400 BrowseCount AttributeValue
401 BrowseBytes AttributeValue
402 BrowsesFailed AttributeValue
403
404 // Rollback and backout
405 RollbackCount AttributeValue
406 BackoutCount AttributeValue
407 MsgsExpired AttributeValue
408 MsgsPurged AttributeValue
409 MsgsNotQueued AttributeValue
410
411 QTimeShort AttributeValue
412 QTimeLong AttributeValue
413 }
414
415 type ChannelStatistics struct {
416 Name string
417 Type ChannelType
418 Status ChannelStatus
419
420 Messages AttributeValue
421 Bytes AttributeValue
422 FullBatches AttributeValue
423 IncompleteBatches AttributeValue
424 AvgBatchSize AttributeValue
425
426 BuffersSent AttributeValue
427 BuffersReceived AttributeValue
428 PutRetries AttributeValue
429
430 NetworkTime AttributeValue
431 ExitTime AttributeValue
432 BatchTime AttributeValue
433 SpeedIndicators [4]AttributeValue
434 }
435
436 type MQIStatistics struct {
437 Name string
438
439 Opens AttributeValue
440 OpensFailed AttributeValue
441
442 Closes AttributeValue
443 ClosesFailed AttributeValue
444
445 Inqs AttributeValue
446 InqsFailed AttributeValue
447
448 Sets AttributeValue
449 SetsFailed AttributeValue
450
451 Puts AttributeValue
452 PutBytes AttributeValue
453 PutsFailed AttributeValue
454
455 Gets AttributeValue
456 GetBytes AttributeValue
457 GetsFailed AttributeValue
458
459 Cbs AttributeValue
460 CbsFailed AttributeValue
461
462 Commits AttributeValue
463 Backs AttributeValue
464 SubsReqs AttributeValue
465 SubsPubs AttributeValue
466 Browses AttributeValue
467 }
468
469 type StatisticsType int
470
471 const (
472 StatisticsTypeQueue StatisticsType = 1
473 StatisticsTypeChannel StatisticsType = 2
474 StatisticsTypeMQI StatisticsType = 3
475 )
476
477 type StatisticsMessage struct {
478 Type StatisticsType
479 Command int32
480 QueueStats []QueueStatistics
481 ChannelStats []ChannelStatistics
482 MQIStats []MQIStatistics
483 }
484
485 type StatisticsCollectionResult struct {
486 Messages []StatisticsMessage
487 }
488
489 type SubscriptionMetrics struct {
490 Name string
491 TopicString string
492 Type AttributeValue
493 MessageCount AttributeValue
494 LastMessageDate string
495 LastMessageTime string
496 }
497
498 // Collection result types
499 type CollectionStats struct {
500 Discovery struct {
501 Success bool
502 AvailableItems int64
503 InvisibleItems int64
504 IncludedItems int64
505 ExcludedItems int64
506 UnparsedItems int64
507 ErrorCounts map[int32]int
508 Total int
509 Matched int
510 }
511 Config *EnrichmentStats
512 Metrics *EnrichmentStats
513 Reset *EnrichmentStats
514 }
515
516 type EnrichmentStats struct {
517 TotalItems int64
518 OkItems int64
519 FailedItems int64
520 ErrorCounts map[int32]int
521 }
522
523 type CollectionPhaseStats struct {
524 Total int
525 Success int
526 Errors int
527 Filtered int
528 OkItems int64
529 FailedItems int64
530 }
531
532 type QueueCollectionResult struct {
533 Queues []QueueMetrics
534 Stats CollectionStats
535 }
536
537 type ChannelCollectionResult struct {
538 Channels []ChannelMetrics
539 Stats CollectionStats
540 }
541
542 type TopicCollectionResult struct {
543 Topics []TopicMetrics
544 Stats CollectionStats
545 }
546
547 type ListenerCollectionResult struct {
548 Listeners []ListenerMetrics
549 Stats CollectionStats
550 }
551
552 type SubscriptionCollectionResult struct {
553 Subscriptions []SubscriptionMetrics
554 Stats CollectionStats
555 }