This is an automated email from the ASF dual-hosted git repository.
pvillard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new 5699759c29 NIFI-15351 Show NiFi build information in Prometheus metrics
5699759c29 is described below
commit 5699759c2978ba7f4cf227440f0aade29cb04ade
Author: Adam Turley <[email protected]>
AuthorDate: Tue Dec 16 17:50:03 2025 -0700
NIFI-15351 Show NiFi build information in Prometheus metrics
Signed-off-by: Pierre Villard <[email protected]>
This closes #10655.
---
.../nifi/prometheusutil/PrometheusMetricsUtil.java | 20 +++++
.../nifi/prometheusutil/VersionInfoRegistry.java | 92 ++++++++++++++++++++++
.../apache/nifi/web/StandardNiFiServiceFacade.java | 7 +-
.../nifi/web/api/request/FlowMetricsRegistry.java | 5 +-
4 files changed, 122 insertions(+), 2 deletions(-)
diff --git
a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/prometheusutil/PrometheusMetricsUtil.java
b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/prometheusutil/PrometheusMetricsUtil.java
index c34ac20928..70a75887ce 100644
---
a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/prometheusutil/PrometheusMetricsUtil.java
+++
b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/prometheusutil/PrometheusMetricsUtil.java
@@ -478,6 +478,26 @@ public class PrometheusMetricsUtil {
return niFiMetricsRegistry.getRegistry();
}
+ public static void createVersionInfoMetrics(final VersionInfoRegistry
versionInfoRegistry, final String instanceId) {
+ // Retrieve the calculated version details
+ final VersionInfoRegistry.VersionDetails details =
versionInfoRegistry.getVersionDetails();
+
+ versionInfoRegistry.setDataPoint(
+ 1,
+ "NIFI_VERSION_INFO",
+ instanceId,
+ details.frameworkVersion(),
+ details.javaVersion(),
+ details.revision(),
+ details.tag(),
+ details.buildBranch(),
+ details.osName(),
+ details.osVersion(),
+ details.osArchitecture(),
+ details.javaVendor()
+ );
+ }
+
public static CollectorRegistry createClusterMetrics(final
ClusterMetricsRegistry clusterMetricsRegistry, final String instId, final
boolean isClustered, final boolean isConnectedToCluster,
final String
connectedNodes, final int connectedNodeCount, final int totalNodeCount) {
final String instanceId = StringUtils.isEmpty(instId) ?
DEFAULT_LABEL_STRING : instId;
diff --git
a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/prometheusutil/VersionInfoRegistry.java
b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/prometheusutil/VersionInfoRegistry.java
new file mode 100644
index 0000000000..a07c25b894
--- /dev/null
+++
b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/prometheusutil/VersionInfoRegistry.java
@@ -0,0 +1,92 @@
+/*
+ * 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.
+ */
+
+package org.apache.nifi.prometheusutil;
+
+import io.prometheus.client.Gauge;
+import org.apache.nifi.nar.NarClassLoadersHolder;
+import org.apache.nifi.bundle.Bundle;
+import org.apache.nifi.bundle.BundleDetails;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class VersionInfoRegistry extends AbstractMetricsRegistry {
+ private static final Logger LOGGER =
LoggerFactory.getLogger(VersionInfoRegistry.class);
+ private static final String DEFAULT_LABEL_STRING = "unknown";
+
+ public VersionInfoRegistry() {
+ nameToGaugeMap.put("NIFI_VERSION_INFO", Gauge.build()
+ .name("nifi_version_info")
+ .help("NiFi framework and environment version information.")
+ .labelNames(
+ "instance_id",
+ "framework_version",
+ "java_version",
+ "revision",
+ "build_tag",
+ "build_branch",
+ "os_name",
+ "os_version",
+ "os_architecture",
+ "java_vendor"
+ )
+ .register(registry)
+ );
+ }
+
+ public record VersionDetails(
+ String frameworkVersion,
+ String revision,
+ String tag,
+ String buildBranch,
+ String javaVersion,
+ String javaVendor,
+ String osVersion,
+ String osName,
+ String osArchitecture
+ ) { }
+
+ public VersionDetails getVersionDetails() {
+ String frameworkVersion = DEFAULT_LABEL_STRING;
+ String revision = DEFAULT_LABEL_STRING;
+ String tag = DEFAULT_LABEL_STRING;
+ String buildBranch = DEFAULT_LABEL_STRING;
+
+ // Retrieve universal system properties
+ final String javaVersion = System.getProperty("java.version",
DEFAULT_LABEL_STRING);
+ final String javaVendor = System.getProperty("java.vendor",
DEFAULT_LABEL_STRING);
+ final String osVersion = System.getProperty("os.version",
DEFAULT_LABEL_STRING);
+ final String osName = System.getProperty("os.name",
DEFAULT_LABEL_STRING);
+ final String osArchitecture = System.getProperty("os.arch",
DEFAULT_LABEL_STRING);
+
+ try {
+ // NiFi internal API to get build specifics
+ final Bundle frameworkBundle =
NarClassLoadersHolder.getInstance().getFrameworkBundle();
+ if (frameworkBundle != null) {
+ final BundleDetails frameworkDetails =
frameworkBundle.getBundleDetails();
+ frameworkVersion =
frameworkDetails.getCoordinate().getVersion();
+ revision = frameworkDetails.getBuildRevision();
+ tag = frameworkDetails.getBuildTag();
+ buildBranch = frameworkDetails.getBuildBranch();
+ }
+ } catch (Exception e) {
+ LOGGER.debug("Could not retrieve NiFi bundle details for version
info metric", e);
+ }
+ return new VersionDetails(frameworkVersion, revision, tag,
buildBranch, javaVersion, javaVendor, osVersion, osName, osArchitecture);
+ }
+
+}
diff --git
a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
index c469f10024..56aa46ff4f 100644
---
a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
+++
b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/StandardNiFiServiceFacade.java
@@ -171,6 +171,7 @@ import
org.apache.nifi.prometheusutil.ClusterMetricsRegistry;
import org.apache.nifi.prometheusutil.ConnectionAnalyticsMetricsRegistry;
import org.apache.nifi.prometheusutil.JvmMetricsRegistry;
import org.apache.nifi.prometheusutil.NiFiMetricsRegistry;
+import org.apache.nifi.prometheusutil.VersionInfoRegistry;
import org.apache.nifi.prometheusutil.PrometheusMetricsUtil;
import org.apache.nifi.registry.flow.FlowLocation;
import org.apache.nifi.registry.flow.FlowRegistryBranch;
@@ -6639,6 +6640,7 @@ public class StandardNiFiServiceFacade implements
NiFiServiceFacade {
// Include registries which are fully refreshed upon each invocation
NiFiMetricsRegistry nifiMetricsRegistry = new NiFiMetricsRegistry();
BulletinMetricsRegistry bulletinMetricsRegistry = new
BulletinMetricsRegistry();
+ VersionInfoRegistry versionInfoRegistry = new VersionInfoRegistry();
final NodeIdentifier node = controllerFacade.getNodeId();
final String instId =
StringUtils.isEmpty(controllerFacade.getInstanceId()) ? "" :
controllerFacade.getInstanceId();
@@ -6661,6 +6663,8 @@ public class StandardNiFiServiceFacade implements
NiFiServiceFacade {
nifiMetricsRegistry.setDataPoint(aggregateEvent.getBytesReceived(),
"TOTAL_BYTES_RECEIVED",
instanceId, ROOT_PROCESS_GROUP, rootPGName, rootPGId, "");
+ //Add version info metrics to NiFi metrics
+ PrometheusMetricsUtil.createVersionInfoMetrics(versionInfoRegistry,
instanceId);
//Add flow file repository, content repository and provenance
repository usage to NiFi metrics
final StorageUsage flowFileRepositoryUsage =
controllerFacade.getFlowFileRepositoryStorageUsage();
final Map<String, StorageUsage> contentRepositoryUsage =
controllerFacade.getContentRepositoryStorageUsage();
@@ -6737,7 +6741,8 @@ public class StandardNiFiServiceFacade implements
NiFiServiceFacade {
jvmMetricsRegistry,
connectionAnalyticsMetricsRegistry,
bulletinMetricsRegistry,
- clusterMetricsRegistry
+ clusterMetricsRegistry,
+ versionInfoRegistry
);
return metricsRegistries;
diff --git
a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/request/FlowMetricsRegistry.java
b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/request/FlowMetricsRegistry.java
index e1de1d578c..5b52749214 100644
---
a/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/request/FlowMetricsRegistry.java
+++
b/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/api/request/FlowMetricsRegistry.java
@@ -22,6 +22,7 @@ import org.apache.nifi.prometheusutil.ClusterMetricsRegistry;
import org.apache.nifi.prometheusutil.ConnectionAnalyticsMetricsRegistry;
import org.apache.nifi.prometheusutil.JvmMetricsRegistry;
import org.apache.nifi.prometheusutil.NiFiMetricsRegistry;
+import org.apache.nifi.prometheusutil.VersionInfoRegistry;
/**
* Flow Metrics Registries
@@ -35,7 +36,9 @@ public enum FlowMetricsRegistry {
CONNECTION("CONNECTION", ConnectionAnalyticsMetricsRegistry.class),
- CLUSTER("CLUSTER", ClusterMetricsRegistry.class);
+ CLUSTER("CLUSTER", ClusterMetricsRegistry.class),
+
+ VERSION_INFO("VERSION_INFO", VersionInfoRegistry.class);
private final String registry;