How to monitor your ping latency in macOS with Go Programming Language
Create you own ping latency monitoring on your mac during the pandemic.
How to monitor your ping latency in macOS with Go Programming Language
Background Story
During this COVID-19 period, we are encouraged to work from home. With the limitations of the existing internet, we often want to find out how much our ping latency. In this case, we can just execute a ping command from the terminal to get our ping latency. But that’s bad, we must switch the window to the terminal if we want to watch our latency. In this article, we will learn how to create your own tools for monitoring ping latency, and it will appear in the system tray.
Requirements
- Mac OS
- Go programming language installed
Coding section
We need to import some library
- Library to ping
- Library to use MacOS system tray
Create the ping function to return the latencies
|
|
In code above, I use google.com as a parameter for measuring latency. After that we need onReady, and onExit function to make your app running in the system tray:
|
|
In onReady function above we use Go routine, to ping google.com every two second. After we get the result, we will set it to system tray title. After that, we need to create our main function like the code below:
|
|
Actually, onExit function is not really needed in this tool. That’s a function if you want to gracefully close the tools which is not used in this case.
Building section
If you compile the Golang code, you will get an executable binary not .app extensions like macOS common applications. So I already created a shell script to create macOS application of this tool. Here we go:
|
|
After your build success, you will find your application in your home directory applications. You can use login items in system preferences to use auto startup application after your mac boot.
That’s it thank you for reading my article. If you want to see my Github, visit the link below. Hope you guys enjoy and stay productive during this pandemic.