zentol commented on a change in pull request #6702: [FLINK-10135] The 
JobManager does not report the cluster-level metrics
URL: https://github.com/apache/flink/pull/6702#discussion_r223466964
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/dispatcher/Dispatcher.java
 ##########
 @@ -909,6 +926,70 @@ private void clearDispatcherState() {
                terminateJobManagerRunners();
        }
 
+       private void instantiateJobManagerOverviewMetrics(MetricGroup 
jobManagerMetricGroup) {
+               long defaultTimeoutValue = 
configuration.getLong(RestOptions.CONNECTION_TIMEOUT);
+               Time defaultRequestTimeout = 
Time.milliseconds(defaultTimeoutValue);
+
+               jobManagerMetricGroup.gauge("taskSlotsAvailable", () -> {
+                       try {
+                               return (long) resourceManagerGateway
+                                       
.requestResourceOverview(defaultRequestTimeout)
+                                       .get()
+                                       .getNumberFreeSlots();
+                       } catch (InterruptedException e) {
+                               Thread.currentThread().interrupt();
+                       } catch (ExecutionException e) {
+                               log.error("Request resource overview occurs 
exception.", e);
+                       }
+
+                       return 0L;
+               });
+
+               jobManagerMetricGroup.gauge("taskSlotsTotal", () -> {
+                       try {
+                               return (long) resourceManagerGateway
+                                       
.requestResourceOverview(defaultRequestTimeout)
+                                       .get()
+                                       .getNumberRegisteredSlots();
+                       } catch (InterruptedException e) {
+                               Thread.currentThread().interrupt();
+                       } catch (ExecutionException e) {
+                               log.error("Request resource overview occurs 
exception.", e);
+                       }
+
+                       return 0L;
+               });
+
+               jobManagerMetricGroup.gauge("numRegisteredTaskManagers", () -> {
+                       try {
+                               return (long) resourceManagerGateway
+                                       
.requestResourceOverview(defaultRequestTimeout)
+                                       .get()
+                                       .getNumberTaskManagers();
+                       } catch (InterruptedException e) {
+                               Thread.currentThread().interrupt();
+                       } catch (ExecutionException e) {
+                               log.error("Request resource overview occurs 
exception.", e);
+                       }
+
+                       return 0L;
+               });
+
+               jobManagerMetricGroup.gauge("numRunningJobs", () -> {
+                       try {
+                               return (long) 
requestOverviewForAllJobs(defaultRequestTimeout)
 
 Review comment:
   This results in a wave of RPC calls to every single JM. Would it not be 
feasible to simple count the number of job IDs contained in 
`jobManagerRunnerFutures`?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to