Class: Fluent::ApacheModStatus

Inherits:
Input
  • Object
show all
Defined in:
lib/fluent/plugin/in_apache_modstatus.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



13
14
15
16
17
# File 'lib/fluent/plugin/in_apache_modstatus.rb', line 13

def configure(conf)
  super
  require 'net/http'
  require 'uri'
end

#outputObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/fluent/plugin/in_apache_modstatus.rb', line 35

def output

  record = {}

  page_content = Net::HTTP.get(URI.parse(@url))
  status_values = page_content.lines.map(&:chomp)
  status_values.each do |item|
    if item.include? "Scoreboard: "
#       Scoreboard Key:
#       "_" Waiting for Connection, "S" Starting up, "R" Reading Request,
#       "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
#       "C" Closing connection, "L" Logging, "G" Gracefully finishing,
#       "I" Idle cleanup of worker, "." Open slot with no current process        
      values = item.split(": ")
      scores = values[1].split(//)
      
      scoreboard = {
        "wait" => 0,
        "start" => 0,
        "read" => 0,
        "reply" => 0,
        "keepalive" => 0,
        "dns" => 0,
        "closing" => 0,
        "log" => 0,
        "graceful" => 0,
        "cleanup" => 0,
        "openslot" => 0
        }
      
      scores.each do |score|
        if score == "_"
          scoreboard["wait"] = scoreboard["wait"] + 1
        elsif score == "S"
          scoreboard["start"] = scoreboard["start"] + 1
        elsif score == "R"
          scoreboard["read"] = scoreboard["read"] + 1
        elsif score == "W"
          scoreboard["reply"] = scoreboard["reply"] + 1
        elsif score == "K"
          scoreboard["keepalive"] = scoreboard["keepalive"] + 1
        elsif score == "D"
          scoreboard["dns"] = scoreboard["dns"] + 1
        elsif score == "C"
          scoreboard["closing"] = scoreboard["closing"] + 1
        elsif score == "L"
          scoreboard["log"] = scoreboard["log"] + 1
        elsif score == "G"
          scoreboard["graceful"] = scoreboard["graceful"] + 1
        elsif score == "I"
          scoreboard["cleanup"] = scoreboard["cleanup"] + 1
        elsif score == "."
          scoreboard["openslot"] = scoreboard["openslot"] + 1
        end
      end
      
      scoreboard.each do |key,score|
        record["scoreboard_count_#{key}"] = score
      end
      
    elsif item.include? ": "
      values = item.split(": ")
      values[0].downcase!
      values[0].gsub!(/ /,"_")
      if valid_float(values[1])
        record[values[0]] = values[1].to_f
      else
        record[values[0]] = values[1]
      end
    end
  end
  

  time = Fluent::Engine.now
  router.emit(tag,time,record)
end

#runObject



28
29
30
31
32
33
# File 'lib/fluent/plugin/in_apache_modstatus.rb', line 28

def run
  while true
    output
    sleep @refresh_interval
  end
end

#shutdownObject



112
113
114
115
116
# File 'lib/fluent/plugin/in_apache_modstatus.rb', line 112

def shutdown
  @watcher.terminate
  @watcher.join

end

#startObject



23
24
25
26
# File 'lib/fluent/plugin/in_apache_modstatus.rb', line 23

def start
  super
  @watcher = Thread.new(&method(:run))
end

#valid_float(value) ⇒ Object



19
20
21
# File 'lib/fluent/plugin/in_apache_modstatus.rb', line 19

def valid_float(value)
  !!Float(value) rescue false
end