Skip to content

Commit

Permalink
ELK update
Browse files Browse the repository at this point in the history
  • Loading branch information
DucBaoUIT committed Dec 13, 2024
1 parent d6a2e33 commit ce6b014
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,14 @@
</dependency>


<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>7.0.1</version>
</dependency>



</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
import org.springframework.web.bind.annotation.RequestBody;
import lombok.AllArgsConstructor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

@RestController
@RequestMapping("/comment")
@AllArgsConstructor
Expand All @@ -39,11 +43,15 @@ public class CommentController {

private final CommentRepository commentRepository;

private static final Logger logger = LoggerFactory.getLogger(CommentController.class);

@Autowired
private CommentService commentService;

@GetMapping("/")
public String getServiceName() {
MDC.put("type", "commentservice");
logger.info("Comment Service Start");
return "Comment Service";
}

Expand Down Expand Up @@ -100,6 +108,14 @@ public ResponseEntity<?> uploadComment(@RequestBody Comment comment) {

// Lưu comment đã xử lý vào MongoDB
Comment savedComment = commentRepository.save(sanitizedComment);

//ELK
MDC.put("type", "commentservice");
MDC.put("action", "upload");
logger.info("CommentId: " + savedComment.getId());
logger.info("VideoId: " + comment.getVideoId());
logger.info("UserId: " + comment.getUserId());

return ResponseEntity.ok(savedComment);
} catch (Exception e) {
return ResponseEntity.internalServerError().body(e.getMessage());
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
spring.kafka.producer.properties.max.request.size=500000000 # Set the maximum request size for producer
spring.kafka.producer.properties.buffer.memory=1024000000 # Set the buffer memory for producer

# ELK
logging.config=classpath:logback-spring.xml
10 changes: 10 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<configuration>
<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>192.168.120.213:5060</destination>
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="LOGSTASH"/>
</root>
</configuration>

0 comments on commit ce6b014

Please sign in to comment.