@Override public void open(MetricConfig config) { String host = config.getString(ARG_HOST, null); int port = config.getInteger(ARG_PORT, -1); if (host == null || host.length() == 0 || port < 1) { throw new IllegalArgumentException("Invalid host/port configuration. Host: " + host + " Port: " + port); } this.address = new InetSocketAddress(host, port); try { this.socket = new DatagramSocket(0); } catch (SocketException e) { throw new RuntimeException("Could not create datagram socket. ", e); } log.info("Configured StatsDReporter with {host:{}, port:{}}", host, port); }
public String getString(String key, String defaultValue) { return getProperty(key, defaultValue); }
@Override public void open(MetricConfig config) { super.open(config); String host = config.getString(HOST.key(), HOST.defaultValue()); int port = config.getInteger(PORT.key(), PORT.defaultValue()); String configuredJobName = config.getString(JOB_NAME.key(), JOB_NAME.defaultValue()); boolean randomSuffix = config.getBoolean(RANDOM_JOB_NAME_SUFFIX.key(), RANDOM_JOB_NAME_SUFFIX.defaultValue()); deleteOnShutdown = config.getBoolean(DELETE_ON_SHUTDOWN.key(), DELETE_ON_SHUTDOWN.defaultValue()); if (host == null || host.isEmpty() || port < 1) { throw new IllegalArgumentException("Invalid host/port configuration. Host: " + host + " Port: " + port); } if (randomSuffix) { this.jobName = configuredJobName + new AbstractID(); } else { this.jobName = configuredJobName; } pushGateway = new PushGateway(host + ':' + port); log.info("Configured PrometheusPushGatewayReporter with {host:{}, port:{}, jobName: {}, randomJobNameSuffix:{}, deleteOnShutdown:{}}", host, port, jobName, randomSuffix, deleteOnShutdown); }
MetricReporter reporterInstance = (MetricReporter) reporterClass.newInstance(); MetricConfig metricConfig = new MetricConfig(); reporterConfig.addAllToProperties(metricConfig); LOG.info("Configuring {} with {}.", namedReporter, metricConfig);
@Override public void open(MetricConfig config) { boolean filterLabelValueCharacters = config.getBoolean( FILTER_LABEL_VALUE_CHARACTER.key(), FILTER_LABEL_VALUE_CHARACTER.defaultValue()); if (!filterLabelValueCharacters) { labelValueCharactersFilter = input -> input; } }
MetricReporter reporterInstance = (MetricReporter) reporterClass.newInstance(); MetricConfig metricConfig = new MetricConfig(); reporterConfig.addAllToProperties(metricConfig); LOG.info("Configuring {} with {}.", reporterClass.getSimpleName(), metricConfig);
@Override public void open(MetricConfig config) { super.open(config); String portsConfig = config.getString(ARG_PORT, DEFAULT_PORT); Iterator<Integer> ports = NetUtils.getPortRangeFromString(portsConfig); while (ports.hasNext()) { int port = ports.next(); try { // internally accesses CollectorRegistry.defaultRegistry httpServer = new HTTPServer(port); this.port = port; log.info("Started PrometheusReporter HTTP server on port {}.", port); break; } catch (IOException ioe) { //assume port conflict log.debug("Could not start PrometheusReporter HTTP server on port {}.", port, ioe); } } if (httpServer == null) { throw new RuntimeException("Could not start PrometheusReporter HTTP server on any configured port. Ports: " + portsConfig); } }
@Override public ScheduledReporter getReporter(MetricConfig config) { String host = config.getString(ARG_HOST, null); int port = config.getInteger(ARG_PORT, -1); String prefix = config.getString(ARG_PREFIX, null); String conversionRate = config.getString(ARG_CONVERSION_RATE, null); String conversionDuration = config.getString(ARG_CONVERSION_DURATION, null); String protocol = config.getString(ARG_PROTOCOL, "TCP");
MetricReporter reporterInstance = (MetricReporter) reporterClass.newInstance(); MetricConfig metricConfig = new MetricConfig(); reporterConfig.addAllToProperties(metricConfig); LOG.info("Configuring {} with {}.", namedReporter, metricConfig);
/** * Searches for the property with the specified key in this property list. * If the key is not found in this property list, the default property list, * and its defaults, recursively, are then checked. The method returns the * default value argument if the property is not found. * * @param key the hashtable key. * @param defaultValue a default value. * @return the value in this property list with the specified key value parsed as a float. */ public float getFloat(String key, float defaultValue) { String argument = getProperty(key, null); return argument == null ? defaultValue : Float.parseFloat(argument); }
@Override public void open(MetricConfig config) { String portsConfig = config.getString(ARG_PORT, null); if (portsConfig != null) { Iterator<Integer> ports = NetUtils.getPortRangeFromString(portsConfig); JMXServer server = new JMXServer(); while (ports.hasNext()) { int port = ports.next(); try { server.start(port); LOG.info("Started JMX server on port " + port + "."); // only set our field if the server was actually started jmxServer = server; break; } catch (IOException ioe) { //assume port conflict LOG.debug("Could not start JMX server on port " + port + ".", ioe); try { server.stop(); } catch (Exception e) { LOG.debug("Could not stop JMX server.", e); } } } if (jmxServer == null) { throw new RuntimeException("Could not start JMX server on any configured port. Ports: " + portsConfig); } } LOG.info("Configured JMXReporter with {port:{}}", portsConfig); }
MetricReporter reporterInstance = (MetricReporter) reporterClass.newInstance(); MetricConfig metricConfig = new MetricConfig(); reporterConfig.addAllToProperties(metricConfig); LOG.info("Configuring {} with {}.", namedReporter, metricConfig);
/** * Searches for the property with the specified key in this property list. * If the key is not found in this property list, the default property list, * and its defaults, recursively, are then checked. The method returns the * default value argument if the property is not found. * * @param key the hashtable key. * @param defaultValue a default value. * @return the value in this property list with the specified key value parsed as an int. */ public int getInteger(String key, int defaultValue) { String argument = getProperty(key, null); return argument == null ? defaultValue : Integer.parseInt(argument); }
@Override public void open(MetricConfig config) { synchronized (this) { if (path == null) { path = config.getString("path", null); log.info("Opening file: {}", path); if (path == null) { throw new IllegalStateException("FileReporter metrics config needs 'path' key"); } try { FileOutputStream fos = new FileOutputStream(path); ps = new PrintStream(fos); } catch (FileNotFoundException e) { throw new IllegalStateException("FileReporter couldn't open file", e); } } } }
/** * Searches for the property with the specified key in this property list. * If the key is not found in this property list, the default property list, * and its defaults, recursively, are then checked. The method returns the * default value argument if the property is not found. * * @param key the hashtable key. * @param defaultValue a default value. * @return the value in this property list with the specified key value parsed as a long. */ public long getLong(String key, long defaultValue) { String argument = getProperty(key, null); return argument == null ? defaultValue : Long.parseLong(argument); }
@Override public void open(MetricConfig config) { String portsConfig = config.getString(ARG_PORT, null); if (portsConfig != null) { Iterator<Integer> ports = NetUtils.getPortRangeFromString(portsConfig); JMXServer server = new JMXServer(); while (ports.hasNext()) { int port = ports.next(); try { server.start(port); LOG.info("Started JMX server on port " + port + "."); // only set our field if the server was actually started jmxServer = server; break; } catch (IOException ioe) { //assume port conflict LOG.debug("Could not start JMX server on port " + port + ".", ioe); try { server.stop(); } catch (Exception e) { LOG.debug("Could not stop JMX server.", e); } } } if (jmxServer == null) { throw new RuntimeException("Could not start JMX server on any configured port. Ports: " + portsConfig); } } LOG.info("Configured JMXReporter with {port:{}}", portsConfig); }
/** * Searches for the property with the specified key in this property list. * If the key is not found in this property list, the default property list, * and its defaults, recursively, are then checked. The method returns the * default value argument if the property is not found. * * @param key the hashtable key. * @param defaultValue a default value. * @return the value in this property list with the specified key value parsed as a double. */ public double getDouble(String key, double defaultValue) { String argument = getProperty(key, null); return argument == null ? defaultValue : Double.parseDouble(argument); }
/** * Searches for the property with the specified key in this property list. * If the key is not found in this property list, the default property list, * and its defaults, recursively, are then checked. The method returns the * default value argument if the property is not found. * * @param key the hashtable key. * @param defaultValue a default value. * @return the value in this property list with the specified key value parsed as a boolean. */ public boolean getBoolean(String key, boolean defaultValue) { String argument = getProperty(key, null); return argument == null ? defaultValue : Boolean.parseBoolean(argument); } }