I've installed Collectd on Nginx instances and I'm using it to count HTTP status codes. The current Collectd configuration looks like this:
Hostname "localhost"
FQDNLookup false
BaseDir "/var/lib/collectd"
PluginDir "/usr/lib/collectd"
TypesDB "/usr/share/collectd/types.db"
AutoLoadPlugin true
Interval 30
MaxReadInterval 86400
Timeout 2
ReadThreads 5
WriteThreads 5
<Plugin "logfile">
LogLevel "info"
File "/var/log/collectd.log"
Timestamp true
</Plugin>
<Plugin "tail">
<File "/var/log/nginx/access.log">
Instance "prod1_nginx"
<Match>
Regex "HTTP/1..\" 2[0-9]{2}"
DSType "CounterInc"
Type "counter"
Instance "prod1_nginx_2xx"
</Match>
<Match>
Regex "HTTP/1..\" 3[0-9]{2}"
DSType "CounterInc"
Type "counter"
Instance "prod1_nginx_3xx"
</Match>
<Match>
Regex "HTTP/1..\" 4[0-9]{2}"
DSType "CounterInc"
Type "counter"
Instance "prod1_nginx_4xx"
</Match>
<Match>
Regex "HTTP/1..\" 5[0-9]{2}"
DSType "CounterInc"
Type "counter"
Instance "prod1_nginx_5xx"
</Match>
</File>
</Plugin>
<Plugin "network">
Server "INFLUX_DB_IP" "25826"
</Plugin>
This configurtion is not perfect, and I'm still diagnosing other issues, but for now I want to understand how Collectd will work when the Nginx log file is rotated.
What is happening now is that when the file is rotated, Nginx will write data to the rotated file until Nginx is reloaded, which is normal behaviour. But for that time, Collectd reports metrics as 0. How can I make Collectd file rotation aware?