arpadboda commented on a change in pull request #1032:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1032#discussion_r609510112



##########
File path: libminifi/include/core/state/nodes/AgentInformation.h
##########
@@ -425,77 +427,123 @@ class AgentStatus : public StateMonitorNode {
 
   std::vector<SerializedResponseNode> serialize() {
     std::vector<SerializedResponseNode> serialized;
+    auto serializedRepositories = serializeRepositories();
+    if (!serializedRepositories.empty()) {
+      serialized.push_back(serializedRepositories);
+    }
+    serialized.push_back(serializeUptime());
 
-    SerializedResponseNode uptime;
-
-    uptime.name = "uptime";
-    if (nullptr != monitor_) {
-      uptime.value = monitor_->getUptime();
-    } else {
-      uptime.value = "0";
+    auto serializedComponents = serializeComponents();
+    if (!serializedComponents.empty()) {
+      serialized.push_back(serializedComponents);
     }
 
-    if (!repositories_.empty()) {
-      SerializedResponseNode repositories;
+    serialized.push_back(serializeResourceConsumption());
 
-      repositories.name = "repositories";
+    return serialized;
+  }
+
+ protected:
+  SerializedResponseNode serializeRepositories() {
+    SerializedResponseNode repositories;
 
-      for (auto &repo : repositories_) {
-        SerializedResponseNode repoNode;
-        repoNode.collapsible = false;
-        repoNode.name = repo.first;
+    repositories.name = "repositories";
 
-        SerializedResponseNode queuesize;
-        queuesize.name = "size";
-        queuesize.value = repo.second->getRepoSize();
+    for (auto &repo : repositories_) {
+      SerializedResponseNode repoNode;
+      repoNode.collapsible = false;
+      repoNode.name = repo.first;
 
-        SerializedResponseNode isRunning;
-        isRunning.name = "running";
-        isRunning.value = repo.second->isRunning();
+      SerializedResponseNode queuesize;
+      queuesize.name = "size";
+      queuesize.value = repo.second->getRepoSize();
 
-        SerializedResponseNode isFull;
-        isFull.name = "full";
-        isFull.value = repo.second->isFull();
+      SerializedResponseNode isRunning;
+      isRunning.name = "running";
+      isRunning.value = repo.second->isRunning();
 
-        repoNode.children.push_back(queuesize);
-        repoNode.children.push_back(isRunning);
-        repoNode.children.push_back(isFull);
-        repositories.children.push_back(repoNode);
-      }
-      serialized.push_back(repositories);
+      SerializedResponseNode isFull;
+      isFull.name = "full";
+      isFull.value = repo.second->isFull();
+
+      repoNode.children.push_back(queuesize);
+      repoNode.children.push_back(isRunning);
+      repoNode.children.push_back(isFull);
+      repositories.children.push_back(repoNode);
     }
+    return repositories;
+  }
 
-    serialized.push_back(uptime);
+  SerializedResponseNode serializeUptime() {
+    SerializedResponseNode uptime;
 
+    uptime.name = "uptime";
     if (nullptr != monitor_) {
+      uptime.value = monitor_->getUptime();
+    } else {
+      uptime.value = "0";
+    }
+
+    return uptime;
+  }
+
+  SerializedResponseNode serializeComponents() {
+    SerializedResponseNode components_node(false);
+    components_node.name = "components";
+    if (monitor_ != nullptr) {
       auto components = monitor_->getAllComponents();
-      SerializedResponseNode componentsNode(false);
-      componentsNode.name = "components";
 
       for (auto component : components) {
-        SerializedResponseNode componentNode(false);
-        componentNode.name = component->getComponentName();
+        SerializedResponseNode component_node(false);
+        component_node.name = component->getComponentName();
 
-        SerializedResponseNode uuidNode;
-        uuidNode.name = "uuid";
-        uuidNode.value = 
std::string{component->getComponentUUID().to_string()};
+        SerializedResponseNode uuid_node;
+        uuid_node.name = "uuid";
+        uuid_node.value = 
std::string{component->getComponentUUID().to_string()};
 
-        SerializedResponseNode componentStatusNode;
-        componentStatusNode.name = "running";
-        componentStatusNode.value = component->isRunning();
+        SerializedResponseNode component_status_node;
+        component_status_node.name = "running";
+        component_status_node.value = component->isRunning();
 
-        componentNode.children.push_back(componentStatusNode);
-        componentNode.children.push_back(uuidNode);
-        componentsNode.children.push_back(componentNode);
+        component_node.children.push_back(component_status_node);
+        component_node.children.push_back(uuid_node);
+        components_node.children.push_back(component_node);
       }
-      serialized.push_back(componentsNode);
     }
+    return components_node;
+  }
+
+  SerializedResponseNode serializeAgentMemoryUsage() {

Review comment:
       This func could be const

##########
File path: libminifi/include/core/state/nodes/AgentInformation.h
##########
@@ -425,77 +427,123 @@ class AgentStatus : public StateMonitorNode {
 
   std::vector<SerializedResponseNode> serialize() {
     std::vector<SerializedResponseNode> serialized;
+    auto serializedRepositories = serializeRepositories();
+    if (!serializedRepositories.empty()) {
+      serialized.push_back(serializedRepositories);
+    }
+    serialized.push_back(serializeUptime());
 
-    SerializedResponseNode uptime;
-
-    uptime.name = "uptime";
-    if (nullptr != monitor_) {
-      uptime.value = monitor_->getUptime();
-    } else {
-      uptime.value = "0";
+    auto serializedComponents = serializeComponents();
+    if (!serializedComponents.empty()) {
+      serialized.push_back(serializedComponents);
     }
 
-    if (!repositories_.empty()) {
-      SerializedResponseNode repositories;
+    serialized.push_back(serializeResourceConsumption());
 
-      repositories.name = "repositories";
+    return serialized;
+  }
+
+ protected:
+  SerializedResponseNode serializeRepositories() {
+    SerializedResponseNode repositories;
 
-      for (auto &repo : repositories_) {
-        SerializedResponseNode repoNode;
-        repoNode.collapsible = false;
-        repoNode.name = repo.first;
+    repositories.name = "repositories";
 
-        SerializedResponseNode queuesize;
-        queuesize.name = "size";
-        queuesize.value = repo.second->getRepoSize();
+    for (auto &repo : repositories_) {
+      SerializedResponseNode repoNode;
+      repoNode.collapsible = false;
+      repoNode.name = repo.first;
 
-        SerializedResponseNode isRunning;
-        isRunning.name = "running";
-        isRunning.value = repo.second->isRunning();
+      SerializedResponseNode queuesize;
+      queuesize.name = "size";
+      queuesize.value = repo.second->getRepoSize();
 
-        SerializedResponseNode isFull;
-        isFull.name = "full";
-        isFull.value = repo.second->isFull();
+      SerializedResponseNode isRunning;
+      isRunning.name = "running";
+      isRunning.value = repo.second->isRunning();
 
-        repoNode.children.push_back(queuesize);
-        repoNode.children.push_back(isRunning);
-        repoNode.children.push_back(isFull);
-        repositories.children.push_back(repoNode);
-      }
-      serialized.push_back(repositories);
+      SerializedResponseNode isFull;
+      isFull.name = "full";
+      isFull.value = repo.second->isFull();
+
+      repoNode.children.push_back(queuesize);
+      repoNode.children.push_back(isRunning);
+      repoNode.children.push_back(isFull);
+      repositories.children.push_back(repoNode);
     }
+    return repositories;
+  }
 
-    serialized.push_back(uptime);
+  SerializedResponseNode serializeUptime() {
+    SerializedResponseNode uptime;
 
+    uptime.name = "uptime";
     if (nullptr != monitor_) {
+      uptime.value = monitor_->getUptime();
+    } else {
+      uptime.value = "0";
+    }
+
+    return uptime;
+  }
+
+  SerializedResponseNode serializeComponents() {
+    SerializedResponseNode components_node(false);
+    components_node.name = "components";
+    if (monitor_ != nullptr) {
       auto components = monitor_->getAllComponents();
-      SerializedResponseNode componentsNode(false);
-      componentsNode.name = "components";
 
       for (auto component : components) {

Review comment:
       I know it's old code, but as we touch it - copy seems to be needless 
here.

##########
File path: libminifi/src/utils/SystemCPUUsageTracker.cpp
##########
@@ -0,0 +1,190 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "utils/SystemCPUUsageTracker.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace utils {
+#ifdef __linux__
+
+SystemCPUUsageTracker::SystemCPUUsageTracker() :
+    total_user_(0), previous_total_user_(0),
+    total_user_low_(0), previous_total_user_low_(0),
+    total_sys_(0), previous_total_sys_(0),
+    total_idle_(0), previous_total_idle_(0) {
+  queryCPUTimes();
+}
+
+double SystemCPUUsageTracker::getCPUUsageAndRestartCollection() {
+  queryCPUTimes();
+  if (isCurrentQuerySameAsPrevious() || isCurrentQuerySameAsPrevious()) {

Review comment:
       Do I miss something, or is it A || A?
   
   I think in one of the conditions you wanted if check if query is **older** 
than previous

##########
File path: libminifi/include/core/state/nodes/AgentInformation.h
##########
@@ -425,77 +427,123 @@ class AgentStatus : public StateMonitorNode {
 
   std::vector<SerializedResponseNode> serialize() {
     std::vector<SerializedResponseNode> serialized;
+    auto serializedRepositories = serializeRepositories();
+    if (!serializedRepositories.empty()) {
+      serialized.push_back(serializedRepositories);
+    }
+    serialized.push_back(serializeUptime());
 
-    SerializedResponseNode uptime;
-
-    uptime.name = "uptime";
-    if (nullptr != monitor_) {
-      uptime.value = monitor_->getUptime();
-    } else {
-      uptime.value = "0";
+    auto serializedComponents = serializeComponents();
+    if (!serializedComponents.empty()) {
+      serialized.push_back(serializedComponents);
     }
 
-    if (!repositories_.empty()) {
-      SerializedResponseNode repositories;
+    serialized.push_back(serializeResourceConsumption());
 
-      repositories.name = "repositories";
+    return serialized;
+  }
+
+ protected:
+  SerializedResponseNode serializeRepositories() {
+    SerializedResponseNode repositories;
 
-      for (auto &repo : repositories_) {
-        SerializedResponseNode repoNode;
-        repoNode.collapsible = false;
-        repoNode.name = repo.first;
+    repositories.name = "repositories";
 
-        SerializedResponseNode queuesize;
-        queuesize.name = "size";
-        queuesize.value = repo.second->getRepoSize();
+    for (auto &repo : repositories_) {

Review comment:
       Does it modify anything on the original container?
   I don't see such line, so I would go with const & here




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to