Filebeat is a lightweight exe that can do some very basic log parsing and forwarding, either directly to ElasticSearch or more likely via Logstash, which is a much heavier weight and scalable application that can perform various parsing and modifications of messages before they go into ElasticSearch. In this case, IIS logs should be modified in LogStash to give them more useful metadata.
Logstash is too big and resource hungry to use on App Services (unless it was installed centrally somewhere but that would likely not work well) but fortunately, FileBeat measures in at about 30MB expanded and 8MB in a zip file which is easily small enough for App Services.
The steps are straight-forward and this worked for me with v6.1.1 of filebeat for Windows.
- Download filebeat and extract the contents to a folder somewhere to edit
- You can delete the install and uninstall as a service PS scripts as well as the reference yml file to save a few KB!
- Add a file called run.cmd which includes the command line .\filebeat.exe -e
- It is recommended that you test filebeat locally first to ensure your pipeline is working before you bring Azure into the mix but if you already know that works, you can skip that step.
- Edit filebeat.yml using the code as shown at the bottom (keep other stuff if you know you need it). The only specific bit for App Services is the log path.
- ZIP the contents of your extracted folder by selecting all files and folders in the directory that contains filebeat.exe and choosing Send to compressed (zipped) folder. Do NOT do this on the parent directory, otherwise the zip will include the parent directory at the top level. Call it something like webjob.zip
- In the Azure portal, select the App Service you want to use, choose Web Jobs and the + button to add a new one.
- Choose a name, select Continuous as a type and select the ZIP file you created, choose multi-instance if these needs to run on every instance of your app (it probably will need to unless you are testing) and press OK.
- It will run immediately so make sure that your endpoint is running correctly
Note: The path used on App Services works on my current setup but I cannot tell whether this drive letter and path is guaranteed not to change! I don't currently know how to query the logs directory using e.g. an environment variable.
#=========================== Filebeat prospectors =============================
- type: log
# Change to true to enable this prospector configuration.
# Paths that should be crawled and fetched. Glob based paths.
# Exclude lines. A list of regular expressions to match. It drops the lines that are
# matching any regular expression from the list.
#============================= Filebeat modules ===============================
# Glob pattern for configuration loading
# Set to true to enable config reloading
#==================== Elasticsearch template setting ==========================
#----------------------------- Logstash output --------------------------------
# The Logstash hosts