Giter VIP home page Giter VIP logo

metrics-reporter-config's Introduction

Description

Coda Hale's Metrics package makes it easy to create useful metrics so you know what is going on in production. In addition to showing up in the normal Java places (JMX), Metrics supports an arbitrary number of Reporters (where to send the application telemetry to make pretty graphs). Ganglia and Graphite (or both!) are among the most popular choices.

However, Metrics purposefully doesn't come with a kitchen sink of support for every dependency injection or configuration tool yet devised by Java developers. Metrics-Reporter-Config aims to provide a simple way to configure and enable a set of Reporters that can be shared among applications. It should fit most (say 90% of) use cases and avoid situations like a plethora of subtly incompatible properties files.

In particular, it should seamlessly fit into Dropwizard service Configuration classes.

Use

Maven

<dependency>
  <groupId>com.addthis.metrics</groupId>
  <artifactId>reporter-config</artifactId>
  <version>2.0.5</version>
</dependency>

Basics

Current supported reporters include:

  • console
  • csv
  • ganglia
  • graphite
  • influx
  • prometheus

Note that Metrics-Reporter-Config's dependencies on non-core reporters are optional in maven-speak. That means that depending on Metrics-Reporter-Config should not pull in "a bunch of junk", but your applications will need to explicitly depend on the reporters they want (such as metrics-ganglia).

An example config file might look like this:

csv:
  -
    outdir: '/tmp/metrics/crazy-debugging'
    period: 2
    timeunit: 'MINUTES'
ganglia:
  -
    period: 60
    timeunit: 'SECONDS'
    hosts:
      - host: 'gmond.domain.local'
        port: 8649
      - host: 'gmond-backup.domain.local'
        port: 8649
graphite:
  -
    period: 120
    timeunit: 'SECONDS'
    hosts:
     - host: 'graphite-server.domain.local'
       port: 2003

And then to wire up your app call ReporterConfig.loadFromFileAndValidate() (or loadFromFile() if you aren't into validating), and then enableAll().

In addition to an inline list, the ganglia config supports gmondConf field which tells it where to find gmond's config file (ie /etc/ganglia/gmond.conf) and read any UDP send channels there. This should make it easy to keep the java app config and the rest of the system in sync.

Dropwizard

Just add a ReporterConfig instance to your app's Configuration class. Metrics-Reporter-Config uses the same validation implementation as dropwizard. You will still need to call an enable method when initialization your app.

Predicates

predicate:
  color: "black"
  patterns:
    - ".*JMXONLY$"

Each reporter can have a simple name based predicate with a white or black list of regular expressions. Use this for rarely used metrics that will only show up in JMX without flooding ganglia with 20k extra metrics. In practice our configurations tend to look like this:

ganglia:
  -
    period: 60
    timeunit: 'SECONDS'
    gmondConf: '/etc/ganglia/gmond.conf'
    predicate:
      color: "black"
      patterns:
      - ".*JMXONLY$"

By default predicates operate on the "Metric Name" (usually something like MyClass). If you want to operable on the conventional "full" name (org.example.foo.MyClass) enable useQualifiedName.

[EXPERIMENTAL] If you want to report only a subset of the measurements that are reported by a meter then use can use the measurement options on the predicate configuration. This feature is only available if you include as a dependency a fork of the metrics project that supports this feature. Forks supporting this feature: for metrics2: http://github.com/mspiegel/metrics; for metrics3 (graphite reporter only): http://github.com/thelastpickle/metrics. If the per measurement filtering is available then it is only applied once a metric has passed the top level filter.

ganglia:
  -
    period: 60
    timeunit: 'SECONDS'
    gmondConf: '/etc/ganglia/gmond.conf'
    predicate:
      color: "black"
      patterns:
      - ".*JMXONLY$"
      histogram:
          color: "white"
          patterns:
          - metric: ".*WidgetRunner$"
            measure: "mean|stddev"
          - metric: ".*SprocketRunner$"
            measure: ".*percentile"

Graphite and Ganglia

The Graphite and Ganglia reporters supports the "prefix" parameter. Its value will be prepended to each metric name sent by reporter. This feature is only available if you include as a dependency a fork of the metrics project that supports this feature. Forks supporting this feature: for metrics2: http://github.com/mspiegel/metrics; None yet known for metrics3. This value may contain one of the following variable references using "${variable.name}" as format.

- host.name = the value returned for local host by `java.net.InetAddress#getHostAddress()`
- host.name.short = same as ${host.name} up to first dot
- host.address = the value returned for local host by `java.net.InetAddress#getHostName()`
- host.fqdn = the value returned for local host by `java.net.InetAddress#getCanonicalHostName()`

Each substituted value gets sanitized by replacing all characters that are not allowed in the host name plus "-" with the underscore. The Ganglia reporter additionally supports the "groupPrefix" parameter. This will add a prefix to the Ganglia metric group.

Zabbix

The Zabbix reporter requires the dependency zabbix-sender-0.0.3.jar (Maven group ID: io.github.hengyunabc, Maven artifact ID: zabbix-sender, version: 0.0.3).

InfluxDB

The InfluxDB reporter currently requires the dependency metrics-influxdb-1.1.7.jar Sources (Maven group ID: com.izettle, Maven artifact ID: metrics-influxdb, version 1.1.7).

Metrics 4.0 will introduce native InfluxDB support.

InfluxDB connection requires a few more configuration properties:

influxdb:
  -
    period: 60
    timeunit: 'SECONDS'
    protocol: 'http'
    auth: 'troll:admin123'
    dbName: 'db1'
    connectionTimeout: 1000
    readTimeout: 1000
    tags:
     host: '${host.name}'
     env: 'prod'
    measurementMappings:
     cassandra_Table_ReadLatency: org.apache.cassandra.metrics.Table.ReadLatency.*
    prefix: ''
    hosts:
      - host: 'localhost'
        port: 8086
  • hosts - must contain exactly one host configured. For HA see the InfluxDB Relay
  • protocol - http or https
  • auth - username:password, can be empty
  • dbName - InfluxDB database name
  • connectionTimeout - java.net.URLConnection connection timeout in milliseconds
  • readTimeout - java.net.URLConnection read timeout in milliseconds
  • tags - every send measurement will be tagged with this tags map. Tags values can contain variables described for Graphite prefix parameter - host.name, host.name.short, host.address, host.fqdn.
  • prefix - its value will be prepended to each metric name sent by reporter (see Graphite & Ganglia). Prefix can contain variables described for Graphite prefix parameter - host.name, host.name.short, host.address, host.fqdn. Please also look at tags.

Prometheus

only metric3 is currently supported

The Prometheus configuration provides two options to report metrics. The first is the push gateway and the second is the metrics servlet.

Prometheus Specific Configuration Options:

  • job - prometheus job name. This is added to every metric
  • labels - map<string, string> that will be added to every metric. Variable substitution is available for label values (see graphite & ganglia)
  • type - (pushgateway|servlet) pushgateway requires host(s), period and timeunit. Servlet does not.

Push Gateway Configuration

prometheus:
  -
    type: pushgateway
    period: 60
    timeunit: 'SECONDS'
    job: 'app_name'
    labels:
        env: test
        host: '${host.name}'
    hosts:
        - host: localhost
          port: 9091

Servlet Configuration

prometheus:
  -
    type: servlet
    job: 'app_name'
    labels:
        env: test
        host: '${host.name}'

In addition to the yaml configuration, you will also need to register the servlet with your environment.

config.getReporterConfig().enablePrometheus(environment.metrics());
MetricsServlet servlet = config.getReporterConfig().getPrometheus().get(0).getMetricsServlet();
environment.admin()
           .addServlet("prometheus-metrics", servlet)
           .addMapping("/prometheus-metrics");

Riemann

In order to use the riemann reporter, you need the following dependencies:

  • riemann-java-client-0.2.10.jar (Maven group ID: com.aphyr, Maven artifact ID: java-client, version: 0.2.10).
  • netty-all-3.6.1.Final.jar (Maven group ID: io.netty, Maven artifact ID: netty, version: 3.6.1.Final)
  • protobuf-java-2.5.0.jar (Maven group ID: com.google.protobuf, Maven artifact ID: protobuf-java, version: 2.5.0)

Building

Assuming you have Apache Maven installed and configured:

mvn package

And you should be all set.

To run individual tests use -Dtest= and -Dorg.slf4j.simpleLogger.defaultLogLevel= to change the test log level.

Administrivia

Versioning

It's x.y.z where:

  • x: compatible Metrics major version
  • y: next release
  • z: bug fix only

License

Metrics-Reporter-Config is released under the Apache License Version 2.0. See Apache or the LICENSE file in this distribution for details.

Where People Hang Out

Main Metrics mailing list: http://groups.google.com/group/metrics-user

metrics-reporter-config's People

Contributors

addthis-buildbot avatar cburroughs avatar dlobue avatar jhorwit2 avatar jiayangodc avatar jimlar avatar lucky avatar michaelsembwever avatar mmatloka avatar mspiegel avatar ngrigoriev avatar sio2boss avatar snazy avatar stephenwithph avatar tedpearson avatar trepik avatar yuesong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

metrics-reporter-config's Issues

Options on the config yaml file

Hi,

We want to start using the pluggable metrics on our Cassandra DB and I saw that they are using your Components.

Where can I get an explanation of the options in your config metric file? so I can know how to use it, I've tried to search and didn't find any, except sample files.

Thanks

Support for metrics 3.x

Hi,

It would be great to upgrade metrics-reporter-config to align with upstream release of metrics 3.0 (now mandatory version starting from Dropwizard 0.7.x).

Cheers,

GraphtieReporter initialized via reporter-config cannot follow DNS changes

From what I see in the code (and what I observed today in our applications), GraphiteReporterConfig calls the constructor of Graphite class that forces it to stick to Graphite server address resolved at startup. Even if DNS information changes, the application won't be able to follow the change.

build(new Graphite(new InetSocketAddress(hostPort.getHost(),
                        hostPort.getPort())));

I think it should call public Graphite(String hostname, int port) instead.

Failed to load metrics-reporter-config, metric sinks will not be activated

then using the metrics-reporter-config with cassandra , no matter what reporter configuration i use(graphite,riemann,console) i always get this

INFO [main] 2014-08-03 21:27:01,911 CassandraDaemon.java (line 393) Trying to load metrics-reporter-config from file: /etc/cassandra/metrics.yaml
WARN [main] 2014-08-03 21:27:01,912 CassandraDaemon.java (line 401) Failed to load metrics-reporter-config, metric sinks will not be activated
java.lang.NullPointerException
at org.apache.cassandra.service.CassandraDaemon.setup(CassandraDaemon.java:396)
at org.apache.cassandra.service.CassandraDaemon.activate(CassandraDaemon.java:496)
at org.apache.cassandra.service.CassandraDaemon.main(CassandraDaemon.java:585)

i've tried the reporter-config 2.1.0 that comes with cassandra 2.0.9
as well versions 2.2.0 and 2.4.0-SNAPSHOT build from the repo
with relevant reporters jars(and dependencies) deployed under cassandra lib dir
the result is always the same error , even for console reporter config like this

console:
  -
    outfile: '/tmp/metrics.out'
    period: 10
    timeunit: 'SECONDS'

i've verified that /etc/cassandra/metrics.yaml is valid yaml file
any clues what can be wrong?

custom prefix support

I'd like to send metrics from cassandra to hostedgraphite but need to prefix an api key to every metric.

Can I do this now, I don't see how.

IllegalArgumentException: metric already exists

looks like commit b8cbf4d seems to cause a problem with dropwizard whose Bootstrap class does something very similar this.getMetricRegistry().register("jvm.attribute", new JvmAttributeGaugeSet()); and thus causes an exception when enableAll is called:

Exception in thread "main" java.lang.IllegalArgumentException: A metric named jvm.attribute.vendor already exists
	at com.codahale.metrics.MetricRegistry.register(MetricRegistry.java:91)
	at com.codahale.metrics.MetricRegistry.registerAll(MetricRegistry.java:389)
	at com.codahale.metrics.MetricRegistry.register(MetricRegistry.java:85)
	at com.addthis.metrics3.reporter.config.ReporterConfig.registerJvmMetrics(ReporterConfig.java:306)

Should refactor registering jvm metrics into a separate class that is not automatically called here. It also makes sense to decouple registering specific metrics from registering specific metrics reporters.

Predicate filters are not working

I'm using the following configuration to monitor my cassandra metrics. However the filters on histogram, time and meter don't seem to work. I'm still seeing the values in my influxDB.
Is there anything wrong with my config?

influxdb:
  -
    period: 10
    timeunit: 'SECONDS'
    protocol: 'http'
    dbName: 'cassandra'
    connectionTimeout: 1000
    readTimeout: 1000
    tags:
     host: '${host.name}'
    prefix: ''
    hosts:
      - host: 'localhost'
        port: 8086
    measurementMappings:
     cassandra_Table_ReadLatency: org.apache.cassandra.metrics.Table.ReadLatency.*
    predicate:
      color: "white"
      useQualifiedName: true
      patterns:
        - "^org.apache.cassandra.metrics.Cache.*"
        - "^org.apache.cassandra.metrics.ClientRequest.*" # includes ClientRequestMetrics
        - "^org.apache.cassandra.metrics.CommitLog.*"
        - "^org.apache.cassandra.metrics.Compaction.*"
        - "^org.apache.cassandra.metrics.DroppedMessage.*"
        - "^org.apache.cassandra.metrics.ReadRepair.*"
        - "^org.apache.cassandra.metrics.Storage.*"
        - "^org.apache.cassandra.metrics.ThreadPools.*"
        - "^jvm.gc.*"
      histogram:
        color: "black"
        patterns:
        - metric: ".*"
          measure: "999percentile|mean|stddev"
      timer:
        color: "black"
        patterns:
        - metric: ".*"
          measure: "999percentile|mean|stddev"
      meter:
        color: "black"
        patterns:
        - metric: ".*"
          measure: "count"

CsvReporterConfig returns null if directory exists

Class: CsvReporterConfig
Method: enable
Line 39: File foutDir = createFile();
The line above invokes the Parent AbstractCsvReporterConfig's createFile() method.
In createFile() method's
Line Number 45: boolean success = foutDir.mkdirs();
This method will return false, if the directory already exists.
Since the value returned is false in CsvReporterConfig the enable method will return false.
I don't know if this is correct implementation, the reporter should continue to update the CSV files if the directory and file already exists.

Include more reporters

Hi there,
I thought about doing a similar project, so I did some research and found this repository and noticed that it lacks many reporters that might be important for people.
To be specific, I am talking about this list.

Knowing that implementing all reporters mentioned there will take a huge amount of time, I do plan on submitting a PR addressing this issue, but since I am currently running low on time, I thought about posting the note here to maybe find someone to divide the work.

Greetings, vat

Missing license headers

Please include license headers for files:
reporter-config2/src/main/java/com/addthis/metrics/reporter/config/MetricPredicateTransformer.java
reporter-config2/src/test/java/com/addthis/metrics/reporter/config/GraphiteReporterConfigTest.java
reporter-config3/src/main/java/com/addthis/metrics3/reporter/config/MetricFilterTransformer.java
reporter-config3/src/test/java/com/addthis/metrics3/reporter/config/GraphiteReporterConfigTest.java

Thank you

Statsd reporter error on cassandra 3.0.5

I am getting this error on cassandra startup

INFO 11:02:37 Trying to load metrics-reporter-config from file: metrics-reporter-statsd.yaml WARN 11:02:37 Failed to load metrics-reporter-config, metric sinks will not be activated org.yaml.snakeyaml.constructor.ConstructorException: null; Can't construct a java object for tag:yaml.org,2002:com.addthis.metrics3.reporter.config.ReporterConfig; exception=Cannot create property=statsd for JavaBean=com.addthis.metrics3.reporter.config.ReporterConfig@752637ed; Unable to find property 'statsd' on class: com.addthis.metrics3.reporter.config.ReporterConfig; in 'reader', line 1, column 1: statsd: ^ at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:333) ~[snakeyaml-1.11.jar:na] at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:182) ~[snakeyaml-1.11.jar:na] at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:141) ~[snakeyaml-1.11.jar:na] at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:127) ~[snakeyaml-1.11.jar:na] at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:481) ~[snakeyaml-1.11.jar:na] at org.yaml.snakeyaml.Yaml.load(Yaml.java:412) ~[snakeyaml-1.11.jar:na] at com.addthis.metrics.reporter.config.AbstractReporterConfig.loadFromFile(AbstractReporterConfig.java:41) ~[reporter-config-base-3.0.0.jar:3.0.0] at com.addthis.metrics3.reporter.config.ReporterConfig.loadFromFile(ReporterConfig.java:249) ~[reporter-config3-3.0.0.jar:3.0.0] at org.apache.cassandra.service.CassandraDaemon.setup(CassandraDaemon.java:351) [apache-cassandra-3.0.5.jar:3.0.5] at org.apache.cassandra.service.CassandraDaemon.activate(CassandraDaemon.java:551) [apache-cassandra-3.0.5.jar:3.0.5] at org.apache.cassandra.service.CassandraDaemon.main(CassandraDaemon.java:679) [apache-cassandra-3.0.5.jar:3.0.5] Caused by: org.yaml.snakeyaml.error.YAMLException: Cannot create property=statsd for JavaBean=com.addthis.metrics3.reporter.config.ReporterConfig@752637ed; Unable to find property 'statsd' on class: com.addthis.metrics3.reporter.config.ReporterConfig at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:299) ~[snakeyaml-1.11.jar:na] at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.construct(Constructor.java:189) ~[snakeyaml-1.11.jar:na] at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:331) ~[snakeyaml-1.11.jar:na] ... 10 common frames omitted Caused by: org.yaml.snakeyaml.error.YAMLException: Unable to find property 'statsd' on class: com.addthis.metrics3.reporter.config.ReporterConfig at org.yaml.snakeyaml.introspector.PropertyUtils.getProperty(PropertyUtils.java:132) ~[snakeyaml-1.11.jar:na] at org.yaml.snakeyaml.introspector.PropertyUtils.getProperty(PropertyUtils.java:121) ~[snakeyaml-1.11.jar:na] at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.getProperty(Constructor.java:308) ~[snakeyaml-1.11.jar:na] at org.yaml.snakeyaml.constructor.Constructor$ConstructMapping.constructJavaBean2ndStep(Constructor.java:240) ~[snakeyaml-1.11.jar:na] ... 12 common frames omitted INFO 11:02:37 Waiting for gossip to settle before accepting client requests...

Cassandra version:3.0.5

Other libraries:
metrics2-statsd-4.1.2.jar
metrics3-statsd-4.1.0.jar
metrics-core-3.1.0.jar
metrics-logback-3.1.0.jar
metrics-statsd-common-4.1.0.jar

Same setup worked on cassandra 3.11.3

I have verified that there is no error in config yaml file. I am doubting I need to change the version of libraries.

GmondConfigParser dies with unhelpful message if no send channels found

Not sure yet if we should warn or still die and just provide a more helpful error message

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
        at com.addthis.metrics.reporter.config.GmondConfigParser.mapifyChannelString(GmondConfigParser.java:122)
        at com.addthis.metrics.reporter.config.GmondConfigParser.getGmondSendChannelsFromConf(GmondConfigParser.java:72)
        at com.addthis.metrics.reporter.config.GmondConfigParser.getGmondSendChannels(GmondConfigParser.java:55)
        at com.addthis.metrics.reporter.config.GangliaReporterConfig.getFullHostList(GangliaReporterConfig.java:75)
        at com.addthis.metrics.reporter.config.GangliaReporterConfig.enable(GangliaReporterConfig.java:98)
        at com.addthis.metrics.reporter.config.ReporterConfig.enableGanglia(ReporterConfig.java:147)
        at com.addthis.metrics.reporter.config.ReporterConfig.enableAll(ReporterConfig.java:193)

Thanks @lorri

New version release

Hi,
Can you release to maven central new version with zabbix and influxdb support? :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.