Java 类com.codahale.metrics.JmxAttributeGauge 实例源码

项目:jhipster-ng-admin    文件:JCacheGaugeSet.java   
@Override
public Map<String, Metric> getMetrics() {
    Set<ObjectInstance> objectInstances = getCacheMBeans();

    Map<String, Metric> gauges = new HashMap<String, Metric>();

    List<String> availableStatsNames = retrieveStatsNames();

    for (ObjectInstance objectInstance : objectInstances) {
        ObjectName objectName = objectInstance.getObjectName();
        String cacheName = objectName.getKeyProperty("Cache");

        for (String statsName : availableStatsNames) {
            JmxAttributeGauge jmxAttributeGauge = new JmxAttributeGauge(objectName, statsName);
            gauges.put(name(cacheName, toDashCase(statsName)), jmxAttributeGauge);
        }
    }

    return Collections.unmodifiableMap(gauges);
}
项目:blueflood    文件:AbstractJmxCache.java   
public void instantiateYammerMetrics(Class klass, String scope, ObjectName nameObj) {
    String name = MetricRegistry.name(klass);
    if (scope != null) {
        name = MetricRegistry.name(name, scope);
    }
    MetricRegistry reg = Metrics.getRegistry();
    hitCount = reg.register(MetricRegistry.name(name, "Hit Count"),
            new JmxAttributeGauge(nameObj, "HitCount"));
    hitRate = reg.register(MetricRegistry.name(name, "Hit Rate"),
            new JmxAttributeGauge(nameObj, "HitRate"));
    loadCount = reg.register(MetricRegistry.name(name, "Load Count"),
            new JmxAttributeGauge(nameObj, "LoadCount"));
    missRate = reg.register(MetricRegistry.name(name, "Miss Rate"),
            new JmxAttributeGauge(nameObj, "MissRate"));
    requestCount = reg.register(MetricRegistry.name(name, "Request Count"),
            new JmxAttributeGauge(nameObj, "RequestCount"));
    totalLoadTime = reg.register(MetricRegistry.name(name, "Total Load Time"),
            new JmxAttributeGauge(nameObj, "TotalLoadTime"));
}
项目:chaperone    文件:KafkaIngesterConsumer.java   
private void init() {
  // register kafka offset lag metrics, one Gauge is for per consumer level granularity
  MetricRegistry registry = Metrics.getRegistry();
  try {
    fetchedMsgCounter = registry.meter("kafkaIngesterConsumer." + this.getName() + "-msgFetchRate");
    failedToIngestCounter = registry.meter("kafkaIngesterConsumer." + this.getName() + "-failedToIngest");
    kafkaOffsetLagGauge =
        registry.register("kafkaIngesterConsumer." + this.getName() + "-kafkaOffsetLag", new JmxAttributeGauge(
            new ObjectName(maxLagMetricName), "Value"));
  } catch (MalformedObjectNameException | IllegalArgumentException e) {
    logger.error("Register failure for metrics of KafkaIngesterConsumer", e);
  }

  TopicFilter topicFilter = new Whitelist(AuditConfig.AUDIT_TOPIC_NAME);
  logger.info("{}: Topic filter is {}", getName(), AuditConfig.AUDIT_TOPIC_NAME);
  this.consumer = Consumer.createJavaConsumerConnector(createConsumerConfig());
  KafkaStream<byte[], byte[]> stream = consumer.createMessageStreamsByFilter(topicFilter, 1).get(0);
  iterator = stream.iterator();
  logger.info("KafkaIngesterConsumer thread {} is initialized successfully", getName());

  if (AuditConfig.INGESTER_ENABLE_DEDUP) {
    deduplicator =
        new Deduplicator(threadId, AuditConfig.INGESTER_REDIS_HOST, AuditConfig.INGESTER_REDIS_PORT,
            AuditConfig.INGESTER_REDIS_KEY_TTL_SEC, AuditConfig.INGESTER_DUP_HOST_PREFIX,
            AuditConfig.INGESTER_HOSTS_WITH_DUP);
    deduplicator.open();
  } else {
    deduplicator = null;
  }
}
项目:jmx-cloudwatch-reporter    文件:ReporterAgent.java   
protected void handleAttributes(MBeanInfo mBeanInfo, ObjectName objectName, ObjectNode attributesToMonitor) {
    for (MBeanAttributeInfo attr : mBeanInfo.getAttributes()) {
        // check if we are interested in this attribute
        String attrName = attr.getName();
        JsonNode jsonNode = attributesToMonitor.get(attrName);
        if (jsonNode != null) {
            if (!attr.isReadable()) {
                log.warn("cannot monitor unreadable attribute {}@{}", objectName.toString(), attrName);
                continue;
            }
            if (jsonNode.isTextual()) {
                String monitorName = jsonNode.asText() + metricsSuffix;
                metricRegistry.register(monitorName, new JmxAttributeGauge(mBeanServer, objectName, attrName));
                log.info("attribute {}@{} registered as {}", objectName , attrName, monitorName);
            } else if (jsonNode.isObject()) {
                if (!CompositeData.class.getName().equals(attr.getType())) {
                    log.warn("attribute {}@{} is not CompositeData", objectName, attr);
                    continue;
                }
                try {
                    CompositeData attribute = (CompositeData) mBeanServer.getAttribute(objectName, attrName);
                    handleComposite(objectName, attrName, attribute, (ObjectNode) jsonNode);
                } catch (JMException e) {
                    log.warn("unable to get composite attributes {}@{}",objectName,attrName,e);
                }

            }
        } else if (settings.logIgnoredAttributes) {
            log.info("{}@{} ignored",objectName,attr.getName());
        }
    }

}
项目:blueflood    文件:ZKShardLockManager.java   
/**
 * Registers the different ZooKeeper metrics.
 */
private void registerMetrics(final ObjectName nameObj, MetricRegistry reg) {
    reg.register(MetricRegistry.name(ZKShardLockManager.class, "Lock Disinterested Time Millis"),
            new JmxAttributeGauge(nameObj, "LockDisinterestedTimeMillis"));
    reg.register(MetricRegistry.name(ZKShardLockManager.class, "Min Lock Hold Time Millis"),
            new JmxAttributeGauge(nameObj, "MinLockHoldTimeMillis"));
    reg.register(MetricRegistry.name(ZKShardLockManager.class, "Seconds Since Last Scavenge"),
            new JmxAttributeGauge(nameObj, "SecondsSinceLastScavenge"));

    reg.register(MetricRegistry.name(ZKShardLockManager.class, "Zk Connection Status"),
            new JmxAttributeGauge(nameObj, "ZkConnectionStatus") {
                @Override
                public Object getValue() {
                    Object val = super.getValue();
                    if (val.equals("connected")) {
                        return 1;
                    }
                    return 0;
                }
            });
    reg.register(MetricRegistry.name(ZKShardLockManager.class, "Held Shards"),
            new Gauge<Integer>() {
                @Override
                public Integer getValue() {
                    return getHeldShards().size();
                }
            });

    reg.register(MetricRegistry.name(ZKShardLockManager.class, "Unheld Shards"),
            new Gauge<Integer>() {
                @Override
                public Integer getValue() {
                    return getUnheldShards().size();
                }
            });
    reg.register(MetricRegistry.name(ZKShardLockManager.class, "Error Shards"),
            new Gauge<Integer>() {
                @Override
                public Integer getValue() {
                    return getErrorShards().size();
                }
            });
}