How to monitor the latest version of a file whose name includes a date
In the FKM plugin, use a wildcard character or the date generation function to match the filename to be monitored. There are two ways to set up the FKM sampler to look at the latest file:
- You can add a wildcard at the end of the filename. The FKM plugin supports using
*and?characters to represent a wildcard, as typically used in a UNIX shell session.
For example, we want to monitor a file named siteserver2021-09-16.log. We can use the following pattern <absolute path>/siteserver*.log when defining the source filename as seen below:
The FKM sampler can grab the latest timestamp of the file by using the Wildcard Match Time setting in the FKM Advanced tab.
This setting controls how the latest file is picked. You have the option of selecting changed or modified. Below is the difference between each setting:
Changed (default): In Unix, the changed time is updated when a file inode is updated, which occurs when a file is created, moved, copied, or the file permissions are changed.
This is the default FKM setting since most processes monitored by FKM tend to roll-over log files by creating a new file and using this for logging. In addition some backup utilities alter the modification time during backup, which can interfere with monitoring if this time is checked.
Note
The value of changed time for Windows and Unix is not the same. In Windows, the changed time is the same with creation time. It does not change even if the status of the file changes.
Modified: The modified time is updated when the content of a file is changed. This time may be preferred over the changed time if monitored log files will be renamed or their permissions changed.
When using the wildcard approach, kindly ensure that the setting Wildcard monitor all matches is not ticked (unchecked) or greyed out.
If the setting is ticked (checked), FKM will monitor all files that starts with siteserver and ends with .log. This setting can also be found in the FKM sampler’s Advanced tab.
- Since the above example contains today’s date in the filename, we can use the today function with the below date format:
<absolute path>/siteserver<today %Y-%m-%d>.log
The following xml is the Monitor Latest File Version sampler. Please note this sampler was set up on version GA5.9.0.
<sampler name="Monitor Latest File Version">
<plugin>
<fkm>
<files>
<file>
<source>
<filename>
<data>/export/home/mmuniz/FKM_TEST_FOLDER/siteserver*.log</data>
</filename>
</source>
</file>
<file>
<source>
<filename>
<data>/export/home/mmuniz/FKM_TEST_FOLDER/siteserver<today %Y-%m-%d>.log</data>
</filename>
</source>
</file>
</files>
</fkm>
</plugin>
</sampler>
To see more date generation function codes supported by the FKM plugin, please refer to the date generation section of the FKM documentation.