Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/haproxyctl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def main(args):
"enable" : cmds.enableServer,
"disable" : cmds.disableServer,
"get-weight" : cmds.getWeight,
"sessions" : cmds.getServerSessions,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you add a test for this?

"servers" : cmds.listServers,
"set-weight" : cmds.setWeight,
"frontends" : cmds.showFrontends,
Expand Down
22 changes: 22 additions & 0 deletions haproxy/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,25 @@ def getResultObj(self, res):
"bOut: %s" % outCols[cols['bout']])))

return servers

class getServerSessions(baseStat):
"""Get Current Sessions for given server"""

p_args = ["backend", "server"]
cmdTxt = "show stat\r\n"
helpTxt = "Get current sessions for server in the given backend"

def getResult(self, res):
if self.args['backend'] is None:
raise Exception("Need to specify backend")
if self.args['server'] is None:
raise Exception("Need to specify server")
cols = self.getCols(res)

for line in res.split('\n'):
if line.startswith(self.args['backend']):
# Lines for server start with the name of the
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed an indent here, right?

# backend.
outCols = line.split(',')
if outCols[cols['svname']] == self.args['server']:
return outCols[cols['scur']]