Hi,
When we speak about devops it is necessary to have useful tools for each of the phases of CI. In this post I will present a tool for the monitoring.
In the SAP Cloud Platform one response to monitoring is "Application Login" + "Kibana". But, what are these two products?
- Application Login is a service is a service in charge of storing the log traces of our applications
- Kibana according with wikipedia: is an open source data visualization dashboard for Elasticsearch. It provides visualization capabilities on top of the content indexed on an Elasticsearch cluster. Users can create bar, line and scatter plots, or pie charts and maps on top of large volumes of data
Application Loggin and Kibana
Let's play to integrate application login into our node.js application (using SAP Cloud Platform foundry)
- Access to the marketplace of subaccount:
- In the wizard we will select the plan, assign our application (if it already exists) to this service (that is, make binding) and give the name to our service. It's important in this point to understand the applications that we want to monitor must be bindined with this service
Now we can visualize the data in an easy way with Kibana, we will see how to access this software.
- To access, we go to any applications deployed in SAP Cloud foundry and go to the logs section. There we will have the link to Kibana.
Once in kibana, apart from customizing the dashboards I recommend the following standard views
- Performance and Quality: Statistics of response codes of our calls.
- Network and Load: Number of calls and details.
Add your logs in Node.js
We may need to add traces to our code exceptions in a fancy way.
npm install cf-nodejs-logging-support
OR in webIde adding Package.json
"dependencies": {
"cf-nodejs-logging-support": "^6.2.0",
"express": "^4.17.1"
}
- Now, it is ready to use to register our logs. As an example we add the modifications to our application:
const express = require('express');
const log = require('cf-nodejs-logging-support');
const app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
// Add log with request info from user
log.info("Log registered" , {"myfieldA" : "Hello world",
"myfieldB" :new Date()
});
//console.log('Hello World sent to Browser at: ' + new Date() ); //new line
});
const port = process.env.PORT || 3000;
app.listen(port, function () {
log.registerCustomFields(["myfieldA", "myfieldB"]);
});
With this we can inject custom fields in Kibana.
Regards