GilbN / geoip2influx

A python script that will parse the nginx access.log and send geolocation metrics and log metrics to InfluxDB
MIT License
73 stars 15 forks source link

SWAG Logs filling up with geoip2influx warnings #7

Closed makerduck closed 3 years ago

makerduck commented 3 years ago

Hi, I followed your guide at technicalramblings on how to get nginx geo information into grafana. So far its works well but my swag container log is filling up with geoip2influx warnings almost every second. Copied a few over as the warning said. I dont really know how to fix that as everything else seems to work fine grafana shows logs and positions as it should. I would very appreciate your help on how to fix or eliminate those warnings, thanks in advance!

LOGS:

GEOIP2INFLUX 14/Sep/2021 15:38:54 :: INFO :: Starting geoip2influx..
GEOIP2INFLUX 14/Sep/2021 15:38:54 :: INFO :: Starting log parsing
GEOIP2INFLUX 14/Sep/2021 15:39:07 :: WARNING :: Failed to match regex that previously matched!? Skipping this line!

If you think the regex should have mathed the line, please share the log line below on https://discord.gg/HSPa4cz or Github: https://github.com/gilbN/geoip2influx
Line: 154.16.192.XXX - - [14/Sep/2021:15:39:06 +0200] "GET /api/history/period/2021-09-13T13:39:04.831Z?filter_entity_id=sensor.fritz_box_7530_kb_s_received,sensor.fritz_box_7530_kb_s_sent,sensor.google,sensor.hyperion&end_time=2021-09-14T13:39:04.831Z&minimal_response HTTP/2.0" 200 117101 "https://homeassistant.DOMAIN.de/lovelace/wg-home" "Mozilla/5.0 (Linux; Android 11; AC2003 Build/RP1A.201005.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/93.0.4577.62 Mobile Safari/537.36"

GEOIP2INFLUX 14/Sep/2021 15:39:07 :: WARNING :: Failed to match regex that previously matched!? Skipping this line!

If you think the regex should have mathed the line, please share the log line below on https://discord.gg/HSPa4cz or Github: https://github.com/gilbN/geoip2influx
Line: 154.16.192.XXX - - [14/Sep/2021:15:39:06 +0200] "GET /api/history/period/2021-09-13T13:39:04.831Z?filter_entity_id=sensor.fritz_box_7530_kb_s_received,sensor.fritz_box_7530_kb_s_sent,sensor.google,sensor.hyperion&end_time=2021-09-14T13:39:04.831Z&minimal_response HTTP/2.0" 200 117101 "https://homeassistant.DOMAIN.de/lovelace/wg-home" "Mozilla/5.0 (Linux; Android 11; AC2003 Build/RP1A.201005.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/93.0.4577.62 Mobile Safari/537.36"

GEOIP2INFLUX 14/Sep/2021 15:39:38 :: WARNING :: Failed to match regex that previously matched!? Skipping this line!

If you think the regex should have mathed the line, please share the log line below on https://discord.gg/HSPa4cz or Github: https://github.com/gilbN/geoip2influx
Line: 154.16.192.XXX - - [14/Sep/2021:15:39:38 +0200] "GET /api/history/period/2021-09-13T13:39:36.266Z?filter_entity_id=sensor.fritz_box_7530_kb_s_received,sensor.fritz_box_7530_kb_s_sent,sensor.google,sensor.hyperion&end_time=2021-09-14T13:39:36.266Z&minimal_response HTTP/2.0" 200 117093 "https://homeassistant.DOMAIN.de/lovelace/wg-home" "Mozilla/5.0 (Linux; Android 11; AC2003 Build/RP1A.201005.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/93.0.4577.62 Mobile Safari/537.36"

nginx.conf edits:

 geoip2 /config/geoip2db/GeoLite2-City.mmdb {
        auto_reload 5m;
        $geoip2_data_country_iso_code country iso_code;
        $geoip2_data_city_name city names en;
    }

    log_format custom '$remote_addr - $remote_user [$time_local]'
           '"$request" $status $body_bytes_sent'
           '"$http_referer" $host "$http_user_agent"'
           '"$request_time" "$upstream_connect_time"'
           '"$geoip2_data_city_name" "$geoip2_data_country_iso_code"';

    access_log /config/log/nginx/access.log custom;
GilbN commented 3 years ago

Looks like you have something that is logging to the same access.log but not using the custom log_format look for any access_log lines in your server_blocks that doesnt have custom; at the end.

makerduck commented 3 years ago

That makes a lot of sense, thanks that did the trick!