|
@ -6,7 +6,6 @@ import ( |
|
|
"fmt" |
|
|
"fmt" |
|
|
"html" |
|
|
"html" |
|
|
"net/http" |
|
|
"net/http" |
|
|
"net/url" |
|
|
|
|
|
"strconv" |
|
|
"strconv" |
|
|
"time" |
|
|
"time" |
|
|
|
|
|
|
|
@ -30,7 +29,7 @@ var ( |
|
|
pollCounter = prometheus.NewCounterVec(prometheus.CounterOpts{ |
|
|
pollCounter = prometheus.NewCounterVec(prometheus.CounterOpts{ |
|
|
Name: "goneb_rss_polls_total", |
|
|
Name: "goneb_rss_polls_total", |
|
|
Help: "The number of feed polls from RSS services", |
|
|
Help: "The number of feed polls from RSS services", |
|
|
}, []string{"url", "http_status"}) |
|
|
|
|
|
|
|
|
}, []string{"http_status"}) |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
const minPollingIntervalSeconds = 60 * 5 // 5 min (News feeds can be genuinely spammy)
|
|
|
const minPollingIntervalSeconds = 60 * 5 // 5 min (News feeds can be genuinely spammy)
|
|
@ -200,21 +199,15 @@ func (s *Service) OnPoll(cli *gomatrix.Client) time.Time { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func incrementMetrics(urlStr string, err error) { |
|
|
func incrementMetrics(urlStr string, err error) { |
|
|
// extract domain part of RSS feed URL to get coarser (more useful) statistics
|
|
|
|
|
|
domain := urlStr |
|
|
|
|
|
u, urlErr := url.Parse(urlStr) |
|
|
|
|
|
if urlErr == nil { |
|
|
|
|
|
domain = u.Host |
|
|
|
|
|
} |
|
|
|
|
|
if err != nil { |
|
|
if err != nil { |
|
|
herr, ok := err.(gofeed.HTTPError) |
|
|
herr, ok := err.(gofeed.HTTPError) |
|
|
statusCode := 0 // e.g. network timeout
|
|
|
statusCode := 0 // e.g. network timeout
|
|
|
if ok { |
|
|
if ok { |
|
|
statusCode = herr.StatusCode |
|
|
statusCode = herr.StatusCode |
|
|
} |
|
|
} |
|
|
pollCounter.With(prometheus.Labels{"url": domain, "http_status": strconv.Itoa(statusCode)}).Inc() |
|
|
|
|
|
|
|
|
pollCounter.With(prometheus.Labels{"http_status": strconv.Itoa(statusCode)}).Inc() |
|
|
} else { |
|
|
} else { |
|
|
pollCounter.With(prometheus.Labels{"url": domain, "http_status": "200"}).Inc() // technically 2xx but gofeed doesn't tell us which
|
|
|
|
|
|
|
|
|
pollCounter.With(prometheus.Labels{"http_status": "200"}).Inc() // technically 2xx but gofeed doesn't tell us which
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|