check_passenger 1.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ac4b91af6cd0dfb61d99dccd54d6b0929bf314d1
4
+ data.tar.gz: fae7ccced65cb78805f5829ed260ab75798b2c5c
5
+ SHA512:
6
+ metadata.gz: 7f567d1df12c061229ad83fc44b234416af3289ac128f94967f20fc9a984cd153d9346e16168a65510d3d24aa1b7473e6e30f4d5f36915c5b23babff7a6fbd89
7
+ data.tar.gz: 9eb4de4362e5bb4721453bb1baa751d2234047e0a99786cb71aded782f7ae60035cf05e22e72ec1acb04745df005fdad7695ffbe265818c0458e13959e394372
@@ -0,0 +1,8 @@
1
+ # Save as .codeclimate.yml (note leading .) in project root directory
2
+ languages:
3
+ Ruby: true
4
+ JavaScript: false
5
+ PHP: false
6
+ Python: false
7
+ # exclude_paths:
8
+ # - "foo/bar.rb"
@@ -0,0 +1,32 @@
1
+ Documentation:
2
+ Enabled: false
3
+ Metrics/AbcSize:
4
+ Enabled: false
5
+ Metrics/ClassLength:
6
+ Enabled: false
7
+ Metrics/MethodLength:
8
+ Enabled: false
9
+ Metrics/ModuleLength:
10
+ Enabled: false
11
+ Style/AndOr:
12
+ Enabled: false
13
+ Style/ClassAndModuleChildren:
14
+ Enabled: false
15
+ Style/PerlBackrefs:
16
+ Enabled: false
17
+
18
+ Style/CollectionMethods:
19
+ Enabled: yes
20
+ Lint/LiteralInInterpolation:
21
+ Enabled: yes
22
+
23
+ Metrics/LineLength:
24
+ Max: 120
25
+ Metrics/ParameterLists:
26
+ CountKeywordArgs: false
27
+ Style/DotPosition:
28
+ EnforcedStyle: trailing
29
+ Style/EmptyElse:
30
+ EnforcedStyle: empty
31
+ Style/SpaceInsideHashLiteralBraces:
32
+ EnforcedStyle: no_space
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.1.6
5
+ - 2.2.2
6
+ script: bundle exec rake test
7
+ addons:
8
+ code_climate:
9
+ repo_token: 6214a7723a1d2d9de5f408fc150f9ddc857fdb3c641eab55b3c2a5d231aef571
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+
3
+ ## 1.1.0
4
+
5
+ - Add checks for application queues and top-level queue sizes
6
+ - Improve documentation
7
+
8
+
9
+ ## 1.0
10
+
11
+ - Improve command help
12
+ - Raise CRIT alert a sought application is not found running
13
+ - Bug fixes
14
+
15
+
16
+ ## 0.2
17
+
18
+ - Bug fixes
19
+
20
+
21
+ ## 0.1
22
+
23
+ Initial release
@@ -0,0 +1,12 @@
1
+ # Contribution Guidelines
2
+
3
+ 1. Fork this repository (https://github.com/aredondo/check_passenger/fork). The repository follows the [Git Flow branching model](http://nvie.com/posts/a-successful-git-branching-model/) so when forking, please do so from the `develop` branch, as there may be commits that have still not made it to `master`.
4
+ 2. Create your feature branch: `git checkout -b feature/my-new-feature`
5
+ 3. Commit your changes
6
+ 4. Make sure that all the tests pass: `rake test`
7
+ 5. Run Rubocop to confirm that it does not raise any warnings
8
+ 6. Make sure to update [CHANGELOG.md](CHANGELOG.md) to list your changes. Also, update [README.md](README.md) if necessary. Please, do not update the gem version.
9
+ 7. Push to the branch: `git push origin feature/my-new-feature`
10
+ 8. Create a new Pull Request
11
+
12
+ Thanks!
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in check_passenger.gemspec
4
4
  gemspec
5
+
6
+ gem 'codeclimate-test-reporter', group: :test, require: nil
data/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # check_passenger
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/check_passenger.svg)](http://badge.fury.io/rb/check_passenger)
4
+ [![Build Status](https://travis-ci.org/aredondo/check_passenger.svg?branch=master)](https://travis-ci.org/aredondo/check_passenger)
5
+ [![Code Climate](https://codeclimate.com/github/aredondo/check_passenger/badges/gpa.svg)](https://codeclimate.com/github/aredondo/check_passenger)
6
+ [![License](http://img.shields.io/:license-mit-blue.svg)](LICENSE.txt)
7
+
3
8
  This gem provides a Nagios check command to monitor running Passenger processes and the memory that they use.
4
9
 
5
10
  It can report data on a global or per-application basis, and raise warnings and alerts when consumption exceeds given thresholds.
@@ -15,30 +20,39 @@ Alternatively, the gem can be built from the source code with `gem build`, and m
15
20
 
16
21
  Either way, the `check_passenger` command should become available in the path—although it may be necessary to perform an additional action, such as running `rbenv rehash` or similar.
17
22
 
23
+ This gem requires Ruby 1.9+.
24
+
18
25
 
19
26
  ## Usage
20
27
 
21
28
  **check\_passenger** is intended to be executed in the same machine or machines where Passenger is running. It will call `passenger-status` and gather all data from its output.
22
29
 
23
- Typically, the Nagios service will be running in a separate machine from those being monitored. Remote execution of `check_passenger` is then usually achieved with Nagios Remote Plugin Executor (NRPE), or MK's Remote Plugin Executor (MRPE).
30
+ Typically, the Nagios service will be running in a separate machine from those being monitored. Remote execution of **check\_passenger** is then usually achieved with Nagios Remote Plugin Executor (NRPE), or MK's Remote Plugin Executor (MRPE).
24
31
 
25
- `check_passenger` reads all necessary settings from the command-line when it's run, and does not take configuration from a file. It supports three working modes depending on the aspect being monitored, which are called with an argument as:
32
+ **check\_passenger** reads all necessary settings from the command-line when it's run, and does not take configuration from a file. It supports several working modes, one for each aspect that can be monitored, which are called with an argument as:
26
33
 
27
34
  # check_passenger <mode>
28
35
 
29
- Where the `<mode>` argument can be on of the following:
36
+ Where the `<mode>` argument can be one of the following:
30
37
 
31
38
  * `processes`: These are the Passenger processes that are currently running, associated to applications.
32
39
  * `live_processes`: Of all the running processes, how many are actually being used. See the section [Passenger Live Processes](#passenger-live-processes) below.
33
40
  * `memory`: Memory occupied by the Passenger processes that are running.
41
+ * `requests`: Number of requests that are waiting in application queues. See the section [Passenger Request Queues](#passenger-request-queues) below.
42
+ * `top_level_requests`: Number of requests waiting in the top-level queue. See the section [Passenger Request Queues](#passenger-request-queues) below.
34
43
 
35
- In addition, **check\_passenger** can be called with the following options:
44
+ When checking for `processes`, `live_processes`, `memory`, or `requests`—that is, any check type except for `top_level_requests`—, the following options can be provided to filter data by application, or to get separate counters for each running application:
36
45
 
37
46
  * `-n, --app-name`: Limit check to application with *APP_NAME*—see the section [Global or Per-Application Reporting](#global-or-per-application-reporting) below.
47
+ * `-a, --include-all`: Apart from reporting on a global counter, add data for the same counter for each running Passenger application—see the section [Global or Per-Application Reporting](#global-or-per-application-reporting) below.
48
+
49
+ These two options are mutually exclusive.
50
+
51
+ In addition, **check\_passenger** can be called with the following options for any check type:
52
+
38
53
  * `-C, --cache`: Cache parsed output of `passenger-status`—see the section [Data Caching](#data-caching) below.
39
54
  * `-D, --debug`: Let exception raise to the command-line, and keep the output of `passenger-status` in a file for debugging purposes.
40
55
  * `-d, --dump`: Keep the output of `passenger-status` in a file for debugging purposes.
41
- * `-a, --include-all`: Apart from reporting on a global counter, add data for the same counter for each running Passenger application—see the section [Global or Per-Application Reporting](#global-or-per-application-reporting) below.
42
56
  * `-p, --passenger-status-path`: Full path to the `passenger-status` command—most of the time not needed.
43
57
 
44
58
  To raise warnings and alerts, use the `-w, --warn`, and `-c, --crit` options. Ranges can be provided as described in the [Nagios Plugin Development Guidelines](https://nagios-plugins.org/doc/guidelines.html#THRESHOLDFORMAT). Note that memory is measured in megabytes.
@@ -48,7 +62,7 @@ Finally, run `check_passenger help [mode]` to get usage information on the comma
48
62
 
49
63
  ## Global or Per-Application Reporting
50
64
 
51
- For each of the aspects that **check\_passenger** can monitor (processes, live processes, and memory), it can focus on all the applications running with Passenger, or on a specific application. This is controlled with the `-n` (`--app-name`), and `-a` (`--include-all`) options, as seen in the following examples.
65
+ For most of the aspects that **check\_passenger** can monitor (processes, live processes, application request queue size, and memory), it can focus on all the applications running with Passenger, or on a specific application. This is controlled with the `-n` (`--app-name`), and `-a` (`--include-all`) options, as seen in the following examples.
52
66
 
53
67
  The following command returns a counter for all the running Passenger processes in the machine:
54
68
 
@@ -75,7 +89,7 @@ Finally, it's possible to obtain a global counter, together with additional coun
75
89
 
76
90
  This allows to monitor a resource, together with how much of it is being used by each application. Note though, that when monitoring a particular counter for all the applications in this way, it won't be possible to set alerts—just add an additional check for the alert you want to set for an application or globally.
77
91
 
78
- All these examples work the same with processes, live processes, and memory.
92
+ All these examples work the same with processes, live processes, request queue size, and memory. The exception is the check for requests waiting in the top-level queue, which is just a global counter.
79
93
 
80
94
 
81
95
  ## Passenger Live Processes
@@ -85,6 +99,23 @@ Passenger reuses running processes in a sort of LIFO manner. This means that whe
85
99
  In order to estimate the live process count, **check\_passenger** takes a look at those that have been run in the last 300 seconds (or 5 minutes). This works well as long as **check\_passenger** is executed with a periodicity of 5 minutes or less.
86
100
 
87
101
 
102
+ ## Passenger Request Queues
103
+
104
+ > Phusion Passenger's internal state consists of a list of Groups (representing applications), each which consist of a list of Processes (representing application processes). When spawning the first process for an application, Phusion Passenger has to create and initialize a Group data structure, run hooks, etc. Since this involves reading from disk and running processes, it can potentially take an arbitrary amount of time. During that time, said request, and any new requests targeted at that application, are put in the top-level queue until the Group is done initializing.
105
+
106
+ > Each Group has its own queue. As soon as the Group is initialized, relevant requests from the top-level queue are moved to the Group-local queue. This is the reason why the top-level queue is usually empty. The sum of the values of all Group-local queues, plus the value of the top-level queue, is the total number of requests that are queued. In general, if they are non-zero and increasing, the number of workers needs to be increased.
107
+
108
+ Hongli. (2014, April 12). Re: Difference between "requests in top-level queue" and "requests in queue" in Phusion Passenger [Online forum comment]. Retrieved from http://stackoverflow.com/questions/23025028/difference-between-requests-in-top-level-queue-and-requests-in-queue-in-phus
109
+
110
+ Three different queued requests counters can be monitored:
111
+
112
+ * The total number of queued requests: `check_passenger requests`. This is the sum of the top-level queued requests, plus the requests queued in every application group.
113
+ * The number of requests queued for a specific application: `check_passenger requests --app-name APP_NAME`
114
+ * The number of requests waiting in the top-level queue: `check_passenger top_level_requests`
115
+
116
+ According to the [Phusion Passenger documentation](https://www.phusionpassenger.com/library/admin/apache/overall_status_report.html#viewing-process-and-request-queue-information), the top-level request queue size is supposed to be almost always zero. If it is non-zero for an extended period of time, then there is something very wrong, possibly a Passenger bug.
117
+
118
+
88
119
  ## Data Caching
89
120
 
90
121
  In order to set alerts per global or application counter, **check\_passenger** must be called successive times with different settings. For example, to raise alerts on global memory consumption:
@@ -106,11 +137,7 @@ Cached data is stored in the temporary directory of the system, with a time-to-l
106
137
 
107
138
  ## Contributing
108
139
 
109
- 1. Fork it ( https://github.com/aredondo/check_passenger/fork )
110
- 2. Create your feature branch (`git checkout -b my-new-feature`)
111
- 3. Commit your changes (`git commit -am ‘Add some feature'`)
112
- 4. Push to the branch (`git push origin my-new-feature`)
113
- 5. Create a new Pull Request
140
+ Please, see [CONTRIBUTING.md](CONTRIBUTING.md) for details.
114
141
 
115
142
 
116
143
  ## License
@@ -10,16 +10,15 @@ require 'tmpdir'
10
10
  class CheckPassengerCLI < Thor
11
11
  include CheckPassenger::NagiosCheck
12
12
 
13
- class_option :app_name, aliases: 'n', banner: 'Limit check to application with APP_NAME'
14
13
  class_option :cache, aliases: 'C', type: :boolean,
15
- banner: 'Cache data to avoid fast successive calls to passenger-status'
14
+ banner: 'Cache data to avoid fast successive calls to passenger-status'
16
15
  class_option :debug, aliases: 'D', type: :boolean, banner: 'Debug mode'
17
16
  class_option :dump, aliases: 'd', type: :boolean, banner: 'Dump passenger-status output on error'
18
- class_option :include_all, aliases: 'a', type: :boolean,
19
- banner: 'Also include counter for all running apps'
20
17
  class_option :passenger_status_path, aliases: 'p', banner: 'Path to passenger-status command'
21
18
 
22
19
  desc 'memory', 'Check memory used by Passenger processes'
20
+ option :app_name, aliases: 'n', banner: 'Limit check to application with APP_NAME'
21
+ option :include_all, aliases: 'a', type: :boolean, banner: 'Also include counter for all running apps'
23
22
  option :warn, banner: 'Memory usage threshold to raise warning status', aliases: 'w'
24
23
  option :crit, banner: 'Memory usage threshold to raise critical status', aliases: 'c'
25
24
  def memory
@@ -29,6 +28,8 @@ class CheckPassengerCLI < Thor
29
28
  end
30
29
 
31
30
  desc 'processes', 'Check running Passenger processes'
31
+ option :app_name, aliases: 'n', banner: 'Limit check to application with APP_NAME'
32
+ option :include_all, aliases: 'a', type: :boolean, banner: 'Also include counter for all running apps'
32
33
  option :warn, aliases: 'w', banner: 'Process count threshold to raise warning status'
33
34
  option :crit, aliases: 'c', banner: 'Process count threshold to raise critical status'
34
35
  def processes
@@ -38,6 +39,8 @@ class CheckPassengerCLI < Thor
38
39
  end
39
40
 
40
41
  desc 'live_processes', 'Check live Passenger processes'
42
+ option :app_name, aliases: 'n', banner: 'Limit check to application with APP_NAME'
43
+ option :include_all, aliases: 'a', type: :boolean, banner: 'Also include counter for all running apps'
41
44
  option :warn, aliases: 'w', banner: 'Live process count threshold to raise warning status'
42
45
  option :crit, aliases: 'c', banner: 'Live process count threshold to raise critical status'
43
46
  def live_processes
@@ -46,6 +49,26 @@ class CheckPassengerCLI < Thor
46
49
  end
47
50
  end
48
51
 
52
+ desc 'requests', 'Check queued Passenger requests'
53
+ option :app_name, aliases: 'n', banner: 'Limit check to application with APP_NAME'
54
+ option :include_all, aliases: 'a', type: :boolean, banner: 'Also include counter for all running apps'
55
+ option :warn, aliases: 'w', banner: 'Request count threshold to raise warning status'
56
+ option :crit, aliases: 'c', banner: 'Request count threshold to raise critical status'
57
+ def requests
58
+ run_check do
59
+ CheckPassenger::Check.request_count(options)
60
+ end
61
+ end
62
+
63
+ desc 'top_level_requests', 'Check requests waiting in top-level queue'
64
+ option :warn, aliases: 'w', banner: 'Request count threshold to raise warning status'
65
+ option :crit, aliases: 'c', banner: 'Request count threshold to raise critical status'
66
+ def top_level_requests
67
+ run_check do
68
+ CheckPassenger::Check.top_level_request_count(options)
69
+ end
70
+ end
71
+
49
72
  private
50
73
 
51
74
  def dump_passenger_status_output(exception = nil)
@@ -60,41 +83,53 @@ class CheckPassengerCLI < Thor
60
83
  end
61
84
 
62
85
  if passenger_status_output
63
- filename = 'passenger_status_output_dump-%s.txt' % Time.now.strftime('%Y%m%d%H%M%S')
86
+ filename = format('passenger_status_output_dump-%s.txt', Time.now.strftime('%Y%m%d%H%M%S'))
64
87
  dump_path = File.expand_path(filename, Dir.tmpdir)
65
88
  File.open(dump_path, 'wb') { |file| file.write passenger_status_output }
66
- return dump_path
89
+ dump_path
90
+ else
91
+ nil
92
+ end
93
+ end
94
+
95
+ def exception_for_dumped_passenger_status_output(exception, dump_path)
96
+ if dump_path
97
+ message = e.message + " -- passenger-status output dumped to #{dump_path}"
98
+ exception.class.new(message)
99
+ else
100
+ exception
101
+ end
102
+ end
103
+
104
+ def output_exception(e)
105
+ case e
106
+ when CheckPassenger::StatusOutputError
107
+ nagios_error("Passenger UNKNOWN - An error occurred while parsing passenger-status output: #{e.message}")
67
108
  else
68
- return nil
109
+ nagios_error("Passenger UNKNOWN - #{e.message} (#{e.class})")
69
110
  end
70
111
  end
71
112
 
72
113
  def run_check
73
114
  if options[:include_all] and options[:app_name]
74
- raise ArgumentError, 'Data for all apps can only be included when monitoring a global counter'
115
+ fail ArgumentError, 'Data for all apps can only be included when monitoring a global counter'
75
116
  end
76
117
 
77
118
  output_status, output_data = yield
78
119
  nagios_output(output_status, output_data)
79
120
 
80
121
  rescue StandardError => e
81
- if options[:debug] or options[:dump]
82
- if dump_path = dump_passenger_status_output(e)
83
- message = e.message + ' -- passenger-status output dumped to %s' % dump_path
84
- e = e.class.new(message)
85
- end
122
+ if should_dump_passenger_status_output?
123
+ dump_path = dump_passenger_status_output(e)
124
+ e = exception_for_dumped_passenger_status_output(e, dump_path)
86
125
  end
87
126
 
88
- if options[:debug]
89
- raise e
90
- else
91
- case e
92
- when CheckPassenger::StatusOutputError
93
- nagios_error('Passenger UNKNOWN - An error occurred while parsing passenger-status output: %s' % e.message)
94
- else
95
- nagios_error('Passenger UNKNOWN - %s (%s)' % [e.message, e.class.to_s])
96
- end
97
- end
127
+ raise e if options[:debug]
128
+ output_exception(e)
129
+ end
130
+
131
+ def should_dump_passenger_status_output?
132
+ options[:debug] or options[:dump]
98
133
  end
99
134
  end
100
135
 
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.version = CheckPassenger::VERSION
11
11
  spec.authors = ['Alvaro Redondo']
12
12
  spec.email = ['alvaro@redondo.name']
13
- spec.summary = %q{Nagios check to monitor Passenger processes and memory}
13
+ spec.summary = 'Nagios check to monitor Passenger processes and memory'
14
14
  # spec.description = %q{TODO: Write a longer description. Optional.}
15
15
  spec.homepage = 'https://github.com/aredondo/check_passenger'
16
16
  spec.license = 'MIT'
@@ -1,4 +1,4 @@
1
- %w{
1
+ %w(
2
2
  nagios_check
3
3
  check
4
4
  parser
@@ -7,7 +7,7 @@
7
7
  no_application_error
8
8
  status_output_error
9
9
  version
10
- }.each { |lib| require 'check_passenger/' + lib }
10
+ ).each { |lib| require 'check_passenger/' + lib }
11
11
 
12
12
  module CheckPassenger
13
13
  LIVE_PROCESS_TTL_IN_SECONDS = 300
@@ -10,7 +10,9 @@ module CheckPassenger
10
10
  COUNTER_LABELS = {
11
11
  live_process_count: ['%d live process', '%d live processes'],
12
12
  memory: '%dMB memory used',
13
- process_count: ['%d process', '%d processes']
13
+ process_count: ['%d process', '%d processes'],
14
+ request_count: ['%d request', '%d requests'],
15
+ top_level_request_count: ['%d top-level request', '%d top-level requests']
14
16
  }
15
17
 
16
18
  def check_counter(counter_name, options = {})
@@ -21,12 +23,10 @@ module CheckPassenger
21
23
  output_status = nagios_status(counter, options)
22
24
 
23
25
  data = {
24
- text: 'Passenger %s %s - %s' %
25
- [
26
- options[:app_name] || parsed_data.passenger_version,
27
- output_status.to_s.upcase,
28
- counter_with_label(counter, counter_name)
29
- ],
26
+ text: format('Passenger %s %s - %s',
27
+ options[:app_name] || parsed_data.passenger_version,
28
+ output_status.to_s.upcase,
29
+ counter_with_label(counter, counter_name)),
30
30
  counter: counter_name.to_s, value: counter,
31
31
  warn: options[:warn], crit: options[:crit],
32
32
  min: 0, max: nil
@@ -36,11 +36,11 @@ module CheckPassenger
36
36
  end
37
37
  output_data << data
38
38
 
39
- if !options[:app_name] and options[:include_all]
39
+ if options[:include_all]
40
40
  parsed_data.application_names.each do |app_name|
41
41
  counter = parsed_data.send(counter_name.to_sym, app_name)
42
42
  output_data << {
43
- text: '%s %s' % [app_name, counter_with_label(counter, counter_name)],
43
+ text: format('%s %s', app_name, counter_with_label(counter, counter_name)),
44
44
  counter: app_name, value: counter
45
45
  }
46
46
  end
@@ -50,7 +50,7 @@ module CheckPassenger
50
50
 
51
51
  rescue NoApplicationError => e
52
52
  status = :crit
53
- return [status, 'Passenger %s %s - %s' % [e.name, status.to_s.upcase, e.to_s]]
53
+ return [status, format('Passenger %s %s - %s', e.name, status.to_s.upcase, e.to_s)]
54
54
  end
55
55
 
56
56
  def method_missing(method, *args)
@@ -68,39 +68,46 @@ module CheckPassenger
68
68
 
69
69
  private
70
70
 
71
+ def cache_file_path
72
+ File.expand_path('check_passenger_cache.dump', Dir.tmpdir)
73
+ end
74
+
75
+ def cache_parsed_data(data)
76
+ File.open(cache_file_path, 'wb') { |file| file.write Marshal.dump(data) }
77
+ end
78
+
71
79
  def counter_with_label(counter, counter_type)
72
80
  counter_type = counter_type.to_sym
73
81
 
74
82
  unless COUNTER_LABELS.keys.include?(counter_type)
75
- raise ArgumentError, 'Unknown counter type: %s' % counter_type.to_s
83
+ fail ArgumentError, "Unknown counter type: #{counter_type}"
76
84
  end
77
85
 
78
86
  label = if COUNTER_LABELS[counter_type].is_a?(Array)
79
- counter == 1 ? COUNTER_LABELS[counter_type].first : COUNTER_LABELS[counter_type].last
80
- else
81
- COUNTER_LABELS[counter_type]
82
- end
87
+ if counter == 1
88
+ COUNTER_LABELS[counter_type].first
89
+ else
90
+ COUNTER_LABELS[counter_type].last
91
+ end
92
+ else
93
+ COUNTER_LABELS[counter_type]
94
+ end
83
95
 
84
96
  label % counter
85
97
  end
86
98
 
99
+ def load_cached_data
100
+ return nil unless File.exist?(cache_file_path) and (Time.now - File.mtime(cache_file_path) < CACHE_TTL)
101
+ File.open(cache_file_path, 'rb') { |file| return Marshal.load(file.read) }
102
+ end
103
+
87
104
  def load_parsed_data(options)
88
105
  @parsed_data = options[:parsed_data]
89
-
90
- if @parsed_data.nil? and options[:cache]
91
- cache_file_path = File.expand_path('check_passenger_cache.dump', Dir.tmpdir)
92
-
93
- if File.exist?(cache_file_path) and (Time.now - File.mtime(cache_file_path) < CACHE_TTL)
94
- File.open(cache_file_path, 'rb') { |file| @parsed_data = Marshal.load(file.read) }
95
- end
96
- end
106
+ @parsed_data = load_cached_data if @parsed_data.nil? and options[:cache]
97
107
 
98
108
  if @parsed_data.nil?
99
109
  @parsed_data = Parser.new(passenger_status(options[:passenger_status_path]).run)
100
-
101
- if options[:cache]
102
- File.open(cache_file_path, 'wb') { |file| file.write Marshal.dump(@parsed_data) }
103
- end
110
+ cache_parsed_data(@parsed_data) if options[:cache]
104
111
  end
105
112
 
106
113
  @parsed_data