-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LB load new util Reviewed-by: Anton Kachurin <[email protected]> Reviewed-by: Rodion Gyrbu <[email protected]> Reviewed-by: Anton Sidelnikov <None> Reviewed-by: None <None>
- Loading branch information
1 parent
93133ae
commit ae42f2d
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .lb_monitor import main as lb_monitor |
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,44 @@ | ||
import logging | ||
import socket | ||
|
||
import requests | ||
from ocomone.logging import setup_logger | ||
|
||
from ..common import base_parser, sub_parsers | ||
|
||
LB_TIMING = "lb_timing" | ||
LB_TIMEOUT = "lb_timeout" | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
LOGGER.setLevel(logging.DEBUG) | ||
|
||
AGP = sub_parsers.add_parser("lb_load", add_help=False, parents=[base_parser]) | ||
|
||
|
||
def main(): | ||
args, _ = AGP.parse_known_args() | ||
setup_logger(LOGGER, "lb_load", log_dir=args.log_dir, log_format="[%(asctime)s] %(message)s") | ||
timeout = 20 | ||
try: | ||
res = requests.get(args.target, headers={"Connection": "close"}, timeout=timeout) | ||
except requests.Timeout as ex: | ||
LOGGER.exception("Timeout sending request to LB") | ||
result = { | ||
"reason": LB_TIMEOUT, | ||
"client": socket.gethostname(), | ||
"timeout": timeout * 1000, | ||
"exception": ex | ||
} | ||
else: | ||
result = { | ||
"reason": LB_TIMING, | ||
"client": socket.gethostname(), | ||
"server": res.headers["Server"], | ||
"elapsed": res.elapsed.microseconds / 1000 | ||
} | ||
|
||
print(result) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |