lordgamez commented on code in PR #1340:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1340#discussion_r905858178


##########
libminifi/include/core/state/nodes/RepositoryMetrics.h:
##########
@@ -90,15 +87,18 @@ class RepositoryMetrics : public ResponseNode {
     return serialized;
   }
 
+  std::vector<PublishedMetric> calculateMetrics() override {
+    std::vector<PublishedMetric> metrics;
+    for (const auto& [_, repo] : repositories_) {
+      metrics.push_back({"is_running", (repo->isRunning() ? 1.0 : 0.0), 
{{"metric_class", getName()}, {"repository_name", repo->getName()}}});
+      metrics.push_back({"is_full", (repo->isFull() ? 1.0 : 0.0), 
{{"metric_class", getName()}, {"repository_name", repo->getName()}}});
+      metrics.push_back({"repository_size", 
static_cast<double>(repo->getRepoSize()), {{"metric_class", getName()}, 
{"repository_name", repo->getName()}}});
+    }
+    return metrics;
+  }

Review Comment:
   Thanks, now I see what you mean. It would be better if they would be 
interchangeable somehow, but I think it would be problematic to implement it at 
the moment. Currently the common denominator between publishing through metrics 
exposers and through C2 is the `ResponseNode` which is passed to both to 
Prometheus and the C2Client, but they work quite differently through the 
`serialize` and the `calculateMetrics` as they do more now than just formatting.
   
   The `serialize` member defines a tree structure of the metrics, how they 
should be aligned which returns a `SerializedResponseNode` (which is then moved 
to `C2Payload` objects, then those are transformed to json objects by 
rapidjsons so it's quite complex, something we may need to rewrite in the 
future). Opposed to this the calculateMetrics returns a flat format with 
key-value pairs with additional labels, so it's structured quite differently. 
We also have an `ObjectNode` responsenode for mimicing the C2 properties' tree 
structure containing children nodes. Its serialization process goes through the 
nodes recursively which requires to have this `serialize` as a member function 
so it would be hard to move it to the C2Client. 
   
   Also moving the serialization and the metrics calculation to C2Client and 
the metrics publisher would require us to define parts of a newly introduced 
metric in 3 places, which would not be really intuitive.
   
   Another problem is that both members contain different metrics as 
`calculateMetrics` only collects quantifiable data, that can be represented as 
a double for monitoring tools, while `serialize` contains string data as well 
for example.



##########
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:
   Okay, I think we would have more input and would be able to generalize these 
things a bit easier if we had another monitoring tool support, that would make 
it easier to see what needs to be more generalized.
   
   I see there is a mixup in the descriptions I'll fix it.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to