apache/kafka · warning · AttributeNotFoundException
Could not find attribute {name}
Error message
Could not find attribute {name} What it means
Thrown by KafkaMbean.getAttribute(String) when a JMX client queries an attribute name that the mbean does not contain. JmxReporter's KafkaMbean is a DynamicMBean whose attributes are the metric names it has registered; asking for any other name raises AttributeNotFoundException. The message echoes the requested attribute name so the offending query is identifiable.
Source
Thrown at clients/src/main/java/org/apache/kafka/common/metrics/JmxReporter.java:242
KafkaMbean(String mbeanName) throws MalformedObjectNameException {
this.metrics = new HashMap<>();
this.objectName = new ObjectName(mbeanName);
}
public ObjectName name() {
return objectName;
}
void setAttribute(String name, KafkaMetric metric) {
this.metrics.put(name, metric);
}
@Override
public Object getAttribute(String name) throws AttributeNotFoundException {
if (this.metrics.containsKey(name))
return this.metrics.get(name).metricValue();
else
throw new AttributeNotFoundException("Could not find attribute " + name);
}
@Override
public AttributeList getAttributes(String[] names) {
AttributeList list = new AttributeList();
for (String name : names) {
try {
list.add(new Attribute(name, getAttribute(name)));
} catch (Exception e) {
log.warn("Error getting JMX attribute '{}'", name, e);
}
}
return list;
}
KafkaMetric removeAttribute(String name) {
return this.metrics.remove(name);
}View on GitHub (pinned to c31c9215e1)
Solutions
- Confirm the attribute name in the message matches a real Kafka metric — list the mbean's actual attributes with jconsole/jmc or Jolokia's list operation.
- Update your JMX client / monitoring config to use the current metric names for your Kafka version (metric names have changed across major versions — check the upgrade notes).
- If polling dynamic metrics, treat AttributeNotFoundException as a non-fatal 'metric not present' signal and skip rather than erroring.
- Verify the metric hasn't been removed at runtime — check Metrics.removeMetric / sensor lifecycle in your code.
- Pin a consistent Kafka version across the cluster and monitoring stack so metric names do not drift out from under dashboards.
Example fix
// before — exporter config lists an old attribute that no longer exists
rules:
- pattern: 'kafka.producer<type=producer-metrics><>(.*):' # wrong/old name
name: kafka_producer_$1
# JMX client -> AttributeNotFoundException: Could not find attribute ...
// after — name aligned to the running Kafka version's actual metric
rules:
- pattern: 'kafka.producer<type=producer-metrics><>compression-rate-avg'
name: kafka_producer_compression_rate_avg Defensive patterns
Strategy: validation
Validate before calling
// Before reading a JMX attribute, confirm it exists on the mbean.
MBeanServer server = ManagementFactory.getPlatformMBeanServer();
ObjectName on = ...;
String attr = "records-rate";
MBeanInfo info = server.getMBeanInfo(on);
boolean present = Arrays.stream(info.getAttributes())
.anyMatch(a -> a.getName().equals(attr));
if (present) {
Object value = server.getAttribute(on, attr);
} else {
// skip / report unknown metric
} Type guard
// Narrow a JMX attribute name to 'one this mbean actually exposes'.
static Set<String> availableAttributes(MBeanServer server, ObjectName on) throws JMException {
return Arrays.stream(server.getMBeanInfo(on).getAttributes())
.map(MBeanAttributeInfo::getName)
.collect(Collectors.toSet());
} Try / catch
try {
Object v = server.getAttribute(objectName, attributeName);
} catch (AttributeNotFoundException e) {
// metric was removed or never existed; treat as 'not available' rather than an error.
log.debug("JMX attribute {} not present on {}", attributeName, objectName);
return Optional.empty();
} Prevention
- Do not hard-code JMX attribute names in dashboards; discover them from getMBeanInfo() so removed metrics do not break scraping.
- Metric attribute names are derived from MetricName.name(); reference the same constants when querying.
- When scraping Kafka JMX, log AttributeNotFoundException at DEBUG and skip — it is expected during metric churn.
- Refresh the attribute list after metric reconfiguration rather than caching forever.
When it happens
Trigger: An external JMX client (jconsole, jmc, Prometheus JMX exporter, custom JMX query) calls getAttribute on a Kafka mbean with a name the mbean never registered. Occurs when a metric was removed (metricName removed via Metrics.removeMetric) but the JMX client still queries the old attribute, or when the client uses a guessed/hardcoded attribute name that does not match the metricName name in Kafka.
Common situations: Monitoring tooling or dashboards configured against an older Kafka version where metric names differed; a metric dynamically added/removed at runtime (e.g. per-partition sensors) while a polling JMX client keeps asking for the now-absent attribute; JMX exporter rules (jmx_exporter) listing metrics by name that have since been renamed in Kafka; scripted JMX automation that iterates an assumed set of names and hits one that is not present.
Related errors
- Error creating mbean attribute for metricName :{metricName}
- Error unregistering mbean
- Error registering mbean {mbeanName}
- Set not allowed.
- JMX filter for configuration{metricsConfigPrefix}.(include/e
AI-assisted analysis of apache/kafka@c31c9215e1 (2026-08-03).
Data as JSON: /data/errors/7ad5ee02e1823a09.json.
Report an issue: GitHub.