Search in sources :

Example 1 with MetricTreeObject

use of org.platformlayer.metrics.MetricTreeObject in project platformlayer by platformlayer.

the class PlatformlayerMetricsReporter method processHistogram.

@Override
public void processHistogram(MetricName name, Histogram histogram, MetricTreeObject tree) throws IOException {
    MetricTreeObject subtree = getSubtree(tree, name);
    // final String sanitizedName = sanitizeName(name);
    sendSummarizable(subtree, histogram);
    sendSampling(subtree, histogram);
}
Also used : MetricTreeObject(org.platformlayer.metrics.MetricTreeObject)

Example 2 with MetricTreeObject

use of org.platformlayer.metrics.MetricTreeObject in project platformlayer by platformlayer.

the class PlatformlayerMetricsReporter method printVmMetrics.

protected void printVmMetrics(MetricTreeObject tree) {
    MetricTreeObject jvmTree = tree.getSubtree("jvm");
    MetricTreeObject memoryTree = jvmTree.getSubtree("memory");
    memoryTree.addFloat("heap_usage", vm.heapUsage());
    memoryTree.addFloat("non_heap_usage", vm.nonHeapUsage());
    MetricTreeObject memoryPoolUsages = memoryTree.getSubtree("memory_pool_usages");
    for (Entry<String, Double> pool : vm.memoryPoolUsage().entrySet()) {
        memoryPoolUsages.addFloat(pool.getKey(), pool.getValue());
    }
    jvmTree.addInt("daemon_thread_count", vm.daemonThreadCount());
    jvmTree.addInt("thread_count", vm.threadCount());
    jvmTree.addInt("uptime", vm.uptime());
    jvmTree.addFloat("fd_usage", vm.fileDescriptorUsage());
    MetricTreeObject threadStates = jvmTree.getSubtree("thread-states");
    for (Entry<State, Double> entry : vm.threadStatePercentages().entrySet()) {
        threadStates.addFloat(entry.getKey().toString().toLowerCase(), entry.getValue());
    }
    MetricTreeObject gcTree = jvmTree.getSubtree("gc");
    for (Entry<String, VirtualMachineMetrics.GarbageCollectorStats> entry : vm.garbageCollectors().entrySet()) {
        MetricTreeObject collectorTree = gcTree.getSubtree(entry.getKey());
        collectorTree.addInt("time", entry.getValue().getTime(TimeUnit.MILLISECONDS));
        collectorTree.addInt("runs", entry.getValue().getRuns());
    }
}
Also used : MetricTreeObject(org.platformlayer.metrics.MetricTreeObject) State(java.lang.Thread.State)

Example 3 with MetricTreeObject

use of org.platformlayer.metrics.MetricTreeObject in project platformlayer by platformlayer.

the class MetricClientImpl method copyPropertiesToTree.

private static void copyPropertiesToTree(Map<String, String> properties, MetricTreeObject dest) {
    for (Entry<String, String> entry : properties.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        List<String> tokens = Lists.newArrayList(Splitter.on('.').split(key));
        MetricTreeObject subtree = dest;
        for (int i = 0; i < tokens.size() - 1; i++) {
            subtree = subtree.getSubtree(tokens.get(i));
        }
        String valueKey = tokens.get(tokens.size() - 1);
        subtree.addString(valueKey, value);
    }
}
Also used : MetricTreeObject(org.platformlayer.metrics.MetricTreeObject)

Example 4 with MetricTreeObject

use of org.platformlayer.metrics.MetricTreeObject in project platformlayer by platformlayer.

the class MetricTreeSerializer method serialize.

public void serialize(MetricTreeBase tree, OutputStream os) throws IOException {
    final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(os);
    tree.accept(new MetricTreeVisitor() {

        private void writeKey(MetricTreeBase o) throws JsonGenerationException, IOException {
            if (o.getKey() != null) {
                jsonGenerator.writeFieldName(o.getKey());
            }
        }

        @Override
        public void visit(MetricTreeObject o) {
            try {
                writeKey(o);
                jsonGenerator.writeStartObject();
                o.visitChildren(this);
                jsonGenerator.writeEndObject();
            } catch (IOException e) {
                throw new IllegalStateException("Error serializing to JSON", e);
            }
        }

        @Override
        public void visit(MetricTreeString o) {
            try {
                writeKey(o);
                jsonGenerator.writeString(o.getValue());
            } catch (IOException e) {
                throw new IllegalStateException("Error serializing to JSON", e);
            }
        }

        @Override
        public void visit(MetricTreeArray o) {
            try {
                writeKey(o);
                jsonGenerator.writeStartArray();
                o.visitItems(this);
                jsonGenerator.writeEndArray();
            } catch (IOException e) {
                throw new IllegalStateException("Error serializing to JSON", e);
            }
        }

        @Override
        public void visit(MetricTreeInteger o) {
            try {
                writeKey(o);
                jsonGenerator.writeNumber(o.getValue());
            } catch (IOException e) {
                throw new IllegalStateException("Error serializing to JSON", e);
            }
        }

        @Override
        public void visit(MetricTreeFloat o) {
            try {
                writeKey(o);
                jsonGenerator.writeNumber(o.getValue());
            } catch (IOException e) {
                throw new IllegalStateException("Error serializing to JSON", e);
            }
        }
    });
    jsonGenerator.close();
}
Also used : MetricTreeString(org.platformlayer.metrics.MetricTreeBase.MetricTreeString) MetricTreeVisitor(org.platformlayer.metrics.MetricTreeVisitor) MetricTreeObject(org.platformlayer.metrics.MetricTreeObject) MetricTreeInteger(org.platformlayer.metrics.MetricTreeBase.MetricTreeInteger) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) MetricTreeBase(org.platformlayer.metrics.MetricTreeBase) MetricTreeFloat(org.platformlayer.metrics.MetricTreeBase.MetricTreeFloat) IOException(java.io.IOException) MetricTreeArray(org.platformlayer.metrics.MetricTreeBase.MetricTreeArray) JsonGenerationException(com.fasterxml.jackson.core.JsonGenerationException)

Example 5 with MetricTreeObject

use of org.platformlayer.metrics.MetricTreeObject in project platformlayer by platformlayer.

the class PlatformlayerMetricsReporter method processTimer.

@Override
public void processTimer(MetricName name, Timer timer, MetricTreeObject tree) throws IOException {
    processMeter(name, timer, tree);
    // final String sanitizedName = sanitizeName(name);
    MetricTreeObject subtree = getSubtree(tree, name);
    sendSummarizable(subtree, timer);
    sendSampling(subtree, timer);
}
Also used : MetricTreeObject(org.platformlayer.metrics.MetricTreeObject)

Aggregations

MetricTreeObject (org.platformlayer.metrics.MetricTreeObject)11 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 CertificateAndKey (com.fathomdb.crypto.CertificateAndKey)1 IOException (java.io.IOException)1 State (java.lang.Thread.State)1 MetricTreeBase (org.platformlayer.metrics.MetricTreeBase)1 MetricTreeArray (org.platformlayer.metrics.MetricTreeBase.MetricTreeArray)1 MetricTreeFloat (org.platformlayer.metrics.MetricTreeBase.MetricTreeFloat)1 MetricTreeInteger (org.platformlayer.metrics.MetricTreeBase.MetricTreeInteger)1 MetricTreeString (org.platformlayer.metrics.MetricTreeBase.MetricTreeString)1 MetricTreeVisitor (org.platformlayer.metrics.MetricTreeVisitor)1 MetricsSource (org.platformlayer.metrics.MetricsSource)1