-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for the system stats query endpoint.
- Loading branch information
1 parent
5158cd3
commit 316fadb
Showing
13 changed files
with
334 additions
and
84 deletions.
There are no files selected for viewing
Empty file.
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,36 @@ | ||
import autograder.api.common | ||
import autograder.api.config | ||
|
||
API_ENDPOINT = 'stats/system/query' | ||
API_PARAMS = [ | ||
autograder.api.config.PARAM_USER_EMAIL, | ||
autograder.api.config.PARAM_USER_PASS, | ||
|
||
autograder.api.config.APIParam('limit', | ||
'The maximum number of records to return.', | ||
required = False, parser_options = {'action': 'store', 'type': int}), | ||
|
||
autograder.api.config.APIParam('after', | ||
'If supplied, only return stat records after this timestamp.', | ||
required = False), | ||
|
||
autograder.api.config.APIParam('before', | ||
'If supplied, only return stat records before this timestamp.', | ||
required = False), | ||
|
||
autograder.api.config.APIParam('sort', | ||
'Sort the results. -1 for ascending, 0 for no sorting, 1 for descending.', | ||
required = False, parser_options = {'action': 'store', 'type': int}), | ||
] | ||
|
||
DESCRIPTION = 'Query system stats from the autograder server.' | ||
|
||
def send(arguments, **kwargs): | ||
return autograder.api.common.handle_api_request(arguments, API_PARAMS, API_ENDPOINT, **kwargs) | ||
|
||
def _get_parser(): | ||
parser = autograder.api.config.get_argument_parser( | ||
description = DESCRIPTION, | ||
params = API_PARAMS) | ||
|
||
return parser |
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,14 @@ | ||
""" | ||
The `autograder.cli.stats` package contains tools for | ||
managing stats from the autograder server. | ||
""" | ||
|
||
import sys | ||
|
||
import autograder.util.cli | ||
|
||
def main(): | ||
return autograder.util.cli.main() | ||
|
||
if (__name__ == '__main__'): | ||
sys.exit(main()) |
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,14 @@ | ||
""" | ||
The `autograder.cli.stats.system` package contains tools for | ||
managing system-level stats from the autograder server. | ||
""" | ||
|
||
import sys | ||
|
||
import autograder.util.cli | ||
|
||
def main(): | ||
return autograder.util.cli.main() | ||
|
||
if (__name__ == '__main__'): | ||
sys.exit(main()) |
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,20 @@ | ||
import json | ||
import sys | ||
|
||
import autograder.api.stats.system.query | ||
|
||
def run(arguments): | ||
result = autograder.api.stats.system.query.send(arguments, exit_on_error = True) | ||
print(json.dumps(result['results'], indent = 4)) | ||
return 0 | ||
|
||
def main(): | ||
return run(_get_parser().parse_args()) | ||
|
||
def _get_parser(): | ||
parser = autograder.api.stats.system.query._get_parser() | ||
|
||
return parser | ||
|
||
if (__name__ == '__main__'): | ||
sys.exit(main()) |
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
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
33 changes: 33 additions & 0 deletions
33
tests/api/testdata/stats/system/stats_system_query_base.json
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,33 @@ | ||
{ | ||
"module": "autograder.api.stats.system.query", | ||
"arguments": { | ||
"user": "[email protected]", | ||
"pass": "server-admin" | ||
}, | ||
"output-modifier": "fake_system_stats", | ||
"output": { | ||
"results": [ | ||
{ | ||
"timestamp": 100, | ||
"cpu-percent": 1, | ||
"mem-percent": 1, | ||
"net-bytes-sent": 1, | ||
"net-bytes-received": 1 | ||
}, | ||
{ | ||
"timestamp": 200, | ||
"cpu-percent": 2, | ||
"mem-percent": 2, | ||
"net-bytes-sent": 2, | ||
"net-bytes-received": 2 | ||
}, | ||
{ | ||
"timestamp": 300, | ||
"cpu-percent": 3, | ||
"mem-percent": 3, | ||
"net-bytes-sent": 3, | ||
"net-bytes-received": 3 | ||
} | ||
] | ||
} | ||
} |
Oops, something went wrong.