Skip to content

Commit

Permalink
updating gh-pages repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Hsin Yuan Yeh authored and Hsin Yuan Yeh committed Nov 4, 2023
1 parent a0d6df6 commit cb1b398
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 28 additions & 0 deletions v2/examples/ex-ping.md
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
```
3 changes: 2 additions & 1 deletion v2/examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ Last Updated on 2023/10/31

* [Checking the syncing status of two MySQL servers](mysqlsyncstate)
* [Who is attacking your server?](ex-lasdb)
* [Check Disk Usage](ex-df)
* [Check Disk Usage](ex-df)
* [Using ping to check network quality](ex-ping

0 comments on commit cb1b398

Please sign in to comment.