<commit_before># SignalFx client libraries [![Build Status](https://travis-ci.org/signalfx/signalfx-java.svg?branch=master)](https://travis-ci.org/signalfx/signalfx-java)

This repository contains libraries for instrumenting Java applications and
reporting metrics to SignalFx. You will need a SignalFx account and organization
API token to use them. For more information on SignalFx and to create an
account, go to [http://www.signalfx.com](http://www.signalfx.com).

We recommend sending metrics with Java using Codahale Metrics version 3.0+. You
can also use Yammer Metrics 2.0.x (an earlier version of Codahale Metrics). More
information on the Codahale Metrics library can be found on the
[Codahale Metrics website](https://dropwizard.github.io/metrics/).

You can also use the module `signalfx-java` to send metrics directly to SignalFx
using protocol buffers, without using Codahale or Yammer metrics.

## Supported languages

* Java 6+ with `signalfx-metrics`.

## Using this library in your project

### With Maven

If you're using Maven, add the following to your project's `pom.xml` file.

* To work with Codahale 3.0.x:

```xml
<dependency>
  <groupId>com.signalfx.public</groupId>
  <artifactId>signalfx-codahale</artifactId>
  <version>0.0.48</version>
</dependency>
```

* To work with Yammer Metrics 2.0.x:

```xml
<dependency>
<groupId>com.signalfx.public</groupId>
  <artifactId>signalfx-yammer</artifactId>
  <version>0.0.48</version>
</dependency>
```

### With SBT

If you're using SBT, add the following to your project's `build.sbt` file.

* To work with Codahale 3.0.x:

```
libraryDependencies += "com.signalfx.public" % "signalfx-codahale" % "0.0.48"
```

* To work with Yammer Metrics 2.0.x:

```
libraryDependencies += "com.signalfx.public" % "signalfx-yammer" % "0.0.48"
```

### From source

You can also install this library from source by cloning the repo and using
`mvn install` as follows. However, we strongly recommend using the automated
mechanisms described above.

```
$ git clone https://github.com/signalfx/signalfx-java.git
Cloning into 'signalfx-java'...
remote: Counting objects: 930, done.
remote: Compressing objects: 100% (67/67), done.
remote: Total 930 (delta 20), reused 0 (delta 0)
Receiving objects: 100% (930/930), 146.79 KiB | 0 bytes/s, done.
Resolving deltas: 100% (289/289), done.
Checking connectivity... done.
$ cd signalfx-java
$ mvn install
[INFO] Scanning for projects...
...
...
...
[INFO] SignalFx parent .................................. SUCCESS [  2.483 s]
[INFO] SignalFx Protocol Buffer definitions ............. SUCCESS [  5.503 s]
[INFO] SignalFx Protobuf Utilities ...................... SUCCESS [  2.269 s]
[INFO] SignalFx java libraries .......................... SUCCESS [  3.728 s]
[INFO] Codahale to SignalFx ............................. SUCCESS [  2.910 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 17.120 s
[INFO] ------------------------------------------------------------------------
```

## Sending metrics

### Codahale Metrics 3.0.x

#### 1. Set up the Codahale reporter

```java
final MetricRegistry metricRegistry = new MetricRegistry();
final SignalFxReporter signalfxReporter = new SignalFxReporter.Builder(
    metricRegistry,
    "SIGNALFX_AUTH_TOKEN"
).build();
signalfxReporter.start(1, TimeUnit.SECONDS);
final MetricMetadata metricMetadata = signalfxReporter.getMetricMetadata();
final SfxMetrics metrics = new SfxMetrics(metricRegistry, metricMetadata);
```

#### 2. Send a metric

```java
// This will send the current time in ms to SignalFx as a gauge
metrics.registerGauge("gauge", new Gauge<Long>() {
    public Long getValue() {
        return System.currentTimeMillis();
    }
});
```

#### 3. Add dimensions and metadata to metrics

```java
/*
 * This will send the size of a queue as a gauge, and attach dimension
 * 'queue_name' to the gauge.
 */
final Queue customerQueue = new ArrayBlockingQueue(100);
metrics.registerGauge("queue_size", new Gauge<Long>() {
    @Override
    public Long getValue() {
        return customerQueue.size();
    }
}, "queue_name", "customer_backlog");
```

We recommend creating your Codahale object as a field of your class (a
`Counter`, `Gauge<?>`, `Histogram` or `Timer`) then using that field to
increment or update values. If you don't want to maintain this for reasons of
code cleanliness, you can always just create it on the fly.

For example, if you wanted a timer that included a dimension indicating which
store it is from, you could use code like this.

```java
Timer t = metrics.timer("request_time", "storename", "electronics");

Timer.Context c = t.time();
try {
    System.out.println("Doing store things");
} finally {
    c.close();
}

/*
 * Java 7+ alternative:
 *
 * try (Timer.Context ignored = t.time()) {
 *     System.out.println("Doing store things");
 * }
 */

// Or on the fly:
Timer.Context c = metrics.timer("request_time").time();
try {
    // Do something
} finally {
    c.close();
}
```

#### After setting up Codahale

After setting up a SignalFxReporter, you can use Codahale metrics as you
normally would, reported at the frequency configured by the `SignalFxReporter`.

### Yammer Metrics

You can also use this library with Yammer metrics 2.0.x as shown in the
following examples.

#### 1. Set up Yammer metrics

```java
final MetricRegistry metricRegistry = new MetricRegistry();
final SignalFxReporter signalfxReporter = new SignalFxReporter.Builder(
    metricRegistery,
    "SIGNALFX_AUTH_TOKEN"
).build();
signalfxReporter.start(1, TimeUnit.SECONDS);
final MetricMetadata metricMetadata = signalfxReporter.getMetricMetadata();
```

Note: the `SfxMetrics` helper is not supported for Yammer metrics.
<commit_msg>Fix typos in README.md (fixes #64)<commit_after># SignalFx client libraries [![Build Status](https://travis-ci.org/signalfx/signalfx-java.svg?branch=master)](https://travis-ci.org/signalfx/signalfx-java)

This repository contains libraries for instrumenting Java applications and
reporting metrics to SignalFx. You will need a SignalFx account and organization
API token to use them. For more information on SignalFx and to create an
account, go to [http://www.signalfx.com](http://www.signalfx.com).

We recommend sending metrics with Java using Codahale Metrics version 3.0+. You
can also use Yammer Metrics 2.0.x (an earlier version of Codahale Metrics). More
information on the Codahale Metrics library can be found on the
[Codahale Metrics website](https://dropwizard.github.io/metrics/).

You can also use the module `signalfx-java` to send metrics directly to SignalFx
using protocol buffers, without using Codahale or Yammer metrics.

## Supported languages

* Java 6+ with `signalfx-metrics`.

## Using this library in your project

### With Maven

If you're using Maven, add the following to your project's `pom.xml` file.

* To work with Codahale 3.0.x:

```xml
<dependency>
  <groupId>com.signalfx.public</groupId>
  <artifactId>signalfx-codahale</artifactId>
  <version>0.0.48</version>
</dependency>
```

* To work with Yammer Metrics 2.0.x:

```xml
<dependency>
<groupId>com.signalfx.public</groupId>
  <artifactId>signalfx-yammer</artifactId>
  <version>0.0.48</version>
</dependency>
```

### With SBT

If you're using SBT, add the following to your project's `build.sbt` file.

* To work with Codahale 3.0.x:

```
libraryDependencies += "com.signalfx.public" % "signalfx-codahale" % "0.0.48"
```

* To work with Yammer Metrics 2.0.x:

```
libraryDependencies += "com.signalfx.public" % "signalfx-yammer" % "0.0.48"
```

### From source

You can also install this library from source by cloning the repo and using
`mvn install` as follows. However, we strongly recommend using the automated
mechanisms described above.

```
$ git clone https://github.com/signalfx/signalfx-java.git
Cloning into 'signalfx-java'...
remote: Counting objects: 930, done.
remote: Compressing objects: 100% (67/67), done.
remote: Total 930 (delta 20), reused 0 (delta 0)
Receiving objects: 100% (930/930), 146.79 KiB | 0 bytes/s, done.
Resolving deltas: 100% (289/289), done.
Checking connectivity... done.
$ cd signalfx-java
$ mvn install
[INFO] Scanning for projects...
...
...
...
[INFO] SignalFx parent .................................. SUCCESS [  2.483 s]
[INFO] SignalFx Protocol Buffer definitions ............. SUCCESS [  5.503 s]
[INFO] SignalFx Protobuf Utilities ...................... SUCCESS [  2.269 s]
[INFO] SignalFx java libraries .......................... SUCCESS [  3.728 s]
[INFO] Codahale to SignalFx ............................. SUCCESS [  2.910 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 17.120 s
[INFO] ------------------------------------------------------------------------
```

## Sending metrics

### Codahale Metrics 3.0.x

#### 1. Set up the Codahale reporter

```java
final MetricRegistry metricRegistry = new MetricRegistry();
final SignalFxReporter signalfxReporter = new SignalFxReporter.Builder(
    metricRegistry,
    "SIGNALFX_AUTH_TOKEN"
).build();
signalfxReporter.start(1, TimeUnit.SECONDS);
final MetricMetadata metricMetadata = signalfxReporter.getMetricMetadata();
final SfxMetrics metrics = new SfxMetrics(metricRegistry, metricMetadata);
```

#### 2. Send a metric

```java
// This will send the current time in ms to SignalFx as a gauge
metrics.registerGauge("gauge", new Gauge<Long>() {
    public Long getValue() {
        return System.currentTimeMillis();
    }
});
```

#### 3. Add dimensions and metadata to metrics

```java
/*
 * This will send the size of a queue as a gauge, and attach dimension
 * 'queue_name' to the gauge.
 */
final Queue customerQueue = new ArrayBlockingQueue(100);
metrics.registerGauge("queue_size", new Gauge<Long>() {
    @Override
    public Long getValue() {
        return customerQueue.size();
    }
}, "queue_name", "customer_backlog");
```

We recommend creating your Codahale object as a field of your class (a
`Counter`, `Gauge<?>`, `Histogram` or `Timer`) then using that field to
increment or update values. If you don't want to maintain this for reasons of
code cleanliness, you can always just create it on the fly.

For example, if you wanted a timer that included a dimension indicating which
store it is from, you could use code like this.

```java
Timer t = metrics.timer("request_time", "storename", "electronics");

Timer.Context c = t.time();
try {
    System.out.println("Doing store things");
} finally {
    c.close();
}

/*
 * Java 7+ alternative:
 *
 * try (Timer.Context ignored = t.time()) {
 *     System.out.println("Doing store things");
 * }
 */

// Or on the fly:
Timer.Context c = metrics.timer("request_time").time();
try {
    // Do something
} finally {
    c.close();
}
```

#### After setting up Codahale

After setting up a SignalFxReporter, you can use Codahale metrics as you
normally would, reported at the frequency configured by the `SignalFxReporter`.

### Yammer Metrics

You can also use this library with Yammer metrics 2.0.x as shown in the
following examples.

#### 1. Set up Yammer metrics

```java
final MetricsRegistry metricsRegistry = new MetricsRegistry();
final SignalFxReporter signalfxReporter = new SignalFxReporter.Builder(
    metricsRegistry,
    "SIGNALFX_AUTH_TOKEN"
).build();
signalfxReporter.start(1, TimeUnit.SECONDS);
final MetricMetadata metricMetadata = signalfxReporter.getMetricMetadata();
```

Note: the `SfxMetrics` helper is not supported for Yammer metrics.

{'fraction_non_alphanumeric': 0.16973729102695326, 'fraction_numerical': 0.018764926646195838, 'mean_word_length': 3.280759401241329, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 8, 'lorem ipsum': 0, 'www.': 4, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '436254', 'n_tokens_mistral': 3772, 'n_tokens_neox': 3485, 'n_words': 1219}