Logz.io Plugin
In this tutorial, we take the example application, used in Writing an Application, and add a remote logging service container using Fluentd with Logz.
WARNING: You will need an account at Logz.io :fa-external-link-square: to continue."
Install the example application and configure Fluentd
With the Oak API, we can install the example application and the fluentd component, with Logz.
Be sure to specify the Logz type and token, in the API call, with your organization information.
{
"services": [{
"image": "index.docker.io/oaklabs/app-example:release-1.0.1",
"environment": {
"TZ": "America/Phoenix"
}
},
{
"image": "index.docker.io/oaklabs/component-fluentd:logzio",
"environment": {
"LOGZ_TYPE": "{{logzType}}",
"LOGZ_TOKEN": "{{logzToken}}"
}
}
]
}
Remember to authenticate, against the API, before installing.
Depending on your network connection, it may take some time to complete installing the Docker containers on your OakOS device.
INFO You may view the idle application before swapping idle, with the Oak Platform API.
Viewing the logs
The example application sends two logging statements, one with all environment variables and another, with the REMOTE_URL
variable: https://github.com/OakLabsInc/app-example/blob/master/src/index.js
const oak = require('oak')
console.log(process.env)
console.log("REMOTE_URL", process.env.REMOTE_URL)
oak.on('ready', () => {
oak.load({
url: process.env.REMOTE_URL || 'https://www.zivelo.com'
})
})
The first console.log() call will send the hash of environment variables as separate items in Logz.io - Kibana.
The second statement specifically logs REMOTE_URL
, which is shown in the Kibana Discover search form.
Figure 1.1 - Search results for REMOTE_URL
, in Kibana, at Logz.io.
Once the example application is deployed to the Oak Device, the console logging sends information to Logz.io, see Figure 1.1.
All the logging entries are expandable and contain {{logzType}}
set in type, along with the hostname and other data.
Figure 1.2 - Expanded log entry for the TZ
environment variable on Kibana - Logz.io.
When we installed the example application, we also set an environment variable for the timezone TZ
, that got passed into the application, see Figure 1.2.