Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command to get current sessions for server in backend #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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']]