Search in sources :

Example 1 with Notification

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

the class UdpReceiver method parse.

public void parse(byte[] packet) throws IOException {
    int total = packet.length;
    ByteArrayInputStream buffer = new ByteArrayInputStream(packet);
    DataInputStream is = new DataInputStream(buffer);
    PacketObject obj = new PacketObject();
    while ((0 < total) && (total > Network.HEADER_LEN)) {
        int type = is.readUnsignedShort();
        int len = is.readUnsignedShort();
        if (len < Network.HEADER_LEN) {
            //packet was filled to the brim
            break;
        }
        total -= len;
        len -= Network.HEADER_LEN;
        if (type == Network.TYPE_VALUES) {
            readValues(is, obj.getValueList());
        } else if (type == Network.TYPE_TIME) {
            obj.pd.setTime(is.readLong() * 1000);
        } else if (type == Network.TYPE_INTERVAL) {
            obj.getValueList().setInterval(is.readLong());
        } else if (type == Network.TYPE_HOST) {
            obj.pd.setHost(readString(is, len));
        } else if (type == Network.TYPE_PLUGIN) {
            obj.pd.setPlugin(readString(is, len));
        } else if (type == Network.TYPE_PLUGIN_INSTANCE) {
            obj.pd.setPluginInstance(readString(is, len));
        } else if (type == Network.TYPE_TYPE) {
            obj.pd.setType(readString(is, len));
        } else if (type == Network.TYPE_TYPE_INSTANCE) {
            obj.pd.setTypeInstance(readString(is, len));
        } else if (type == Network.TYPE_MESSAGE) {
            Notification notif = obj.getNotification();
            notif.setMessage(readString(is, len));
            if (_dispatcher != null) {
                _dispatcher.dispatch(notif);
            }
        } else if (type == Network.TYPE_SEVERITY) {
            obj.getNotification().setSeverity((int) is.readLong());
        } else {
            break;
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) Notification(org.collectd.api.Notification)

Example 2 with Notification

use of org.collectd.api.Notification 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)

Aggregations

Notification (org.collectd.api.Notification)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 ValueList (org.collectd.api.ValueList)1 Dispatcher (org.collectd.protocol.Dispatcher)1 UdpReceiver (org.collectd.protocol.UdpReceiver)1