0

I use 303 codes (correctly, I believe) to redirect a user after they've submitted a form. Unfortunately this means that a few times every day I get an alert from netdata along the lines of:

netdata notification
yoursite needs attention
web_log_yoursite.response_statuses
1m redirects = 21.1% 
the ratio of HTTP redirects (3xx except 304) over the last minute

I think I'd like to customise this behaviour so it becomes "(3xx except 304 or 303)", but I've no idea if this is possible or how I'd go about doing it.

Thanks

1 Answer 1

1

You are correct of the purpose of 303 See Other, just as described in RFC 7231 6.4.4.

This status code is applicable to any HTTP method. It is primarily used to allow the output of a POST action to redirect the user agent to a selected resource, since doing so provides the information corresponding to the POST response in a form that can be separately identified, bookmarked, and cached, independent of the original request.

It seems your site is based on these POST requests and their redirects more than usual sites, thus exceeding the threshold defined in the 1m_redirects template of NetData's conf.d/health.d/web_log.conf. Easiest way would be to increase the thresholds on lines warn: and crit:, as the "(3xx except 304)" in the configuration is merely an info text, not part of the logic used for matching log lines:

template: 1m_redirects
      on: web_log.response_statuses
families: *
  lookup: sum -1m unaligned of redirects
    calc: $this * 100 / $1m_requests
   units: %
   every: 10s
    warn: ($1m_requests > 120) ? ($this > (($status >= $WARNING ) ? (  1 ) : ( 20 )) ) : ( 0 )
    crit: ($1m_requests > 120) ? ($this > (($status == $CRITICAL) ? ( 20 ) : ( 30 )) ) : ( 0 )
   delay: up 2m down 15m multiplier 1.5 max 1h
    info: the ratio of HTTP redirects (3xx except 304) over the last minute
      to: webmaster

The special handling of 304 Not Modified comes from the fact that it's truly comparable to 200 OK:

RFC 7232, 4.1. 304 Not Modified

The 304 (Not Modified) status code indicates that a conditional GET or HEAD request has been received and would have resulted in a 200 (OK) response if it were not for the fact that the condition evaluated to false. In other words, there is no need for the server to transfer a representation of the target resource because the request indicates that the client, which made the request conditional, already has a valid representation; the server is therefore redirecting the client to make use of that stored representation as if it were the payload of a 200 (OK) response.

This definition is followed correctly in python.d/web_log.chart.p lines 746-761 and 906-921:

746/906:    def get_data_per_statuses(self, code):
747/907:        """
748/908:        :param code: str: response status code. Ex.: '202', '499'
749/909:        :return:
750/910:        """
751/911:        code_class = code[0]
752/912:        if code_class == '2' or code == '304' or code_class == '1':
753/913:            self.data['successful_requests'] += 1
754/914:        elif code_class == '3':
755/915:            self.data['redirects'] += 1
756/916:        elif code_class == '4':
757/917:            self.data['bad_requests'] += 1
758/918:        elif code_class == '5':
759/919:            self.data['server_errors'] += 1
760/920:        else:
761/921:            self.data['other_requests'] += 1

If you really wish to modify this to exclude 303, then add or code == '303' to lines 752 & 912.

3
  • Thanks. I have a photo-tagging part of my site which is why this arises. If a photographer is on the site at a quiet time and doing some tagging, they can easily generate 20-30 303's per minute.
    – Codemonkey
    Aug 30, 2018 at 12:02
  • 1
    The 303 is the correct way to prevent re-uploading the same file. You can increase the thresholds or disable the template altogether, if you don't expect having real problems with redirects. Aug 30, 2018 at 12:16
  • Not sure which file to edit when I have 3 copied of web_log.chart.py, so I've gone for all 3... /opt/netdata/usr/libexec/netdata/python.d/web_log.chart.py, /usr/libexec/netdata/python.d/web_log.chart.py and /usr/src/netdata.git/python.d/web_log.chart.py. The only .pyc file resides with the first file I listed, so I assume that's the active one.
    – Codemonkey
    Aug 30, 2018 at 15:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .