Search in sources :

Example 1 with DataSource

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

Example 2 with DataSource

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

the class TypesDB method load.

public void load(InputStream is) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    String line;
    while ((line = reader.readLine()) != null) {
        DataSet ds;
        ds = DataSet.parseDataSet(line);
        if (ds != null) {
            String type = ds.getType();
            List<DataSource> dsrc = ds.getDataSources();
            this._types.put(type, dsrc);
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) DataSet(org.collectd.api.DataSet) BufferedReader(java.io.BufferedReader) DataSource(org.collectd.api.DataSource)

Example 3 with DataSource

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

the class CollectdMBeanRegistry method getMBean.

private Map<String, Number> getMBean(ValueList vl) {
    String instance = vl.getPluginInstance();
    StringBuffer bname = new StringBuffer();
    bname.append(getRootName(vl.getHost(), vl));
    if (!vl.defined(instance)) {
        List<DataSource> ds = vl.getDataSource();
        if (ds == null) {
            ds = TypesDB.getInstance().getType(vl.getType());
        }
        if ((ds != null) && (ds.size() > 1)) {
            // e.g. ds = {rx,tx} -> type=if_octets,typeInstance=en1
            instance = vl.getTypeInstance();
        }
    }
    if (vl.defined(instance)) {
        bname.append(',').append("name=").append(instance);
    }
    ObjectName name;
    try {
        name = new ObjectName(bname.toString());
    } catch (MalformedObjectNameException e) {
        throw new IllegalArgumentException(bname + ": " + e);
    }
    Map<String, Number> metrics = getMBean(name);
    if (metrics != null) {
        return metrics;
    }
    metrics = new HashMap<String, Number>();
    beans.put(name, metrics);
    try {
        bs.registerMBean(new CollectdMBean(metrics), name);
        if (_doSummary) {
            ObjectName sname = new ObjectName(getRootName("__summary__", vl));
            if (!bs.isRegistered(sname)) {
                ObjectName query = new ObjectName(getRootName(null, vl));
                CollectdSummaryMBean summary = new CollectdSummaryMBean(query, metrics);
                summary.setMBeanRegistry(this);
                bs.registerMBean(summary, sname);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return metrics;
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) MalformedObjectNameException(javax.management.MalformedObjectNameException) ListenerNotFoundException(javax.management.ListenerNotFoundException) DataSource(org.collectd.api.DataSource) ObjectName(javax.management.ObjectName)

Aggregations

DataSource (org.collectd.api.DataSource)3 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 ListenerNotFoundException (javax.management.ListenerNotFoundException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 ObjectName (javax.management.ObjectName)1 DataSet (org.collectd.api.DataSet)1 ValueList (org.collectd.api.ValueList)1