# AppDynamics File Watcher Extension

## Use Case

The AppDynamics File Watcher Extension can be used to provide metrics from configured files and directories.

## Prerequisites

The extension can be deployed on the same box as the one with the files to be monitored, or remotely if monitoring shared network paths. For Windows network paths, it is recommended to map the paths locally prior to monitoring.

## Installation

1. To build from source, clone this repository and run 'mvn clean install'. This will produce a FileWatcher-VERSION.zip in the target directory Alternatively, download the latest release archive from GitHub
2. Unzip the file FileWatcher-[version].zip into <MACHINE_AGENT_HOME>/monitors/
3. In the newly-created directory "FileWatcher", edit the config.yml to configure the parameters (See Configuration section below)
4. Restart the Machine Agent
5. In the AppDynamics Metric Browser, look for Application Infrastructure Performance|\|Custom Metrics|File Watcher. If SIM is enabled, look for the metric browser under the Servers tab.

## Configuration

Configure the File Watcher Extension by editing the config.yml & monitor.xml files in <MACHINE_AGENT_HOME>/monitors/FileWatcher/.

### 1. Tier Configuration

Configure the Tier under which the metrics should be reported. This can be done by adding the Tier ID to the metric prefix. metricPrefix: "Server|Component:<TIER_ID>|Custom Metrics|File Watcher|"

If SIM is enabled, please use the default metric prefix. metricPrefix: "Custom Metrics|File Watcher|

### 2. Path Configuration

The paths to be monitored must be configured under pathsToProcess. The following fields are present in each:

#### 2.1 displayName

A mandatory field that acts as an alias for a configured path in the Metric Browser.

#### 2.2 path

The actual path to the directories or files to be monitored. Consider our directory to be /src/test/resources/TestFiles. There are multiple scenarios that can be configured in the pathsToProcess section. The use cases supported are as follows:

(Note: For Windows, path should be configured with 4 backslashes as separator - C:\\\\src\\\\test\\\\resources\\\\TestFiles.
For Windows Network paths, you can configure path like - \\\\\\\\1.2.3.4\\\\abc\\\\def\\\\ProductI)

#### 2.2.1 Monitoring a specific directory

path: "src/test/resources/TestFiles" Directory metrics for 'TestFiles' will be generated. Please ensure that the directory does not end with a slash for this scenario.

#### 2.2.2 Monitoring a specific file

path: "src/test/resources/TestFiles/TF1.txt" File metrics for TF1.txt will be generated in this case. Refer to the Metrics section to differentiate between Directory metrics & File metrics.

#### 2.2.3. Monitoring files of a specific type

path: "src/test/resources/TestFiles/*.txt" This will generate file metrics for only txt files withing TestFiles.

#### 2.2.4. Monitoring files of any type

path: "src/test/resources/TestFiles/*.*" This will generate file metrics for files of all extensions within TestFiles.

#### 2.2.5. Directory and File Glob Patterns

path: "src/test/resources/TestFiles/2020*/*.log" This will generate file metrics for all log files within subdirectories of TestFiles that begin with '2020'.

#### 2.2.6 Non-recursive, single level

path: "src/test/resources/TestFiles/*" This will generate file and directory metrics for all files and subdirectories within TestFiles only at the first level.

#### 2.2.7 Fully Recursive

path: "src/test/resources/TestFiles/**" This will recursively generate file and directory metrics for all files and subdirectories within TestFiles at all levels.

#### 2.2.8 Fully Recursive + File Extensions

path: "src/test/resources/TestFiles/**/*.*" This will recursively generate file metrics for all files that match the glob pattern within TestFiles at all levels.

#### 2.3 ignoreHiddenFiles

A flag to include or exclude any hidden files or directories encountered.

#### 2.4 excludeSubdirectoriesFromFileCount

Every directory has a metric that counts the number of files within that directory. When this flag is set to true, the extension will simply exclude any subdirectories from this count.

#### 2.5 recursiveFileCounts

The count mentioned in 2.4 only includes the files within a directory at the immediate next level. When this flag is set to true, the extension will publish a new metric that recursively counts the number of files within the configured directory and within all subdirectories. This can be used in conjunction with 2.3 & 2.4.

#### 2.6 recursiveFileSizes

The File Size metric for each directory only shows the size of the directory's contents (in bytes) at the first level. When this flag is set to true, the extension publishes a new metric that shows the size of the directory on the disk. Please note that this metric is only available for directories.

## Metrics

The extension provides the following metrics:

### 1. File Size (Bytes)

Available for both, files and directories.

### 2. Oldest File Age

Available only for directories.

### 3. File Count

Available only for directories.

### 4. Number of Lines

Available only for files.

Available for both, files and directories.

### 6. Available

Available for both, files and directories. Will have a value of 0 when a previously 'available' file gets deleted.

### 7. Recursive File Count

Available only for directories. Refer to 2.5 for detailed information.

### 8. Size on Disk (Bytes)

Available only for directories. Refer to 2.6 for detailed information.

### 9. Modified

Available for both, files and directories. Will have a value of 1 if a file/directory being monitored was modified in the last 60 seconds.

Always include one thread per base directory + 1.

### Configuring the monitor.xml

Configure the path to the config.yml by editing the <task-arguments> in the monitor.xml file in the <MACHINE_AGENT_HOME>/monitors/FileWatcher/ directory:

<task-arguments>
<!-- config file-->
<argument name="config-file" is-required="true" default-value="monitors/FileWatcher/config.yml" />
....


Restart the machine agent once this is done. Note that this is a continuous extension, as it actively watches each configured path for changes.

## Extensions Workbench

Workbench is an inbuilt feature provided with each extension in order to assist you to fine-tune the extension setup before you actually deploy it on the controller. Please review the following document for how to use the Extensions WorkBench

## Troubleshooting

Please follow the steps listed in the extensions troubleshooting document in order to troubleshoot your issue. These are a set of common issues that customers might face during the installation of the extension. If these don't solve your issue, please follow the last step on the troubleshooting-document to contact the support team.

## Support Tickets

If after going through the Troubleshooting Document, you haven't been able to get your extension working, please file a ticket with the following information.

1. Stop the running machine agent .
2. Delete all existing logs under/logs .
3. Please enable debug logging by editing the file/conf/logging/log4j.xml. Change the level value of the followingelements to debug.
   <logger name="com.singularity">
<logger name="com.appdynamics">

1. Start the machine agent and please let it run for 10 mins. Then zip and upload all the logs in the directory/logs/*.
2. Attach the zipped/conf/* directory.
3. Attach the zipped/monitors/FileWatcher directory.

For any support related questions, you can also contact help@appdynamics.com.

## Contributing

Always feel free to fork and contribute any changes directly via GitHub.

## Version

NameVersion
Extension Version3.1.3
Agent Compatibility4.5.13+
Controller Compatibility4.5 or Later
Last Update18/02/2021
List of ChangesChange log

### Release Notes

v3.1.3 - Updated to work with MachineAgent 21.x