Search in sources :

Example 1 with MeasurementsInfo

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();
}
Also used : MeasurementAccumulator(org.spf4j.perf.MeasurementAccumulator) StringWriter(java.io.StringWriter) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) MeasurementsInfo(org.spf4j.perf.MeasurementsInfo) HashMap(java.util.HashMap) Map(java.util.Map) TObjectLongMap(gnu.trove.map.TObjectLongMap) TObjectLongHashMap(gnu.trove.map.hash.TObjectLongHashMap) JmxExport(org.spf4j.jmx.JmxExport)

Example 2 with MeasurementsInfo

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);
    }
}
Also used : MeasurementAccumulator(org.spf4j.perf.MeasurementAccumulator) OpenType(javax.management.openmbean.OpenType) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) MeasurementsInfo(org.spf4j.perf.MeasurementsInfo) OpenDataException(javax.management.openmbean.OpenDataException) HashMap(java.util.HashMap) Map(java.util.Map) TObjectLongMap(gnu.trove.map.TObjectLongMap) TObjectLongHashMap(gnu.trove.map.hash.TObjectLongHashMap) CompositeType(javax.management.openmbean.CompositeType)

Example 3 with MeasurementsInfo

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();
}
Also used : StringWriter(java.io.StringWriter) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) MeasurementsInfo(org.spf4j.perf.MeasurementsInfo) JmxExport(org.spf4j.jmx.JmxExport)

Example 4 with MeasurementsInfo

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());
}
Also used : MeasurementsInfo(org.spf4j.perf.MeasurementsInfo) GenericExportedValue(org.spf4j.jmx.GenericExportedValue) DynamicMBeanBuilder(org.spf4j.jmx.DynamicMBeanBuilder)

Example 5 with MeasurementsInfo

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());
}
Also used : MeasurementsInfo(org.spf4j.perf.MeasurementsInfo) GenericExportedValue(org.spf4j.jmx.GenericExportedValue) DynamicMBeanBuilder(org.spf4j.jmx.DynamicMBeanBuilder)

Aggregations

MeasurementsInfo (org.spf4j.perf.MeasurementsInfo)6 TObjectLongMap (gnu.trove.map.TObjectLongMap)2 TObjectLongHashMap (gnu.trove.map.hash.TObjectLongHashMap)2 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 UncheckedIOException (java.io.UncheckedIOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DynamicMBeanBuilder (org.spf4j.jmx.DynamicMBeanBuilder)2 GenericExportedValue (org.spf4j.jmx.GenericExportedValue)2 JmxExport (org.spf4j.jmx.JmxExport)2 MeasurementAccumulator (org.spf4j.perf.MeasurementAccumulator)2 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)1 CompositeType (javax.management.openmbean.CompositeType)1 OpenDataException (javax.management.openmbean.OpenDataException)1 OpenType (javax.management.openmbean.OpenType)1