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
}
}
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);
}
}
}
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;
}
Aggregations