Module: Turnstile

Defined in:
lib/turnstile.rb,
lib/turnstile/logger.rb,
lib/turnstile/sampler.rb,
lib/turnstile/tracker.rb,
lib/turnstile/version.rb,
lib/turnstile/web_app.rb,
lib/turnstile/commands.rb,
lib/turnstile/observer.rb,
lib/turnstile/collector.rb,
lib/turnstile/redis/spy.rb,
lib/turnstile/cli/parser.rb,
lib/turnstile/cli/runner.rb,
lib/turnstile/cli/launcher.rb,
lib/turnstile/dependencies.rb,
lib/turnstile/commands/base.rb,
lib/turnstile/commands/show.rb,
lib/turnstile/configuration.rb,
lib/turnstile/logger/helper.rb,
lib/turnstile/redis/adapter.rb,
lib/turnstile/collector/actor.rb,
lib/turnstile/logger/provider.rb,
lib/turnstile/commands/flushdb.rb,
lib/turnstile/redis/connection.rb,
lib/turnstile/collector/flusher.rb,
lib/turnstile/collector/formats.rb,
lib/turnstile/collector/session.rb,
lib/turnstile/commands/print_keys.rb,
lib/turnstile/collector/controller.rb,
lib/turnstile/collector/log_reader.rb,
lib/turnstile/collector/regexp_matcher.rb,
lib/turnstile/collector/formats/json_matcher.rb,
lib/turnstile/collector/formats/custom_matcher.rb,
lib/turnstile/collector/formats/delimited_matcher.rb

Defined Under Namespace

Modules: CLI, Collector, Commands, Dependencies, Logger, Redis Classes: CommandNotFoundError, ConfigFileError, Configuration, HiredisDriverNotFound, Observer, RedisConfig, Sampler, Stats, Tracker, WebApp

Constant Summary collapse

VERSION =
'3.0.2'
DEFAULT_PORT =
9090
GEM_DESCRIPTION =
<<-EOF
Turnstile is a Redis-based library that can accurately track total number
of concurrent users accessing a web/API based server application. It can
break it down by "platform" or a device type, and returns data in JSON,
CSV of NAD formats. While user tracking may happen synchronously using a
Rack middleware, another method is provided that is based on log file
analysis, and can therefore be performed outside web server process.


EOF
DESCRIPTION =
<<-EOF
Turnstile can be run as a daemon, in which case it watches a given log
file. Or, you can run turnstile to print the current aggregated stats in
several supported formats, such as JSON.

When Turnstile is used to tail the log files, ideally you should start
turnstile daemon on each app sever that's generating log file, or be
content with the effects of sampling.

Note that the IP address is not required to track uniqueness. Only
platform and UID are used. Also note that custom formatter can be
specified in a config file to parse arbitrary complex log lines.

For tailing a log files, Turnstile must first match a log line expected to
contain the tokens, and then extract is using one of the matchers. You can
specify which matcher to use depending on whether you can add Turnstile's 
tokens to your log or not. If you can, great! If not, implement your own 
custom matcher and great again.

The following matchers are available, and can be selected with -F:

1. Format named "delimited", which expects the following token in the
   log file:

   x-turnstile:platform:ip:user-identifier

   Where ':' (the delimiter) can be set via -l option, OR you can use one
   of the following formats: "json_formatted", "pipe_formatted",
   "comma_formatted", "colon_formatted" (the default). The match is 
   performed on a string "x-turnstile", other log lines are skipped.

2. Format "json_delimited", which expects to find a single-line JSON
   Hash, containing keys "platform", "ip_address", and "user_id". The match
   is performed on any log line containing string '"ip_address"', other
   lines are skipped.
  
 3.  Format "custom" requires passing an additional flag -c/--config
   file.rb, which will be required, and which can define a matcher and
   assign it to the `Turnstile.config.custom_matcher` config variable.


EOF
NS =
"x-turnstile|#{VERSION.gsub(/\./,'')}".freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.debugObject

Returns the value of attribute debug.



20
21
22
# File 'lib/turnstile.rb', line 20

def debug
  @debug
end

Class Method Details

.configObject



30
31
32
# File 'lib/turnstile.rb', line 30

def config
  @configuration ||= create_config
end

.configure(&block) ⇒ Object



26
27
28
# File 'lib/turnstile.rb', line 26

def configure(&block)
  @configuration = create_config.configure(&block)
end

.debug?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/turnstile.rb', line 22

def debug?
  self.debug
end