NMS-19403: Add device specific metrics for Traps #8271
NMS-19403: Add device specific metrics for Traps #8271cgorantla wants to merge 10 commits intofoundation-2024from
Conversation
This will add device (location:ipAddress) specific metrics for Trap processing. These metrics are not enabled by default. Need to enable with specific system property
There was a problem hiding this comment.
Pull request overview
This PR adds device-specific metrics for SNMP trap processing, allowing operators to track trap processing statistics per device (identified by location and IP address). The feature is disabled by default and can be enabled via system property on OpenNMS or OSGi configuration on Minion.
Changes:
- Added per-device trap metrics tracked by location and IP address
- Removed deprecated
trapsDispatchedmetric from the codebase - Added new JMX MBean interfaces and implementations for device-level metrics
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| opennms-container/minion/container-fs/prom-jmx-default-config.yaml | Adds JMX exporter pattern for device-specific trap metrics |
| opennms-container/minion/container-fs/confd/templates/prom-jmx-exporter.yaml.tmpl | Adds template configuration for device trap metrics in Minion |
| opennms-container/core/container-fs/confd/templates/prom-jmx-exporter.yaml.tmpl | Adds template configuration for device trap metrics in OpenNMS core |
| features/events/traps/src/main/resources/OSGI-INF/blueprint/blueprint-trapd-listener.xml | Adds OSGi configuration property and Identity reference for device metrics |
| features/events/traps/src/main/java/org/opennms/netmgt/trapd/jmx/TrapdMBean.java | Removes deprecated getTrapsDispatched() method |
| features/events/traps/src/main/java/org/opennms/netmgt/trapd/jmx/TrapdInstrumentation.java | Adds device-level metrics tracking and registry management |
| features/events/traps/src/main/java/org/opennms/netmgt/trapd/jmx/Trapd.java | Removes getTrapsDispatched() implementation |
| features/events/traps/src/main/java/org/opennms/netmgt/trapd/jmx/DeviceTrapMetricsRegistry.java | New registry class for managing per-device JMX MBeans |
| features/events/traps/src/main/java/org/opennms/netmgt/trapd/jmx/DeviceTrapMetricsMBean.java | New MBean interface for listener-side device metrics |
| features/events/traps/src/main/java/org/opennms/netmgt/trapd/jmx/DeviceTrapMetrics.java | Implementation of listener-side device metrics |
| features/events/traps/src/main/java/org/opennms/netmgt/trapd/jmx/DeviceConsumerTrapMetricsMBean.java | New MBean interface for consumer-side device metrics |
| features/events/traps/src/main/java/org/opennms/netmgt/trapd/jmx/DeviceConsumerTrapMetrics.java | Implementation of consumer-side device metrics |
| features/events/traps/src/main/java/org/opennms/netmgt/trapd/TrapSinkConsumer.java | Updates trap processing to track device-specific metrics |
| features/events/traps/src/main/java/org/opennms/netmgt/trapd/TrapListenerMetrics.java | Adds device metrics registry and removes trapsDispatched counter |
| features/events/traps/src/main/java/org/opennms/netmgt/trapd/TrapListener.java | Updates trap reception to track device-specific metrics and removes dispatch counting |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
features/events/traps/src/main/java/org/opennms/netmgt/trapd/jmx/DeviceTrapMetricsRegistry.java
Outdated
Show resolved
Hide resolved
features/events/traps/src/main/java/org/opennms/netmgt/trapd/TrapListenerMetrics.java
Outdated
Show resolved
Hide resolved
christianpape
left a comment
There was a problem hiding this comment.
Looks good. The only issue is that maybe shutdown() will not work as expected in the case of IPv6 addresses.
features/events/traps/src/main/java/org/opennms/netmgt/trapd/jmx/DeviceTrapMetricsRegistry.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
features/events/traps/src/main/java/org/opennms/netmgt/trapd/jmx/TrapdInstrumentation.java
Show resolved
Hide resolved
features/events/traps/src/main/java/org/opennms/netmgt/trapd/TrapListenerMetrics.java
Outdated
Show resolved
Hide resolved
The base branch was changed.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@cgorantla I've tested it with a few nodes, here are the metrics per IP from the Core: Metrics are exposed per IP address. We need to tweak the Prometheus configuration so that we also expose the location attribute as well. An IP address can be in many locations and isn't unique enough. The JMX export in Hawtio gives the location, it seems this is something we need to fix in the JMX Prometheus Exporter template.
To make it work in Prometheus we need the location as a label like this: The |
|
@cgorantla your patch solved the problem. Here is how it looks like on the Minion now: Core: Minion: A little detail here for Core: I would have expected to see 2 metrics on core for type "consumer", one for location "ipc-kafka" and one for location "Default" + an additional trapd_device_rawtrapsreceived_total{ip="10.42.2.1",location="Default",type="listener"} where the listener is running on the Core? Here is an attachment how these metric look like now on Core and Minion |
|
trapd_device_rawtrapsreceived_total{ip="10.42.2.1",location="Default",type="listener"} where the listener is running on the Core? - Yeah, this should also be there. Let me check again why it is missing |
|
On Core, I can see this |
Yes I have a listener running on core on port 1162 and on the Minion port 1163 to test the behaviour for both use cases. |
I would have expected to see it the same per "device" as it is on the Minion. |
Latest commit should fix this. |


This will add device (location:ipAddress) specific metrics for Trap processing.
These metrics are not enabled by default.
Need to enable with specific system property on opennms and through osgi config on Minion
External References