13
13
import java .io .IOException ;
14
14
import java .util .ArrayList ;
15
15
import java .util .Hashtable ;
16
+ import java .util .List ;
16
17
17
18
/**
18
19
* MQPCFSubscriber is technically not a subscriber, but a runnable object, which sends PCFCommands every n seconds to
@@ -24,7 +25,7 @@ public class MQPCFSubscriber implements Runnable {
24
25
private String queueManagerName ;
25
26
private MQObject object ;
26
27
private PCFMessageAgent agent ;
27
- private ArrayList <MQObject > objects ;
28
+ private List <MQObject > objects ;
28
29
29
30
/**
30
31
* MQPCFSubscriber constructor which is used, when exporter is configured to use 1 MQPCFSubscriber per 1 MQObject.
@@ -43,9 +44,9 @@ public MQPCFSubscriber(String queueManagerName, Hashtable<String, Object> connec
43
44
*
44
45
* @param queueManagerName - queue manager name.
45
46
* @param connectionProperties - connection properties.
46
- * @param objects - Array with all MQObjects.
47
+ * @param objects - List with all MQObjects.
47
48
*/
48
- public MQPCFSubscriber (String queueManagerName , Hashtable <String , Object > connectionProperties , ArrayList <MQObject > objects ) {
49
+ public MQPCFSubscriber (String queueManagerName , Hashtable <String , Object > connectionProperties , List <MQObject > objects ) {
49
50
establishMQConnection (queueManagerName , connectionProperties );
50
51
this .objects = objects ;
51
52
this .object = new MQObject ("*" , objects .get (0 ).getType ());
@@ -90,39 +91,45 @@ private void updateMetricWithoutWildcards(PCFMessage response, String objectName
90
91
private void updateMetricsWithWildcards (PCFMessage [] pcfResponse ) {
91
92
ArrayList <String > objectNames = new ArrayList <>();
92
93
//copy all objects names to temporary array
93
- for (MQObject object : objects ) {
94
- objectNames .add (object .getName ());
94
+ for (MQObject monitoredObject : objects ) {
95
+ objectNames .add (monitoredObject .getName ());
95
96
}
96
97
for (PCFMessage response : pcfResponse ) {
97
98
String objectName = (String ) response .getParameterValue (MQObject .objectNameCode (object .getType ()));
98
99
objectName = objectName .trim ();
99
100
//if temporary array contains metric, then remove it from temporary array and update metric
100
101
if (objectNames .contains (objectName )) {
101
102
objectNames .remove (objectName );
102
- Object result = response .getParameterValue (object .getPCFHeader ());
103
- double prometheusValue = MetricsReference .getMetricValue (object .getType (), (Integer ) result );
104
- MetricsManager .updateMetric (MetricsReference .getMetricName (object .getType ()), prometheusValue , queueManagerName , objectName );
103
+ updateMetricWithoutWildcards (response , objectName );
105
104
}
106
105
}
107
-
108
- //There are some objects in temporary array? It means that "*" wildcard didn't return all values.
106
+ //Are there any objects left in temporary array? It means that "*" wildcard didn't return all values.
109
107
//There are multiple reasons why it could happen. For example, MQ channel has status "inactive".
110
108
//Then we send direct PCF command for specific object. If some error occurs, we have custom processing for it.
111
- if (objectNames .size () > 0 ) {
112
- for (String objectName : objectNames ) {
113
- MQObject directObject = new MQObject (objectName , object .getType ());
114
- try {
115
- PCFMessage [] directPCFResponse = agent .send (directObject .getPCFCmd ());
116
- updateMetricWithoutWildcards (directPCFResponse [0 ], objectName );
117
- } catch (PCFException e ) {
118
- //This error means, that channel has status "inactive".
109
+ updateWithDirectPCFCommand (objectNames );
110
+ }
111
+
112
+ /**
113
+ * Retrieves info about all objects from input array via direct pcf commands.
114
+ *
115
+ * @param objectNames - input array with objects.
116
+ */
117
+ private void updateWithDirectPCFCommand (ArrayList <String > objectNames ) {
118
+ for (String objectName : objectNames ) {
119
+ MQObject directObject = new MQObject (objectName , object .getType ());
120
+ try {
121
+ PCFMessage [] directPCFResponse = agent .send (directObject .getPcfCmd ());
122
+ updateMetricWithoutWildcards (directPCFResponse [0 ], objectName );
123
+ } catch (PCFException e ) {
124
+ //This error means, that channel has status "inactive".
125
+ if (e .reasonCode == MQConstants .MQRCCF_CHL_STATUS_NOT_FOUND ) {
119
126
logger .warn ("Channel {} is possibly inactive." , objectName );
120
- if (e .reasonCode == MQConstants .MQRCCF_CHL_STATUS_NOT_FOUND ) {
121
- MetricsManager .updateMetric (MetricsReference .getMetricName (object .getType ()), MetricsReference .getMetricValue (object .getType (), MQConstants .MQCHS_INACTIVE ), queueManagerName , objectName );
122
- }
123
- } catch (IOException | MQException e ) {
127
+ MetricsManager .updateMetric (MetricsReference .getMetricName (object .getType ()), MetricsReference .getMetricValue (object .getType (), MQConstants .MQCHS_INACTIVE ), queueManagerName , objectName );
128
+ } else {
124
129
logger .error ("Error occurred during sending PCF command: " , e );
125
130
}
131
+ } catch (IOException | MQException e ) {
132
+ logger .error ("Error occurred during sending PCF command: " , e );
126
133
}
127
134
}
128
135
}
@@ -131,7 +138,7 @@ private void updateMetricsWithWildcards(PCFMessage[] pcfResponse) {
131
138
public void run () {
132
139
try {
133
140
logger .debug ("Sending PCF command for object type {} with name {}..." , object .getType (), object .getName ());
134
- PCFMessage [] pcfResponse = agent .send (object .getPCFCmd ());
141
+ PCFMessage [] pcfResponse = agent .send (object .getPcfCmd ());
135
142
if (!objects .isEmpty ()) {
136
143
updateMetricsWithWildcards (pcfResponse );
137
144
} else {
@@ -145,6 +152,10 @@ public void run() {
145
152
logger .warn ("Channel {} is possibly inactive." , object .getName ());
146
153
MetricsManager .updateMetric (MetricsReference .getMetricName (object .getType ()), MetricsReference .getMetricValue (object .getType (), MQConstants .MQCHS_INACTIVE ), queueManagerName , object .getName ());
147
154
}
155
+ if (object .getType () == MQObject .MQType .LISTENER && e .reasonCode == MQConstants .MQRC_UNKNOWN_OBJECT_NAME ) {
156
+ MetricsManager .updateMetric (MetricsReference .getMetricName (object .getType ()), MetricsReference .getMetricValue (object .getType (), MQConstants .MQSVC_STATUS_STOPPED ), queueManagerName , object .getName ());
157
+ logger .warn ("Listener {} is possibly stopped." , object .getName ());
158
+ }
148
159
} catch (MQException | IOException e ) {
149
160
logger .error ("Error occurred during sending PCF command: " , e );
150
161
}
0 commit comments