From 144fdbff40c1b8339e18b59fa48e6bddda2434a4 Mon Sep 17 00:00:00 2001 From: Berant Lemmenes Date: Wed, 27 Sep 2023 10:19:11 -0400 Subject: [PATCH 1/2] Add argument to adjust timeout when requesting data from the cluster --- radosgw_usage_exporter.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/radosgw_usage_exporter.py b/radosgw_usage_exporter.py index fbfc0f0..b1906c3 100644 --- a/radosgw_usage_exporter.py +++ b/radosgw_usage_exporter.py @@ -26,13 +26,14 @@ class RADOSGWCollector(object): enabled by 'rgw enable usage log = true' in the appropriate section of ceph.conf see Ceph documentation for details """ - def __init__(self, host, admin_entry, access_key, secret_key, cluster_name, insecure): + def __init__(self, host, admin_entry, access_key, secret_key, cluster_name, insecure, timeout): super(RADOSGWCollector, self).__init__() self.host = host self.access_key = access_key self.secret_key = secret_key self.cluster_name = cluster_name self.insecure = insecure + self.timeout = timeout # helpers for default schema if not self.host.startswith("http"): @@ -111,7 +112,7 @@ def _request_data(self, query, args): url = "{0}{1}/?format=json&{2}".format(self.url, query, args) try: - response = self.session.get(url, verify=self.insecure, + response = self.session.get(url, verify=self.insecure, timeout=self.timeout, auth=S3Auth(self.access_key, self.secret_key, self.host)) @@ -492,14 +493,18 @@ def parse_args(): help='Port to listen', default=int(os.environ.get('VIRTUAL_PORT', '9242')) ) - parser.add_argument( '-c', '--cluster', required=False, help='cluster name', default=os.environ.get('CLUSTER_NAME', 'ceph'), ) - + parser.add_argument( + '-t', '--timeout', + required=False, + help='Timeout when getting metrics', + default=os.environ.get('TIMEOUT', '60'), + ) return parser.parse_args() @@ -507,7 +512,7 @@ def main(): try: args = parse_args() REGISTRY.register(RADOSGWCollector( - args.host, args.admin_entry, args.access_key, args.secret_key, args.cluster, args.insecure)) + args.host, args.admin_entry, args.access_key, args.secret_key, args.cluster, args.insecure, args.timeout)) start_http_server(args.port) print(("Polling {0}. Serving at port: {1}".format(args.host, args.port))) while True: From 7d12b1c852fce75f5683db2dd23bbea12a7c82cd Mon Sep 17 00:00:00 2001 From: Berant Lemmenes Date: Wed, 4 Oct 2023 07:37:35 -0400 Subject: [PATCH 2/2] change timeout to float --- radosgw_usage_exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radosgw_usage_exporter.py b/radosgw_usage_exporter.py index b1906c3..5f6eade 100644 --- a/radosgw_usage_exporter.py +++ b/radosgw_usage_exporter.py @@ -112,7 +112,7 @@ def _request_data(self, query, args): url = "{0}{1}/?format=json&{2}".format(self.url, query, args) try: - response = self.session.get(url, verify=self.insecure, timeout=self.timeout, + response = self.session.get(url, verify=self.insecure, timeout=float(self.timeout), auth=S3Auth(self.access_key, self.secret_key, self.host))