I recently had a couple customers ask if we are able to monitor a Windows folder and count the number of files that are present. Although this is not something the Infrastructure monitoring agents do out of the box, Foglight has built in tooling for creating your own script agents.
Luckily for me, I found that a colleague had already written an agent to do just this. It also contained code for using agent properties with a script agent, versus having to hardcode parameters into the script.
First, we will need to save some files. We have attached (hopefully!) to this post:
1- monitoring-policy.xml
2- Filecount.bat.txt - this is the script, it will need to be saved as Filecount.bat
(Please visit the site to view this file)
(Please visit the site to view this file)
We will first start by loading the monitoring-policy.xml file using fglcmd from the command prompt.
C:\Quest_Software\Foglight\bin\fglcmd -srv fmshost -port 8080 -usr foglight -pwd foglight -cmd util:configimport -f C:\Foglight\FileCount\monitoring-policy.xml
You will need to change the items in red to suit your environment. Usr is the foglight user (with Administrator role) and pwd is the password.
Once that completes, navigate to Administration -> Tooling -> Script Agent Builder. Select the Filecount.bat file, then click "Build Script Agent". Internally, this creates a cartridge that you can view in Cartridge Inventory and an agent package that can be deployed to a Foglight Agent Manager (fglam). The script is set to monitor the filesystem of the machine running the fglam. So go ahead and deploy the package and create an agent using the Agent Status page.
You can edit the properties for the Filecount agent. As a good practice, I'll clone the Directories list and make my entries there. Once you're done adding directory names, click Save on the way out, then activate the agent.
That's pretty much it! The data will get collected into a Filecount topology object, and is now available to evaluate in rules, to place on a dashboard, etc. Here is a quick dashboard which also shows the path I took to get to the data.
From the Data tab, it was easiest to expand "Management Server" -> "All Agents" -> Filecount* agent name, then Tables. Each folder for that agent then has a metric named "fileCount" that can be dragged to the dashboard.
Bonus Time - we'll see who has read this far. The script collects the count of files in a folder. If you just run Filecount.bat from your command prompt, there is a hard-code to return c:\ and c:\temp. You might notice the values returned are different from what you get when you run "dir" on those folders. Post below if you can explain why. I'll post an update if/when we get some responses..