private <T> Map<String, T> getMetricValues(String group, String metric, String attribute) {
    try {
      StringBuilder nameBuilder = new StringBuilder();
      nameBuilder.append(JmxUtil.makeNameJmxSafe(group));
      nameBuilder.append(":type=*,name=");
      nameBuilder.append(JmxUtil.makeNameJmxSafe(metric));
      ObjectName query = new ObjectName(nameBuilder.toString());
      Map<String, T> values = new HashMap<>();
      MBeanServerConnection conn = jmxc.getMBeanServerConnection();
      for (ObjectName objName : conn.queryNames(query, null)) {
        String type = objName.getKeyProperty("type");
        T val = (T) conn.getAttribute(objName, attribute);
        values.put(type, val);
      }
      return values;
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      return Collections.EMPTY_MAP;
    }
  }
JMX metrics accessor.
It connects to a container JMX url,and get metrics values by querying the MBeans.
samza-core/src/main/java/org/apache/samza/metrics/JmxMetricsAccessor.java