do not crash on unhandled exception
This commit is contained in:
parent
65ce1d3be1
commit
bfd9a94cac
|
@ -0,0 +1 @@
|
||||||
|
3.10
|
|
@ -4,7 +4,6 @@ import time
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from httpx import RequestError
|
|
||||||
from prometheus_client import start_http_server, Gauge, Counter
|
from prometheus_client import start_http_server, Gauge, Counter
|
||||||
|
|
||||||
from ecommerce_exporter.scrape_target import ScrapeError, ScrapeTarget
|
from ecommerce_exporter.scrape_target import ScrapeError, ScrapeTarget
|
||||||
|
@ -43,7 +42,7 @@ def main():
|
||||||
'--user-agent',
|
'--user-agent',
|
||||||
help='The user-agent to spoof. (default: %(default)s)',
|
help='The user-agent to spoof. (default: %(default)s)',
|
||||||
type=str,
|
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(
|
parser.add_argument(
|
||||||
'-p', '--listen-port',
|
'-p', '--listen-port',
|
||||||
|
@ -69,6 +68,7 @@ def main():
|
||||||
}
|
}
|
||||||
|
|
||||||
# start the http server to server the prometheus metrics
|
# 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_http_server(args.listen_port, args.listen_address)
|
||||||
|
|
||||||
# start the main loop
|
# start the main loop
|
||||||
|
@ -85,7 +85,9 @@ def main():
|
||||||
product_name=scrape_target.product_name,
|
product_name=scrape_target.product_name,
|
||||||
target_name=scrape_target.target_name,
|
target_name=scrape_target.target_name,
|
||||||
).inc()
|
).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))
|
print("Failed to scrape! product: '%s', target: '%s', message: '%s'" % (scrape_target.product_name, scrape_target.target_name, e))
|
||||||
ECOMMERCE_SCRAPE_TARGET_FAILURE.labels(
|
ECOMMERCE_SCRAPE_TARGET_FAILURE.labels(
|
||||||
product_name=scrape_target.product_name,
|
product_name=scrape_target.product_name,
|
||||||
|
|
Loading…
Reference in New Issue