PrometheusHttpConsumerMetrics { protected static void exposeKafkaMetrics() { try { for (Map.Entry<ObjectName, BiFunction<ObjectName, MBeanAttributeInfo, Gauge.Child>> entry : kafkaJmxNameToPrometheusLabeler.entrySet()) { ObjectName baseKafkaJmxName = entry.getKey(); BiFunction<ObjectName, MBeanAttributeInfo, Gauge.Child> prometheusMetricLabelsFromObjectNameAndAttr = entry.getValue(); for (ObjectName name : MBS.queryNames(baseKafkaJmxName, null)) { MBeanInfo info = MBS.getMBeanInfo(name); MBeanAttributeInfo[] attrInfo = info.getAttributes(); for (MBeanAttributeInfo attr : attrInfo) { if (attr.isReadable() && attr.getType().equals("double")) { prometheusMetricLabelsFromObjectNameAndAttr.apply(name, attr) .set((Double) MBS.getAttribute(name, attr.getName())); } } } } } catch (InstanceNotFoundException | IntrospectionException | ReflectionException | MBeanException | AttributeNotFoundException e) { LOGGER.error(e.getMessage(), e); } } PrometheusHttpConsumerMetrics(int prometheusPort); void terminate(); static final String RELEASE; static final Counter GARMADON_READER_METRICS; static final Summary LATENCY_INDEXING_TO_ES; static final Counter.Child ISSUE_READING_GARMADON_MESSAGE_BAD_HEAD; static final Gauge GARMADON_READER_LAST_EVENT_TIMESTAMP; static final Counter.Child ISSUE_READING_PROTO_HEAD; static final Counter.Child ISSUE_READING_PROTO_BODY; }
@Test public void Prometheus_Collect_Kafka_metrics() throws MBeanException, IntrospectionException, ReflectionException, AttributeNotFoundException, InstanceNotFoundException { PrometheusHttpConsumerMetrics.exposeKafkaMetrics(); assertNotNull(CollectorRegistry.defaultRegistry.getSampleValue("garmadon_kafka_metrics", new String[]{"name", "hostname", "release", "consumer_id"}, new String[]{"IoStats", GarmadonReader.getHostname(), PrometheusHttpConsumerMetrics.RELEASE, "consumer-1"})); }