Search in sources :

Example 1 with ValueList

use of org.collectd.api.ValueList in project metrics by dropwizard.

the class CollectdReporterTest method sanitizesMetricName.

@Test
public void sanitizesMetricName() throws Exception {
    Counter counter = registry.counter("dash-illegal.slash/illegal");
    counter.inc();
    reporter.report();
    ValueList values = receiver.next();
    assertThat(values.getPlugin()).isEqualTo("dash_illegal.slash_illegal");
}
Also used : Counter(com.codahale.metrics.Counter) ValueList(org.collectd.api.ValueList) Test(org.junit.Test)

Example 2 with ValueList

use of org.collectd.api.ValueList in project metrics by dropwizard.

the class CollectdReporterTest method reportsBooleanGauges.

@Test
public void reportsBooleanGauges() throws Exception {
    reporter.report(map("gauge", (Gauge) () -> true), map(), map(), map(), map());
    ValueList data = receiver.next();
    assertThat(data.getValues()).containsExactly(1d);
    reporter.report(map("gauge", (Gauge) () -> false), map(), map(), map(), map());
    data = receiver.next();
    assertThat(data.getValues()).containsExactly(0d);
}
Also used : ValueList(org.collectd.api.ValueList) Gauge(com.codahale.metrics.Gauge) Test(org.junit.Test)

Example 3 with ValueList

use of org.collectd.api.ValueList in project metrics by dropwizard.

the class Receiver method before.

@Override
protected void before() throws Throwable {
    receiver = new UdpReceiver(new Dispatcher() {

        @Override
        public void dispatch(ValueList values) {
            queue.offer(new ValueList(values));
        }

        @Override
        public void dispatch(Notification notification) {
            throw new UnsupportedOperationException();
        }
    });
    receiver.setPort(port);
    new Thread(() -> {
        try {
            receiver.listen();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }).start();
}
Also used : ValueList(org.collectd.api.ValueList) UdpReceiver(org.collectd.protocol.UdpReceiver) Dispatcher(org.collectd.protocol.Dispatcher) Notification(org.collectd.api.Notification)

Example 4 with ValueList

use of org.collectd.api.ValueList in project jcollectd by collectd.

the class MBeanCollector method dispatch.

private void dispatch(MBeanQuery query, String plugin, String typeInstance, ObjectName name, MBeanAttribute attr, Number val) {
    if (attr.getDataType() == Network.DS_TYPE_GAUGE) {
        val = new Double(val.doubleValue());
    } else {
        val = new Long(val.longValue());
    }
    String pluginInstance = query.getPluginInstance();
    if (pluginInstance == null) {
        pluginInstance = _sender.getInstanceName();
    }
    String beanName = query.getAlias();
    ValueList vl = new ValueList();
    vl.setInterval(getInterval());
    vl.setPlugin(plugin);
    if (beanName == null) {
        beanName = getBeanName(null, name);
    } else if (query.getName().isPattern()) {
        String instName = getBeanName(query.getName(), name);
        if (instName != null) {
            beanName += " " + instName;
        }
    }
    vl.setPluginInstance(pluginInstance + "-" + beanName);
    vl.setType(attr.getTypeName());
    vl.setTypeInstance(typeInstance);
    vl.addValue(val);
    _sender.dispatch(vl);
}
Also used : ValueList(org.collectd.api.ValueList)

Example 5 with ValueList

use of org.collectd.api.ValueList in project jcollectd by collectd.

the class PacketWriter method write.

public void write(PluginData data) throws IOException {
    String type = data.getType();
    writeString(Network.TYPE_HOST, data.getHost());
    writeNumber(Network.TYPE_TIME, data.getTime() / 1000);
    writeString(Network.TYPE_PLUGIN, data.getPlugin());
    writeString(Network.TYPE_PLUGIN_INSTANCE, data.getPluginInstance());
    writeString(Network.TYPE_TYPE, type);
    writeString(Network.TYPE_TYPE_INSTANCE, data.getTypeInstance());
    if (data instanceof ValueList) {
        ValueList vl = (ValueList) data;
        List<DataSource> ds = _types.getType(type);
        List<Number> values = vl.getValues();
        if ((ds != null) && (ds.size() != values.size())) {
            String msg = type + " datasource mismatch, expecting " + ds.size() + ", given " + values.size();
            throw new IOException(msg);
        }
        writeNumber(Network.TYPE_INTERVAL, vl.getInterval());
        writeValues(ds, values);
    } else {
    // XXX Notification
    }
}
Also used : ValueList(org.collectd.api.ValueList) IOException(java.io.IOException) DataSource(org.collectd.api.DataSource)

Aggregations

ValueList (org.collectd.api.ValueList)12 Test (org.junit.Test)3 Counter (com.codahale.metrics.Counter)2 Gauge (com.codahale.metrics.Gauge)2 IOException (java.io.IOException)1 DataSource (org.collectd.api.DataSource)1 Notification (org.collectd.api.Notification)1 Dispatcher (org.collectd.protocol.Dispatcher)1 UdpReceiver (org.collectd.protocol.UdpReceiver)1