fluent-plugin-cadvisor 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/fluent-plugin-cadvisor.gemspec +1 -1
- data/lib/fluent/plugin/in_cadvisor.rb +32 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8c52e996ec86213f0cd62cf672df4b4cc869c11
|
4
|
+
data.tar.gz: ec72b06ecd2dd458451d96980876808607f05367
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0191fdb4d03c98ee25b4eabe55c2229ee8a139a63a9daa13058847e74a859be5672ec7680d19ed2aa5b5bc24160c35e1964ae6511482f0e997d1cc8651eb7ccc
|
7
|
+
data.tar.gz: 90f6369b7c024434c20013018dbc54f08a64b35424d0db73a6036c3b9b44fd5add78607061308f38ef9568a942ee058d0df677c37a65cf4e533c7456f8053300
|
@@ -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-cadvisor"
|
7
|
-
spec.version = "0.
|
7
|
+
spec.version = "0.2.0"
|
8
8
|
spec.authors = ["Woorank"]
|
9
9
|
spec.email = ["dev@woorank.com"]
|
10
10
|
spec.summary = "cadvisor input plugin for Fluent event collector"
|
@@ -22,7 +22,7 @@ class CadvisorInput < Fluent::Input
|
|
22
22
|
config_param :host, :string, :default => 'localhost'
|
23
23
|
config_param :port, :string, :default => 8080
|
24
24
|
config_param :api_version, :string, :default => '1.1'
|
25
|
-
config_param :stats_interval, :time, :default =>
|
25
|
+
config_param :stats_interval, :time, :default => 60 # every minute
|
26
26
|
config_param :tag_prefix, :string, :default => "metric"
|
27
27
|
|
28
28
|
def initialize
|
@@ -53,6 +53,14 @@ class CadvisorInput < Fluent::Input
|
|
53
53
|
log.error_backtrace
|
54
54
|
end
|
55
55
|
|
56
|
+
def get_interval (current, previous)
|
57
|
+
cur = Time.parse(current).to_f
|
58
|
+
prev = Time.parse(previous).to_f
|
59
|
+
|
60
|
+
# to nano seconds
|
61
|
+
(cur - prev) * 1000000000
|
62
|
+
end
|
63
|
+
|
56
64
|
def get_spec
|
57
65
|
response = RestClient.get(@cadvisorEP + "/machine")
|
58
66
|
JSON.parse(response.body)
|
@@ -90,20 +98,38 @@ class CadvisorInput < Fluent::Input
|
|
90
98
|
# Set max memory
|
91
99
|
memory_limit = @machine['memory_capacity'] < res['spec']['memory']['limit'] ? @machine['memory_capacity'] : res['spec']['memory']['limit']
|
92
100
|
|
93
|
-
|
94
|
-
|
101
|
+
latest_timestamp = @dict[id] ||= 0
|
102
|
+
|
103
|
+
# Order from
|
104
|
+
rev_stats = res['stats'].reverse
|
105
|
+
|
106
|
+
rev_stats.each_with_index do | stats, index |
|
107
|
+
# Break if it's the last item
|
108
|
+
# We need 2 items to create the percentage, in this case the prev will be
|
109
|
+
# out of the array
|
110
|
+
break if index == (rev_stats.count - 1)
|
111
|
+
|
95
112
|
timestamp = Time.parse(stats['timestamp']).to_i
|
96
|
-
|
113
|
+
# We already have stored these items
|
114
|
+
break if timestamp < latest_timestamp
|
97
115
|
|
98
116
|
@dict[id] = timestamp
|
99
117
|
|
118
|
+
num_cores = stats['cpu']['usage']['per_cpu_usage'].count
|
119
|
+
|
120
|
+
# CPU percentage variables
|
121
|
+
prev = rev_stats[index + 1];
|
122
|
+
raw_usage = stats['cpu']['usage']['total'] - prev['cpu']['usage']['total']
|
123
|
+
interval_in_ns = get_interval(stats['timestamp'], prev['timestamp'])
|
124
|
+
|
100
125
|
record = {
|
101
126
|
'container_id' => id,
|
102
127
|
'image' => obj[:name],
|
103
128
|
'memory_current' => stats['memory']['usage'],
|
104
129
|
'memory_limit' => memory_limit,
|
105
|
-
'cpu_usage' =>
|
106
|
-
'
|
130
|
+
'cpu_usage' => raw_usage,
|
131
|
+
'cpu_usage_pct' => (((raw_usage / interval_in_ns ) / num_cores ) * 100).round(2),
|
132
|
+
'cpu_num_cores' => num_cores,
|
107
133
|
'network_rx_bytes' => stats['network']['rx_bytes'],
|
108
134
|
'network_rx_packets' => stats['network']['rx_packets'],
|
109
135
|
'network_rx_errors' => stats['network']['rx_errors'],
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-cadvisor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Woorank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest_client
|