Pm2 là một app để run các ứng dụng nodejs một cách dễ quản lý.
Để thực hiện đẩy log pm2 lên ES, ta làm như sau:
Cài đặt:
pm2 install pm2-elasticsearch-logger
Sau khi cài, pm2 list sẽ thấy hiển thị module:
Tiếp tục, cấu hình cho pm2-elasticsearch-logger, cú pháp như sau:
pm2 set pm2-elasticsearch-logger:<option> <value>
Các Option hỗ trợ:
option | default | |
---|---|---|
elasticUrl | URL of Elasticsearch API | http://localhost:9200 |
insecure | allow https connections to servers with invalid certificate | false |
index | Elasticsearch index to use | pm2 |
type | Document type to use | pm2 |
host | host attribute of the document |
os.hostname() |
Ví dụ mình đang có 1 con Elasticsearch trong cụm ELK để thu gom log, mình export nó ra ngoài ở địa chỉ: https://es.tool.vn (có firewall allow IP của những server có thể kết nối đến) và con ES này có sử dụng authen, mình config như sau:
pm2 set pm2-elasticsearch-logger:elasticUrl https://user:pass@es.tool.vn
Đặt tên cho index cho dễ quản lý:
pm2 set pm2-elasticsearch-logger:index <index_name>
Như vậy là xong, log pm2 sẽ đẩy lên ES ngon lành. Index được tạo trên ES có dạng index_name-2020-26-02/pm2
Trên Kibana, mình tạo index tương ứng: index_name*
Một số field đáng chú ý là
host: hostname của server đẩy log
process: process name của pm2