Nginx provides access and error logs. The rsyslog agent can monitor these files and submit the logs to Nixstats.

Open up the nginx logging configuration file:
sudo vim /etc/rsyslog.d/31-nginx-nixstats.conf

Now add the following in this file:

Replace USERTOKEN with your usertoken and SERVERTOKEN with your server token. You can find these values on the logging setup page.

$ModLoad imfile
$InputFilePollInterval 10
$PrivDropToGroup adm
$WorkDirectory /var/spool/rsyslog

$InputFileName /var/log/nginx/access.log
$InputFileTag nginx-access:
$InputFileStateFile stat-nginx-access
$InputFileSeverity info
$InputFilePersistStateInterval 20000
$InputRunFileMonitor

$InputFileName /var/log/nginx/error.log
$InputFileTag nginx-error:
$InputFileStateFile stat-nginx-error
$InputFileSeverity error
$InputFilePersistStateInterval 20000
$InputRunFileMonitor

$template NixstatsNginxTemplate,"<%pri%>%protocol-version% %timestamp:::date-rfc3339% %HOSTNAME% %app-name% %procid% %msgid% [USERTOKEN@SERVERTOKEN tag=\"nginx\"] %msg%\n"

if $programname == 'nginx-access' then @@log.nixstats.com:514;NixstatsNginxTemplate
if $programname == 'nginx-access' then ~
if $programname == 'nginx-error' then @@log.nixstats.com:514;NixstatsNginxTemplate
if $programname == 'nginx-error' then ~


Restart rsyslogd:

sudo service rsyslog restart

It can take a couple of minutes for your first data to appear on the dashboard.
Was this article helpful?
Cancel
Thank you!