Ruby Ping for 1.9.1

ruby ping for 1.9.1

You can always do this and use regexps to parse the result or just check the exit status:

ping_count = 10
server = "www.google.com"
result = `ping -q -c #{ping_count} #{server}`
if ($?.exitstatus == 0) do
puts "Device is up!"
end

Ping return values that you can check against:

The ping utility returns an exit status of zero if at least one response was heard from the specified host; a status of two if the transmission was successful but no responses were received; or another value (from <sysexits.h>) if an error occurred.

http://www.manpagez.com/man/8/ping

Are Ruby odd-numbered releases stable and for production? (eg. 1.9.1, 1.9.3)

Yes, it is in fact true that odd-numbered releases were unstable in the past. (However, note that "odd-numbered" refers to the minor number, not the tiny number, i.e. 1.1.x, 1.3.x, 1.5.x and 1.7.x were unstable development releases.)

This was changed with Ruby 1.9 for a very simple (and very embarassing) reason: there are tons of Ruby scripts as well as shell scripts (including the scripts that the Ruby maintainers themselves use to automate the development, testing and releasing of Ruby) out there, which simply assume that the major version is a single digit. They would simply break otherwise, mostly because they did things like

if RUBY_VERSION > '1.6.3'

which fails for '1.10.0', because the string '1.10.0' is lexicograhically smaller than the string '1.6.3'.

As a result, it was decided to give up the distinction between odd-numbered and even-numbered releases, and make the next stable release 1.9, because that was easier than convincing everybody that their scripts are broken.

So, the 1.9.0-x series of releases corresponds to 1.9.x under the old numbering scheme (i.e. a series of development releases in preparation of the next release) and the 1.9.(x > 0) series of releases corresponds to 1.10.(x-1), i.e. 1.9.2 is really 1.10.1. (Well, except that 1.9.1 was a botched release, so it is more like a 1.10.0-pre and 1.9.2 is 1.10.0 and 1.9.3 is 1.10.1.)

Also, Ruby 2.0 is intended to be fully backwards-compatible, which means that it's really 1.12 ... does that clear up any confusion? :-)

So, in summary: Yes, it used to be true (but in a different way than you thought), but it is no longer true, and hasn't been true since the 1.7 series which ended with the release of Ruby 1.8.0 in August of 2003, over eight years ago.

Why is this running like it isn't threaded?

Ruby threads are controlled by Ruby Interpreter. to operating system, Ruby Interpreter is still just one process(just like any other processes). Ruby Interpreter split that one process into multiple ruby threads.

`ping #{xaddr}`  

this line forces the Ruby Interpreter to temporarily give up its control, since you are asking the operating system to execute another process. The ruby interpreter will not regain its control until after the 'ping' finishes. That's probably why the code is slow.

How do i monitor my mongodb server in ruby?

If you are getting timeouts during periods of low activity that go away after a few minutes of requests, a likely cause is that you have stale connections in your connection pool that are discovered when you try to use the connections. A stale connection will result in a timeout error to your application and the database connection will be re-established. As your application makes new requests, the stale connections will be refreshed and the timeout errors will go away.

You may be able to fix this by reducing your timeout value, but you could also handle by retrying the query on a timeout exception. MongoHQ support may have some specific advice on setting your timeout value appropriately for their service.



Related Topics



Leave a reply



Submit