1
0
Fork 0

do not crash on unhandled exception

This commit is contained in:
Massaki Archambault 2024-10-09 18:21:30 -04:00
parent 65ce1d3be1
commit bfd9a94cac
2 changed files with 6 additions and 3 deletions

1
.python-version Normal file
View File

@ -0,0 +1 @@
3.10

View File

@ -4,7 +4,6 @@ import time
import yaml
from httpx import RequestError
from prometheus_client import start_http_server, Gauge, Counter
from ecommerce_exporter.scrape_target import ScrapeError, ScrapeTarget
@ -43,7 +42,7 @@ def main():
'--user-agent',
help='The user-agent to spoof. (default: %(default)s)',
type=str,
default='Mozilla/5.0 (X11; Linux x86_64; rv:106.0) Gecko/20100101 Firefox/106.0',
default='Mozilla/5.0 (X11; Linux x86_64; rv:131.0) Gecko/20100101 Firefox/131.0',
)
parser.add_argument(
'-p', '--listen-port',
@ -69,6 +68,7 @@ def main():
}
# start the http server to server the prometheus metrics
print("serving metrics on http://%s:%s/metrics" % (args.listen_address, args.listen_port))
start_http_server(args.listen_port, args.listen_address)
# start the main loop
@ -85,7 +85,9 @@ def main():
product_name=scrape_target.product_name,
target_name=scrape_target.target_name,
).inc()
except (RequestError, ScrapeError) as e:
except KeyboardInterrupt:
return
except Exception as e:
print("Failed to scrape! product: '%s', target: '%s', message: '%s'" % (scrape_target.product_name, scrape_target.target_name, e))
ECOMMERCE_SCRAPE_TARGET_FAILURE.labels(
product_name=scrape_target.product_name,