如何使用 bench.sh 更了解你的設備

延續我們剛剛建立的 VPC ; 我們需要再多一些設備資訊上的了解

例如這個有趣的 Github: bench-scripts

具體來說有哪些資訊好參考呢? 我們來準備些範例

只要可以連外的設備只要執行指令

$ wget -qO- bench.sh | bash

就可以得到下面資訊示意圖了

root@fv-az444-456:~# wget -qO- bench.sh | bash
-------------------- A Bench.sh Script By Teddysun -------------------
 Version            : v2022-06-01
 Usage              : wget -qO- bench.sh | bash
----------------------------------------------------------------------
 CPU Model          : Intel(R) Xeon(R) Platinum 8272CL CPU @ 2.60GHz
 CPU Cores          : 2 @ 2593.905 MHz
 CPU Cache          : 36608 KB
 AES-NI             : Enabled
 VM-x/AMD-V         : Disabled
 Total Disk         : 96.9 GB (57.1 GB Used)
 Total Mem          : 6.8 GB (649.1 MB Used)
 Total Swap         : 4.0 GB (0 Used)
 System uptime      : 0 days, 0 hour 18 min
 Load average       : 0.00, 0.02, 0.05
 OS                 : Ubuntu 22.04.2 LTS
 Arch               : x86_64 (64 Bit)
 Kernel             : 5.15.0-1037-azure
 TCP CC             : cubic
 Virtualization     : Hyper-V
 Organization       : AS8075 Microsoft Corporation
 Location           : Boydton / US
 Region             : Virginia
----------------------------------------------------------------------
 I/O Speed(1st run) : 203 MB/s
 I/O Speed(2nd run) : 202 MB/s
 I/O Speed(3rd run) : 202 MB/s
 I/O Speed(average) : 202.3 MB/s
----------------------------------------------------------------------
 Node Name        Upload Speed      Download Speed      Latency
 Speedtest.net    1423.55 Mbps      7765.46 Mbps        9.77 ms
 Los Angeles, US  1371.19 Mbps      7562.81 Mbps        61.78 ms
 Dallas, US       1425.68 Mbps      7985.29 Mbps        34.13 ms
 Montreal, CA     306.80 Mbps       305.41 Mbps         23.43 ms
 Paris, FR        1289.77 Mbps      6770.10 Mbps        83.94 ms
 Amsterdam, NL    938.54 Mbps       5735.30 Mbps        91.23 ms
 Shanghai, CN     153.89 Mbps       2439.34 Mbps        300.14 ms
 Nanjing, CN      69.53 Mbps        1931.12 Mbps        209.68 ms
 Guangzhou, CN    0.89 Mbps         487.31 Mbps         206.84 ms
 Hongkong, CN     551.95 Mbps       3867.24 Mbps        216.28 ms
 Singapore, SG    381.25 Mbps       74.03 Mbps          230.53 ms
 Tokyo, JP        483.98 Mbps       4942.85 Mbps        158.25 ms
----------------------------------------------------------------------
 Finished in        : 6 min 25 sec
 Timestamp          : 2023-05-18 17:09:01 UTC
----------------------------------------------------------------------

ubuntu-latest 解釋了當下建立的版本 Ubuntu 22.04.2 LTS

雖然 Virtualization: Hyper-V 但資源配置可能還是以 Container 形式共用硬體資源會比較合理些

CPU 諸元整體 26 cores ; 但配置到設備上就剩下兩個

root@fv-az444-456:~# cat /proc/cpuinfo | grep processor
processor	: 0
processor	: 1

比較亮眼的是網路的頻寬傳輸 ; 因為機房在 US ; 所以設備出門的骨幹頻寬也是讓我長了些見識

使用 GitHub Action 快速建立免費的 VPC

會使用到的工具有二
1. Github Action
2. ngrok

先從 ngrok 取得一組 API Token 備用 ; 沒有帳號的同學請使用 Github / Google 帳號連動即可

接著處理 Github Action 的基礎設定

Create new repo: 記得選成 private ; 因為需要放 ngrok API Token

Master Branch 甚至也不用 commit 資訊,因為重點在 Actions 環節

接著準備 main.yml 資訊 ; 記得把 ${API Token} 替換成自己的資訊

# 1682879657
name: CI
on: [push, workflow_dispatch]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:

    - name: package install
      run: sudo apt-get -qq install neofetch speedtest-cli aptitude php-cli

    - name: Download ssh config
      run: wget https://raw.githubusercontent.com/GogoZin/sshd/main/sshd_config -O sshd_config

    - name: replace ssh config
      run: sudo cp sshd_config /etc/ssh/sshd_config

    - name: restart ssh service
      run: sudo service ssh restart

    - name: Remove root password
      run: sudo passwd -d root

    - name: remove runner password

      run: sudo passwd -d runner

    - name: download ngrok package
      run: wget https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz

    - name: unzip ngrok package
      run: tar zxvf ngrok-v3-stable-linux-amd64.tgz

    - name: setup ngrok API token
      run: ./ngrok config add-authtoken ${API Token}

    - name: Tunel for SSH port
      run: ./ngrok tcp 22

直接 New 一份 workflow

因為 main.yml 已經準備好了,所以就 set up a workflow yourself

把 main.yml 貼完後 commit change

通常第一次 commit 完會自動執行,但如果需要重新執行時,也可以使用 Re-run all jobs 處理

點選 Build 也可以確認 CI/CD 狀態

這個時候我們可以回到 ngrok 確認資源啟動狀態 ; hmmm, endpoint 已經正常啟動了 ; 並且點選可以看到設備的基礎資訊

通常介面資訊就已經可以取得 SSH 接入方式了 ; 但如果使用量大的話 endpoint 變換其實是非常大的

所以寫了個程式擷取資訊

#!/bin/bash

api_endpoint="https://api.ngrok.com/endpoints"
authtoken="${ngrok_api_token}"
ngrok_version="2"

hostport=$(curl -sSL \
           -X GET \
           -H "Authorization: Bearer ${authtoken}" \
           -H "Ngrok-Version: ${ngrok_version}" \
           "${api_endpoint}" | jq -r '.endpoints[].hostport')

host=$(echo "${hostport}" | cut -d':' -f1)
port=$(echo "${hostport}" | cut -d':' -f2)

ssh "root@${host}" -p "${port}"

就連 ssh 接入設備也就是一下子的事

最後一定要備註的事,這 VPC 不是永久設備,過一陣子就會消失了

實際測試時間有長有短,但有帳面紀錄的時間我會說 43 min

 18:15:56 up 43 min,  1 user,  load average: 0.00, 0.00, 0.00
 18:15:57 up 43 min,  1 user,  load average: 0.00, 0.00, 0.00
 18:15:58 up 43 min,  1 user,  load average: 0.00, 0.00, 0.00
Connection to 0.tcp.ngrok.io closed by remote host.
Connection to 0.tcp.ngrok.io closed.

Quickly understand the differences between PromQL avg_over_time, min_over_time, and max_over_time

為什麼需要了解

我們正在重新設計當週與三個月前的當週 Usage 成長率 ; 直到開始研究了相關時間序列函數

看文件上的文字說明總覺得無法直觀理解

所以嘗試用一張圖來說明

Rule A 的 date range 將從 date picker 指定

但 Rule [C,D,E] 將從 Variables 的 interval 指定 $date = 1h 的呈現

當 $date = 1d 時候的曲線遷移狀態

跟布林通道概念有點類似

Tips and Tricks for Testing Your Environment with bench.sh Script

What is bench.sh?

Just curl https://bench.sh/

Installing and Setting up bench.sh

不用安裝,直接存取原始檔案執行即可

Executive Command Suggestions

Interpreting the Results

root@fv-az422-569:~# wget -qO- bench.sh | bash
 OS                 : Ubuntu 22.04.2 LTS
-------------------- A Bench.sh Script By Teddysun -------------------
 Version            : v2022-06-01
 Usage              : wget -qO- bench.sh | bash
----------------------------------------------------------------------
 CPU Model          : Intel(R) Xeon(R) Platinum 8171M CPU @ 2.60GHz
 CPU Cores          : 2 @ 2095.173 MHz
 CPU Cache          : 36608 KB
 AES-NI             : Enabled
 VM-x/AMD-V         : Disabled
 Total Disk         : 96.9 GB (56.8 GB Used)
 Total Mem          : 6.8 GB (599.8 MB Used)
 Total Swap         : 4.0 GB (0 Used)
 System uptime      : 0 days, 0 hour 6 min
 Load average       : 0.04, 0.25, 0.16
 OS                 : Ubuntu 22.04.2 LTS
 Arch               : x86_64 (64 Bit)
 Kernel             : 5.15.0-1036-azure
 TCP CC             : cubic
 Virtualization     : Hyper-V
 Organization       : AS8075 Microsoft Corporation
 Location           : San Jose / US
 Region             : California
----------------------------------------------------------------------
 I/O Speed(1st run) : 200 MB/s
 I/O Speed(2nd run) : 202 MB/s
 I/O Speed(3rd run) : 202 MB/s
 I/O Speed(average) : 201.3 MB/s
----------------------------------------------------------------------
 Node Name        Upload Speed      Download Speed      Latency
 Speedtest.net    1426.17 Mbps      9096.61 Mbps        1.12 ms
 Los Angeles, US  1424.66 Mbps      14050.23 Mbps       10.36 ms
 Dallas, US       1425.80 Mbps      8363.59 Mbps        39.13 ms
 Montreal, CA     191.80 Mbps       901.43 Mbps         68.53 ms
 Paris, FR        749.30 Mbps       4829.11 Mbps        149.39 ms
 Amsterdam, NL    606.65 Mbps       4816.54 Mbps        147.69 ms
 Guangzhou, CN    18.88 Mbps        17.38 Mbps          388.49 ms
 Hongkong, CN     6.11 Mbps         0.89 Mbps           151.28 ms
 Singapore, SG    508.98 Mbps       88.97 Mbps          168.32 ms
 Tokyo, JP        727.35 Mbps       6674.47 Mbps        104.88 ms
----------------------------------------------------------------------
 Finished in        : 5 min 21 sec
 Timestamp          : 2023-04-27 16:54:21 UTC
----------------------------------------------------------------------

網路測通也在幾個重點 Region 跑過一輪

不同虛擬平台,如果想增加些掌握度的話,資訊的確夠用了我覺得

使用 MAC 快速測試網路頻寬

Environment

Host: 2023 MAC Mini M2

user@userdeMac-mini ~ % uname -a
Darwin userdeMac-mini.local 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar 6 21:01:02 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T8112 arm64

也假設 Homebrew 已經安裝完成了 ; 其實預設也有 speedtest-cli 可以用,但如果有官方的原創,好像也不賴,重點其實也就測試數據罷了

Install

先清掉舊的

brew uninstall speedtest-cli --force\n

再來裝新的

brew tap teamookla/speedtest\n
brew update
brew install speedtest --force

How to use it?

先看 help

user@userdeMac-mini ~ % networkQuality --help
networkQuality: illegal option -- -
USAGE: networkQuality [-C ] [-c] [-h] [-I ] [-k] [-p] [-r host] [-s] [-v]
-C: override Configuration URL or path (with scheme file://)
-c: Produce computer-readable output
-h: Show help (this message)
-I: Bind test to interface (e.g., en0, pdp_ip0,…)
-k: Disable certificate validation
-p: Use Private Relay
-r: Connect to host or IP, overriding DNS for initial config request
-s: Run tests sequentially instead of parallel upload/download
-v: Verbose output

啟動執行的話就是加個 -v 即可 ; 建議 sequentially 執行畢竟也是個非對稱線路,數據不好看

user@userdeMac-mini ~ % networkQuality -v -s
Downlink: capacity 396.405 Mbps, responsiveness 684 RPM (15.609 MB transferred) - Uplink: capacity 0.000 Mbps, responsiveness 0 RPM (0 B transferred
skip
Downlink: capacity 436.744 Mbps, responsiveness 267 RPM (472.174 MB transferred) - Uplink: capacity 218.527 Mbps, responsiveness 1865 RPM (457.728 M
==== SUMMARY ====
Uplink capacity: 224.981 Mbps (Accuracy: High)
Downlink capacity: 436.744 Mbps (Accuracy: High)
Uplink Responsiveness: High (1865 RPM) (Accuracy: High)
Downlink Responsiveness: Medium (267 RPM) (Accuracy: High)
Idle Latency: 12.958 milliseconds (Accuracy: High)
Interface: en1
Uplink bytes transferred: 461.166 MB
Downlink bytes transferred: 472.174 MB
Uplink Flow count: 20
Downlink Flow count: 12
Start: 2023/4/25 上午12:00:04
End: 2023/4/25 上午12:00:31
OS Version: Version 13.3.1 (Build 22E261)

以光世代 500M/250M 802.11ax (其實雜訊不低) 測試這樣

應該也夠 WFH 用了