-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hsin Yuan Yeh
authored and
Hsin Yuan Yeh
committed
Nov 4, 2023
1 parent
a0d6df6
commit cb1b398
Showing
2 changed files
with
30 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<div style="text-align:right"><a href="./index">Back to Index</a></div> | ||
|
||
|
||
## Using ping to check network quality | ||
Server group A has members A1, A2, ..., A10, which share the same database server B. | ||
You want to regularly check the connection states from group A to B. | ||
This example shows how to connect to all servers in group A and execute the "ping" command to database server B. | ||
|
||
``` | ||
databaseServer = '192.168.1.100' | ||
## suppose they share the same credentials | ||
username = 'user' | ||
password = '1234' | ||
groupsA = [] | ||
for i in range(10): | ||
groupsA.append([f'{username}@host{i}',password) | ||
## This keeps average speeds of "ping" | ||
states = {} | ||
for account,password in group: | ||
with $.connect(account,password) as host: | ||
$f'ping -c 3 -w 3 {databaseServer}' | ||
if 'transmitted' in line: | ||
## eg. 3 packets transmitted, 3 received, 0% packet loss, time 2003ms | ||
words = line.split() | ||
received, time = int(cols[3]),int(cols[9][:-2]) | ||
avg = sum(times)/len(times) if len(times) else 0 | ||
states[account] = time / received if received else 0 | ||
``` |
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