forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[counterpoll]: cli to change counter polling configuration (sonic-net…
…#257) Signed-off-by: Sihui Han <sihan@microsoft.com>
- Loading branch information
1 parent
9087d5f
commit fffe98e
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#! /usr/bin/python -u | ||
|
||
import click | ||
import swsssdk | ||
from tabulate import tabulate | ||
|
||
@click.group() | ||
def cli(): | ||
""" SONiC Static Counter Poll configurations """ | ||
|
||
# Queue counter commands | ||
@cli.group() | ||
def queue(): | ||
""" Queue counter commands """ | ||
|
||
@queue.command() | ||
@click.argument('poll_interval', type=click.IntRange(100, 30000)) | ||
def interval(poll_interval): | ||
""" Set queue counter query interval """ | ||
configdb = swsssdk.ConfigDBConnector() | ||
configdb.connect() | ||
queue_info = {} | ||
if poll_interval is not None: | ||
queue_info['POLL_INTERVAL'] = poll_interval | ||
configdb.mod_entry("FLEX_COUNTER_TABLE", "QUEUE", queue_info) | ||
|
||
# Port counter commands | ||
@cli.group() | ||
def port(): | ||
""" Queue counter commands """ | ||
|
||
@port.command() | ||
@click.argument('poll_interval', type=click.IntRange(100, 30000)) | ||
def interval(poll_interval): | ||
""" Set queue counter query interval """ | ||
configdb = swsssdk.ConfigDBConnector() | ||
configdb.connect() | ||
port_info = {} | ||
if poll_interval is not None: | ||
port_info['POLL_INTERVAL'] = poll_interval | ||
configdb.mod_entry("FLEX_COUNTER_TABLE", "test", port_info) | ||
|
||
@cli.command() | ||
def show(): | ||
""" Show the counter configuration """ | ||
configdb = swsssdk.ConfigDBConnector() | ||
configdb.connect() | ||
queue_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'QUEUE') | ||
port_info = configdb.get_entry('FLEX_COUNTER_TABLE', 'PORT') | ||
|
||
header = ("Type", "Interval") | ||
data = [] | ||
if queue_info: | ||
data.append(["QUEUE_STAT", queue_info["POLL_INTERVAL"]]) | ||
if port_info: | ||
data.append(["PORT_STAT", port_info["POLL_INTERVAL"]]) | ||
|
||
print tabulate(data, headers=header, tablefmt="simple", missingval="") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
_counterpoll_completion() { | ||
COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \ | ||
COMP_CWORD=$COMP_CWORD \ | ||
_COUNTERPOLL_COMPLETE=complete $1 ) ) | ||
return 0 | ||
} | ||
|
||
complete -F _counterpoll_completion -o default counterpoll; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters