use of org.spf4j.perf.MeasurementsInfo in project spf4j by zolyfarkas.
the class ScalableMeasurementRecorderSource method getMeasurementsAsString.
@JmxExport(description = "measurements as csv")
public String getMeasurementsAsString() {
StringWriter sw = new StringWriter(128);
Map<Object, MeasurementAccumulator> entitiesMeasurements = getEntitiesMeasurements();
MeasurementsInfo info = this.processorTemplate.getInfo();
try {
Csv.writeCsvRow2(sw, "Measured", (Object[]) info.getMeasurementNames());
Csv.writeCsvRow2(sw, "string", (Object[]) info.getMeasurementUnits());
for (Map.Entry<Object, MeasurementAccumulator> entry : entitiesMeasurements.entrySet()) {
Csv.writeCsvElement(entry.getKey().toString(), sw);
sw.write(',');
final long[] measurements = entry.getValue().get();
if (measurements != null) {
Csv.writeCsvRow(sw, measurements);
}
}
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
return sw.toString();
}
use of org.spf4j.perf.MeasurementsInfo in project spf4j by zolyfarkas.
the class ScalableMeasurementRecorderSource method getMeasurements.
public CompositeDataSupport getMeasurements() {
Map<Object, MeasurementAccumulator> entitiesMeasurements = getEntitiesMeasurements();
MeasurementsInfo info = this.processorTemplate.getInfo();
int nrStuff = entitiesMeasurements.size();
String[] names = new String[nrStuff];
String[] descriptions = new String[nrStuff];
OpenType<?>[] types = new OpenType[nrStuff];
Object[] values = new Object[nrStuff];
int i = 0;
for (Map.Entry<Object, MeasurementAccumulator> entry : entitiesMeasurements.entrySet()) {
MeasurementAccumulator acc = entry.getValue();
MeasurementsInfo eInfo = acc.getInfo();
String cattrName = eInfo.getMeasuredEntity().toString();
names[i] = cattrName;
String cattrDesc = eInfo.getDescription();
if (cattrDesc.isEmpty()) {
cattrDesc = cattrName;
}
descriptions[i] = cattrDesc;
types[i] = eInfo.toCompositeType();
values[i] = acc.getCompositeData();
i++;
}
try {
String name = info.getMeasuredEntity().toString();
String description = info.getDescription();
if (description.isEmpty()) {
description = name;
}
CompositeType setType = new CompositeType(name, description, names, descriptions, types);
return new CompositeDataSupport(setType, names, values);
} catch (OpenDataException ex) {
throw new IllegalArgumentException("Not composite data compatible " + this, ex);
}
}
use of org.spf4j.perf.MeasurementsInfo in project spf4j by zolyfarkas.
the class ScalableMeasurementRecorder method getMeasurementsAsString.
@JmxExport(description = "measurements as csv")
public String getMeasurementsAsString() {
StringWriter sw = new StringWriter(128);
MeasurementsInfo info = getInfo();
try {
Csv.writeCsvRow(sw, (Object[]) info.getMeasurementNames());
Csv.writeCsvRow(sw, (Object[]) info.getMeasurementUnits());
final long[] values = get();
if (values != null) {
Csv.writeCsvRow(sw, values);
}
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
return sw.toString();
}
use of org.spf4j.perf.MeasurementsInfo in project spf4j by zolyfarkas.
the class ScalableMeasurementRecorder method registerJmx.
@SuppressWarnings("unchecked")
public void registerJmx() {
MeasurementsInfo info = processorTemplate.getInfo();
new DynamicMBeanBuilder().withJmxExportObject(this).withAttribute(new GenericExportedValue<>("measurements", info.getDescription(), this::getCompositeData, null, getInfo().toCompositeType())).register("org.spf4j.perf.recorders", info.getMeasuredEntity().toString());
}
use of org.spf4j.perf.MeasurementsInfo in project spf4j by zolyfarkas.
the class ScalableMeasurementRecorderSource method registerJmx.
@SuppressWarnings("unchecked")
public void registerJmx() {
MeasurementsInfo info = this.processorTemplate.getInfo();
new DynamicMBeanBuilder().withJmxExportObject(this).withAttribute(new GenericExportedValue<>("measurements", info.getDescription(), this::getMeasurements, null, info.toCompositeType())).register("org.spf4j.perf.recorders", info.getMeasuredEntity().toString());
}
Aggregations