You are not logged in.

#41 2016-05-31 22:46:51

Eraph
Member
From: /au/qld/bne
Registered: 2016-02-29
Posts: 282
Website

Re: Show my web server on conky

Okay, back to the OP's original problem, how to probe a webserver to determine whether it's up or not. Personally I'm having trouble getting this to work and I can't see why, it's killing my Conky and I have to re-add it again. In theory it should work, but I can't see what's going wrong. Any ideas?
Is okay, I fixed it smile
Solution stolen from inspired by this answer:

Server Status: ${if_match "${execi 60 curl -sL https://www.bunsenlabs.org/index.html -w '%{http_code}' -o /dev/null}"=="200"}${alignr}${color1}Online${else}${alignr}${color2}Offline${endif}

Once working, this could be expanded to check for other errors too; 404 if it's completely offline, 5xx errors if there are server errors, etc.

Last edited by Eraph (2016-06-01 05:06:25)


Lenovo IdeaPad Yoga 13 | BunsenLabs Hydrogen (x64)
Intel Core i7-3537U | Intel HD4000 | 8GB DDR3 | 256GB SSD

Offline

#42 2016-06-01 04:48:41

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,737

Re: Show my web server on conky

@Eraph, missing } ? (at the end probably)

Last edited by brontosaurusrex (2016-06-01 04:49:46)

Offline

#43 2016-06-01 05:07:20

Eraph
Member
From: /au/qld/bne
Registered: 2016-02-29
Posts: 282
Website

Re: Show my web server on conky

brontosaurusrex wrote:

@Eraph, missing } ? (at the end probably)

By 'eck, you're right. As soon as you said it, I saw it. Fix'd and updated!


Lenovo IdeaPad Yoga 13 | BunsenLabs Hydrogen (x64)
Intel Core i7-3537U | Intel HD4000 | 8GB DDR3 | 256GB SSD

Offline

#44 2016-06-01 06:19:27

ohnonot
...again
Registered: 2015-09-29
Posts: 5,592

Re: Show my web server on conky

Eraph, a few thoughts:

If you just want to check online status, why isn't a simple ping sufficient? why muck around with curl?

In bash and dash, i can simply test for the return value of ping, so i can do sth like this:

#!/bin/dash
if ping myserver.com >/dev/null 2>&1; then
echo -n '${color 00ff00}Online'
else
echo -n '${color ff0000}Offline'
fi

i tend to pack it in a script and let conky execute that, but i'm sure it's also possible to do it from within conky.

maybe pure conky syntax can do it.

or maybe like this:

${execpi 60 dash -c "if ping myserver.com >/dev/null 2>&1;then echo -n '${color 00ff00}Online';else
echo -n '${color ff0000}Offline';fi"}

if that for some reason isn't sufficient, you can try to run a script locally on the server, one that outputs something suitable for conky, and execute that with ssh from within conky.

btw, i really recommend to use dash instead of bash for that kind of stuff (executing a script every n seconds), because it is much smaller, faster and lighter.
dash's man page is also much shorter than bash's!

Offline

#45 2016-06-01 06:30:06

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,737

Re: Show my web server on conky

Just to be pedantic: online and offline are probably misplaced terms (at least with scripts presented so far), if your conky machine is offline for example (and other reasons) you may get offline printed there when in fact in most cases it would actually mean more like missing data (that is way I suggested -- as output).

@ohnonot: ping is at the lower abstraction layer than web server, so even if ping returns true, that does not mean that web service is actually working (if that is the question), there are other reasons that ping may be unreliable in certain scenarios even for basic machine up/down status.

Last edited by brontosaurusrex (2016-06-01 06:49:25)

Offline

#46 2016-06-01 06:54:20

Eraph
Member
From: /au/qld/bne
Registered: 2016-02-29
Posts: 282
Website

Re: Show my web server on conky

ohnonot wrote:

If you just want to check online status, why isn't a simple ping sufficient? why muck around with curl?

I was primarily interested in getting the status code (200: OK, 404: Page not found, 500: Internal Server Error), but brontosaurusrex's point about pinging a host and getting a false positive is also valid. Hey, they're all good approaches, frankly I love the variety of solutions on display here!


Lenovo IdeaPad Yoga 13 | BunsenLabs Hydrogen (x64)
Intel Core i7-3537U | Intel HD4000 | 8GB DDR3 | 256GB SSD

Offline

Board footer

Powered by FluxBB