influxdb-lineprotocol-writer 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2307f068a4620a1b356e831401a146b86181b0a
4
- data.tar.gz: 46145262953662339106ba706239c0029ee3c6e8
3
+ metadata.gz: 2a6bd82a5bc5351981041f25ce0d1a874dbe147e
4
+ data.tar.gz: f5c51246e047119578f8f8b8e09b1f903c091e4f
5
5
  SHA512:
6
- metadata.gz: 222af5f8370017815d43eb23a07fa6d13b49f5f4831e62cf9eb0ead20ed4738277ff49a044f13c9b4a49b5e31970b7e5f71b036c59055407858f487ba5914242
7
- data.tar.gz: f2a9c4063ec8ae03cc0758150c7bad1df9da637ae065111fcbd4edd3da7b4833011a3ef0aadd5a4fda3b81c3cbb82321ebe5afe4bf4653960b343df268d41932
6
+ metadata.gz: 232be04dbc631056180ad87355a779c86a5a7b78f61b443b7c73718bbb2519f0d9f473ffa56e5619f6f1d91f3932a209732dfa6b646005dcd049ad4e71c882ac
7
+ data.tar.gz: ed4907e75587a960fb6fbd9f12b5d45bbf30a315a48300892640e2caa5ee43e1232293450d3553b7b767a0b152055190137b73bae17a41e673674a1f439e24f5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- influxdb-lineprotocol-writer (0.2.0)
4
+ influxdb-lineprotocol-writer (0.2.1)
5
5
  excon (~> 0.45, >= 0.45.3)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -19,28 +19,4 @@ $ gem install influxdb-lineprotocol-writer
19
19
 
20
20
  ## Usage
21
21
 
22
- ```ruby
23
- require 'influxdb-lineprotocol-writer'
24
-
25
-
26
- client = InfluxDB::LineProtocolWriter::Core.new host: '<host/IP>',
27
- db: '<DB>',
28
- user: '<USER>',
29
- pass: '<PASS>'
30
- client.debug = true # Enable debug Excon output
31
- client.connect
32
-
33
- client.add_metric 'test', {test: 'test', test2: 'test2', a: 'val'}, {value: 1.0}
34
- sleep 0.1
35
- client.add_metric 'test', {z: 'val2', test: 'test', test2: 'test2'}, {value: 2.0}
36
- sleep 0.1
37
- client.add_metric 'test', {z: 'val2', test: 'test', test2: 'test2'}, {value: 2.0}
38
- client.add_metric 'test', {test: 'test', test2: 'test2'}, {value: 3.0}
39
- sleep 0.1
40
- client.add_metric 'test', nil, {value: 3.0}
41
- client.add_metric 'test3', nil, {value: 3.0, test: 'string', deploy: 'v2.0'}
42
- sleep 0.1
43
- client.add_metric 'test3', nil, {value: 3.0, test: 'string', deploy: 'v2.1'}, 1434077536000
44
-
45
- client.write
46
- ```
22
+ Files in the `examples` demonstrate usage both as a regular library and as a [Sensu](http://sensuapp.org) Check and Handler.
@@ -1,14 +1,40 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  require 'influxdb-lineprotocol-writer/sensu-metric-handler'
4
3
 
5
4
  class InfluxDBHandler < ::InfluxDB::LineProtocolWriter::Metric::Handler
6
5
 
6
+ # for this example, which doesn't actually use Sensu, I disabled the filter method below
7
+ # because this example doesn't have access to the settings hash.
7
8
  def filter; end
8
9
 
9
10
  def handle
11
+
12
+ # the sensu metric check helper class (lib/influxdb-lineprotocol-write/sensu-metric-check)
13
+ # writes metrics as a JSON Hash, one per line. If, for whatever reason, a metric does not
14
+ # parse correctly from the json gem, it can be caught in the output variable below and
15
+ # handled as appropriate. This should perhaps be handled better by a mutator.
16
+ #
17
+ # Example Output as originally printed by the check:
18
+ # {"measurement": "ping", "tags": {"host": "google.com"}, "fields": {"value": 0.1}}
19
+ # Ping Metric Check Successful
10
20
  metrics, output = split_metrics_from_output
11
21
 
22
+ # This is a hack which would not be used in a production handler
23
+ #
24
+ # For a real handler, settings for a specific cluster can
25
+ # be added to the handler settings as such:
26
+ # {
27
+ # { "influxdb":
28
+ # "host": "hostname",
29
+ # "user": "username",
30
+ # "pass": "password",
31
+ # "ssl": boolean,
32
+ # "db": "database",
33
+ # "consistency": "one",
34
+ # "retentionPolicy": "default"
35
+ # },
36
+ # { handler_specific_settings.. }
37
+ # }
12
38
  begin
13
39
  settings = settings['influxdb']
14
40
  rescue
@@ -19,12 +45,18 @@ class InfluxDBHandler < ::InfluxDB::LineProtocolWriter::Metric::Handler
19
45
  settings['pass'] ||= 'admin'
20
46
  settings['db'] ||= 'graphite'
21
47
 
48
+ # We tack the AWS Instance on the end of a Sensu Client Name for tracking
22
49
  hostname, instance_id = @event['client']['name'].split('--')
50
+
51
+ # The write_metrics method in the gem can do all the heavy lifting, not
52
+ # to mention add tags at the handler level based on data added by Sensu
53
+ # to the @event hash which could prove useful
23
54
  write_metrics metrics, settings do |metric|
24
55
  metric['tags']['source'] = hostname
25
56
  metric['tags']['instance_id'] = instance_id unless instance_id.nil?
26
57
  end
27
58
 
59
+ # This'll end up in the Uchiwa Logs
28
60
  puts output
29
61
 
30
62
  end
@@ -3,9 +3,10 @@
3
3
  require 'influxdb-lineprotocol-writer/sensu-metric-check'
4
4
  require 'net/ping'
5
5
 
6
- class PingMetric < InfluxDB::LineProtocolWriter::Metric::CLI
6
+ class PingMetric < ::InfluxDB::LineProtocolWriter::Metric::CLI
7
7
  option :host,
8
8
  short: '-h host',
9
+ proc: proc(&:to_s),
9
10
  default: 'localhost'
10
11
 
11
12
  option :timeout,
@@ -11,7 +11,7 @@ module InfluxDB
11
11
  def split_metrics_from_output
12
12
  metrics = []
13
13
  output = ''
14
- @event['output'].each_line do |line|
14
+ @event['check']['output'].each_line do |line|
15
15
  begin
16
16
  metrics << JSON.parse(line.chomp).to_h
17
17
  rescue
@@ -1,5 +1,5 @@
1
1
  module InfluxDB
2
2
  module LineProtocolWriter
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxdb-lineprotocol-writer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Randy D. Wallace Jr.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-15 00:00:00.000000000 Z
11
+ date: 2015-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon