How can I forward my logs to Splunk or Logz.io?
Platform.sh DevRel
I’d like to integrate my log monitoring across my organization, including applications not hosted on Platform.sh.
0
Comments
Both Logz.io’s recommended forwarder, Filebeat, and the Splunk Universal Forwarder expect a file system with write access to ship logs to their indexers. Platform.sh by design is set-up to host applications on a read-only file system, so it is necessary to utilize mounts to provide these services with write access.
Installation, configuration, and shipping are explained briefly below for both Logz.io and Splunk, but more detailed How-tos are also available for more in-depth instruction:
Forwarding to Logz.io
1. Define mounts
Define a mount in
.platform.app.yamlthat Filebeat can write to when it ships your logs,filebeat.Mounts aren’t available during build hooks, so one way we can install Filebeat is to create a subdirectory in our project called
config/filebeatwhere we can store installation scripts and temporary builds, and then move them here afterwards.2. Modify build and deploy hooks
Include the following commands to your existing hooks in
.platform.app.yaml:In the build hook here an installation script
config/filebeat/scripts/install.shwill install Filebeat in a temporary location during the build hook so long as a project level variable is not defined to show that this step has already been completed.An example
install.shbelow installs Filebeat to the directoryconfig/filebeat/build/and downloads a certificate for it. On your Logz.io dashboard under ‘Log Forwarding’ the Filebeat instructions include more detail about these steps.In the deploy hook if the mount point is empty, a configuration script
config/filebeat/scripts/config.shmoves the temporary Filebeat installation to thefilebeatand creates a directoryregistrythat will be used to save registry files.3. Configure with
filebeat.yamlIn the application directory, place the
filebeat.ymlfile that the Logz.io Wizard created for you in the ‘Log Forwarding’ section.To ship all Platform.sh logs, enter
var/log/*.logas its input. It will specify outputs for you as well.4. Complete
At this point if you push to
platform remoteFilebeat will install, configure itself, and ship Platform.sh logs with the last line of the deploy hook:./filebeat/filebeat run --once.If you keep the build hook as written, a new install will occur with each deployment unless you set a project level variable that designates that Filebeat is already configured:
Forwarding to Splunk
1. Define mounts
Define a pair mount in
.platform.app.yamlthat the Forwarder can write to when it ships your logs. It will usesplunkto write modified log files before they ship and.splunkto write authorization files so that it can remember configurations and credentials after it connects to your indexer.Same as above, since mounts aren’t available during build we can install the Universal Forwarder in a subdirectory called
config/filebeatwhere we can store installation scripts and temporary builds.2. Modify build and deploy hooks
In the build hook, the Forwarder will be installed in the temporary directory
config/splunk/build, so long as a project level variable that denotes a completed configuration has not been set.In the deploy hook,
3. Create configuration files
Splunk has a dedicated CLI that allows you to configure inputs and outputs, but it recommends creating a set of configuration seed files instead.
user.conf: The Forwarder comes with a defaultadminuser with the passwordchangeme. You will need to create this file to update the password or else remote access will not be available. Once it has been moved, you can start the Forwarder for the first time and modify the remaining configurations.outputs.conf: This file configures information about the Splunk Receiver/Indexer. Replace<receiver ip>with the IP address of the Indexer. If you have changed the default listening port for the Indexer from9997, you will need to change that as well.inputs.conf: Finally, configure the forward to monitor all files in/var/log, the location of Platform.sh log files.Each of these seed files can be placed in
config/splunk/seedsin your project directory, and each is moved to the Forwarder’s final installation location during the deploy hook.4. Complete
Like the Logz.io instructions above, these configuration settings will install and configure the Splunk Universal Forwarder to ship Platform.sh logs on every deployment with the last line of the deploy hook:
./splunk/splunkforwarder/bin/splunk restart.If you keep the build hook as written, a new install will occur with each deployment unless you set a project level variable that designates that Splunk is already configured:
Please sign in to leave a comment.