Giter Club home page Giter Club logo

signalfx-ruby's Introduction

ℹ️  SignalFx was acquired by Splunk in October 2019. See Splunk SignalFx for more information.

Ruby client library for SignalFx

This is a programmatic interface in Ruby for SignalFx's metadata and ingest APIs. It is meant to provide a base for communicating with SignalFx APIs that can be easily leveraged by scripts and applications to interact with SignalFx or report metric and event data to SignalFx.

This library supports Ruby versions 2.2.x and above.

Installation

Add this line to your application's Gemfile:

gem 'signalfx'

And then execute:

$ bundle

Or install it yourself as:

$ gem install signalfx

Installing with Ruby 2.2.0 and 2.2.1

This library's protobuf dependency requires activesupport >=3.2. 5.x versions of activesupport require Ruby >=2.2.2, so users of older Ruby versions will need to install activesupport 4.2.10 before signalfx to avoid attempts of installing a more recent gem. Building and installing signalfx from source will fulfill this for you:

$ gem build signalfx.gemspec && gem install signalfx-<current_version>.gem

Usage

Configuring your endpoints

In order to send your data to the correct realm, you may need to configure your endpoints. If no endpoints are set manually, this library uses the us0 realm by default. If you are not in this realm, you will need to explicitly set the endpoint config options below. To determine if you are in a different realm and need to explicitly set the endpoints, check your profile page in the SignalFx web application.

require('signalfx')
# Create client with alternate ingest endpoint
client = SignalFx.new('ORG_TOKEN', ingest_endpoint: 'https://ingest.{REALM}.signalfx.com',
                      stream_endpoint: 'https:/stream.{REALM}.signalfx.com')

Access tokens

To use this library, you will also need to specify an access token when requesting one of those clients. For the ingest client, you need to specify your organization access token (which can be obtained from the SignalFx organization you want to report data into). For the SignalFlow client, either an organization access token or a user access token may be used. For more information on access tokens, see the API's authentication documentation.

Create client

The default constructor SignalFx uses Protobuf to send data to SignalFx. If it cannot send Protobuf, it falls back to sending JSON.

require('signalfx')

# Create client
client = SignalFx.new 'MY_SIGNALFX_TOKEN'

Optional constructor parameters:

  • api_token (string): your private SignalFx token.
  • enable_aws_unique_id (boolean): false by default. If true, the library will retrieve the Amazon instance unique identifier and set it as AWSUniqueId dimension for each datapoint and event. Use this option only if your application is deployed on Amazon AWS.
  • ingest_endpoint (string): to override the target ingest API endpoint.
  • stream_endpoint (string): to override the target stream endpoint for SignalFlow.
  • timeout (number): timeout, in seconds, for requests to SignalFx.
  • batch_size (number): size of datapoint batches to send to SignalFx.
  • user_agents (array of strings): an array of additional User-Agent strings to use when making requests to SignalFx.

Reporting data

This example shows how to report metrics to SignalFx, as gauges, counters, or cumulative counters.

require('signalfx')

client = SignalFx.new 'MY_SIGNALFX_TOKEN'

client.send(
           cumulative_counters:[
             {  :metric => 'myfunc.calls_cumulative',
                :value => 10,
                :timestamp => 1442960607000 },
             ...
           ],
           gauges:[
             {  :metric => 'myfunc.time',
                :value => 532,
                :timestamp => 1442960607000},
             ...
           ],
           counters:[
             {  :metric => 'myfunc.calls',
                :value => 42,
                :timestamp => 1442960607000},
             ...
           ])

The timestamp must be a millisecond precision timestamp; the number of milliseconds elapsed since Epoch. The timestamp field is optional, but strongly recommended. If not specified, it will be set by SignalFx's ingest servers automatically; in this situation, the timestamp of your datapoints will not accurately represent the time of their measurement (network latency, batching, etc. will all impact when those datapoints actually make it to SignalFx).

Reporting data through a HTTP proxy

To send data through a HTTP proxy, set the environment variable http_proxy with the proxy URL.

The SignalFlow client by default will use the proxy set in the http_proxy envvar by default. To send SignalFlow websocket data through a separate proxy, set the proxy_url keyword arg on the client.signalflow call.

Sending multi-dimensional data

Reporting dimensions for the data is also optional, and can be accomplished by specifying a dimensions parameter on each datapoint containing a dictionary of string to string key/value pairs representing the dimensions:

require('signalfx')

client = SignalFx.new 'MY_SIGNALFX_TOKEN'

client.send(
          cumulative_counters:[
            {   :metric => 'myfunc.calls_cumulative',
                :value => 10,
                :dimensions => [{:key => 'host', :value => 'server1'}]},
            ...
          ],
          gauges:[
            {   :metric => 'myfunc.time',
                :value=> 532,
                :dimensions=> [{:key => 'host', :value => 'server1'}]},
            ...
          ],
          counters:[
            {   :metric=> 'myfunc.calls',
                :value=> 42,
                :dimensions=> [{:key => 'host', :value => 'server1'}]},
            ...
          ])

See examples/generic_usecase.rb for a complete code example for reporting data.

Sending events

Events can be sent to SignalFx via the send_event() function. The event type must be specified, and dimensions and extra event properties can be supplied as well. Also please specify event category: for that get option from dictionary EVENT_CATEGORIES. Different categories of events are supported. Available categories of events are USER_DEFINED, ALERT, AUDIT, JOB, COLLECTD, SERVICE_DISCOVERY, EXCEPTION.

require('signalfx')

timestamp = (Time.now.to_i * 1000).to_i

client = SignalFx.new 'MY_SIGNALFX_TOKEN'

client.send_event(
    '<event_type>',
    event_category: '<event_category>',
    dimensions: { host: 'myhost',
      service: 'myservice',
      instance: 'myinstance' },
    properties: { version: 'event_version' },
    timestamp: timestamp)

See examples/generic_usecase.rb for a complete code example for sending events.

SignalFlow

You can run SignalFlow computations as well. This library supports all of the functionality described in our API docs for SignalFlow. Right now, the only supported transport mechanism is WebSockets.

Configure the SignalFlow client endpoint

By default, this library connects to the us0 stream endpoint. If you are not in this realm, you will need to explicitly set the endpoint config options below when creating the client. To determine if you are in a different realm and need to explicitly set the endpoints, check your profile page in the SignalFx web application.

client = SignalFx.new(
  'ORG_TOKEN',
  ingest_endpoint: 'https://ingest.{REALM}.signalfx.com',
  stream_endpoint: 'wss://stream.{REALM}.signalfx.com'
)

To create a new SignalFlow client instance from an existing SignalFx client:

signalflow = client.signalflow()

For the full API see the RubyDocs for the SignalFlow client (the signalflow var above).

There is also a demo script that shows basic usage.

License

Apache Software License v2. Copyright © 2015-2016 SignalFx

signalfx-ruby's People

Contributors

aeuio avatar asuresh4 avatar benkeith-splunk avatar cep21 avatar dependabot[bot] avatar harnitsignalfx avatar jamesfrost avatar jtmal-signalfx avatar keitwb avatar lestopher avatar mdubbyap avatar molner avatar mpetazzoni avatar owais avatar pas256 avatar rmfitzpatrick avatar sheremetat avatar tedoc2000 avatar theletterf avatar wjossey avatar

Stargazers

 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  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

signalfx-ruby's Issues

gem should call out `eventmachine` dependency

using this gem outside of Rails yields this message...
workaround is to include eventmachine in my own project

/Users/benmullin/.rvm/gems/ruby-2.2.2/gems/signalfx-2.0.1/lib/signalfx/signalflow/websocket.rb:6:in `require': cannot load such file -- eventmachine (LoadError)
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/gems/signalfx-2.0.1/lib/signalfx/signalflow/websocket.rb:6:in `<top (required)>'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/gems/signalfx-2.0.1/lib/signalfx/signalflow/client.rb:5:in `require_relative'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/gems/signalfx-2.0.1/lib/signalfx/signalflow/client.rb:5:in `<top (required)>'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/gems/signalfx-2.0.1/lib/signalfx/signal_fx_client.rb:5:in `require_relative'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/gems/signalfx-2.0.1/lib/signalfx/signal_fx_client.rb:5:in `<top (required)>'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/gems/signalfx-2.0.1/lib/signalfx/protobuf_signal_fx_client.rb:5:in `require_relative'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/gems/signalfx-2.0.1/lib/signalfx/protobuf_signal_fx_client.rb:5:in `<top (required)>'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/gems/signalfx-2.0.1/lib/signalfx.rb:4:in `require_relative'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/gems/signalfx-2.0.1/lib/signalfx.rb:4:in `<top (required)>'
	from /Users/benmullin/Workspace/devops_chef/.chef/plugins/knife/change_deploy_times.rb:2:in `require'
	from /Users/benmullin/Workspace/devops_chef/.chef/plugins/knife/change_deploy_times.rb:2:in `<top (required)>'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/gems/chef-12.9.38/lib/chef/knife/core/subcommand_loader.rb:100:in `load'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/gems/chef-12.9.38/lib/chef/knife/core/subcommand_loader.rb:100:in `block in load_commands'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/gems/chef-12.9.38/lib/chef/knife/core/subcommand_loader.rb:100:in `each'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/gems/chef-12.9.38/lib/chef/knife/core/subcommand_loader.rb:100:in `load_commands'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/gems/chef-12.9.38/lib/chef/knife/core/subcommand_loader.rb:110:in `load_command'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/gems/chef-12.9.38/lib/chef/knife/core/subcommand_loader.rb:124:in `command_class_from'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/gems/chef-12.9.38/lib/chef/knife.rb:153:in `subcommand_class_from'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/gems/chef-12.9.38/lib/chef/knife.rb:214:in `run'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/gems/chef-12.9.38/lib/chef/application/knife.rb:148:in `run'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/gems/chef-12.9.38/bin/knife:25:in `<top (required)>'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/bin/knife:23:in `load'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/bin/knife:23:in `<main>'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `eval'
	from /Users/benmullin/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in `<main>'

Minor syntax

I noticed the use of end of line ;s in your docs, which is not advised in the Ruby style guide and basically never done. To improve adoption of this gem among nitpicky Ruby engineers, maybe remove them?

curious - why i18n specifically 1.1.0?

In #43, the gemspec was made to require i18n gem specifically at version 1.1.0. May I ask (out of curiosity only) why that would be? Were there any problems discovered with using other versions of i18n gem?

Since this is not causing any version problems for me, this question is for curiosity only and not because something is broken. So it can be treated with accordingly low priority. You don't need to remove the requirement in order to close this issue, just an explanation suffices. Thanks.

Rename deprecated `Conf`

After installing the gem, every time I start Rails I now get the warning

...gems/signalfx-0.1.0/lib/signalfx/conf.rb:3:in `<top (required)>': Use RbConfig instead of obsolete and deprecated Config.

https://github.com/signalfx/signalfx-ruby/blob/master/lib/signalfx/conf.rb#L3

Config has been deprecated since Ruby 1.9.2 so it would be great to replace this with RbConfig.

SignalFlow computations don't automatically reconnect

If the backend service is restarted/upgraded on the SignalFx side and the connection is closed, the Ruby client library should automatically and transparently re-execute running SignalFlow computations from their last known received timestamp.

Upgrade tzinfo to 2.0.0

While trying to upgrade our fluentd to 1.7.3 I got this error.

/usr/local/lib/ruby/2.6.0/rubygems/specification.rb:2302:in `raise_if_conflicts': 
Unable to activate activesupport-6.0.0, because tzinfo-2.0.0 conflicts with 
tzinfo (~> 1.1) (Gem::ConflictError)

Basically, fluentd 1.7.3 needs tzinfo 2.0.0
https://github.com/fluent/fluentd/blob/v1.7.3/fluentd.gemspec#L27
and SignalFx requires tzinfo 1.1
https://github.com/signalfx/signalfx-ruby/blob/master/Gemfile.lock#L17

Any chance to provide some compatibility with tzinfo 2.0.0?
We would like to upgrade fluentd and keep our custom SignalFx plugin working too.

Improve Logging (Replace 'puts')

The current use of puts inside the gem is problematic.

You can't control what gets logged, or where the logs go. Whenever our application gets loaded, the gem prints something to stdout. This is filling up our logs.

A potential solution would be to allow users to pass an instance of the standard library Logger class.

Gem has permission issues

Hi!

Thanks for taking care of #20 so quickly!

I believe your permissions are borked in the gem.
Several files are set to 640 when they should be set to 644.
This is blocking the ability for multiple users to share one ruby installation on the same system.

Here's what you have:

/usr/local/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/signalfx-2.0.1

[bmullin@flybox-007 signalfx-2.0.1]# ls -al
total 60
drwxr-xr-x   5 bmullin bmullin  4096 Jan 17 19:49 .
drwxr-xr-x 189 bmullin bmullin 12288 Jan 17 21:45 ..
drwxr-xr-x   2 bmullin bmullin  4096 Jan 17 19:49 bin
drwxr-xr-x   2 bmullin bmullin  4096 Jan 17 19:49 examples
-rw-r-----   1 bmullin bmullin   177 Jan 17 19:49 Gemfile
-rw-r-----   1 bmullin bmullin  2613 Jan 17 19:49 Gemfile.lock
-rw-r-----   1 bmullin bmullin   695 Jan 17 19:49 .gitignore
drwxr-xr-x   4 bmullin bmullin  4096 Jan 17 19:49 lib
-rw-r-----   1 bmullin bmullin   117 Jan 17 19:49 Rakefile
-rw-r-----   1 bmullin bmullin  5554 Jan 17 19:49 README.md
-rw-r-----   1 bmullin bmullin  2032 Jan 17 19:49 signalfx.gemspec
-rw-r-----   1 bmullin bmullin    59 Jan 17 19:49 .travis.yml

Here's an example of what I think works better.

[bmullin@flybox-007 signalfx-2.0.1]# ls -al ../thor-0.19.1/
total 56
drwxr-xr-x   5 bmullin bmullin  4096 Oct 24 21:49 .
drwxr-xr-x 189 bmullin bmullin 12288 Jan 17 21:45 ..
drwxr-xr-x   2 bmullin bmullin  4096 Oct 24 21:49 bin
-rw-r--r--   1 bmullin bmullin  5946 Oct 24 21:49 CHANGELOG.md
-rw-r--r--   1 bmullin bmullin    49 Oct 24 21:49 .document
drwxr-xr-x   3 bmullin bmullin  4096 Oct 24 21:49 lib
-rw-r--r--   1 bmullin bmullin  1075 Oct 24 21:49 LICENSE.md
-rw-r--r--   1 bmullin bmullin  1462 Oct 24 21:49 README.md
drwxr-xr-x   9 bmullin bmullin  4096 Oct 24 21:49 spec
-rw-r--r--   1 bmullin bmullin   692 Oct 24 21:49 Thorfile
-rw-r--r--   1 bmullin bmullin   916 Oct 24 21:49 thor.gemspec

Thanks!
Ben

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.