Module: Fluent::Mixin::Deis
- Included in:
- Plugin::DeisOutput
- Defined in:
- lib/fluent/mixin/deis.rb
Instance Method Summary collapse
- #build_series(message) ⇒ Object
- #from_container?(message, regex) ⇒ Boolean
- #from_router?(message) ⇒ Boolean
- #kubernetes?(message) ⇒ Boolean
-
#parse_router_log(message, host) ⇒ Object
href="2016-05-31T16:56:12+00:00">log”=>“ - foo - 10.164.1.1 - - - 200 - "GET / HTTP/1.0" - 211 - "-" - "ApacheBench/2.3" - "~^foo\x5C.(?<domain>.+)$" - 10.167.243.4:80 - foo.devart.io - 0.002 - 0.046n” request_time - request processing time in seconds with a milliseconds resolution; time elapsed between the first bytes were read from the client and the log write after the last bytes were sent to the client response_time - keeps time spent on receiving the response from the upstream server; the time is kept in seconds with millisecond resolution.
Instance Method Details
#build_series(message) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fluent/mixin/deis.rb', line 21 def build_series() metric = parse_router_log(['log'], ['kubernetes']['host']) if metric = ( metric['timestamp'].to_f * 1_000_000_000 + Time.now.nsec ).to_i # Using current nanosecond resolution to avoid replacing points = { app: metric['app'], status_code: metric['status_code'], host: metric['host'] } data = [ { series: 'deis_router_request_time_ms', values: { value: metric['request_time'] }, tags: , timestamp: }, { series: 'deis_router_response_time_ms', values: { value: metric['response_time'] }, tags: , timestamp: }, { series: 'deis_router_bytes_sent', values: { value: metric['bytes_sent'] }, tags: , timestamp: } ] return data end nil end |
#from_container?(message, regex) ⇒ Boolean
14 15 16 17 18 19 |
# File 'lib/fluent/mixin/deis.rb', line 14 def from_container?(, regex) if kubernetes? return true unless Regexp.new(regex).match(['kubernetes']['container_name']).nil? end false end |
#from_router?(message) ⇒ Boolean
10 11 12 |
# File 'lib/fluent/mixin/deis.rb', line 10 def from_router?() from_container?(, 'deis-router') end |
#kubernetes?(message) ⇒ Boolean
6 7 8 |
# File 'lib/fluent/mixin/deis.rb', line 6 def kubernetes?() !['kubernetes'].nil? end |
#parse_router_log(message, host) ⇒ Object
href="2016-05-31T16:56:12+00:00">log”=>“ - foo - 10.164.1.1 - - - 200 - "GET / HTTP/1.0" - 211 - "-" - "ApacheBench/2.3" - "~^foo\x5C.(?<domain>.+)$" - 10.167.243.4:80 - foo.devart.io - 0.002 - 0.046n” request_time - request processing time in seconds with a milliseconds resolution; time elapsed between the first bytes were read from the client and the log write after the last bytes were sent to the client response_time - keeps time spent on receiving the response from the upstream server; the time is kept in seconds with millisecond resolution.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/fluent/mixin/deis.rb', line 57 def parse_router_log(, host) = .split(' - ') return nil if .length < 14 metric = {} metric['timestamp'] = Time.parse([0]) metric['app'] = [1].strip metric['status_code'] = [4].strip metric['bytes_sent'] = [6].strip.to_f metric['response_time'] = [12].strip.to_f metric['request_time'] = [13].strip.to_f metric['host'] = host return metric rescue Exception => e # rubocop:disable RescueException puts "Error:#{e.}" return nil end |