Skip to content

Conversation

@norrs
Copy link
Owner

@norrs norrs commented Aug 4, 2015

This is rebased on top of PR flores#29 .

This code is provided as is with no guarantees.

librhapr breaking changes:

rhapr interface has changed, send(message) is now send(message, process=1) so it can pass on which process id to try to look up for a socket.

in rhapr environment module:
socket_path is renamed to socket_paths and now returns an hash for socket paths , keyed on process id's. It still throws an runtime exception if no socket is found. A future enhancement might be to let it return an empty hash and let the client code which uses the library figure out what to do if it doesn't find any admin sockets.
socket now accepts an argument for the parameter process.

haproxyctl binary accepts the parameter -p where the argument has to be numeric identifier for the process id. if nbprocs > 1 , 0 means talking to every socket it finds.

Known bugs:
Regex doesn't skip #comments in file, so if you "redefine" the admin socket in a comment below the original comment, it will sadly overwrite it in the internal hash map.

Example outputs:

with nbprocs > 1

[root@a7504fbfa532 source]#  ./bin/haproxyctl -p1 show pools
Dumping pools usage. Use SIGQUIT to flush them.
  - Pool pipe (32 bytes) : 5 allocated (160 bytes), 5 used, 3 users [SHARED]
  - Pool capture (64 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
  - Pool channel (80 bytes) : 2 allocated (160 bytes), 2 used, 1 users [SHARED]
  - Pool task (112 bytes) : 24 allocated (2688 bytes), 24 used, 1 users [SHARED]
  - Pool uniqueid (128 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
  - Pool connection (320 bytes) : 2 allocated (640 bytes), 2 used, 1 users [SHARED]
  - Pool hdr_idx (416 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
  - Pool session (864 bytes) : 1 allocated (864 bytes), 1 used, 1 users [SHARED]
  - Pool requri (1024 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
  - Pool buffer (16416 bytes) : 2 allocated (32832 bytes), 2 used, 1 users [SHARED]
Total: 10 pools, 37344 bytes allocated, 37344 used.

[root@a7504fbfa532 source]#  ./bin/haproxyctl -p0 show pools
1: Dumping pools usage. Use SIGQUIT to flush them.
1:   - Pool pipe (32 bytes) : 5 allocated (160 bytes), 5 used, 3 users [SHARED]
1:   - Pool capture (64 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
1:   - Pool channel (80 bytes) : 2 allocated (160 bytes), 2 used, 1 users [SHARED]
1:   - Pool task (112 bytes) : 24 allocated (2688 bytes), 24 used, 1 users [SHARED]
1:   - Pool uniqueid (128 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
1:   - Pool connection (320 bytes) : 2 allocated (640 bytes), 2 used, 1 users [SHARED]
1:   - Pool hdr_idx (416 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
1:   - Pool session (864 bytes) : 1 allocated (864 bytes), 1 used, 1 users [SHARED]
1:   - Pool requri (1024 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
1:   - Pool buffer (16416 bytes) : 2 allocated (32832 bytes), 2 used, 1 users [SHARED]
1: Total: 10 pools, 37344 bytes allocated, 37344 used.
1: 
2: Dumping pools usage. Use SIGQUIT to flush them.
2:   - Pool pipe (32 bytes) : 5 allocated (160 bytes), 5 used, 3 users [SHARED]
2:   - Pool capture (64 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
2:   - Pool channel (80 bytes) : 2 allocated (160 bytes), 2 used, 1 users [SHARED]
2:   - Pool task (112 bytes) : 24 allocated (2688 bytes), 24 used, 1 users [SHARED]
2:   - Pool uniqueid (128 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
2:   - Pool connection (320 bytes) : 2 allocated (640 bytes), 2 used, 1 users [SHARED]
2:   - Pool hdr_idx (416 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
2:   - Pool session (864 bytes) : 1 allocated (864 bytes), 1 used, 1 users [SHARED]
2:   - Pool requri (1024 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
2:   - Pool buffer (16416 bytes) : 2 allocated (32832 bytes), 2 used, 1 users [SHARED]
2: Total: 10 pools, 37344 bytes allocated, 37344 used.
2: 
3: Dumping pools usage. Use SIGQUIT to flush them.
3:   - Pool pipe (32 bytes) : 5 allocated (160 bytes), 5 used, 3 users [SHARED]
3:   - Pool capture (64 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
3:   - Pool channel (80 bytes) : 2 allocated (160 bytes), 2 used, 1 users [SHARED]
3:   - Pool task (112 bytes) : 24 allocated (2688 bytes), 24 used, 1 users [SHARED]
3:   - Pool uniqueid (128 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
3:   - Pool connection (320 bytes) : 2 allocated (640 bytes), 2 used, 1 users [SHARED]
3:   - Pool hdr_idx (416 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
3:   - Pool session (864 bytes) : 1 allocated (864 bytes), 1 used, 1 users [SHARED]
3:   - Pool requri (1024 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
3:   - Pool buffer (16416 bytes) : 2 allocated (32832 bytes), 2 used, 1 users [SHARED]
3: Total: 10 pools, 37344 bytes allocated, 37344 used.
3: 
4: Dumping pools usage. Use SIGQUIT to flush them.
4:   - Pool pipe (32 bytes) : 5 allocated (160 bytes), 5 used, 3 users [SHARED]
4:   - Pool capture (64 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
4:   - Pool channel (80 bytes) : 2 allocated (160 bytes), 2 used, 1 users [SHARED]
4:   - Pool task (112 bytes) : 24 allocated (2688 bytes), 24 used, 1 users [SHARED]
4:   - Pool uniqueid (128 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
4:   - Pool connection (320 bytes) : 2 allocated (640 bytes), 2 used, 1 users [SHARED]
4:   - Pool hdr_idx (416 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
4:   - Pool session (864 bytes) : 1 allocated (864 bytes), 1 used, 1 users [SHARED]
4:   - Pool requri (1024 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
4:   - Pool buffer (16416 bytes) : 2 allocated (32832 bytes), 2 used, 1 users [SHARED]
4: Total: 10 pools, 37344 bytes allocated, 37344 used.
4: 
5: Dumping pools usage. Use SIGQUIT to flush them.
5:   - Pool pipe (32 bytes) : 5 allocated (160 bytes), 5 used, 3 users [SHARED]
5:   - Pool capture (64 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
5:   - Pool channel (80 bytes) : 2 allocated (160 bytes), 2 used, 1 users [SHARED]
5:   - Pool task (112 bytes) : 24 allocated (2688 bytes), 24 used, 1 users [SHARED]
5:   - Pool uniqueid (128 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
5:   - Pool connection (320 bytes) : 2 allocated (640 bytes), 2 used, 1 users [SHARED]
5:   - Pool hdr_idx (416 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
5:   - Pool session (864 bytes) : 1 allocated (864 bytes), 1 used, 1 users [SHARED]
5:   - Pool requri (1024 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
5:   - Pool buffer (16416 bytes) : 2 allocated (32832 bytes), 2 used, 1 users [SHARED]
5: Total: 10 pools, 37344 bytes allocated, 37344 used.
5: 
6: Dumping pools usage. Use SIGQUIT to flush them.
6:   - Pool pipe (32 bytes) : 5 allocated (160 bytes), 5 used, 3 users [SHARED]
6:   - Pool capture (64 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
6:   - Pool channel (80 bytes) : 2 allocated (160 bytes), 2 used, 1 users [SHARED]
6:   - Pool task (112 bytes) : 24 allocated (2688 bytes), 24 used, 1 users [SHARED]
6:   - Pool uniqueid (128 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
6:   - Pool connection (320 bytes) : 2 allocated (640 bytes), 2 used, 1 users [SHARED]
6:   - Pool hdr_idx (416 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
6:   - Pool session (864 bytes) : 1 allocated (864 bytes), 1 used, 1 users [SHARED]
6:   - Pool requri (1024 bytes) : 0 allocated (0 bytes), 0 used, 1 users [SHARED]
6:   - Pool buffer (16416 bytes) : 2 allocated (32832 bytes), 2 used, 1 users [SHARED]
6: Total: 10 pools, 37344 bytes allocated, 37344 used.
6: 

With nbprocs < 2

[root@6c7b51b85ac6 source]# ./haproxyctl show info -p1
/source/bin/../lib/haproxyctl.rb:94:in `unixsock': Could not find a stats socket with process 1 in /etc/haproxy/haproxy.cfg (RuntimeError)
    from ./haproxyctl:195
[root@6c7b51b85ac6 source]# ./haproxyctl show info -p0
Name: HAProxy
Version: 1.5.2
Release_date: 2014/07/12
Nbproc: 1
Process_num: 1
Pid: 23
Uptime: 0d 0h13m33s
Uptime_sec: 813
Memmax_MB: 0
Ulimit-n: 8036
Maxsock: 8036
Maxconn: 4000
Hard_maxconn: 4000
CurrConns: 0
CumConns: 4
CumReq: 4
MaxSslConns: 0
CurrSslConns: 0
CumSslConns: 0
Maxpipes: 0
PipesUsed: 0
PipesFree: 0
ConnRate: 0
ConnRateLimit: 0
MaxConnRate: 0
SessRate: 0
SessRateLimit: 0
MaxSessRate: 0
SslRate: 0
SslRateLimit: 0
MaxSslRate: 0
SslFrontendKeyRate: 0
SslFrontendMaxKeyRate: 0
SslFrontendSessionReuse_pct: 0
SslBackendKeyRate: 0
SslBackendMaxKeyRate: 0
SslCacheLookups: 0
SslCacheMisses: 0
CompressBpsIn: 0
CompressBpsOut: 0
CompressBpsRateLim: 0
ZlibMemUsage: 0
MaxZlibMemUsage: 0
Tasks: 11
Run_queue: 1
Idle_pct: 100
node: 6c7b51b85ac6
description: 
[root@1cfa2370b6cf source]# ./haproxyctl -p4 set weight backend/node01 40

[root@1cfa2370b6cf source]# ./haproxyctl -p0 get weight backend/node01 
1: 60 (initial 60)
1: 
2: 60 (initial 60)
2: 
3: 60 (initial 60)
3: 
4: 40 (initial 60)
4: 
5: 60 (initial 60)
5: 
6: 60 (initial 60)
6: 

@norrs norrs closed this Aug 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants