Skip to main content

Apm and elk

 


This project requires having an elk stack up and running. For our project, we have 2 servers


  •  The elk server with elasticsearch and kibana install with IP address( 192.168.208.132)

  • The fleet server  with IP address (192.168.208.134)


For our demonstration, we use elk version 8.5.2. In our journey, we will show you how to monitor a simple nodejs app with the elk APM.
To monitor your application, you have to create a fleet server in kibana. we will follow the steps below.

1) we have to create the fleet server, so we need to go into our kibana and in the menu on the left, click on fleet.



2) On the fleet page we have to click on settings and create hosts. this will allow us to configure the fleet server. In our case, it is an ubuntu server with the IP address 192.169.208.134.



3) We have to configure the IP address for our fleet server like below




4) For the output part we have to configure our elk ip address and because we do not use our own certificate, we have to add the flag ssl.verification_mode: none. This command tells elastic to do not verify the SSL certificate that it receives. It is obvious that it is not something to do in a production environment. In the end, you have to choose a name for your policy and add the fleet server.


5) after adding the fleet server, we have to add an agent. this part will give you the command to run on your fleet server (192.168.208.134). In the deployment mode section, you have to choose quick start because, in the beginning, we didn't configure any certificate. 



You have to copy and paste the commands at the end of the page to your fleet server. remember to choose the commands related to your distribution. A simple copy-paste will get your server run and you will see your fleet server appear on the kibana page like below. 



Now you got your fleet and agent going. You will need to configure the integration. Go to the menu on the left and go into the observability part and click on APM and click on add integration

click on add new integration


you have to put the IP address of your fleet server and name the integration. Since you already have already created an agent policy. at the end of the page,click on the existing host and choose the policy you created, and create the agent


the agent should appear now on the agent page 


Now that you already have everything configured to your elk stack, you can run your app and start to send data to your elk. you can follow the steps to install the agent nodejs here

On a server you can install nodejs, npm and the elastic apm node module.

for ubuntu it goes like this :


apt install nodejs

apt install npm

apt install elastic-apm-node --savede --savenpm install elastic-apm-node --save

https://www.elastic.co/guide/en/apm/guide/current/apm-quick-start.html

Below you can see the code of my nodejs app

// Add this to the VERY top of the first file loaded in your app
var apm = require('elastic-apm-node').start({

// Override the service name from package.json
// Allowed characters: a-z, A-Z, 0-9, -, _, and space
serviceName: 'mon test apm',

// Use if APM Server requires a secret token
secretToken: '',

// Set the custom APM Server URL (default: http://localhost:8200)
serverUrl: 'http://192.168.208.134:8200',

// Set the service environment
environment: 'production'
})

const express = require ('express')
const app = express()
const port = 3030

app.get('/',(req,res) => {
      res.send(' hello world')
          })

app.get('/demo',(req,res) => {
      res.send(' welcome demo')
              })

app.get('/error',(req,res) => {
      res.send(' capture error')
      const err = new Error('Trigger Error')
      apm.captureError(err)
})

app.listen(port, () => {
      console.log (' App lsiten on port 3030')
})


When you run the app, you will get the APM data in your elastic monitoring tool

Comments

Popular posts from this blog

Observability with grafana and prometheus (SSO configutation with active directory)

How to Set Up Grafana Single Sign-On (SSO) with Active Directory (AD) Grafana is a powerful tool for monitoring and visualizing data. Integrating it with Active Directory (AD) for Single Sign-On (SSO) can streamline access and enhance security. This tutorial will guide you through the process of configuring Grafana with AD for SSO. Prerequisites Active Directory Domain : Ensure you have an AD domain set up. Domain: bazboutey.local AD Server IP: 192.168.170.212 Users: grafana (for binding AD) user1 (to demonstrate SSO) we will end up with a pattern like this below Grafana Installed : Install Grafana on your server. Grafana Server IP: 192.168.179.185 Administrator Privileges : Access to modify AD settings and Grafana configurations. Step 1: Configure AD for LDAP Integration Create a Service Account in AD: Open Active Directory Users and Computers. Create a user (e.g., grafana ). Assign this user a strong password (e.g., Grafana 123$ ) and ensure it doesn’t expire. Gather Required AD D...

Deploying a Scalable Monitoring Stack Lab on AWS using Terraform and Ansible

Deploying a Scalable Monitoring Stack Lab on AWS using Terraform and Ansible Introduction Effective monitoring is a cornerstone of cloud infrastructure management, ensuring high availability and performance. This guide provides a professional walkthrough on deploying Prometheus , Grafana , and Node Exporter on AWS using Terraform for infrastructure provisioning and Ansible for configuration management. This lab will create a prometheus server and a grafana server, It will install node exporter on both server. You should be able to see the metrics in grafana, we already install a node exporter dashboard for the user. The diagram below will give you an idea of what the architecture will look like If you want to replicate this lab, you can find the complete code repository here: GitHub - MireCloud Terraform Infra .  Infrastructure Setup with Terraform 1. Creating a Dedicated VPC To ensure isolation, we define a VPC named Monitoring with a CIDR block of 10.0.0.0/16 . reso...

Building a Static Website on AWS with Terraform

The Journey to a Fully Automated Website Deployment A few weeks ago, I found myself needing to deploy a simple static website . Manually setting up an S3 bucket, configuring permissions, and linking it to a CloudFront distribution seemed like a tedious process. As someone who loves automation, I decided to leverage Terraform to simplify the entire process. Why Terraform? Infrastructure as Code (IaC) is a game-changer. With Terraform, I could:  Avoid manual setup errors  Easily reproduce and  Automate security best practices Instead of clicking through AWS settings, I wrote a few Terraform scripts and deployed everything in minutes. Let me walk you through how I did it!  Architecture Overview The architecture consists of three main components: User:  The end user accesses the website via a CloudFront URL.  CloudFront Distribution:  Acts as a content delivery network (CDN) to distribute content efficiently, reduce latency, and enhance security. It ...