惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Heimdal Security Blog
A
Arctic Wolf
K
Kaspersky official blog
V
Vulnerabilities – Threatpost
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Simon Willison's Weblog
Simon Willison's Weblog
L
LINUX DO - 热门话题
MongoDB | Blog
MongoDB | Blog
T
Threat Research - Cisco Blogs
D
Docker
爱范儿
爱范儿
T
Tenable Blog
C
Check Point Blog
B
Blog
C
Cisco Blogs
Vercel News
Vercel News
The Cloudflare Blog
T
Threatpost
NISL@THU
NISL@THU
T
Tor Project blog
V2EX - 技术
V2EX - 技术
P
Palo Alto Networks Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Tailwind CSS Blog
G
GRAHAM CLULEY
P
Privacy & Cybersecurity Law Blog
SecWiki News
SecWiki News
博客园 - 司徒正美
S
Security @ Cisco Blogs
GbyAI
GbyAI
S
Secure Thoughts
Microsoft Security Blog
Microsoft Security Blog
The Register - Security
The Register - Security
Recorded Future
Recorded Future
Cloudbric
Cloudbric
Webroot Blog
Webroot Blog
N
News and Events Feed by Topic
Y
Y Combinator Blog
博客园_首页
T
Troy Hunt's Blog
The Hacker News
The Hacker News
雷峰网
雷峰网
Google DeepMind News
Google DeepMind News
U
Unit 42
AWS News Blog
AWS News Blog
PCI Perspectives
PCI Perspectives
V
Visual Studio Blog
博客园 - 聂微东
有赞技术团队
有赞技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell

Posts on Noah Bailey

How to turn anything into a router Deploy to Cloudfront from GitHub using OpenID Connect Backup Postgres databases with Kubernetes CronJobs The spelling error made 200 billion times a day Restarting Kubernetes pods using a CronJob You've just bought a new domain. Now what? Who Sawed My Motherboard??? Linux on the P8 Aliexpress Mini Laptop Recovering Mysql/Mariadb after a nasty crash Using EXIF data to pick my next lens Converting and developing RAW photos on Linux automatically Thank you, 2016 iPhone Don't Make It Work Self-hosted Surveillance with ZoneMinder Backups, Monitoring, and Security for small Mastodon servers Block web scanners with ipset & iptables Executing commands over SSH with GitHub Actions Debian Sid on encrypted ZFS Protect your dangerously insecure redis server Debian: the luxurious boring lifestyle Monitor radiation with a Raspberry Pi Simple Linux server alerts: Know your performance, errors, security, syslog, and security NUC crashes on debian 11 - How I fixed it Basic Linux server security with fail2ban, ossec, and firewall Windows 11 will create heaps of needless trash Domesticated Kubernetes Networking The Cursed Certificate Our mostly disposable and entirely stupid world Trying out OpenBSD (as a Linux geek) Making VoIP Calls with Antique Rotary Phones Monitoring WAN latency with InfluxDB The Zeroshell botnet returns Installing Gentoo on a vintage Thinkpad T60 Malware emails 2: Russian boogaloo TP-Link Device Weirdness ElasticSearch broke all my nice things (a story of cascading failure) A New Botnet is Targeting Network Infrastructure Malware on the Wire: Monitoring Network Traffic with Suricata and ClamAV Cloud Threat Protection with OSSEC and Suricata Malware Emails From Jerks Surviving the Apocalypse with an Offline Wikipedia Server Being Attacked by Bots Linux Router, Firewall and IDS Appliance You Probably Don't Need a VPN Fix an Oversharded Elasticsearch Cluster Automating KVM Virtualization Update all your linux servers as fast as possible Cleanup Systemd Journald Storage Stop Putting Your SSH Keys on Github! Clustering KVM with Ceph Storage Stealing Windows Sessions FreeRadius Active Directory Integration Retrieving WPA2 Keys on Windows Deploy MDT Litetouch on Linux with TFTPD and Syslinux Generating MSI transform files with Orca The Inflatable Dinghy Generating Cisco IOS config files with Python Homebrew SAN Getting Cloudy
Monitoring WAN speed with speedtest-cli and ElasticSearch
2020-12-10 · via Posts on Noah Bailey

Similar to another post about WAN latency, this is a simple system to automate periodic internet speed tests. The two main components are speedtest-cli and ElasticSearch. These were chosen because I already had both set up and running, along with all the visualization and analytical software. To get a basic POC set up, just install ElasticSearch and Kibana with Docker. Once the node/cluster is running, the ‘speedtest client’ server can be set up.

Install speedtest-cli

Most linux systems will have a reasonably up to date version of this program in their repositories. In my case, Debian 10 has a version 2.0.2 which is fine for our purposes.

sudo apt-get install speedtest-cli

Otherwise, the latest version can be installed from Github - https://github.com/sivel/speedtest-cli

Once installed, be sure to test it by simply running speedtest-cli in the shell.

Though there are many ways to bring the data into the database, I am opting to POST it directly each time the script runs. Another way would be to log locally then use a log collector to forward to Elasticsearch, such as Fluentbit or Filebeat.

Data format

To collect the data, speedtest-cli is used with the --json flag.

speedtest-cli --server 12345 --json
{
    "download": 200132642.07196137,
    "upload": 32705066.252213296,
    "ping": 29.77,
    "server": {
        "url": "http://speedtest.xxx.ca:8080/speedtest/upload.php",
        "lat": "43.000",
        "lon": "-81.000",
        "name": "Town, ON",
        "country": "Canada",
        "cc": "CA",
        "sponsor": "Small Town Cable TV",
        "id": "12345",
        "host": "speedtest.xxx.ca:8080",
        "d": 53.79452630150419,
        "latency": 29.77
    },
    "timestamp": "2020-12-11T01:23:31.996470Z",
    "bytes_sent": 41148416,
    "bytes_received": 250479164,
    "share": null,
    "client": {
        "ip": "203.0.113.12",
        "lat": "42.000",
        "lon": "-84.000",
        "isp": "Internet Co.",
        "isprating": "3.7",
        "rating": "0",
        "ispdlavg": "0",
        "ispulavg": "0",
        "loggedin": "0",
        "country": "CA"
    }
}

The most important part is that the timestamp field is formatted in such a way that it can be imported cleanly into Elasticsearch - fortunately it is, so this JSON object can be uploaded directly into the database.

Bash script

The script is very simple - all it does is run the speedtest program, then send that data to Elasticsearch.

/opt/speedmon.sh

#!/bin/bash
ELASTICSEARCH_SERVER="$1"
DATEFMT=$(date +%Y.%V)

# Select a random server from the 10 closest:
SPEEDTEST_SERVER=$(/usr/local/bin/speedtest-cli --list | tail -n +2 | head -n 10 | awk '{gsub(/\)/,""); print $1}' | shuf | head -n1)

# Run a speedtest against the randomly chosen server:
SPEEDTEST_JSON=$(/usr/local/bin/speedtest-cli --json --server $SPEEDTEST_SERVER)

/usr/bin/curl -s -H "Content-Type: application/json" -XPOST "http://${ELASTICSEARCH_SERVER}:9200/speedtest.$DATEFMT/doc" -d "$SPEEDTEST_JSON" >> /dev/null

The date format is very important in this case, since the ElasticSearch index will be created with the format year-week, or yyyy.ww. This allows the indices to be rotated semi-regularly without causing too many shards to be created. Since this test runs ~hourly each month would have less than a thousand documents, so storage isn’t really a consideration.

Cron job

The script is scheduled to run hourly:

0 * * * *   nobody    /opt/speedmon.sh

Dashboard

There are many ways to visualize Elasticsearch data, in the case I have used Grafana to chart the average download & upload speed for my network.