§2024-05-17

How to install syslog-ng and configure?

¶ Using hc4nas02.yushei.net to record the following replicationSet's /opt/package/mongoDB/log/mongod.log

  1. installation sudo apt install syslog-ng

  2. /etc/syslog-ng/syslog-ng.conf

@version: 3.25
@include "scl.conf"

options {
    keep-hostname(yes);
};

# Sources
source s_net {
    network(ip(0.0.0.0) port(514) transport("udp"));
};

# Destination
destination d_mongoDB {
    file("/var/log/mongoDB-ys20220317.log");
};

# Filters
# filter f_redisMongo {
#     host("redisMongo[0-9]+\.yushei\.com\.tw");
# };

# Log Statements
log {
    source(s_net);
#    filter(f_redisMongo);
    destination(d_mongoDB);
};
@version: 3.25
@include "scl.conf"

options {
    keep-hostname(yes);
};

# Sources
source s_mongo_log {
    file("/opt/package/mongoDB/log/mongod.log" flags(no-parse));
};

# Destination
destination d_mongoDB {
    syslog("hc4nas02.yushei.net" transport("udp") port(514));
};

# Log Statements
log {
    source(s_mongo_log);
#     parser {
#         json-parser(prefix("json."));
#     };
    destination(d_mongoDB);
};
  1. do sudo systemctl restart syslog-ng

  2. monitoring from ssh -p 1765 alexlai@hc4nas02.yushei.net

# tail -f /var/log/mongoDB-ys20220317.log 
# tail -f /var/log/mongoDB-ys20220317.log |grep -iE 'Slow|error'