Redis 中文文档 Redis 中文文档
指南
redis.io (opens new window)
指南
redis.io (opens new window)
  • 关于
    • Redis 开源治理
    • Redis 发布周期
    • Redis 赞助商
  • 入门
  • 数据类型
  • Redis Stack
  • 命令
  • 手册

Redmon


Simple sinatra based dashboard for redis.  After seeing the fnordmetric project I was inspired to write this.  Some of the ideas there have be carried over here.

Watch your redis server live (with configurable pooling seconds).

Watch your redis server live

Interact with redis using a familiar cli interface.

Interact with redis using a familiar cli interface.

Dynamically update your server configuration.

Dynamically update your server configuration.

Installation


Redmon is available as a RubyGem:

  1. ``` shell
  2. gem install redmon
  3. ```

Usage


  1. ``` shell
  2. $ redmon -h
  3. Usage: bin/redmon (options)
  4.     -a, --address ADDRESS            The thin bind address for the app (default: 0.0.0.0)
  5.     -b, --base-path BASE_PATH        The base path to expose the service at (default: /)
  6.     -l, --lifespan MINUTES           Lifespan(in minutes) for polled data (default: 30)
  7.     -n, --namespace NAMESPACE        The root Redis namespace (default: redmon)
  8.     -i, --interval SECS              Poll interval in secs for the worker (default: 10)
  9.     -p, --port PORT                  The thin bind port for the app (default: 4567)
  10.     -r, --redis URL                  The Redis url for monitor (default: redis://127.0.0.1:6379, note: password is support, ie redis://:password@127.0.0.1:6379)
  11.     -s, --secure CREDENTIALS         Use basic auth. Colon separated credentials, eg admin:admin.
  12.         --no-app                     Do not run the web app to present stats (default: true)
  13.         --no-worker                  Do not run a worker to collect the stats (default: true)

  14. $ redmon
  15. Thin web server (v1.7.0 codename Dunder Mifflin)
  16. Maximum connections set to 1024
  17. Listening on 0.0.0.0:4567, CTRL+C to stop
  18. [16-08-22 19:36:53] listening on http://0.0.0.0:4567
  19. ```

If you want to simulate a weak load on redis

  1. ``` shell
  2. $ ruby load_sim.rb
  3. ```

Open your browser to 0.0.0.0:4567

Using in a Rails application


Add to Gemfile:

  1. ``` ruby
  2. gem 'redmon', require: false
  3. ```

Mount redmon in config/routes.rb:

  1. ``` ruby
  2. mount Redmon::App => '/redmon'
  3. ```

Create a config/initializers/redmon.rb file:

  1. ``` ruby
  2. require 'redmon/config'
  3. require 'redmon/redis'
  4. require 'redmon/app'

  5. #
  6. # Optional config overrides
  7. #
  8. Redmon.configure do |config|
  9.   config.redis_url = 'redis://127.0.0.1:6379'
  10.   config.namespace = 'redmon'
  11. end
  12. ```

This will mount the Redmon application to the /redmon path.

Stats worker


The worker that gathers the Redis info stats will not be started when Redmon is mounted like this. In order to get a EventMachine worker running inside your Rails app you can try this Railtie based approach. If you are using a system to execute background tasks in your app (like Sidekiq, Resque, or Delayed Job), you can write your own worker to update the info stats.

A simple worker for Sidekiq looks like this:

  1. ``` ruby
  2. class RedmonWorker
  3.   include Sidekiq::Worker

  4.   def perform
  5.     worker = Redmon::Worker.new
  6.     worker.record_stats
  7.     worker.cleanup_old_stats
  8.   ensure
  9.     self.class.perform_in Redmon.config.poll_interval.seconds
  10.   end
  11. end
  12. ```

Once enqueued, the worker updates the stats and automatically enqueues itself to be performed again after the defined poll interval.

Using with another Sinatra application


Create/Edit config.ru:

  1. ``` ruby
  2. require './app.rb'
  3. require 'redmon'

  4. map '/' do
  5.   run Sinatra::Application
  6. end
  7. map '/redmon' do
  8.   if EM.reactor_running?
  9.     Redmon::Worker.new.run!
  10.   else
  11.     fork do
  12.       trap('INT') { EM.stop }
  13.       trap('TERM') { EM.stop }
  14.       EM.run { Redmon::Worker.new.run! }
  15.     end
  16.   end

  17.   run Redmon::App
  18. end
  19. ```

In order to configure Redmon use this code in your app.rb file:

  1. ``` ruby
  2. Redmon.configure do |config|
  3.   config.redis_url = 'redis://127.0.0.1:6379'
  4.   config.namespace = 'redmon'
  5. end
  6. ```

This will mount the Redmon application to the /redmon path.

License


Copyright (c) 2012-2017 Sean McDaniel

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to use, copy and modify copies of the Software, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Last Updated: 2023-09-03 19:17:54