Thursday, 17 December 2015

nginx: See Active connections / Connections Per Seconds

How do I monitor my nginx server status and connections requests per seconds under Linux or Unix like operating systems?

nginx server has a module called HttpStubStatusModule. This module provides the ability to get some status from nginx. You will get the following information:
  1. Number of all open connections.
  2. Stats about accepted connections.
  3. Connections per second and so on.

Configuration

Edit nginx.conf file:
# vi nginx.conf
Add or append the following in context location:
 
   location /nginx_status {
        # Turn on stats
        stub_status on;
        access_log   off;
        # only allow access from 192.168.1.5 #
        allow 192.168.1.5;
        deny all;
   }
 
Save and close the file. Reload nginx server:
# service nginx reload
OR
# nginx -s reload

Test it

Open a web-browser and type the following url:
http://your-domain-name-here/nginx_status
OR
http://ip.address.here/nginx_status
Sample outputs:
Fig.01: nginx Status Monitor with HttpStubStatusModule
Fig.01: nginx Status Monitor with HttpStubStatusModule

Where,
  1. 586 = Number of all open connections
  2. 9582571 = Accepted connections
  3. 9582571 = Handled connections
  4. 21897888 = Handles requests




Wednesday, 16 December 2015

RubyLex

@scanner = RubyLex.new
@scanner.exception_on_syntax_error = false
a = @scanner.set_prompt do; puts 1; end
=> #<Proc:0x007f845529df70@(pry):37>
a.call
1
=> nil
view raw gistfile1.txt hosted with ❤ by GitHub

Sunday, 13 December 2015

Thursday, 10 December 2015

Mac OS X tmux config Raw

### INSTALLATION NOTES ###
# 1. Install Homebrew (https://github.com/mxcl/homebrew)
# 2. brew install zsh
# 3. Install OhMyZsh (https://github.com/robbyrussell/oh-my-zsh)
# 4. brew install reattach-to-user-namespace --wrap-pbcopy-pbpaste && brew link reattach-to-user-namespace
# 5. Install iTerm2
# 6. In iTerm2 preferences for your profile set:
# Character Encoding: Unicode (UTF-8)
# Report Terminal Type: xterm-256color
# 7. Put itunesartist and itunestrack into PATH
#
#
# Usage:
# - Prefix is set to Ctrl-a (make sure you remapped Caps Lock to Ctrl)
# - All prefixed with Ctrl-a
# - Last used window: /
# - Last used pane: ;
# - Vertical split: v
# - Horizontal split: s
# - Previous window: [
# - Next window: ]
# - Choose session: Ctrl-s
# - Quick window: Ctrl-q
set-option -g default-command "reattach-to-user-namespace -l zsh"
### LOOK & FEEL ###
set -g default-terminal "xterm-256color"
# default statusbar colors
set-option -g status-bg colour235
set-option -g status-fg colour179
set-option -g status-attr default
# default window title colors
set-window-option -g window-status-fg colour244
set-window-option -g window-status-bg default
# active window title colors
set-window-option -g window-status-current-fg colour166
set-window-option -g window-status-current-bg default
set-window-option -g window-status-current-attr bright
# pane border
set-option -g pane-border-fg colour235
set-option -g pane-active-border-fg colour240
# pane number display
set-option -g display-panes-active-colour colour33
set-option -g display-panes-colour colour166
# clock
set-window-option -g clock-mode-colour colour64
# status bar right contents
set -g status-right-length 65
set -g status-right "#[fg=colour187][#(itunesartist) - #(itunestrack)] #[fg=default][%H:%M %e-%b-%Y]"
set -g status-interval 5
set-option -g mouse-select-pane on
set-option -g mouse-select-window on
set-option -g mode-mouse on
set-window-option -g utf8 on
set-option -g status-keys vi
set-option -g mode-keys vi
#no command delay
set -sg escape-time 0
#count windows and panes from 1
set -g base-index 1
setw -g pane-base-index 1
### KEYS ###
#using C-a as prefix
unbind C-b
set-option -g prefix C-a
bind C-a send-prefix
unbind /
bind / last-window
unbind %
bind s split-window -v
unbind '"'
bind v split-window -h
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
unbind {
bind { swap-pane -D
unbind }
bind } swap-pane -U
unbind r
bind r source-file ~/.tmux.conf; display "Reloaded"
bind Escape copy-mode
bind p paste-buffer
unbind [
bind [ previous-window
unbind ]
bind ] next-window
unbind o
bind o select-pane -t :.-
bind C-q command-prompt -I "htop" -p "Quick window command: " "new-window '%%'"
bind -t vi-copy 'v' begin-selection
bind -t vi-copy 'y' copy-selection
bind C-c run "tmux save-buffer - | pbcopy"
bind C-v run "tmux set-buffer \"$(pbpaste)\"; tmux paste-buffer"
bind C-s choose-session
view raw .tmux.conf hosted with ❤ by GitHub
#!/usr/bin/osascript
on run
set info to ""
tell application "System Events"
set num to count (every process whose name is "iTunes")
end tell
if num > 0 then
tell application "iTunes"
if player state is playing then
set info to artist of current track
end if
end tell
end if
return info
end run
view raw itunesartist hosted with ❤ by GitHub
#!/usr/bin/osascript
on run
set info to ""
tell application "System Events"
set num to count (every process whose name is "iTunes")
end tell
if num > 0 then
tell application "iTunes"
if player state is playing then
set info to name of current track
else
set info to "Not Playing."
end if
end tell
end if
return info
end run
view raw itunestrack hosted with ❤ by GitHub
https://gist.github.com/v-yarotsky/2157908

Sunday, 6 December 2015

The Recipe for the World's Largest Rails Monolith by Akira Matsuda

The Recipe for the World's Largest Rails Monolith


by Akira Matsuda



Kage (kah-geh) is a shadow proxy server to duplex HTTP requests

Kage (kah-geh) is a shadow proxy server to duplex HTTP requests


https://github.com/cookpad/kage

Kage (kah-geh) is an HTTP shadow proxy server that sits between clients and your server(s) to enable "shadow requests".
Kage can be used to duplex requests to the master (production) server and shadow servers that have newer code changes that are going to be deployed. By shadowing requests to the new code you can make sure there are no big/surprising changes in the response in terms of data, performance and database loads etc.
Kage is built with EventMachine and em-proxy and all shadow requests are done asynchronously, while responses from master are sent back to the client without blocking the network, so clients will never notice any delays even when shadow traffic is made.
You can customize the behavior of Kage with simple callbacks, when it chooses which backends to send shadow requests to (or not at all), appends or deletes HTTP headers per backend, and examines the complete HTTP response (including headers and body).

RRRSpec

RRRSpec enables you to run RSpec in a distributed manner.
This is developed for the purpose to obtain the fault-tolerance properties to process-failures, machine-failures, and unresponsivenss of processes in the automated testing process.
RRRSpec is used in production as a CI service, running 60+ RSpec processes concurrently, and it undergoes those failures, which include lots of rb_bugs, assertion errors, and segmentation faults.

https://github.com/cookpad/rrrspec

SwitchPoint

Switching database connection between readonly one and writable one.


https://github.com/eagletmt/switch_point


Suppose you have 4 databases: db-blog-master, db-blog-slave, db-comment-master and db-comment-slave. Article model and Category model are stored in db-blog-{master,slave} and Comment model is stored in db-comment-{master,slave}.

Quine Relay

This is a Ruby program that generates Scala program that generates Scheme program that generates ...(through 100 languages in total)... REXX program that generates the original Ruby code again.

https://github.com/mame/quine-relay

How Digital Disruption Is Redefining Industries


Digital Vortex
How Digital Disruption Is Redefining Industries

http://www.imd.org/uupload/IMD.WebSite/DBT/Digital_Vortex_06182015.pdf