fluent-plugin-mackerel 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTY0NzJkZjgzMDMwNzNkNGY1MjdkYmQ5ZTNlNzA2ZTAwZjg2N2I3Nw==
4
+ ZmY3Njg2MTIyNGI1Mzc5ODViZmNhMGQ4ZGYzNWE0ZWViMzM1ZTJhOA==
5
5
  data.tar.gz: !binary |-
6
- MzAyNDI3MTdlODNlMzhhNGMwMzEyNmJhOTdkODdlYzY0ZDNiOTc0MQ==
6
+ NjM0ZDA1YjNlMjU2OWUyOGRkZjk3YTI1NjVkMjA0ZmE3ZDg2ZDRjZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OWU4YzZlM2Q1Zjk5MzY5OGI2ZWVjODUzYWU0YjY3ZmU0M2Y4YjAzMDVkMjRk
10
- Yjk5N2U1NzNlNzQwYWI1YjQyNmVmMGM3NzFkM2Q3NDQ3OTg1Y2E3ODYzZDdh
11
- MjljZDg0MmU1YWUyNzhkNDJjMDQ2YTkxYmRjNmI0ZTI0YjM1YmY=
9
+ ZGYzY2ExMjJhZWY4MGM2Y2QwMjE1ZGRlMGIxOTFhMzdkYWM4ZTQ3ZTIwZDM5
10
+ MWUxNTQ4MzJhZTAxMmNiOTUxOTQ3YmJiMGY5YWNmMzViYjY1NDdkMzgxZTQw
11
+ MWMwNDE1MTZlNmIzNTFjNjUwMzFmYTExNTYwOTE0ZTZiNjgyYTk=
12
12
  data.tar.gz: !binary |-
13
- OTYwYjM0ZGUwMmRjMzRlMjNjYjg2ODIyMWIwMjc5ZWI0OGNlZTkwZmFjNWEx
14
- MjYwZWZjZWRiNjE4Yzc0NTkyZmY0NjhjZjc3YTkyZjU5ODA3NTU1MTI5MmMz
15
- YmM1NjFmODBkOGYwMzcwOTY1MWRhZTU5ZTdiNWQ3MTlkNzhiNGI=
13
+ YTFlYjgwOTIyY2M1MGNkN2Q1NjBmZmE5ZDIwODFjMzk2N2ZlMGJiNDk2MWEy
14
+ OThiYmRkMWViZTVmNTNmZjQ0ZGJkMjBmY2I2YmFkZTdkOGIwOTY1MzI1Y2E3
15
+ YzI3OWU3Y2MxN2JiZDYyOTljNDEwMDA3YmMwMjRjMzdhMmRkZWM=
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # fluent-plugin-mackerel
1
+ # fluent-plugin-mackerel [![Build Status](https://travis-ci.org/tksmd/fluent-plugin-mackerel.png?branch=master)](https://travis-ci.org/tksmd/fluent-plugin-mackerel)
2
2
 
3
3
  ## Overview
4
4
 
@@ -10,10 +10,10 @@ Install with gem or fluent-gem command as:
10
10
 
11
11
  ```
12
12
  # for fluentd
13
- $ gem install fluent-plugin-typetalk
13
+ $ gem install fluent-plugin-mackerel
14
14
 
15
15
  # for td-agent
16
- $ sudo /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-typetalk
16
+ $ sudo /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-mackerel
17
17
  ```
18
18
 
19
19
  ## Configuration
@@ -26,16 +26,17 @@ This plugin uses [APIv0](http://help-ja.mackerel.io/entry/spec/api/v0) of macker
26
26
  type mackerel
27
27
  api_key 123456
28
28
  hostid xyz
29
- metrics_prefix http_status
29
+ metrics_prefix custom.http_status
30
30
  out_keys 2xx_count,3xx_count,4xx_count,5xx_count
31
31
  </match>
32
32
  ```
33
+ When metrics_prefix doesn't start with "custom.", "custom." is automatically appended at its beginning.
33
34
 
34
35
  Then the sent metric data will look like this:
35
36
  ```
36
37
  {
37
38
  "hostId": "xyz",
38
- "name": "http_status.2xx_count",
39
+ "name": "custom.http_status.2xx_count",
39
40
  "time": 1399997498,
40
41
  "value": 100.0
41
42
  }
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-mackerel"
7
- spec.version = "0.0.2"
7
+ spec.version = "0.0.3"
8
8
  spec.authors = ["tksmd"]
9
9
  spec.email = ["someda@isenshi.com"]
10
10
  spec.description = %q{fluent plugin to send metrics to mackerel.io}
@@ -5,9 +5,14 @@ module Fluent
5
5
  config_param :api_key, :string
6
6
  config_param :hostid, :string, :default => nil
7
7
  config_param :hostid_path, :string, :default => nil
8
- config_param :metrics_prefix, :string
9
8
  config_param :out_keys, :string
10
9
 
10
+ config_param :metrics_prefix do |val|
11
+ val.chomp!(".")
12
+ raise Fluent::ConfigError, "metrics_prefix is not allowed to be blank" if val.empty?
13
+ val.start_with?("custom.") ? val : "custom." << val
14
+ end
15
+
11
16
  attr_reader :mackerel
12
17
 
13
18
  # Define `log` method for v0.10.42 or earlier
@@ -38,6 +43,7 @@ module Fluent
38
43
  @hostid = File.open(@hostid_path).read
39
44
  end
40
45
 
46
+ log.info("metrics_prefix is configured to #{@metrics_prefix}")
41
47
  end
42
48
 
43
49
  def start
@@ -110,9 +116,9 @@ module Fluent
110
116
 
111
117
  def wait_for_minute
112
118
  # limit request once per minute
113
- wait_secs = @last_posted ? @last_posted + 60 - Time.now.to_i : 0
119
+ wait_secs = @last_posted ? @last_posted + 60 - Fluent::Engine.now : 0
114
120
  sleep wait_secs if wait_secs > 0
115
- @last_posted = Time.now.to_i
121
+ @last_posted = Fluent::Engine.now
116
122
  wait_secs > 0
117
123
  end
118
124
 
@@ -10,7 +10,7 @@ class MackerelOutputTest < Test::Unit::TestCase
10
10
  type mackerel
11
11
  api_key 123456
12
12
  hostid xyz
13
- metrics_prefix service
13
+ metrics_prefix custom.service
14
14
  out_keys val1,val2,val3
15
15
  ]
16
16
 
@@ -21,7 +21,23 @@ class MackerelOutputTest < Test::Unit::TestCase
21
21
  out_keys val1,val2,val3
22
22
  ]
23
23
 
24
+ CONFIG_BLANK_METRICS = %[
25
+ type mackerel
26
+ api_key 123456
27
+ metrics_prefix
28
+ out_keys val1,val2,val3
29
+ ]
30
+
24
31
  CONFIG_SMALL_FLUSH_INTERVAL = %[
32
+ type mackerel
33
+ api_key 123456
34
+ hostid xyz
35
+ metrics_prefix custom.service
36
+ out_keys val1,val2,val3
37
+ flush_interval 1s
38
+ ]
39
+
40
+ CONFIG_NOT_INSUFFICIENT_PREFIX = %[
25
41
  type mackerel
26
42
  api_key 123456
27
43
  hostid xyz
@@ -44,13 +60,20 @@ class MackerelOutputTest < Test::Unit::TestCase
44
60
  d = create_driver(CONFIG_NOHOST)
45
61
  }
46
62
 
63
+ assert_raise(Fluent::ConfigError) {
64
+ d = create_driver(CONFIG_BLANK_METRICS)
65
+ }
66
+
47
67
  d = create_driver(CONFIG_SMALL_FLUSH_INTERVAL)
48
68
  assert_equal d.instance.instance_variable_get(:@flush_interval), 60
49
69
 
70
+ d = create_driver(CONFIG_NOT_INSUFFICIENT_PREFIX)
71
+ assert_equal d.instance.instance_variable_get(:@metrics_prefix), "custom.service"
72
+
50
73
  d = create_driver()
51
74
  assert_equal d.instance.instance_variable_get(:@api_key), '123456'
52
75
  assert_equal d.instance.instance_variable_get(:@hostid), 'xyz'
53
- assert_equal d.instance.instance_variable_get(:@metrics_prefix), 'service'
76
+ assert_equal d.instance.instance_variable_get(:@metrics_prefix), 'custom.service'
54
77
  assert_equal d.instance.instance_variable_get(:@out_keys), ['val1','val2','val3']
55
78
  assert_equal d.instance.instance_variable_get(:@flush_interval), 60
56
79
  end
@@ -58,12 +81,12 @@ class MackerelOutputTest < Test::Unit::TestCase
58
81
  def test_write
59
82
  d = create_driver()
60
83
  stub(d.instance.mackerel).post_metrics([
61
- {"hostId"=>"xyz", "value"=>1.0, "time"=>1399997498, "name"=>"service.val1"},
62
- {"hostId"=>"xyz", "value"=>2.0, "time"=>1399997498, "name"=>"service.val2"},
63
- {"hostId"=>"xyz", "value"=>3.0, "time"=>1399997498, "name"=>"service.val3"},
64
- {"hostId"=>"xyz", "value"=>5.0, "time"=>1399997498, "name"=>"service.val1"},
65
- {"hostId"=>"xyz", "value"=>6.0, "time"=>1399997498, "name"=>"service.val2"},
66
- {"hostId"=>"xyz", "value"=>7.0, "time"=>1399997498, "name"=>"service.val3"},
84
+ {"hostId"=>"xyz", "value"=>1.0, "time"=>1399997498, "name"=>"custom.service.val1"},
85
+ {"hostId"=>"xyz", "value"=>2.0, "time"=>1399997498, "name"=>"custom.service.val2"},
86
+ {"hostId"=>"xyz", "value"=>3.0, "time"=>1399997498, "name"=>"custom.service.val3"},
87
+ {"hostId"=>"xyz", "value"=>5.0, "time"=>1399997498, "name"=>"custom.service.val1"},
88
+ {"hostId"=>"xyz", "value"=>6.0, "time"=>1399997498, "name"=>"custom.service.val2"},
89
+ {"hostId"=>"xyz", "value"=>7.0, "time"=>1399997498, "name"=>"custom.service.val3"},
67
90
  ])
68
91
 
69
92
  ENV["TZ"]="Asia/Tokyo"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-mackerel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - tksmd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-15 00:00:00.000000000 Z
11
+ date: 2014-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler