Search in sources :

Example 1 with NodeMetrics

use of com.alipay.sofa.jraft.core.NodeMetrics in project sofa-jraft by sofastack.

the class LogManagerTest method setup.

@Override
@Before
public void setup() throws Exception {
    super.setup();
    this.confManager = new ConfigurationManager();
    final RaftOptions raftOptions = new RaftOptions();
    this.logStorage = newLogStorage(raftOptions);
    this.logManager = new LogManagerImpl();
    final LogManagerOptions opts = new LogManagerOptions();
    opts.setConfigurationManager(this.confManager);
    opts.setLogEntryCodecFactory(LogEntryV2CodecFactory.getInstance());
    opts.setFsmCaller(this.fsmCaller);
    opts.setNodeMetrics(new NodeMetrics(false));
    opts.setLogStorage(this.logStorage);
    opts.setRaftOptions(raftOptions);
    assertTrue(this.logManager.init(opts));
}
Also used : RaftOptions(com.alipay.sofa.jraft.option.RaftOptions) NodeMetrics(com.alipay.sofa.jraft.core.NodeMetrics) LogManagerOptions(com.alipay.sofa.jraft.option.LogManagerOptions) ConfigurationManager(com.alipay.sofa.jraft.conf.ConfigurationManager) Before(org.junit.Before)

Example 2 with NodeMetrics

use of com.alipay.sofa.jraft.core.NodeMetrics 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)

Aggregations

NodeMetrics (com.alipay.sofa.jraft.core.NodeMetrics)2 ConfigurationManager (com.alipay.sofa.jraft.conf.ConfigurationManager)1 LogManagerOptions (com.alipay.sofa.jraft.option.LogManagerOptions)1 RaftOptions (com.alipay.sofa.jraft.option.RaftOptions)1 MetricReporter (com.alipay.sofa.jraft.util.MetricReporter)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 Before (org.junit.Before)1