本文整理了Java中com.netflix.servo.Metric
类的一些代码示例,展示了Metric
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Metric
类的具体详情如下:
包路径:com.netflix.servo.Metric
类名称:Metric
[英]Represents a metric value at a given point in time.
[中]表示给定时间点的度量值。
代码示例来源:origin: Netflix/servo
protected static Metric asGauge(Metric m) {
return new Metric(m.getConfig().withAdditionalTag(ATLAS_GAUGE_TAG),
m.getTimestamp(), m.getValue());
}
代码示例来源:origin: Netflix/servo
private Metric normalize(Metric m, long stepBoundary) {
NormalizedValue normalizedValue = cache.get(m.getConfig());
if (normalizedValue == null) {
normalizedValue = new NormalizedValue();
cache.put(m.getConfig(), normalizedValue);
}
double value = normalizedValue.updateAndGet(m.getTimestamp(),
m.getNumberValue().doubleValue());
return new Metric(m.getConfig(), stepBoundary, value);
}
代码示例来源:origin: Netflix/servo
/**
* @param metrics The list of metrics you want to send to CloudWatch
*/
@Override
public void updateImpl(List<Metric> metrics) {
Preconditions.checkNotNull(metrics, "metrics");
List<Metric> batch = new ArrayList<>(batchSize);
for (final Metric m : metrics) {
if (m.hasNumberValue()) {
batch.add(m);
if (batch.size() % batchSize == 0) {
putMetricData(batch);
batch.clear();
}
}
}
if (!batch.isEmpty()) {
putMetricData(batch);
}
}
代码示例来源:origin: Netflix/servo
AtlasMetric(Metric m) {
this(m.getConfig(), m.getTimestamp(), m.getNumberValue());
}
代码示例来源:origin: Netflix/servo
CounterValue(Metric m) {
this(m.getTimestamp(), m.getNumberValue().doubleValue());
}
代码示例来源:origin: com.redhat.lightblue/lightblue-core-hystrix
@Override
public void updateImpl(List<Metric> metrics) {
// The statsd client doesn't do any checks on the underlying socket's state
// and the socket connects only once, so we cannot trust the socket to stay
// open over a period of time. If this is changed/fixed we could reuse the
// client but until then it cannot be safely reused.
StatsDClient statsd = createClient();
LOGGER.debug("sending data");
try {
for (Metric metric : metrics) {
String aspect = namingConvention.getName(metric);
if (metric.getConfig().getTags().getTag(DataSourceType.COUNTER.getValue()) != null) {
statsd.count(aspect, metric.getNumberValue().longValue());
} else if (metric.hasNumberValue()) {
statsd.gauge(aspect, metric.getNumberValue().longValue());
} else {
statsd.set(aspect, metric.getValue().toString());
}
statsd.time(aspect, metric.getTimestamp() / 1000);
}
} finally {
statsd.stop();
}
}
代码示例来源:origin: Netflix/servo
public void add(Metric m) {
if (filter.matches(m.getConfig())) {
list.add(m);
}
}
代码示例来源:origin: Netflix/servo
private void addOptionalMetric(
MonitorConfig config,
long timestamp,
Object obj,
String methodName,
MetricList metrics) {
try {
Method method = obj.getClass().getMethod(methodName);
method.setAccessible(true);
Number value = (Number) method.invoke(obj);
metrics.add(new Metric(config, timestamp, value));
} catch (Exception e) {
final String msg = String.format("failed to get value for %s.%s",
obj.getClass().getName(), methodName);
LOGGER.debug(msg, e);
}
}
代码示例来源:origin: Netflix/servo
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof Metric)) {
return false;
}
Metric m = (Metric) obj;
return config.equals(m.getConfig())
&& timestamp == m.getTimestamp()
&& value.equals(m.getValue());
}
代码示例来源:origin: Netflix/servo
out.append(m.getConfig().getName()).append('\t')
.append(m.getConfig().getTags().toString()).append('\t')
.append(m.getValue().toString()).append('\n');
代码示例来源:origin: Netflix/servo
private static void addMetric(List<Metric> metrics, Metric metric) {
if (metric.getNumberValue().doubleValue() >= 0.0) {
final MonitorConfig c = metric.getConfig();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Adding " + c.getName() + " " + c.getTags() + " "
+ metric.getNumberValue());
}
metrics.add(metric);
} else {
LOGGER.debug("Ignoring {}", metric);
}
}
代码示例来源:origin: Netflix/servo
@Test
public void testNullTags() throws Exception {
long now = System.currentTimeMillis();
Metric m = new Metric("a", null, now, 42);
assertEquals(m.getConfig(), new MonitorConfig.Builder("a").build());
}
代码示例来源:origin: Netflix/servo
private int writeMetrics(Iterable<Metric> metrics, PrintWriter writer) {
int count = 0;
for (Metric metric : metrics) {
String publishedName = namingConvention.getName(metric);
StringBuilder sb = new StringBuilder();
if (serverPrefix != null) {
sb.append(serverPrefix).append(".");
}
sb.append(publishedName).append(" ")
.append(metric.getValue().toString())
.append(" ")
.append(metric.getTimestamp() / 1000);
LOGGER.debug("{}", sb);
writer.write(sb.append("\n").toString());
count++;
}
return count;
}
代码示例来源:origin: Netflix/servo
@Test
public void testEquals() throws Exception {
long now = System.currentTimeMillis();
Metric m1 = new Metric("a", tags1, now, 42);
Metric m2 = new Metric("a", tags2, now, 42);
Metric m3 = new Metric("a", tags1, now, 42);
assertNotNull(m1);
assertFalse(m1.toString().equals(m2.toString()));
assertTrue(m1.equals(m1));
assertFalse(m1.equals(m2));
assertTrue(m1.equals(m3));
}
代码示例来源:origin: Netflix/servo
@Test
public void testHashCode() throws Exception {
long now = System.currentTimeMillis();
Metric m1 = new Metric("a", tags1, now, 42);
Metric m2 = new Metric("a", tags2, now, 42);
Metric m3 = new Metric("a", tags1, now, 42);
assertTrue(m1.hashCode() == m1.hashCode());
assertTrue(m1.hashCode() != m2.hashCode());
assertTrue(m1.hashCode() == m3.hashCode());
}
}
代码示例来源:origin: com.sap.cloud.yaas.service-sdk/service-sdk-monitoring
@Override
public void updateImpl(final List<Metric> metrics)
{
for (final Metric metric : metrics)
{
Object metricValue = metric.getValue();
if (metricValue instanceof Double
&& (((Double) metricValue) == Double.POSITIVE_INFINITY || ((Double) metricValue) == Double.NEGATIVE_INFINITY))
{
metricValue = null;
}
else if (metricValue instanceof Float
&& (((Float) metricValue) == Float.POSITIVE_INFINITY || ((Float) metricValue) == Float.NEGATIVE_INFINITY))
{
metricValue = null;
}
MetricLogger
.newInstance()
.metric(namingConvention.getName(metric))
.type(metric.hasNumberValue() ? MetricType.NUMBER : MetricType.STRING)
.log(metricValue);
}
LOG.debug("Wrote {} metrics to logger", metrics.size());
}
}
代码示例来源:origin: Netflix/servo
@Test
public void testNonNumericMetrics() throws Exception {
MapMXBean mapMXBean = new MapMXBean();
try {
MetricPoller poller = new JmxMetricPoller(
new LocalJmxConnector(),
Collections.singletonList(new ObjectName("com.netflix.servo.test:*")),
MATCH_ALL,
false,
null);
List<Metric> metrics = poller.poll(config -> config.getName().equals("StringValue"));
assertEquals(metrics.size(), 1);
assertEquals(metrics.get(0).getValue(), "AStringResult");
} finally {
mapMXBean.destroy();
}
}
}
代码示例来源:origin: com.sap.cloud.yaas.service-sdk/service-sdk-monitoring
private Event buildEvent(final Metric metric)
{
final EventDSL eventBuilder = client.event()//
.host(observerPrefix)//
.service(namingConvention.getName(metric))//
.state("ok")//
.description(null)//
.time(metric.getTimestamp() / SECOND_AS_MILLI);
if (metric.hasNumberValue())
{
eventBuilder.metric(metric.getNumberValue().doubleValue());
}
else if (metric.getValue() != null)
{
eventBuilder.attribute("value", metric.getValue().toString());
}
for (final Tag tag : metric.getConfig().getTags())
{
eventBuilder.tag(tag.getValue());
}
final Event event = eventBuilder.build();
LOG.debug("Creating metric for '{}.{}' with timestamp '{}' and metric '{}' and attributes '{}'", event.getHost(),
event.getService(), event.getTime(), event.getMetricD(), event.getAttributesList());
return event;
}
代码示例来源:origin: Netflix/servo
MetricDatum createMetricDatum(Metric metric) {
MetricDatum metricDatum = new MetricDatum();
return metricDatum.withMetricName(metric.getConfig().getName())
.withDimensions(createDimensions(metric.getConfig().getTags()))
.withUnit("None")//DataSourceTypeToAwsUnit.getUnit(metric.))
.withTimestamp(new Date(metric.getTimestamp()))
.withValue(truncate(metric.getNumberValue()));
//TODO Need to convert into reasonable units based on DataType
}
代码示例来源:origin: Netflix/servo
/**
* {@inheritDoc}
*/
public final List<Metric> poll(MetricFilter filter, boolean reset) {
Preconditions.checkNotNull(filter, "filter");
List<Metric> metrics = pollImpl(reset);
List<Metric> retained = metrics.stream().filter(m -> filter.matches(m.getConfig()))
.collect(Collectors.toList());
logger.debug("received {} metrics, retained {} metrics", metrics.size(), retained.size());
return Collections.unmodifiableList(retained);
}
}
内容来源于网络,如有侵权,请联系作者删除!