Search in sources :

Example 21 with Graphite

use of com.codahale.metrics.graphite.Graphite in project lucene-solr by apache.

the class SolrGraphiteReporter method validate.

@Override
protected void validate() throws IllegalStateException {
    if (!enabled) {
        log.info("Reporter disabled for registry " + registryName);
        return;
    }
    if (host == null) {
        throw new IllegalStateException("Init argument 'host' must be set to a valid Graphite server name.");
    }
    if (port == -1) {
        throw new IllegalStateException("Init argument 'port' must be set to a valid Graphite server port.");
    }
    if (reporter != null) {
        throw new IllegalStateException("Already started once?");
    }
    if (period < 1) {
        throw new IllegalStateException("Init argument 'period' is in time unit 'seconds' and must be at least 1.");
    }
    GraphiteSender graphite;
    String id = host + ":" + port + ":" + pickled;
    graphite = serviceRegistry.getOrCreate(id, () -> {
        if (pickled) {
            return new PickledGraphite(host, port);
        } else {
            return new Graphite(host, port);
        }
    });
    if (instancePrefix == null) {
        instancePrefix = registryName;
    } else {
        instancePrefix = instancePrefix + "." + registryName;
    }
    GraphiteReporter.Builder builder = GraphiteReporter.forRegistry(metricManager.registry(registryName)).prefixedWith(instancePrefix).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS);
    MetricFilter filter;
    if (!filters.isEmpty()) {
        filter = new SolrMetricManager.PrefixFilter(filters);
    } else {
        filter = MetricFilter.ALL;
    }
    builder = builder.filter(filter);
    reporter = builder.build(graphite);
    reporter.start(period, TimeUnit.SECONDS);
}
Also used : GraphiteSender(com.codahale.metrics.graphite.GraphiteSender) MetricFilter(com.codahale.metrics.MetricFilter) PickledGraphite(com.codahale.metrics.graphite.PickledGraphite) GraphiteReporter(com.codahale.metrics.graphite.GraphiteReporter) PickledGraphite(com.codahale.metrics.graphite.PickledGraphite) Graphite(com.codahale.metrics.graphite.Graphite) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager)

Example 22 with Graphite

use of com.codahale.metrics.graphite.Graphite in project indy by Commonjava.

the class ReporterIntializer method initGraphiteReporterForJVMMetric.

private void initGraphiteReporterForJVMMetric(MetricRegistry metrics, IndyMetricsConfig config) {
    final Graphite graphite = new Graphite(new InetSocketAddress(config.getGrphiterHostName(), config.getGrphiterPort()));
    final GraphiteReporter reporter = GraphiteReporter.forRegistry(metrics).prefixedWith(config.getGrphiterPrefix()).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).filter((name, metric) -> {
        if (!name.contains(FILTER_SIMPLE) && name.contains(FILTER_JVM)) {
            return true;
        }
        return false;
    }).build(graphite);
    reporter.start(config.getGrphiterJVMPriod(), TimeUnit.SECONDS);
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) ZabbixCacheStorage(org.commonjava.indy.metrics.zabbix.cache.ZabbixCacheStorage) IndyMetricsConfig(org.commonjava.indy.metrics.conf.IndyMetricsConfig) IndyZabbixSender(org.commonjava.indy.metrics.zabbix.sender.IndyZabbixSender) Graphite(com.codahale.metrics.graphite.Graphite) InetSocketAddress(java.net.InetSocketAddress) IndyHttpProvider(org.commonjava.indy.subsys.http.IndyHttpProvider) Inject(javax.inject.Inject) TimeUnit(java.util.concurrent.TimeUnit) IndyZabbixReporter(org.commonjava.indy.metrics.zabbix.reporter.IndyZabbixReporter) IndyMetricsNamed(org.commonjava.indy.metrics.conf.annotation.IndyMetricsNamed) GraphiteReporter(com.codahale.metrics.graphite.GraphiteReporter) ConsoleReporter(com.codahale.metrics.ConsoleReporter) ApplicationScoped(javax.enterprise.context.ApplicationScoped) InetSocketAddress(java.net.InetSocketAddress) GraphiteReporter(com.codahale.metrics.graphite.GraphiteReporter) Graphite(com.codahale.metrics.graphite.Graphite)

Example 23 with Graphite

use of com.codahale.metrics.graphite.Graphite in project flink by apache.

the class GraphiteReporter method getReporter.

@Override
public ScheduledReporter getReporter(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);
    }
    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");
    com.codahale.metrics.graphite.GraphiteReporter.Builder builder = com.codahale.metrics.graphite.GraphiteReporter.forRegistry(registry);
    if (prefix != null) {
        builder.prefixedWith(prefix);
    }
    if (conversionRate != null) {
        builder.convertRatesTo(TimeUnit.valueOf(conversionRate));
    }
    if (conversionDuration != null) {
        builder.convertDurationsTo(TimeUnit.valueOf(conversionDuration));
    }
    Protocol prot;
    try {
        prot = Protocol.valueOf(protocol);
    } catch (IllegalArgumentException iae) {
        log.warn("Invalid protocol configuration: " + protocol + " Expected: TCP or UDP, defaulting to TCP.");
        prot = Protocol.TCP;
    }
    log.info("Configured GraphiteReporter with {host:{}, port:{}, protocol:{}}", host, port, prot);
    switch(prot) {
        case UDP:
            return builder.build(new GraphiteUDP(host, port));
        case TCP:
        default:
            return builder.build(new Graphite(host, port));
    }
}
Also used : Graphite(com.codahale.metrics.graphite.Graphite) GraphiteUDP(com.codahale.metrics.graphite.GraphiteUDP)

Example 24 with Graphite

use of com.codahale.metrics.graphite.Graphite in project bookkeeper by apache.

the class CodahaleMetricsProvider method start.

@Override
public void start(Configuration conf) {
    initIfNecessary();
    int metricsOutputFrequency = conf.getInt("codahaleStatsOutputFrequencySeconds", 60);
    String prefix = conf.getString("codahaleStatsPrefix", "");
    String graphiteHost = conf.getString("codahaleStatsGraphiteEndpoint");
    String csvDir = conf.getString("codahaleStatsCSVEndpoint");
    String slf4jCat = conf.getString("codahaleStatsSlf4jEndpoint");
    String jmxDomain = conf.getString("codahaleStatsJmxEndpoint");
    if (!Strings.isNullOrEmpty(graphiteHost)) {
        LOG.info("Configuring stats with graphite");
        HostAndPort addr = HostAndPort.fromString(graphiteHost);
        final Graphite graphite = new Graphite(new InetSocketAddress(addr.getHostText(), addr.getPort()));
        reporters.add(GraphiteReporter.forRegistry(getMetrics()).prefixedWith(prefix).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL).build(graphite));
    }
    if (!Strings.isNullOrEmpty(csvDir)) {
        // NOTE: 1/ metrics output files are exclusive to a given process
        // 2/ the output directory must exist
        // 3/ if output files already exist they are not overwritten and there is no metrics output
        File outdir;
        if (!Strings.isNullOrEmpty(prefix)) {
            outdir = new File(csvDir, prefix);
        } else {
            outdir = new File(csvDir);
        }
        LOG.info("Configuring stats with csv output to directory [{}]", outdir.getAbsolutePath());
        reporters.add(CsvReporter.forRegistry(getMetrics()).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build(outdir));
    }
    if (!Strings.isNullOrEmpty(slf4jCat)) {
        LOG.info("Configuring stats with slf4j");
        reporters.add(Slf4jReporter.forRegistry(getMetrics()).outputTo(LoggerFactory.getLogger(slf4jCat)).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build());
    }
    if (!Strings.isNullOrEmpty(jmxDomain)) {
        LOG.info("Configuring stats with jmx");
        jmx = JmxReporter.forRegistry(getMetrics()).inDomain(jmxDomain).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
        jmx.start();
    }
    for (ScheduledReporter r : reporters) {
        r.start(metricsOutputFrequency, TimeUnit.SECONDS);
    }
}
Also used : HostAndPort(com.google.common.net.HostAndPort) InetSocketAddress(java.net.InetSocketAddress) Graphite(com.codahale.metrics.graphite.Graphite) ScheduledReporter(com.codahale.metrics.ScheduledReporter) File(java.io.File)

Example 25 with Graphite

use of com.codahale.metrics.graphite.Graphite in project okapi by folio-org.

the class DropwizardHelper method config.

public static void config(String graphiteHost, int port, TimeUnit tu, int period, VertxOptions vopt, String hostName) {
    final String registryName = "okapi";
    MetricRegistry registry = SharedMetricRegistries.getOrCreate(registryName);
    DropwizardMetricsOptions metricsOpt = new DropwizardMetricsOptions();
    metricsOpt.setEnabled(true).setRegistryName(registryName);
    vopt.setMetricsOptions(metricsOpt);
    Graphite graphite = new Graphite(new InetSocketAddress(graphiteHost, port));
    final String prefix = "folio.okapi." + hostName;
    GraphiteReporter reporter = GraphiteReporter.forRegistry(registry).prefixedWith(prefix).build(graphite);
    reporter.start(period, tu);
    logger.info("Metrics remote:" + graphiteHost + ":" + port + " this:" + prefix);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) GraphiteReporter(com.codahale.metrics.graphite.GraphiteReporter) MetricRegistry(com.codahale.metrics.MetricRegistry) Graphite(com.codahale.metrics.graphite.Graphite) DropwizardMetricsOptions(io.vertx.ext.dropwizard.DropwizardMetricsOptions)

Aggregations

Graphite (com.codahale.metrics.graphite.Graphite)33 InetSocketAddress (java.net.InetSocketAddress)20 GraphiteReporter (com.codahale.metrics.graphite.GraphiteReporter)16 MetricRegistry (com.codahale.metrics.MetricRegistry)9 TimeUnit (java.util.concurrent.TimeUnit)6 GraphiteSender (com.codahale.metrics.graphite.GraphiteSender)4 GraphiteUDP (com.codahale.metrics.graphite.GraphiteUDP)4 ConsoleReporter (com.codahale.metrics.ConsoleReporter)3 ScheduledReporter (com.codahale.metrics.ScheduledReporter)3 ApplicationScoped (javax.enterprise.context.ApplicationScoped)3 Inject (javax.inject.Inject)3 IndyMetricsConfig (org.commonjava.indy.metrics.conf.IndyMetricsConfig)3 IndyMetricsNamed (org.commonjava.indy.metrics.conf.annotation.IndyMetricsNamed)3 ZabbixCacheStorage (org.commonjava.indy.metrics.zabbix.cache.ZabbixCacheStorage)3 IndyZabbixReporter (org.commonjava.indy.metrics.zabbix.reporter.IndyZabbixReporter)3 IndyZabbixSender (org.commonjava.indy.metrics.zabbix.sender.IndyZabbixSender)3 IndyHttpProvider (org.commonjava.indy.subsys.http.IndyHttpProvider)3 PickledGraphite (com.codahale.metrics.graphite.PickledGraphite)2 HostAndPort (com.google.common.net.HostAndPort)2 DropwizardMetricsOptions (io.vertx.ext.dropwizard.DropwizardMetricsOptions)2