PRTG Network Monitor, Part 2

Since my last post on the PRTG monitor, I’ve added some more probes (thanks to their offer of a free upgrade to 30 sensors).

However, before I got started, the monitor showed that the system health had an alert:

image

I clicked on the red alert box, and the detail page is displayed:

image

The server that hosts the PRTG Network monitor is intentionally underpowered as to consume as little electricity as possible (it’s a HP ProLiant Micro Tower Server as seen here on Amazon. It’s 64 bit, had has 4 non-hot swappable drive bays. It runs 64 Bit Windows 8 very nicely.) Because it’s underpowered, it often can be utilized heavily by the various routine processes that are always running on it. I logged in to the server (remote desktop), and the new Task Manager app made it clear what was happening:

image

I’d started a “maintenance” cycle earlier which apparently included a disk defrag.

Back to the sensors – I‘ve got quite a few network connected devices in the house (see details here). So, there are a number of things that can be monitored, etc. One thing in particular is (ironically?), a network monitor , from Synaccess Networks (the NP-02, which can detect the status of our internet connection and automatically toggle the power to the DSL modem if no internet connection is detected).

So, initially, the list of Devices automatically found included the NP-02. I wanted to add a probe, so, next to the name of the device, you can click Add Sensor.

image

Note that originally, it was just listed by IP Address, but the name is editable:

image

I clicked Add Sensor:

image

There are many things that can be monitored. Each click of a filter at the top reduces the options at the bottom.

image

I selected Ping:

image

You can then edit more sensor appropriate settings (and override defaults):

image

Then to the summary screen for the device:

image

Not much to show right away of course.

Awesomely, it automatically discovered a network connected printer, and selected several probes (I deleted all but one):

image

It’s a very cool system that works well for my home needs. While I can’t speak to the viability of this in a commercial setting, it’s certainly capable and well worth looking at for home or business.

PRTG Network Monitor for Windows

mysql monitoringMy current router/firewall/VPN device has an unfortunately mediocre live monitor for bandwidth statistics, but supports SMNP. So after a reasonably painful search for decent free options (oh boy are there some awful ones!), I installed the freeware version of the Paessler PRTG monitor so that I could easily see the network statistics for our internet connection and a few other neat things that it can track out of the box. I installed it on a shared, always-on Windows 8 Pro PC that does a ton of other things for our house like security camera monitoring, file shares, etc. It installed easily and was up and running quickly. While the paid version is far outside of my budget for this type of thing (budget=$0), the freeware version had just the right features for me.

It’s got tons of things it can monitor, but with the freeware limit of 10 devices, I’ve got it monitoring traffic, disk and a few other things:

image

I’ve got the default page set to just show the internet bandwidth (in/out):

image

The software automatically scanned my network and found way more things to monitor originally than I had expected.

It’s a reasonably sophisticated Ajax web application that works well on modern browsers. My only complaint about the experience is that it requires me to login frequently, yet has a button that makes it basically not be important (a button that if the login is the default, just automatically logs me in). I’d really like it to instead jump straight to the dashboard to show the statistics (maybe in a read-only mode).

image

(And right now, if you blog about the software, they’ll upgrade your license to 30 keys, so I’m doing that right now).

Using $inc to increment a field in a sub-document in an array and a field in main document

(Blog post inspired by question I answered on StackOverflow)

Lets say you have a schema in MongoDB that looks something like this:

{
  '_id' : 'star_wars',
  'count' : 1234,
  'spellings' : [ 
    { spelling: 'Star wars', total: 10}, 
    { spelling: 'Star Wars', total : 15}, 
    { spelling: 'sTaR WaRs', total : 5} ]
}

Atomically, you’d like to update two fields at one time, the total for a particular spelling which is in a sub document in an array, and the overall count field.

The way to handle this is to take advantage of the positional array operator and the $inc operator.

Starting with just updating the count, that’s easy:

db.movies.update( 
    {_id: "star_wars"}, 
    { $inc : { 'count' : 1 }}
)

The query matches on the document with the _id of star_wars, and increments the count by 1.

The positional operator is where the mongo-magic comes into play here. If you wanted to just update a single sub-document in the array, add it to the query. First, we’ll try finding the right document:

db.movies.find( {
    _id: "star_wars", 
    'spellings.spelling' : "Star Wars" }
)

That matches the right document, but also returns all of the elements of the array.

But, wait, there’s more! When you match on an element/document of an array, the position of the match is remembered and can be used in the update phase. You do that using the positional operator. Using the document above, you’ll use this: spellings.$.total. If you knew the specific index into the array, the $ could have been replaced with the zero-based index number (like a 1 for example in this case: spellings.1.total).

Putting it all together then results in a slick and simple way of incrementing multiple fields in a document.

db.movies.update( 
    {_id: "star_wars",
     'spellings.spelling' : "Star Wars" },
    { $inc : 
        { 'spellings.$.total' : 1, 
        'count' : 1 }})

Results:

{
  '_id' : 'star_wars',
  'count' : 1235,
  'spellings' : [ 
    { spelling: 'Star wars', total: 10}, 
    { spelling: 'Star Wars', total : 16}, 
    { spelling: 'sTaR WaRs', total : 5} ]
}

RewriteCond for web based RSS readers

Now that Google Reader is gone, there are more than a handful of replacements popping up. In order to allow images to show in the web-based RSS readers, I needed to edit the .htaccess file for my web site to allow the images to show, as the default for my web site is to prevent hotlinking from most websites (other than wiredprairie.us).

I’ve tried to gather those that seemed popular, so I’m putting the list I’ve got here so that it might help others (and maybe some of you will have other suggestions):

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?wiredprairie.us [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://www.google.com/reader/m/view/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://cloud.feedly.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?feedly.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?pinterest.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?bloglines.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?feedly.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?netvibes.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?facebook.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?twitter.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?feedspot.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?digg.com/reader/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://reader.aol.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)newsblur.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)theoldreader.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)hivereader.com/.*$ [NC] RewriteRule \.(jpe?g?|gif|png|bmp|tiff?|pic|mp3|doc|xls|ico)$ - [F,NC,L]

Modern C++, iterators and loops compared to C#

It has been a while since I looked much at modern C++. I’ve started intentionally simple and was exploring some of the ways that a simple list can be iterated. I hate to say this, but I remember the days when the standard template library was not necessarily something that was the easiest to get working on Windows with a Microsoft C++ compiler in a simple, safe and reliable way. My, how times have changed for the better!

While the overall syntax of C++ lacks the refined and designed elegance of a C# application, it has come a very long way!

I’ve thrown together a simple sample. The code creates a list of strings, pushes (not add, arrgh!) strings onto the list, and then iterates through the list in three similar, but syntactically different methods below:

image

OK, there’s a few awesome things here that make C++ much more approachable these days:

  1. a decent string class! No more hunting for a library or header file that has most of the functionality you need. (there’s a wstring as well for wchar_t needs)
  2. All the common Data structure types like list, map, vector, etc… that you might need without writing them your self.
  3. With using, the code doesn’t need to refer to types with namespaces (much like C#). So, instead of std::list<std:string>, it’s just list<string>, which I consider far more readable at a glance.
  4. No weird casting or worrying about strings when values are passed to the push_back function. Again, it just works.
  5. auto – the var of C# is called auto in C++. If I hadn’t used auto in the first iterator, the code would have declared the type as list<string>::iterator. While not terrible, auto reads well, as it’s likely that I’ll not need the detailed declaration to understand what’s being iterated upon.
  6. Second option is just syntactical sugar as it internally uses a standard for loop like in the first example internally. But, you’ll note there are anonymous functions/lambdas! The square [] brackets is the capture clause of the lambda expression. Unlike C#, where the compiler automatically determines what outer scoped variables will be used by the inner lambda function, in C++, it’s necessary to explicitly declare what is required. While this is a bit annoying, there are times where this extra declaration might cause programmers to think twice about all of the variables that are required in the lambda expression. In this instance, there aren’t any variables needed, so it’s empty.
  7. The last example is the most concise, and maybe a little less friendly at first and that’s mostly due to the heritage of C++ and how to make code most efficient. It’s called a range-based for statement. First, the code is using auto again and the type is a string as it’s declaring the type used within the list. The & symbol remember is a reference and the const is indicating that the value will not be changed by the inner block. These two together ideally make it so the value is observed in-place, without any need for a copy.

While the range-based for statement isn’t quite as readable as C#:

image

I think you might agree that the C++ version is more than passable, and nearly friendly!

image

(Aside, there is a shortcut initializer list syntax that can be used with non-aggregate types in C++, so an int for example that would have gotten rid of the calls to push_back).