Geeking out w/ networkQuality

macOS Monterey has a new command line utility called “networkQuality.” Per the man page:

networkQuality allows for measuring the different aspects of Network Quality, including:

     Maximal capacity (often described as speed)

     The responsiveness of the connection. Responsiveness measures the quality of your network by the number of roundtrips completed per minute (RPM) under working conditions. See https://support.apple.com/kb/HT212313

     Other aspects of the connection that affect the quality of experience.

The best part of this tool (IMO) is that it measures the “Maximal capacity” or speed of my internet connection. I know there are other speed test tools available but I like that this one is built-in. As pointed out by Jeff Butts at macobserver.com, “networkQuality uses Apple’s CDN at https://mensura.cdn-apple.com/api/v1/gm/config as the target for its testing.” I’ve seen pretty big differences between using networkQuality and other web based speed testing sites; but, networkQuality seems to most closely match the speed results reported from my eero router.

Lately, I’ve been using GeekTool to add scripts that report the battery percentage of my connected bluetooth devices (AirPods Pro and my Apple Keyboard). I decided that my download speed would be a good addition. I wrote this small python script that parses the JSON output in Mbps and displays the result in the lower left corner of my screen. I have this geeklet set to run every 30min.

#!/usr/bin/python

import json
import subprocess

def mbps(speed):
    return int(round((speed / 1024 / 1024), 0))

# Args: c – outputs in JSON, s – tests download and upload separately
cmd = ["/usr/bin/networkQuality", "-c", "-s"]

response = json.loads(subprocess.run(cmd, capture_output=True, text=True).stdout)

# Download Speed in Mbps
dl_throughput = mbps(response.get("dl_throughput", 0))

# Upload Speed in Mbps (not used at the moment)
# ul_throughput = mbps(response.get("ul_throughput", 0))

print(dl_throughput)

Screenshot of my GeekTool geeklets. Left to right: left AirPod battery, right AirPod battery, keyboard battery, networkQuality download speed in Mbps