Search in sources :

Example 1 with MetricReporter

use of com.alipay.sofa.jraft.util.MetricReporter in project sofa-jraft by sofastack.

the class NodeMetricsSignalHandler method handle.

@Override
public void handle(final String signalName) {
    final List<Node> nodes = NodeManager.getInstance().getAllNodes();
    if (nodes.isEmpty()) {
        return;
    }
    try {
        final File file = getOutputFile(DIR, BASE_NAME);
        LOG.info("Printing raft nodes metrics with signal: {} to file: {}.", signalName, file);
        try (final PrintStream out = new PrintStream(new FileOutputStream(file, true))) {
            for (final Node node : nodes) {
                final NodeMetrics nodeMetrics = node.getNodeMetrics();
                final MetricRegistry registry = nodeMetrics.getMetricRegistry();
                if (registry == null) {
                    LOG.warn("Node: {} received a signal to print metric, but it does not have metric enabled.", node);
                    continue;
                }
                final MetricReporter reporter = // 
                MetricReporter.forRegistry(registry).outputTo(// 
                out).prefixedWith(// 
                "-- " + node.getNodeId()).build();
                reporter.report();
            }
        }
    } catch (final IOException e) {
        LOG.error("Fail to print nodes metrics: {}.", nodes, e);
    }
}
Also used : PrintStream(java.io.PrintStream) FileOutputStream(java.io.FileOutputStream) MetricRegistry(com.codahale.metrics.MetricRegistry) NodeMetrics(com.alipay.sofa.jraft.core.NodeMetrics) MetricReporter(com.alipay.sofa.jraft.util.MetricReporter) IOException(java.io.IOException) File(java.io.File)

Example 2 with MetricReporter

use of com.alipay.sofa.jraft.util.MetricReporter in project sofa-jraft by sofastack.

the class RheaKVMetricsSignalHandler method handle.

@Override
public void handle(final String signalName) {
    try {
        final File file = getOutputFile(DIR, BASE_NAME);
        LOG.info("Printing rheakv metrics with signal: {} to file: {}.", signalName, file);
        try (final PrintStream out = new PrintStream(new FileOutputStream(file, true))) {
            final MetricReporter reporter = // 
            MetricReporter.forRegistry(KVMetrics.metricRegistry()).outputTo(// 
            out).prefixedWith(// 
            "-- rheakv").build();
            reporter.report();
        }
    } catch (final IOException e) {
        LOG.error("Fail to print rheakv metrics.", e);
    }
}
Also used : PrintStream(java.io.PrintStream) FileOutputStream(java.io.FileOutputStream) MetricReporter(com.alipay.sofa.jraft.util.MetricReporter) IOException(java.io.IOException) File(java.io.File)

Aggregations

MetricReporter (com.alipay.sofa.jraft.util.MetricReporter)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 PrintStream (java.io.PrintStream)2 NodeMetrics (com.alipay.sofa.jraft.core.NodeMetrics)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1