[SOLVED]How to add ping test to conky

Forum rules
Before you post please read how to get help
Post Reply
Crybaby
Level 1
Level 1
Posts: 10
Joined: Fri Jan 04, 2019 3:57 am

[SOLVED]How to add ping test to conky

Post by Crybaby » Wed Apr 03, 2019 4:14 pm

Hi, what I'd like to do is adding a line to conky to monitor the speed of my wired internet connection by pinging a website, like www.google.com, every few seconds.
I see many have the "up" and "down" traffic monitoring but not the ping in ms. I suppose it can be done with a script but I can't script. Help anyone?
Last edited by Crybaby on Wed Apr 10, 2019 2:34 am, edited 2 times in total.
HP Pro 3500 MT PC 64bits
Intel(R) Core(TM) i3-3240 CPU @ 3.40GHz
Dual Boot: Mint 19.1 Mate / Windows 10 Pro

User avatar
AndyMH
Level 8
Level 8
Posts: 2401
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: How to add ping test to conky

Post by AndyMH » Wed Apr 03, 2019 5:29 pm

Google conky execi
Homebrew i5-8400+GTX1080 Cinnamon 19.0, 3 x Thinkpad T430 Cinnamon 19.0, i7-3632 , i5-3320, i5-3210, Thinkpad T60 19.0 Mate

Crybaby
Level 1
Level 1
Posts: 10
Joined: Fri Jan 04, 2019 3:57 am

Re: How to add ping test to conky

Post by Crybaby » Thu Apr 04, 2019 5:44 am

AndyMH wrote:
Wed Apr 03, 2019 5:29 pm
Google conky execi
Thanks for the reply, but what I was hoping for is a line of text that I can add to conky's configuration file, as I mentioned I cannot script...
HP Pro 3500 MT PC 64bits
Intel(R) Core(TM) i3-3240 CPU @ 3.40GHz
Dual Boot: Mint 19.1 Mate / Windows 10 Pro

User avatar
AndyMH
Level 8
Level 8
Posts: 2401
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: How to add ping test to conky

Post by AndyMH » Thu Apr 04, 2019 6:37 am

an example in your conky

Code: Select all

${execi 60 ping 192.168.0.60 -c 1}
60 = run every 60 seconds
replace 192.168.0.60 with the IP address you want to ping
-c 1 means only do it once (default is it keeps pinging until you ^C to stop it).
This is going to generate as an output:

Code: Select all

andy@T430 ~ $ ping 192.168.0.60 -c 1
PING 192.168.0.60 (192.168.0.60) 56(84) bytes of data.
64 bytes from 192.168.0.60: icmp_seq=1 ttl=255 time=28.9 ms

--- 192.168.0.60 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 28.963/28.963/28.963/0.000 ms
What do you want to see as the output in conky?
An example from my conky:

Code: Select all

${execi 43200 inxi -C -c 0 | grep -o 'Intel.*'  | cut -f3- -d\ }
inxi with its parameters generates

Code: Select all

CPU:       Quad core Intel Core i7-3632QM (-MT-MCP-) cache: 6144 KB
           clock speeds: max: 3200 MHz 1: 3038 MHz 2: 2913 MHz 3: 2988 MHz
           4: 2999 MHz 5: 2922 MHz 6: 2983 MHz 7: 3014 MHz 8: 2896 MHz
but using grep and cut reduces this to

Code: Select all

Intel Core i7-3632QM (-MT-MCP-) cache: 6144 KB
which is what I want to see in my conky.

Play around with ping in a terminal to get the output you want before trying it in conky
Homebrew i5-8400+GTX1080 Cinnamon 19.0, 3 x Thinkpad T430 Cinnamon 19.0, i7-3632 , i5-3320, i5-3210, Thinkpad T60 19.0 Mate

Crybaby
Level 1
Level 1
Posts: 10
Joined: Fri Jan 04, 2019 3:57 am

Re: How to add ping test to conky

Post by Crybaby » Thu Apr 04, 2019 11:07 am

Thank you AndyMH, I understand your explanation but it sounds Greek to me, so let's see...I'd like to ping 8.8.8.8 (Google) every 10 secs and the only output I'm interested in is "time=28.9 ms", could you write it for me? I'll buy you a coffee (it is allowed isn't it?)
HP Pro 3500 MT PC 64bits
Intel(R) Core(TM) i3-3240 CPU @ 3.40GHz
Dual Boot: Mint 19.1 Mate / Windows 10 Pro

User avatar
AndyMH
Level 8
Level 8
Posts: 2401
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: How to add ping test to conky

Post by AndyMH » Thu Apr 04, 2019 5:02 pm

You start with ping 8.8.8.8 -c 1 which gives

Code: Select all

PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=124 time=12.1 ms

--- 8.8.8.8 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 12.179/12.179/12.179/0.000 ms
now we need something unique in the line you want to pull it out and ignore the rest

Code: Select all

ping 8.8.8.8 -c 1  | grep "64 bytes"
which gives us

Code: Select all

64 bytes from 8.8.8.8: icmp_seq=1 ttl=124 time=12.8 ms
the | is the pipe operator which takes the output from ping and feeds it to grep to search out the line with the text we specified.
Now we need to extract the 12.8ms from that line, for this we use cut and tell it to chop the line up using "=" as the delimiter between fields and then return the 4th field.

Code: Select all

ping 8.8.8.8 -c 1  | grep "64 bytes" | cut -f4 -d\=
which gives us what we want 12.6 ms.

This is only one way of doing it, linux gives you lots of choices, e.g. awk or sed could have been used (if I understood them enough!) instead of grep and cut.

Finally, for conky wrap it in the execi command (do you really want to ping it every 10 seconds???):

Code: Select all

${execi 10 ping 8.8.8.8 -c 1  | grep "64 bytes" | cut -f4 -d\=}
or if you want put some text in front of it.

Code: Select all

My text here ${execi 10 ping 8.8.8.8 -c 1  | grep "64 bytes" | cut -f4 -d\=}
Homebrew i5-8400+GTX1080 Cinnamon 19.0, 3 x Thinkpad T430 Cinnamon 19.0, i7-3632 , i5-3320, i5-3210, Thinkpad T60 19.0 Mate

User avatar
zcot
Level 5
Level 5
Posts: 501
Joined: Wed Oct 19, 2016 6:08 pm

Re: How to add ping test to conky

Post by zcot » Thu Apr 04, 2019 11:41 pm

Good stuff AndyMH.

Yea, but Crybaby, what about the point of it. You say you want to monitor the speed of your connection?

This is doable and works, but it does seem skewed, or not specifically right, on a number of levels.

10 secs seems excessive for the point, although sure, we can do every 1 second. But, are talking about the real need to have high performance monitoring? -maybe that's not the best implied term here. Either way, give it some thought and adjust longer or shorter depending on the real end goal.

Anyway, more to the point, this exact example is only going to give you the monitoring data of your connection only specifically against that google endpoint.

If you check a trace to that google dns address you can see how many hops you are dealing with through the internet, and might even be able to ascertain a general geographic route. But the point of it being that our "connection" is comprised of a web of hardware points and so monitoring one potentially distant endpoint could give the wrong impression, maybe.

See this example:

Code: Select all

zcot@MDD-6439:~$ tracepath 8.8.8.8
 1?: [LOCALHOST]                      pmtu 1500
 1:  <masked>                                            9.766ms 
 1:  <masked>                                            9.708ms 
 2:  ten0-6-0-11.orld11-car1.bhn.net                      13.366ms 
 3:  bun-21-orld71-car2.bhn.net                           16.177ms 
 4:  72-31-188-176.net.bhntampa.com                       16.980ms 
 5:  bu-ether44.tustca4200w-bcr00.tbone.rr.com            19.425ms 
 6:  bu-ether18.atlngamq47w-bcr01.tbone.rr.com            32.916ms asymm  8 
 7:  107.14.19.19                                         22.953ms 
 8:  ix-ae-14-0.tcore1.a56-atlanta.as6453.net             21.154ms
 9:  no reply
 ...
So, I'm in Orlando. Hops 1-3 are still in Orlando.

Hop 4 is in Tampa(heading quite to my south).

then hop 5-7 not sure without digging around,

but 8 gets to Atlanta back to the North in the opposite direction, and then there are multiple more points and the path becomes unknown.

But other traces(different ip, website, gaming server, etc.) I've seen do not go to Tampa first from here, so at that point am I monitoring "my connection" any more or just one of the many various paths of internet traffic capability?

I may experience the issue of a "traffic jam" in some isolated section of my specific ping to one specific server, yet taking a different route to some other game server even in California or something Chicago proves no trouble at all. So, in that case my monitoring against some distance endpoint is going to give me a false reading.

My nephew often storms out of his room griping about his internet from playing some ps4 games and he's watching some ping monitor and talking about these spikes.. and he's dying in some virtual world of shoot'em'up treachery because of one data packet that stumbled :lol: . He's just doesn't get that idea that all of this stuff can be just like vehicle road traffic in a big city, where you'll have an accident on occasion and it hangs things up for a short time, or there will be some road damage or an actual bad design in the road given a certain traffic load, or road construction going on and that can prove to be another type of issue changing how the results end up.

So, just thought I'd throw it out there. :wink:

I would guess the best interpretation of monitoring "the connection" would be to find only the most distant nearby connection point that is never an alternate. For me that's somewhere between hop 2 and 3. And in this particular trace clearly hop 3 to 4 looks like it probably gets onto some great fiberous pathways... -it takes me over 15ms to get across the city, yet only about another 0.8ms! to get about another 80 miles away to Tampa.

If you do a search for "speedtest" and play with those examples for a minute you might be able to find a specific server node right in your city that is setup for ping tests(a good candidate for doing this type of thing they are typically set on some great equipment pathways). Otherwise check if you can ping one of your nearby connection points. Or maybe just set 2 or 3 different very distant ping points like Miami, Maine, San Francisco or wherever is appropriate geographically to really get a good composite monitoring idea(or ask AndyMH to do it for you and interpolate each previous ping result with the current and combine and average them :P ).

Anyway, that's all. That's the end of my story. :D

Crybaby
Level 1
Level 1
Posts: 10
Joined: Fri Jan 04, 2019 3:57 am

Re: How to add ping test to conky

Post by Crybaby » Fri Apr 05, 2019 3:40 am

To AndyMH: I added your line with Ping as text and the appropriate font and color and it works. Let me know how i can buy you a coffee (a promise is a promise lol)

To zcot: oh boy I feel like I owe you an answer even though I couldn't go through all your post (newbie, level1). In windows I had a nice skin on the desktop monitoring my system that included the ping, and i wanted the same in linux. Why? To keep an eye on the ethernet connection that sometimes behaved strange, to help me choose a fast enough vpn connection and so on. I'm sure there are other/better ways to do that but this is all I need for now
HP Pro 3500 MT PC 64bits
Intel(R) Core(TM) i3-3240 CPU @ 3.40GHz
Dual Boot: Mint 19.1 Mate / Windows 10 Pro

User avatar
zcot
Level 5
Level 5
Posts: 501
Joined: Wed Oct 19, 2016 6:08 pm

Re: How to add ping test to conky

Post by zcot » Fri Apr 05, 2019 2:02 pm

Crybaby wrote:
Fri Apr 05, 2019 3:40 am
To AndyMH: I added your line with Ping as text and the appropriate font and color and it works. Let me know how i can buy you a coffee (a promise is a promise lol)

To zcot: oh boy I feel like I owe you an answer even though I couldn't go through all your post (newbie, level1). In windows I had a nice skin on the desktop monitoring my system that included the ping, and i wanted the same in linux. Why? To keep an eye on the ethernet connection that sometimes behaved strange, to help me choose a fast enough vpn connection and so on. I'm sure there are other/better ways to do that but this is all I need for now
It's fine, if it doesn't mean anything to you, then pinging google dns server is just fine for a generalization of whether the thing is working or not. :wink:

Post Reply

Return to “Compiz, Conky, Docks, & Widgets”