Search in sources :

Example 1 with MetricsSinksConfig

use of org.apache.heron.metricsmgr.MetricsSinksConfig in project heron by twitter.

the class MetricsCacheTest method testMetricCache.

@Test
public void testMetricCache() throws IOException {
    // prepare config files
    SystemConfig systemConfig = SystemConfig.newBuilder(true).putAll(CONFIG_SYSTEM_PATH, true).build();
    MetricsSinksConfig sinksConfig = new MetricsSinksConfig(CONFIG_SINK_PATH, null);
    // initialize metric cache, except looper
    MetricsCache mc = new MetricsCache(systemConfig, sinksConfig, new NIOLooper());
    mc.addMetrics(TopologyManager.PublishMetrics.newBuilder().addMetrics(TopologyManager.MetricDatum.newBuilder().setComponentName("c1").setInstanceId("i1").setName("__jvm-uptime-secs").setTimestamp(System.currentTimeMillis()).setValue("0.1")).addExceptions(TopologyManager.TmanagerExceptionLog.newBuilder().setComponentName("c1").setHostname("h1").setInstanceId("i1").setStacktrace("s1").setLogging("l1").setCount(1).setFirsttime(String.valueOf(System.currentTimeMillis())).setLasttime(String.valueOf(System.currentTimeMillis()))).build());
    // query last 10 seconds
    TopologyManager.MetricResponse response = mc.getMetrics(TopologyManager.MetricRequest.newBuilder().setComponentName("c1").addInstanceId("i1").setInterval(10).addMetric("__jvm-uptime-secs").build());
    assertEquals(response.getMetricCount(), 1);
    assertEquals(response.getMetric(0).getInstanceId(), "i1");
    assertEquals(response.getMetric(0).getMetricCount(), 1);
    assertEquals(response.getMetric(0).getMetric(0).getName(), "__jvm-uptime-secs");
    assertEquals(response.getMetric(0).getMetric(0).getValue(), "0.1");
}
Also used : MetricsSinksConfig(org.apache.heron.metricsmgr.MetricsSinksConfig) TopologyManager(org.apache.heron.proto.tmanager.TopologyManager) SystemConfig(org.apache.heron.common.config.SystemConfig) NIOLooper(org.apache.heron.common.basics.NIOLooper) Test(org.junit.Test)

Example 2 with MetricsSinksConfig

use of org.apache.heron.metricsmgr.MetricsSinksConfig in project heron by twitter.

the class NomadScheduler method getPrometheusMetricsFile.

static String getPrometheusMetricsFile(Config config) {
    MetricsSinksConfig metricsSinksConfig;
    try {
        metricsSinksConfig = new MetricsSinksConfig(Context.metricsSinksFile(config), Context.overrideFile(config));
    } catch (IOException e) {
        return null;
    }
    String prometheusSinkId = null;
    Map<String, Object> prometheusSinkConfig = null;
    for (String sinkId : metricsSinksConfig.getSinkIds()) {
        Map<String, Object> sinkConfig = metricsSinksConfig.getConfigForSink(sinkId);
        Object className = sinkConfig.get(MetricsSinksConfig.CONFIG_KEY_CLASSNAME);
        if (className != null && className instanceof String) {
            if (PrometheusSink.class.getName().equals(className)) {
                prometheusSinkId = sinkId;
                prometheusSinkConfig = sinkConfig;
            }
        }
    }
    if (prometheusSinkId == null || prometheusSinkConfig == null) {
        return null;
    }
    String prometheusMetricsPortFile = PrometheusSink.getServerPortFile(prometheusSinkConfig);
    return prometheusMetricsPortFile;
}
Also used : MetricsSinksConfig(org.apache.heron.metricsmgr.MetricsSinksConfig) PrometheusSink(org.apache.heron.metricsmgr.sink.PrometheusSink) IOException(java.io.IOException)

Example 3 with MetricsSinksConfig

use of org.apache.heron.metricsmgr.MetricsSinksConfig in project heron by twitter.

the class MetricsCacheManager method main.

public static void main(String[] args) throws Exception {
    Options options = constructOptions();
    Options helpOptions = constructHelpOptions();
    CommandLineParser parser = new DefaultParser();
    // parse the help options first.
    CommandLine cmd = parser.parse(helpOptions, args, true);
    if (cmd.hasOption("h")) {
        usage(options);
        return;
    }
    try {
        // Now parse the required options
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        usage(options);
        throw new RuntimeException("Error parsing command line options: ", e);
    }
    Level logLevel = Level.INFO;
    if (cmd.hasOption("v")) {
        logLevel = Level.ALL;
    }
    String cluster = cmd.getOptionValue("cluster");
    String role = cmd.getOptionValue("role");
    String environ = cmd.getOptionValue("environment");
    int serverPort = Integer.valueOf(cmd.getOptionValue("server_port"));
    int statsPort = Integer.valueOf(cmd.getOptionValue("stats_port"));
    String systemConfigFilename = cmd.getOptionValue("system_config_file");
    String overrideConfigFilename = cmd.getOptionValue("override_config_file");
    String metricsSinksConfigFilename = cmd.getOptionValue("sink_config_file");
    String topologyName = cmd.getOptionValue("topology_name");
    String topologyId = cmd.getOptionValue("topology_id");
    String metricsCacheMgrId = cmd.getOptionValue("metricscache_id");
    // read heron internal config file
    SystemConfig systemConfig = SystemConfig.newBuilder(true).putAll(systemConfigFilename, true).putAll(overrideConfigFilename, true).build();
    // Log to file and sink(exception)
    LoggingHelper.loggerInit(logLevel, true);
    LoggingHelper.addLoggingHandler(LoggingHelper.getFileHandler(metricsCacheMgrId, systemConfig.getHeronLoggingDirectory(), true, systemConfig.getHeronLoggingMaximumSize(), systemConfig.getHeronLoggingMaximumFiles()));
    LoggingHelper.addLoggingHandler(new ErrorReportLoggingHandler());
    LOG.info(String.format("Starting MetricsCache for topology %s with topologyId %s with " + "MetricsCache Id %s, server port: %d.", topologyName, topologyId, metricsCacheMgrId, serverPort));
    LOG.info("System Config: " + systemConfig);
    // read sink config file
    MetricsSinksConfig sinksConfig = new MetricsSinksConfig(metricsSinksConfigFilename, overrideConfigFilename);
    LOG.info("Sinks Config: " + sinksConfig.toString());
    // build config from cli
    Config config = Config.toClusterMode(Config.newBuilder().putAll(ConfigLoader.loadClusterConfig()).putAll(Config.newBuilder().put(Key.CLUSTER, cluster).put(Key.ROLE, role).put(Key.ENVIRON, environ).build()).putAll(Config.newBuilder().put(Key.TOPOLOGY_NAME, topologyName).put(Key.TOPOLOGY_ID, topologyId).build()).build());
    LOG.info("Cli Config: " + config.toString());
    // build metricsCache location
    TopologyManager.MetricsCacheLocation metricsCacheLocation = TopologyManager.MetricsCacheLocation.newBuilder().setTopologyName(topologyName).setTopologyId(topologyId).setHost(InetAddress.getLocalHost().getHostName()).setControllerPort(// not used for metricscache
    -1).setServerPort(serverPort).setStatsPort(statsPort).build();
    MetricsCacheManager metricsCacheManager = new MetricsCacheManager(topologyName, METRICS_CACHE_HOST, serverPort, statsPort, systemConfig, sinksConfig, config, metricsCacheLocation);
    metricsCacheManager.start();
    LOG.info("Loops terminated. MetricsCache Manager exits.");
}
Also used : MetricsSinksConfig(org.apache.heron.metricsmgr.MetricsSinksConfig) Options(org.apache.commons.cli.Options) HeronSocketOptions(org.apache.heron.common.network.HeronSocketOptions) SystemConfig(org.apache.heron.common.config.SystemConfig) MetricsSinksConfig(org.apache.heron.metricsmgr.MetricsSinksConfig) SystemConfig(org.apache.heron.common.config.SystemConfig) Config(org.apache.heron.spi.common.Config) TopologyManager(org.apache.heron.proto.tmanager.TopologyManager) CommandLine(org.apache.commons.cli.CommandLine) Level(java.util.logging.Level) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) ErrorReportLoggingHandler(org.apache.heron.common.utils.logging.ErrorReportLoggingHandler) DefaultParser(org.apache.commons.cli.DefaultParser)

Aggregations

MetricsSinksConfig (org.apache.heron.metricsmgr.MetricsSinksConfig)3 SystemConfig (org.apache.heron.common.config.SystemConfig)2 TopologyManager (org.apache.heron.proto.tmanager.TopologyManager)2 IOException (java.io.IOException)1 Level (java.util.logging.Level)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 DefaultParser (org.apache.commons.cli.DefaultParser)1 Options (org.apache.commons.cli.Options)1 ParseException (org.apache.commons.cli.ParseException)1 NIOLooper (org.apache.heron.common.basics.NIOLooper)1 HeronSocketOptions (org.apache.heron.common.network.HeronSocketOptions)1 ErrorReportLoggingHandler (org.apache.heron.common.utils.logging.ErrorReportLoggingHandler)1 PrometheusSink (org.apache.heron.metricsmgr.sink.PrometheusSink)1 Config (org.apache.heron.spi.common.Config)1 Test (org.junit.Test)1