Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a production server alert log in my Slack channel?, so that if there is a problem I will be notified as soon as possible

Current Situation:

  1. Our production server experiences frequent downtime due to:
    1. High CPU loads (100%)

    2. Uncaught exceptions causing crashes

  2. Lack of visibility into API behavior leads to:
    1. Delayed issue identification relying solely on user complaints

    2. Increased downtime resolving problems after they occur

Impact:

  1. Downtime disrupts user experience and damages our reputation.

  2. A reactive approach to troubleshooting is inefficient and leads to further downtime.

  3. The lack of API behavior monitoring hinders proactive problem detection and preventative measures.

Desired Outcome:

  • Implement a system that proactively sends alerts to a designated Slack channel for production server issues, including:

    • High CPU usage

    • Server crashes

    • API errors

  • Gain real-time visibility into API behavior to identify and address potential problems before they cause downtime.

  • Achieve faster reaction times to production server issues, minimizing downtime and improving user experience.

like image 349
Daxesh Italiya Avatar asked Aug 31 '25 16:08

Daxesh Italiya


2 Answers

Using Slack Bot alert you can solve this problem

here I made a global function for slack alert

const axios = require("axios");
exports.responseInClientSlack = async (body) => {
  try {
    return await axios.post(process.env.SLACK_URL, body);
  } catch (error) {
    console.log(error);
  }
};

After Define this global function you can use in your node JS project

I have you this in global error handle function Here is example of this code

 responseInClientSlack({
        attachments: [
          {
            title: `error`,
            text: `\n\nstatusCode: ${err?.status} \n\nMessage : ${err?.message}\n\n stack: ${err?.stack} \n\n user:${req?.user?.id}`,
            color: "#FF0000",
          },
        ],
      });

For set webhook inside slack and get SLACK_URL you can prefer this you tube video https://www.youtube.com/watch?v=sxtC40gUS2A

like image 71
Hiren Kalariya Avatar answered Sep 04 '25 17:09

Hiren Kalariya


Backend Monitoring can be easily done by the Wooffer. Here by implementing the Below steps, you can achieve more future than a description of the question.

Step 1 : Install

npm i wooffer

or

yarn add wooffer

Step 2 : Setup ENV

token = "<Your Token>";
serviceToken = "<Your Service Token>";

Note : get your token and Service Token from https://app.wooffer.io/

Step 3 : Add Wooffer to Root directory

const wooffer = require("wooffer");
const express = require("express");

wooffer(process.env.woofferToken, process.env.woofferServiceToken);

// Add this code to track endpoint usage(Optional)
const app = express();
app.use(wooffer.requestMonitoring);

Now You can track

  1. API Usage
  2. Logs
  3. Bugs
  4. Real-time Usage
  5. Resource Usage

Some Images for reference

enter image description here enter image description here enter image description here enter image description here

like image 30
Daxesh Italiya Avatar answered Sep 04 '25 15:09

Daxesh Italiya