DEV Community

Cover image for เฝ้าดูความเร็วอินเตอร์เน็ตที่บ้าน
Damrongsak Reetanon
Damrongsak Reetanon

Posted on

เฝ้าดูความเร็วอินเตอร์เน็ตที่บ้าน

บ่ายวันอาทิตย์ นั่งเตรียมเนื้อหาบรรยายอยู่ ก็เหลือบไปเห็น Supadej Suthiphongkanasai โพสต์ว่า "ไปเจอ Git อันนึง น่าสนใจดี เป็น Docker Project ที่จะทำ Speedtest ทุกๆ 1 ชม แล้วเก็บ stat ลงกราฟไว้ ..."
น่าสนใจดี กำลังนั่งง่วง ๆ อยู่เลย ก็เลยทิ้งงาน ลองแวะไปดู Repo ใน Github ดูหน่อยสิว่าจะยังไงดี ... นั่งดูสัก 10 นาที ก็เลยตัดสินใจ ก็ลองเล่นดูเลยก็ได้

  • ว่ากันจริง ๆ แล้วใน Github ของ Henry Withaker ที่ public ไว้ก็มีอยู่ 30 repos แต่สิ่งที่เราจะลองดูกันก็คือ repo ที่ชื่อว่า Speed-Tracker ซึ่งมี source code และคำอธิบายอย่างละเอียดในการใช้งาน โดยรวม ๆ ก็บอกว่า เค้าใช้ Laravel เขียน back-end, ใช้ React เขียน front-end ส่วนของการทดสอบความเร็วก็ใช้ CLI ของค่าย speedtest.net และสุดท้ายใช้ Chart.js เป็นคนวาดกราฟออกมา
    ** โดย default จะวัดความเร็วทุก 1 ชั่วโมง (แต่ว่าเราตั้งความถี่เองได้)
    ** กำหนดได้ว่าจะดูข้อมูลย้อนหลังได้กี่วันตอนแสดงผล
    ** สามารถ backup & restore ข้อมูลที่เคยเก็บไว้ได้ในรูปแบบของ JSON หรือ CSV
    ** สามารถส่งข้อความไปยัง Slack, Discord และ Telegram ได้ ถ้าผลที่ speedtest วัดได้ มีค่าต่ำกว่าหรือสูงกว่า ค่าที่คำหนดไว้
    ** ทำงานร่วมกับ healthcheck.io, Organizr และ InfluxDB ได้

  • ลงมือกันเลย โดยที่เครื่องที่จะใช้ได้ทำงานติดตั้ง Docker และ docker-compose ไว้เรียบร้องแล้ว จากนั้นก็สร้าง directory data เอาไว้เก็บข้อมูล และให้เข้าถึง speedtest-tracker ที่ TCP/8765

# mkdir data
# cat > docker-compose.yaml <<EOF
version: '3.3'
services:
     speedtest:
         container_name: speedtest
         image: henrywhitaker3/speedtest-tracker
         ports:
             - 8765:80
         volumes:
             - ./data:/config
         environment:
             - OOKLA_EULA_GDPR=true
         logging:
             driver: "json-file"
             options:
                 max-file: "100"
                 max-size: "2048k"
         restart: unless-stopped
EOF
# docker-compose up -d
Creating network "speedtest_default" with the default driver
Pulling speedtest (henrywhitaker3/speedtest-tracker:)...
latest: Pulling from henrywhitaker3/speedtest-tracker
c91af5d1b23e: Pull complete
740fcfa9e15a: Pull complete
ce5b3694a6d6: Pull complete
a83d676a55d9: Pull complete
38ac933c5d8d: Pull complete
dc32e0469fc9: Pull complete
2692dc6e8a90: Pull complete
36a44203a304: Pull complete
df68ab8ba510: Pull complete
712e86a465e0: Pull complete
b87cc77a8de9: Pull complete
Digest: sha256:47159a9402291275bd9f8a8ed4f5c1ce8502de216465ed29da8a3c995b807df1
Status: Downloaded newer image for henrywhitaker3/speedtest-tracker:latest
Creating speedtest ... done
Enter fullscreen mode Exit fullscreen mode
  • รอสัก 1 นาที แล้วก็ใช้ browser เปิดไปที่ http://hostname:8765 และถ้าต้องการทดสอบการวัดความเร็ว ก็กดปุ่ม "Test again" ได้เลย

Image description

  • สามารถปรับแต่งความถี่ในการวัดความเร็วได้ โดยเลือกเมนู Settings ที่ tab General จากเดิมที่กำหนดไว้ทุก ๆ 1 ชั่วโมง 0 * * * * ผมแก้ไขให้การวัดความเร็วทุก ๆ 30 นาทีเพื่อให้เห็นผลการทำงาน ในช่วงทดสอบได้ชัดเจนขึ้น โดยกำหนดที่ Schedule ให้เป็น */30 * * * *

Image description

ขอให้สนุกกับ technology ครับ

Mady by มูลค่าความสุข

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay