Giter Site home page Giter Site logo

haproxy-ruby's Introduction

HAProxy RubyGem

This gem aims to provide an interface to query HAProxy for statistics, and eventually management through the sockets API.

What's HAProxy?

HAProxy is the Reliable, High Performance TCP/HTTP Load Balancer.

Why this gem?

  • I use HAProxy at my work.
  • I wanted to know how to create gems.
  • I wanted to contribute with OSS.
  • Why not?
  • All of the above.

Example of use

#! /usr/bin/env ruby
require 'haproxy'
require 'pp'

haproxy = HAProxy.read_stats '/path/to/haproxy.stats.socket'

pp haproxy.info

# {:name=>"HAProxy",
#  :version=>"1.3.22",
#  :release_date=>"2009/10/14",
#  :nbproc=>"1",
#  :process_num=>"1",
#  :pid=>"10222",
#  :uptime=>"0d 0h33m12s",
#  :uptime_sec=>"1992",
#  :memmax_mb=>"0",
#  :ulimit_n=>"4013",
#  :maxsock=>"4013",
#  :maxconn=>"2000",
#  :maxpipes=>"0",
#  :currconns=>"1",
#  :pipesused=>"0",
#  :pipesfree=>"0",
#  :tasks=>"1",
#  :run_queue=>"1",
#  :node=>"roke",
#  :"description:"=>nil}

pp haproxy.stats

# [{:pxname=>"app1",
#   :svname=>"thin1",
#   :qcur=>"0",
#   :qmax=>"0",
#   :scur=>"0",
#   :smax=>"0",
#   :slim=>"",
#   :stot=>"0",
#   :bin=>"0",
#   :bout=>"0",
#   :dreq=>"",
#   :dresp=>"0",
#   :ereq=>"",
#   :econ=>"0",
#   :eresp=>"0",
#   :wretr=>"0",
#   :wredis=>"0",
#   :status=>"no check",
#   :weight=>"1",
#   :act=>"1",
#   :bck=>"0",
#   :chkfail=>"",
#   :chkdown=>"",
#   :lastchg=>"",
#   :downtime=>"",
#   :qlimit=>"",
#   :pid=>"1",
#   :iid=>"1",
#   :sid=>"1",
#   :throttle=>"",
#   :lbtot=>"0",
#   :tracked=>"",
#   :type=>"2",
#   :rate=>"0",
#   :rate_lim=>"",
#   :rate_max=>"0"},...]

HAProxy sample configuration

global
	stats socket haproxy

defaults
	mode	http
	option httplog
  option httpclose
	retries	3
	option redispatch
	maxconn	2000
	contimeout	5000
	clitimeout	50000
	srvtimeout	50000
  stats uri /haproxy

listen app1 0.0.0.0:10000
	balance	roundrobin

  server thin1 127.0.0.1:10001
  server thin1 127.0.0.1:10002
  server thin1 127.0.0.1:10003
  server thin1 127.0.0.1:10004
  server thin1 127.0.0.1:10005

frontend app2
  bind 0.0.0.0:10011
  default_backend app2

backend app2
  balance roundrobin
  server thin1 127.0.0.1:10006
  server thin1 127.0.0.1:10007
  server thin1 127.0.0.1:10008
  server thin1 127.0.0.1:10009
  server thin1 127.0.0.1:10010

Roadmap

  • Improve documentation
  • Improve CSV parsing
  • Add tests
  • Add examples
  • Read stats from HTTP and CSV files

License

Copyright (c) 2014 Leandro López

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, 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.

haproxy-ruby's People

Contributors

aasmith avatar dcondomitti avatar decklin avatar inkel avatar ja-johns avatar mk-qi avatar zylad avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

haproxy-ruby's Issues

Proxy object

Add a Proxy object with access to it's frontend, backend and servers.

Do note that it is possible to have different proxies with the same name which is not a good idea, as you may imagine. What to do in that case?

Proxy object could implement control methods?

SocketReader don't close Socket Connections

Hi,

i found a problem in SocketReader. The method send_cmd opens socket connections but never close them.

  def send_cmd(cmd, &block)
      socket = UNIXSocket.new(@path)
      socket.write(cmd + ';')
      socket.each do |line|
        next if line.chomp.empty?
        yield(line.strip)
      end
  end

There should be a socket.close at the end of the method.

Connect with HTTP

Add a HTTP Reader that reads stats from an URL every configurable amount of time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.