lordgamez commented on code in PR #1340: URL: https://github.com/apache/nifi-minifi-cpp/pull/1340#discussion_r905895781
########## libminifi/src/c2/C2Client.cpp: ########## @@ -206,35 +130,13 @@ void C2Client::loadC2ResponseConfiguration(const std::string &prefix) { } std::shared_ptr<state::response::ResponseNode> new_node = std::make_shared<state::response::ObjectNode>(name); if (configuration_->get(classOption, class_definitions)) { - std::vector<std::string> classes = utils::StringUtils::split(class_definitions, ","); - for (const std::string& clazz : classes) { - // instantiate the object - std::shared_ptr<core::CoreComponent> ptr = core::ClassLoader::getDefaultClassLoader().instantiate(clazz, clazz); - if (nullptr == ptr) { - const bool found_metric = [&] { - std::lock_guard<std::mutex> guard{metrics_mutex_}; - auto metric = component_metrics_.find(clazz); - if (metric != component_metrics_.end()) { - ptr = metric->second; - return true; - } - return false; - }(); - if (!found_metric) { - logger_->log_error("No metric defined for %s", clazz); - continue; - } - } - auto node = std::dynamic_pointer_cast<state::response::ResponseNode>(ptr); - std::static_pointer_cast<state::response::ObjectNode>(new_node)->add_node(node); - } - + loadNodeClasses(class_definitions, new_node); } else { std::string optionName = option + "." + name; - auto node = loadC2ResponseConfiguration(optionName, new_node); + loadC2ResponseConfiguration(optionName, new_node); } - std::lock_guard<std::mutex> guard{metrics_mutex_}; + // We don't need to lock here we do it in the initializeResponseNodes Review Comment: Updated in afe6e3ec99c2c21454fd840d031677a2b948f1bd ########## libminifi/include/core/state/ConnectionStore.h: ########## @@ -0,0 +1,60 @@ +/** + * + * 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. + */ +#pragma once + +#include <map> +#include <string> +#include <vector> + +#include "Connection.h" +#include "utils/gsl.h" + +namespace org::apache::nifi::minifi::state { + +class ConnectionStore { + public: + void updateConnection(minifi::Connection* connection) { + if (nullptr != connection) { + connections_[connection->getUUIDStr()] = connection; + } + } + + std::vector<PublishedMetric> calculateConnectionMetrics(const std::string& metric_class) { + std::vector<PublishedMetric> metrics; + + for (const auto& [_, connection] : connections_) { + metrics.push_back({"queue_data_size", static_cast<double>(connection->getQueueDataSize()), + {{"connection_uuid", connection->getUUIDStr()}, {"connection_name", connection->getName()}, {"metric_class", metric_class}}}); + metrics.push_back({"queue_data_size_max", static_cast<double>(connection->getMaxQueueDataSize()), + {{"connection_uuid", connection->getUUIDStr()}, {"connection_name", connection->getName()}, {"metric_class", metric_class}}}); + metrics.push_back({"queue_size", static_cast<double>(connection->getQueueSize()), + {{"connection_uuid", connection->getUUIDStr()}, {"connection_name", connection->getName()}, {"metric_class", metric_class}}}); + metrics.push_back({"queue_size_max", static_cast<double>(connection->getMaxQueueSize()), + {{"connection_uuid", connection->getUUIDStr()}, {"connection_name", connection->getName()}, {"metric_class", metric_class}}}); + } + + return metrics; + } + + virtual ~ConnectionStore() = default; + + protected: + std::map<std::string, minifi::Connection*> connections_; Review Comment: Thanks! Updated in afe6e3ec99c2c21454fd840d031677a2b948f1bd ########## METRICS.md: ########## @@ -0,0 +1,155 @@ +<!-- + 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. +--> + +# Apache NiFi - MiNiFi - C++ Metrics Readme. + + +This readme defines the metrics published by Apache NiFi. All options defined are located in minifi.properties. + +## Table of Contents + +- [Description](#description) +- [Configuration](#configuration) +- [Metrics](#metrics) + +## Description + +Apache NiFi MiNiFi C++ can communicate metrics about the agent's status, that can be a system level or component level metric. +These metrics are exposed through the agent implemented metric publishers that can be configured in the minifi.properties. +Aside from the publisher exposed metrics, metrics are also sent through C2 protocol of which there is more information in the +[C2 documentation](C2.md#metrics). + +## Configuration + +To configure the a metrics publisher first we have to set which publisher class should be used: + + # in minifi.properties + + nifi.metrics.publisher.class=PrometheusMetricsPublisher + +Currently PrometheusMetricsPublisher is the only available publisher in MiNiFi C++ which publishes metrics to a Prometheus server. +To use the publisher a port should also be configured where the metrics will be available to be scraped through: + + # in minifi.properties + + nifi.metrics.publisher.PrometheusMetricsPublisher.port=9936 + +The last option defines which metric classes should be exposed through the metrics publisher in configured with a comma separated value: + + # in minifi.properties + + nifi.metrics.publisher.metrics=QueueMetrics,RepositoryMetrics,GetFileMetrics,DeviceInfoNode,FlowInformation + +## Metrics + +The following section defines the currently available metrics to be published by the MiNiFi C++ agent. + +NOTE: In Prometheus all metrics are extended with a `minifi_` prefix to mark the domain of the metric. For example the `connection_name` metric is published as `minifi_connection_name` in Prometheus. + +### QueueMetrics + +QueueMetrics is a system level metric that reports queue metrics for every connection in the flow. + +| Metric name | Labels | Description | +|----------------------|------------------------------------------------|--------------------------------------------| +| queue_data_size | metric_class, connection_uuid, connection_name | Max queue size to apply back pressure | +| queue_data_size_max | metric_class, connection_uuid, connection_name | Max queue data size to apply back pressure | +| queue_size | metric_class, connection_uuid, connection_name | Current queue size | +| queue_size_max | metric_class, connection_uuid, connection_name | Current queue data size | Review Comment: Updated in afe6e3ec99c2c21454fd840d031677a2b948f1bd -- 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. To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org