<commit_before>[![Build Status](https://travis-ci.org/seuros/hosted_graphite.svg?branch=master)](https://travis-ci.org/seuros/hosted_graphite)
[![Code Climate](https://codeclimate.com/github/seuros/hosted_graphite/badges/gpa.svg)](https://codeclimate.com/github/seuros/hosted_graphite)

# HostedGraphite

A Ruby client for HostedGraphite

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'hosted_graphite'
```

And then execute:

```bash
$ bundle
```

Or install it yourself as:

```bash
$ gem install hosted_graphite
```

## Usage

Set ```ENV['HOSTEDGRAPHITE_APIKEY']```  to your hosted graphite API key.
Your API key can be found on your [account home](https://www.hostedgraphite.com/accounts/profile/) page.

You can also set the hosted graphite API key programatically with:

```bash
HostedGraphite.api_key = 'YOUR API KEY'
```

#### Sending a metric via UDP
```ruby
HostedGraphite.protocol = :udp
HostedGraphite.send_metric('foo.udp', 1.2)
```

#### Sending a metric via TCP
```ruby
HostedGraphite.protocol = :tcp
HostedGraphite.send_metric('foo.tcp', 1.2)
```

#### Sending a metric via HTTP
```ruby
HostedGraphite.protocol = :http
HostedGraphite.send_metric('foo.http', 1.2)
```

### HostedStatsD

Enable Statsd on your [account](https://www.hostedgraphite.com/app/data-sources)

Ensure these line are present in your application's Gemfile:

```ruby
gem 'hosted_graphite'
gem 'statsd-ruby'
```

And then require

```ruby
require 'hosted_graphite/statsd'
```

#### Basic usage

```ruby
# Send some stats
HostedGraphite.increment 'page_views'
HostedGraphite.decrement 'likes_count'
HostedGraphite.timing 'foo', 320
HostedGraphite.gauge 'bar', 100

# Use {#time} to time the execution of a block
HostedGraphite.time('newsletter.monthly') { @newsletter.deliver_now }
```

### Extensions
#### Sidekiq
```ruby 
  require 'hosted_graphite/ext/sidekiq'

  Sidekiq.configure_server do |config|
    config.server_middleware do |chain|
      # chain.prepend Sidekiq::Middleware::Server::StatsdMetrics, namespace: 'my_app'
      # or
      # chain.prepend Sidekiq::Middleware::Server::Metrics
    end
  end
```

## Contributing

1. Fork it ( https://github.com/seuros/hosted_graphite/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request<commit_msg>fix typo<commit_after>[![Build Status](https://travis-ci.org/seuros/hosted_graphite.svg?branch=master)](https://travis-ci.org/seuros/hosted_graphite)
[![Code Climate](https://codeclimate.com/github/seuros/hosted_graphite/badges/gpa.svg)](https://codeclimate.com/github/seuros/hosted_graphite)

# HostedGraphite

A Ruby client for HostedGraphite

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'hosted_graphite'
```

And then execute:

```bash
$ bundle
```

Or install it yourself as:

```bash
$ gem install hosted_graphite
```

## Usage

Set ```ENV['HOSTEDGRAPHITE_APIKEY']```  to your hosted graphite API key.
Your API key can be found on your [account home](https://www.hostedgraphite.com/accounts/profile/) page.

You can also set the hosted graphite API key programatically with:

```bash
HostedGraphite.api_key = 'YOUR API KEY'
```

#### Sending a metric via UDP
```ruby
HostedGraphite.protocol = :udp
HostedGraphite.send_metric('foo.udp', 1.2)
```

#### Sending a metric via TCP
```ruby
HostedGraphite.protocol = :tcp
HostedGraphite.send_metric('foo.tcp', 1.2)
```

#### Sending a metric via HTTP
```ruby
HostedGraphite.protocol = :http
HostedGraphite.send_metric('foo.http', 1.2)
```

### HostedStatsD

Enable Statsd on your [account](https://www.hostedgraphite.com/app/data-sources)

Ensure these line are present in your application's Gemfile:

```ruby
gem 'hosted_graphite'
gem 'statsd-ruby'
```

And then require

```ruby
require 'hosted_graphite/statsd'
```

#### Basic usage

```ruby
# Send some stats
HostedGraphite.increment 'page_views'
HostedGraphite.decrement 'likes_count'
HostedGraphite.timing 'foo', 320
HostedGraphite.gauge 'bar', 100

# Use {#time} to time the execution of a block
HostedGraphite.time('newsletter.monthly') { @newsletter.deliver_now }
```

### Extensions
#### Sidekiq
```ruby 
  require 'hosted_graphite/ext/sidekiq'

  Sidekiq.configure_server do |config|
    config.server_middleware do |chain|
      # chain.prepend HostedGraphite::Ext::Sidekiq::StatsdMetrics, namespace: 'my_app'
      # or
      # chain.prepend HostedGraphite::Ext::Sidekiq::Metrics
    end
  end
```

## Contributing

1. Fork it ( https://github.com/seuros/hosted_graphite/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
{'fraction_non_alphanumeric': 0.1397164577768646, 'fraction_numerical': 0.00698582288884323, 'mean_word_length': 5.054726368159204, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 14, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, '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': '2028176', 'n_tokens_mistral': 1769, 'n_tokens_neox': 1656, 'n_words': 426}