Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ELK 로그를 슬랙 알람으로 연결 #238

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ _더 자세히 보려면 제목을 클릭해 주세요!_

### [로그 모니터링 시스템](https://elastic-bread-9ef.notion.site/3dd807f73d0e4aa8982abcd4b4dad8ed)

<img src="https://github.com/user-attachments/assets/42cf3df1-7051-4f5c-a481-b2d598de4572" alt="kibana 로그" style="width:600px; height:auto;">
<img src="https://github.com/user-attachments/assets/42cf3df1-7051-4f5c-a481-b2d598de4572" alt="kibana 로그" width="600">
<img src="https://github.com/user-attachments/assets/430569da-edf3-44f9-89c9-46fd0beb123b" alt="알림 스크린샷" width="800">

> 로깅 라이브러리로는 Pino, 모니터링 스택으로는 ELK 를 사용했습니다.
> Kibana와 Slack을 연동해 실시간 모니터링 시스템을 구축했습니다.
Expand Down Expand Up @@ -115,23 +116,23 @@ _더 자세히 보려면 제목을 클릭해 주세요!_

---

| **도메인** | **기술 스택** |
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **공통** | ![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?logo=typescript&logoColor=ffffff) ![Prettier](https://img.shields.io/badge/Prettier-F7B93E?logo=prettier&logoColor=ffffff) ![ESLint](https://img.shields.io/badge/ESLint-4B32C3?logo=eslint&logoColor=ffffff) |
| **도메인** | **기술 스택** |
|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **공통** | ![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?logo=typescript&logoColor=ffffff) ![Prettier](https://img.shields.io/badge/Prettier-F7B93E?logo=prettier&logoColor=ffffff) ![ESLint](https://img.shields.io/badge/ESLint-4B32C3?logo=eslint&logoColor=ffffff) |
| **프론트엔드** | ![Vite](https://img.shields.io/badge/Vite-646CFF?logo=Vite&logoColor=ffffff) ![React](https://img.shields.io/badge/React-61DAFB?logo=React&logoColor=ffffff) ![Tailwind CSS](https://img.shields.io/badge/Tailwind_CSS-06B6D4?logo=tailwindcss&logoColor=ffffff) ![React Query](https://img.shields.io/badge/React_Query-FF4154?logo=reactquery&logoColor=ffffff) ![Zustand](https://img.shields.io/badge/Zustand-443E38?logo=react&logoColor=ffffff) |
| **백엔드** | ![Node.js](https://img.shields.io/badge/Node.js-114411?logo=node.js) ![NestJS](https://img.shields.io/badge/NestJS-E0234E?logo=nestjs&logoColor=ffffff) ![MySQL](https://img.shields.io/badge/MySQL-4479A1?logo=mysql&logoColor=ffffff) ![TypeORM](https://img.shields.io/badge/TypeORM-3178C6?logo=typeorm&logoColor=ffffff) ![Elasticsearch](https://img.shields.io/badge/Elasticsearch-005571?logo=elasticsearch&logoColor=ffffff) ![Kibana](https://img.shields.io/badge/Kibana-005571?logo=kibana&logoColor=ffffff) ![Logstash](https://img.shields.io/badge/Logstash-005571?logo=logstash&logoColor=ffffff) |
| **배포** | ![GitHub Actions](https://img.shields.io/badge/GitHub%20Actions-2088FF?logo=githubactions&logoColor=ffffff) ![Nginx](https://img.shields.io/badge/nginx-014532?logo=Nginx&logoColor=009639&) ![Naver Cloud Platform](https://img.shields.io/badge/Naver%20Cloud%20Platform-03C75A?logo=naver&logoColor=ffffff) |
| **협업 도구** | ![GitHub](https://img.shields.io/badge/GitHub-181717?logo=github&logoColor=ffffff) ![Notion](https://img.shields.io/badge/Notion-000000?logo=notion) ![Figma](https://img.shields.io/badge/Figma-F24E1E?logo=figma&logoColor=ffffff) ![Slack](https://img.shields.io/badge/Slack-4A154B?logo=slack&logoColor=ffffff) |
| **백엔드** | ![Node.js](https://img.shields.io/badge/Node.js-114411?logo=node.js) ![NestJS](https://img.shields.io/badge/NestJS-E0234E?logo=nestjs&logoColor=ffffff) ![MySQL](https://img.shields.io/badge/MySQL-4479A1?logo=mysql&logoColor=ffffff) ![TypeORM](https://img.shields.io/badge/TypeORM-3178C6?logo=typeorm&logoColor=ffffff) ![Elasticsearch](https://img.shields.io/badge/Elasticsearch-005571?logo=elasticsearch&logoColor=ffffff) ![Kibana](https://img.shields.io/badge/Kibana-005571?logo=kibana&logoColor=ffffff) ![Logstash](https://img.shields.io/badge/Logstash-005571?logo=logstash&logoColor=ffffff) |
| **배포** | ![GitHub Actions](https://img.shields.io/badge/GitHub%20Actions-2088FF?logo=githubactions&logoColor=ffffff) ![Nginx](https://img.shields.io/badge/nginx-014532?logo=Nginx&logoColor=009639&) ![Naver Cloud Platform](https://img.shields.io/badge/Naver%20Cloud%20Platform-03C75A?logo=naver&logoColor=ffffff) |
| **협업 도구** | ![GitHub](https://img.shields.io/badge/GitHub-181717?logo=github&logoColor=ffffff) ![Notion](https://img.shields.io/badge/Notion-000000?logo=notion) ![Figma](https://img.shields.io/badge/Figma-F24E1E?logo=figma&logoColor=ffffff) ![Slack](https://img.shields.io/badge/Slack-4A154B?logo=slack&logoColor=ffffff) |

<br/>
<br/>

### 팀원 소개

| [J088\_도원진](https://github.com/1119wj) | [J151\_안금장](https://github.com/koomchang) | [J105\_박민서](https://github.com/Miensoap) | [J270 \_한동효](https://github.com/hyohyo12) |
| :------------------------------------------------------------------------: | :------------------------------------------------------------------------: | :------------------------------------------------------------------------: | :-------------------------------------------------------------------------: |
| [J088\_도원진](https://github.com/1119wj) | [J151\_안금장](https://github.com/koomchang) | [J105\_박민서](https://github.com/Miensoap) | [J270 \_한동효](https://github.com/hyohyo12) |
|:--------------------------------------------------------------------------:|:--------------------------------------------------------------------------:|:--------------------------------------------------------------------------:|:---------------------------------------------------------------------------:|
| <img src="https://avatars.githubusercontent.com/u/95432846?v=4" width=150> | <img src="https://avatars.githubusercontent.com/u/90228925?v=4" width=150> | <img src="https://avatars.githubusercontent.com/u/87180146?v=4" width=150> | <img src="https://avatars.githubusercontent.com/u/129946082?v=4" width=150> |
| FE | BE | BE | BE |

| 🏷️ 바로가기 | [**팀 Notion**](https://elastic-bread-9ef.notion.site/12963e6f4ee98074b6f9f70cfa9ac836) | [위키](https://github.com/boostcampwm-2024/web09-DailyRoad/wiki) |
| :---------: | :-------------------------------------------------------------------------------------: | :--------------------------------------------------------------: |
|:--------:|:--------------------------------------------------------------------------------------:|:--------------------------------------------------------------:|
2 changes: 1 addition & 1 deletion backend/src/AppController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class AppController {

@Get()
async getHello() {
this.logger.info('Hello world');
this.logger.error('AppController.getHello의 에러 로그입니다.');
return (await this.appService.getHello()) + ' Web 09 Backend';
}
}
86 changes: 86 additions & 0 deletions setup/production/elk/kibana/dev-tools
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
PUT _ingest/pipeline/add_log_level_msg_and_convert_time
{
"description": "Extract log level, log message, and format timestamp to Seoul timezone",
"processors": [
{
"script": {
"source": """
// Extract 'level'
String keyword = "level";
String key = "\"" + keyword + "\":\"";

if (!ctx.containsKey('message')) {
ctx.log_level = "no stack";
} else {
String message = ctx.message;
if (message == null) {
ctx.log_level = "no stack";
} else {
int startIndex = message.indexOf(key);
int keyLength = key.length();

if (startIndex == -1) {
ctx.log_level = "no message";
} else {
startIndex += keyLength;
int endIndex = message.indexOf('"', startIndex);
if (endIndex == -1) {
ctx.log_level = "no message";
} else {
ctx.log_level = message.substring(startIndex, endIndex);
}
}
}
}

// Extract 'msg' or 'message'
if (!ctx.containsKey('message')) {
ctx.log_msg = "no message";
} else {
String message = ctx.message;
if (message == null) {
ctx.log_msg = "no message";
} else {
int startIndex = message.indexOf("\"msg\":\"");
int keyLength = "\"msg\":\"".length();

if (startIndex == -1) {
startIndex = message.indexOf("\"message\":\"");
keyLength = "\"message\":\"".length();
}

if (startIndex == -1) {
ctx.log_msg = "no message";
} else {
startIndex += keyLength;
int endIndex = message.indexOf('"', startIndex);
if (endIndex == -1) {
ctx.log_msg = "no message";
} else {
ctx.log_msg = message.substring(startIndex, endIndex);
}
}
}
}

// Format @timestamp to Seoul timezone
if (ctx.containsKey('@timestamp')) {
String timestamp = ctx['@timestamp'];
def instant = ZonedDateTime.parse(timestamp).withZoneSameInstant(ZoneId.of('Asia/Seoul'));
ctx['@timestamp_seoul'] = instant.format(DateTimeFormatter.ofPattern("yyyy년 MM월 dd일 HH:mm:ss"));
}
"""
}
}
]
}

PUT dailyroad-*/_settings
{
"index.default_pipeline": "add_log_level_msg_and_convert_time"
}

GET dailyroad-*/_search
{
"size": 1
}
8 changes: 8 additions & 0 deletions setup/production/elk/kibana/log-alarm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
🚨 *긴급 로그 발생*

⭐️ *로그 레벨*: `{{context.hits.0._source.log_level}}`

📄 *내용*:
```{{context.hits.0._source.log_msg}}```

⏰ *발생 시간*: `{{context.hits.0._source.@timestamp_seoul}}`
Loading