public static String toHtmlTable(String domain, Iterable<MetricNameTemplate> allMetrics) {
        Map<String, Map<String, String>> beansAndAttributes = new TreeMap<>();
    
        try (Metrics metrics = new Metrics()) {
            for (MetricNameTemplate template : allMetrics) {
                Map<String, String> tags = new LinkedHashMap<>();
                for (String s : template.tags()) {
                    tags.put(s, "{" + s + "}");
                }
    
                MetricName metricName = metrics.metricName(template.name(), template.group(), template.description(), tags);
                String mBeanName = JmxReporter.getMBeanName(domain, metricName);
                if (!beansAndAttributes.containsKey(mBeanName)) {
                    beansAndAttributes.put(mBeanName, new TreeMap<>());
                }
                Map<String, String> attrAndDesc = beansAndAttributes.get(mBeanName);
                if (!attrAndDesc.containsKey(template.name())) {
                    attrAndDesc.put(template.name(), template.description());
                } else {
                    throw new IllegalArgumentException("mBean '" + mBeanName + "' attribute '" + template.name() + "' is defined twice.");
                }
            }
        }
        StringBuilder b = new StringBuilder();
        b.append("<table class=\"data-table\">\n<tbody>\n");
        b.append("<tr>\n");
        b.append("<th>Metric/Attribute name</th>\n");
        b.append("<th>Description</th>\n");
        b.append("<th>Mbean name</th>\n");
        b.append("</tr>\n");
        for (Entry<String, Map<String, String>> e : beansAndAttributes.entrySet()) {
            for (Entry<String, String> e2 : e.getValue().entrySet()) {
                b.append("<tr>\n");
                b.append("<td>");
                b.append(e2.getKey());
                b.append("</td>\n");
                b.append("<td>");
                b.append(e2.getValue());
                b.append("</td>\n");
                b.append("<td>");
                b.append(e.getKey());
                b.append("</td>\n");
                b.append("</tr>\n");
            }
        }
        b.append("</tbody></table>");
        return b.toString();
    }
Use the specified domain and metric name templates to generate an HTML table documenting the metrics. A separate table section
will be generated for each of the MBeans and the associated attributes. The MBean names are lexicographically sorted to
determine the order of these sections. This order is therefore dependent upon the order of the
tags in each {@link MetricNameTemplate}.

@param domain the domain or prefix for the JMX MBean names; may not be null
@param allMetrics the collection of all {@link MetricNameTemplate} instances each describing one metric; may not be null
@return the string containing the HTML table; never null
clients/src/main/java/org/apache/kafka/common/metrics/Metrics.java