Code Monkey home page Code Monkey logo

haproxy-cadvisor's Introduction

haproxy-cadvisor

haproxy_cadvisor.py is a small utility, created to set backend servers weight on HAProxy based on CPU utilization data from cAdvisor.

This utility will adjust servers balancing weight to make the load on all servers in given backend equal.

You can read more about it in my blog (in Russian).

Install

First, you need to install Python requests lib:

pip install requests
# or apt-get install python-requests on Debian/Ubuntu

Then clone this repo and set up initial config

git clone https://github.com/abulimov/haproxy-cadvisor
cd haproxy-cadvisor
cp config.json.example config.json

Then you have to edit config.json, and change some parameters as described in Configuration section.

Your HAProxy must have admin socket configured, it is done with settings like this in haproxy.cfg:

global
    stats socket /var/run/haproxy.sock level admin

More info about configuring HAProxy socket is in official documentation.

Last step is configuring cron task - type crontab -e as user that can write to HAProxy socket and add something like this:

* * * * * /usr/bin/python /path/to/haproxy_cadvisor.py /path/to/config.json > /dev/null

Don't forget to change path to haproxy_cadvisor.py and config.json to real values.

Configuration

All configuration is done in plain JSON. You can find example configuration in config.json.example.

parameter type description
haproxy_socket string socket for communication with HAProxy
backend string name of HAProxy backend we will control
pattern string regexp to match container aliases we get from cAdvisor and HAProxy server names
urls list of strings list of URLs we'll use to access cAdvisor API

As you can see, you'll have to change at least urls, backend and pattern to match your environment.

Usage

Set up the cron task and watch backend servers weight adjust as the load to servers change.

License

Licensed under the MIT License.

haproxy-cadvisor's People

Contributors

abulimov avatar

Watchers

 avatar  avatar  avatar

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.