@Override public void metricRemoval(KafkaMetric metric) { _interestedMetrics.remove(metric.metricName()); }
private void addMetricIfInterested(KafkaMetric metric) { LOG.trace("Checking Kafka metric {}", metric.metricName()); if (MetricsUtils.isInterested(metric.metricName())) { LOG.debug("Added new metric {} to Cruise Control metrics reporter.", metric.metricName()); _interestedMetrics.put(metric.metricName(), metric); } }
synchronized void registerMetric(KafkaMetric metric) { MetricName metricName = metric.metricName(); if (this.metrics.containsKey(metricName)) throw new IllegalArgumentException("A metric named '" + metricName + "' already exists, can't register another one."); this.metrics.put(metricName, metric); for (MetricsReporter reporter : reporters) { try { reporter.metricChange(metric); } catch (Exception e) { log.error("Error when registering metric on " + reporter.getClass().getName(), e); } } log.trace("Registered metric named {}", metricName); }
@Override public MBeanInfo getMBeanInfo() { MBeanAttributeInfo[] attrs = new MBeanAttributeInfo[metrics.size()]; int i = 0; for (Map.Entry<String, KafkaMetric> entry : this.metrics.entrySet()) { String attribute = entry.getKey(); KafkaMetric metric = entry.getValue(); attrs[i] = new MBeanAttributeInfo(attribute, double.class.getName(), metric.metricName().description(), true, false, false); i += 1; } return new MBeanInfo(this.getClass().getName(), "", attrs, null, null, null); }
private KafkaMbean removeAttribute(KafkaMetric metric, String mBeanName) { MetricName metricName = metric.metricName(); KafkaMbean mbean = this.mbeans.get(mBeanName); if (mbean != null) mbean.removeAttribute(metricName.name()); return mbean; }
private KafkaMbean addAttribute(KafkaMetric metric) { try { MetricName metricName = metric.metricName(); String mBeanName = getMBeanName(prefix, metricName); if (!this.mbeans.containsKey(mBeanName)) mbeans.put(mBeanName, new KafkaMbean(mBeanName)); KafkaMbean mbean = this.mbeans.get(mBeanName); mbean.setAttribute(metricName.name(), metric); return mbean; } catch (JMException e) { throw new KafkaException("Error creating mbean attribute for metricName :" + metric.metricName(), e); } }
/** * Convert a KafkaMetric to a CruiseControlMetric */ public static CruiseControlMetric toCruiseControlMetric(KafkaMetric kafkaMetric, long now, int brokerId) { org.apache.kafka.common.MetricName metricName = kafkaMetric.metricName(); CruiseControlMetric ccm = toCruiseControlMetric(now, brokerId, metricName.name(), metricName.tags(), kafkaMetric.value()); if (ccm == null) { throw new IllegalArgumentException(String.format("Cannot convert KafkaMetric %s to a Cruise Control metric for " + "broker %d at time %d", kafkaMetric.metricName(), brokerId, now)); } return ccm; }
@Override public void metricRemoval(KafkaMetric metric) { synchronized (LOCK) { MetricName metricName = metric.metricName(); String mBeanName = getMBeanName(prefix, metricName); KafkaMbean mbean = removeAttribute(metric, mBeanName); if (mbean != null) { if (mbean.metrics.isEmpty()) { unregister(mbean); mbeans.remove(mBeanName); } else reregister(mbean); } } }
/** * Remove a sensor (if it exists), associated metrics and its children. * * @param name The name of the sensor to be removed */ public void removeSensor(String name) { Sensor sensor = sensors.get(name); if (sensor != null) { List<Sensor> childSensors = null; synchronized (sensor) { synchronized (this) { if (sensors.remove(name, sensor)) { for (KafkaMetric metric : sensor.metrics()) removeMetric(metric.metricName()); log.debug("Removed sensor with name {}", name); childSensors = childrenSensors.remove(sensor); for (final Sensor parent : sensor.parents()) { childrenSensors.getOrDefault(parent, emptyList()).remove(sensor); } } } } if (childSensors != null) { for (Sensor childSensor : childSensors) removeSensor(childSensor.name()); } } }
/** * Register a compound statistic with this sensor which yields multiple measurable quantities (like a histogram) * @param stat The stat to register * @param config The configuration for this stat. If null then the stat will use the default configuration for this * sensor. * @return true if stat is added to sensor, false if sensor is expired */ public synchronized boolean add(CompoundStat stat, MetricConfig config) { if (hasExpired()) return false; this.stats.add(Utils.notNull(stat)); Object lock = metricLock(); for (NamedMeasurable m : stat.stats()) { final KafkaMetric metric = new KafkaMetric(lock, m.name(), m.stat(), config == null ? this.config : config, time); if (!metrics.containsKey(metric.metricName())) { registry.registerMetric(metric); metrics.put(metric.metricName(), metric); } } return true; }
public void close(final Metrics metrics) { metrics.removeSensor(sensor.name()); metrics.removeMetric(metric.metricName()); }
Stat asStat() { return new Stat(metric.metricName().name(), value(), lastEvent); } }
/** * Register a metric with this sensor * * @param metricName The name of the metric * @param stat The statistic to keep * @param config A special configuration for this metric. If null use the sensor default configuration. * @return true if metric is added to sensor, false if sensor is expired */ public synchronized boolean add(final MetricName metricName, final MeasurableStat stat, final MetricConfig config) { if (hasExpired()) { return false; } else if (metrics.containsKey(metricName)) { return true; } else { final KafkaMetric metric = new KafkaMetric( metricLock(), Utils.notNull(metricName), Utils.notNull(stat), config == null ? this.config : config, time ); registry.registerMetric(metric); metrics.put(metric.metricName(), metric); stats.add(stat); return true; } }
public void checkQuotas(long timeMs) { for (KafkaMetric metric : this.metrics.values()) { MetricConfig config = metric.config(); if (config != null) { Quota quota = config.quota(); if (quota != null) { double value = metric.measurableValue(timeMs); if (!quota.acceptable(value)) { throw new QuotaViolationException(metric.metricName(), value, quota.bound()); } } } } }
@Override public void metricRemoval(KafkaMetric metric) { _interestedMetrics.remove(metric.metricName()); }
private void addMetricIfInterested(KafkaMetric metric) { LOG.trace("Checking Kafka metric {}", metric.metricName()); if (MetricsUtils.isInterested(metric.metricName())) { LOG.debug("Added new metric {} to Cruise Control metrics reporter.", metric.metricName()); _interestedMetrics.put(metric.metricName(), metric); } }
synchronized void registerMetric(KafkaMetric metric) { MetricName metricName = metric.metricName(); if (this.metrics.containsKey(metricName)) throw new IllegalArgumentException("A metric named '" + metricName + "' already exists, can't register another one."); this.metrics.put(metricName, metric); for (MetricsReporter reporter : reporters) reporter.metricChange(metric); }
@Override public MBeanInfo getMBeanInfo() { MBeanAttributeInfo[] attrs = new MBeanAttributeInfo[metrics.size()]; int i = 0; for (Map.Entry<String, KafkaMetric> entry : this.metrics.entrySet()) { String attribute = entry.getKey(); KafkaMetric metric = entry.getValue(); attrs[i] = new MBeanAttributeInfo(attribute, double.class.getName(), metric.metricName().description(), true, false, false); i += 1; } return new MBeanInfo(this.getClass().getName(), "", attrs, null, null, null); }
/** * Convert a KafkaMetric to a CruiseControlMetric */ public static CruiseControlMetric toCruiseControlMetric(KafkaMetric kafkaMetric, long now, int brokerId) { org.apache.kafka.common.MetricName metricName = kafkaMetric.metricName(); CruiseControlMetric ccm = toCruiseControlMetric(now, brokerId, metricName.name(), metricName.tags(), kafkaMetric.value()); if (ccm == null) { throw new IllegalArgumentException(String.format("Cannot convert KafkaMetric %s to a Cruise Control metric for " + "broker %d at time %d", kafkaMetric.metricName(), brokerId, now)); } return ccm; }
private void addMetric(KafkaMetric metric) { MetricName metricName = metric.metricName(); MonitorConfig.Builder builder = MonitorConfig.builder(metricName.name()) .withTag("group", metricName.group()); for(Map.Entry<String, String> tag : metricName.tags().entrySet()) { builder.withTag(tag.getKey(), tag.getValue()); } MonitorConfig monitorConfig = builder.build(); gauges.put(Servo.getDoubleGauge(monitorConfig), metric); }