Hi.
This post presents a .Net centric view of the newly introduced support for better runtime monitoring into db4o (as described in this post), so, before you continue reading please, go read the aforementioned post! I'll assume you've read it.
Have you read it yet?
No? Go there, I'll wait for you.
Ok. let's continue...
As you may already know for now, in the last few weeks, we have been busy adding more sophisticated monitoring support to db4o in the form of "Runtime Statistics" a term that we coined because we needed a common way to refer to "these things" in a platform agnostic way (you know, Java developers would not be happy if we just used "Performance Counters" and .Net developers would not be happy either had we choose MBean :); in this post I'm going to use the more natural name in the platform: Performance Counters. If, for some reason, you are not familiar with this concept or want to refresh your knowledge on the subject we recommend to read the MSDN documentation here and here and also this article on codeproject.
After reading the companion post you should already have a good idea about what monitoring data db4o allows you to collect and how it can be useful but we intentionally omitted a description of how to configure and consume this information which is the goal of this post.
The first step to be able consume monitoring information is to let windows know about the counters which means that you either run Db4oTool with the install-performance-counters command line parameter or call the method Db4oPerformanceCounters.Install() from your code. Note that this step is required only once per machine running db4o and also that it requires administrative rights so you probably will perform it at application install time (as opposed to runtime).
With the counters in place, the next step is to configure db4o to start collecting the data. As we explained in the companion post, the process of collecting such information does pose some overhead so we adopted an opt in model grouping counters in the following categories (each category in bold configures db4o to collect statistics for the respective set of counters):
In order to select the category/categories you are interested in, add an instance of the respective xxxxxMonitoringSupport() class to db4o configuration as in the following sample:
IEmbeddedConfiguration config = Db4oEmbedded.NewConfiguration();
// Query
config.Common.Add(new QueryMonitoringSupport());
config.Common.Add(new NativeQueryMonitoringSupport());
// Networking
config.Common.Add(new NetworkingMonitoringSupport());
// IO
config.Common.Add(new IOMonitoringSupport());
// Reference System:
config.Common.Add(new ReferenceSystemMonitoringSupport());
// FreeSpaceManager
config.Common.Add(new FreespaceMonitoringSupport());
Thats it!
Once configured no other action is required to start collecting the information (other than exercising the pieces of code that triggers the interesting counters :)
Next step is to consume the information being collected which can be done either through PerfMon (the main tool in Windows designed to view such counters) or programmatically. We are going to show you how to see the counters using PerfMon first, so start PerfMon.exe and you should see its main window (since I'm running Windows 7, your actual PerfMon window may look a little bit different than mine).
Next step, press + button in the toolbar to select which counters you want to monitor;
In the window that shows up (in Available Counters) locate and expand Db4o and then select the desired counters. Next, select the instances you want to monitor.
Each opened db4o database (or client) will be represented as an instance in the list "Instances of selected object". Local and server databases will display the database file name (in the sample above mydb.db4o) and clients (in C/S mode) will be shown as local port => server ip:port). You may monitor as many instances as you want simultaneously.
That's it again ;)
Now that you already know how to monitor db4o performance counters it is time to learn how to consume them programmatically since this can be useful in some scenarios. Accessing db4o performance counters programmatically is just a matter of calling the Db4objects.Db4o.Monitoring.Db4oPerformanceCounters.CounterFor() method passing the counter and the object container you want to monitor as in the following sample:
PerformanceCounter bytesReadPerSec;
bytesReadPerSec = Db4oPerformanceCounters.CounterFor(PerformanceCounterSpec.QueriesPerSec, db);
Now you can query PerformanceCounter's reference for any of it's properties / methods.
Have fun (and let us know what you think could be improved in this subject!)
Db4o Team!