11import json
2+ import re
23import time
34from typing import Dict , List , Optional
45
@@ -107,6 +108,7 @@ class PrometheusBenchmarkMetricsCollector:
107108 """Collects Prometheus client_java benchmark metrics from GitHub."""
108109
109110 RESULTS_URL = "https://raw.githubusercontent.com/prometheus/client_java/benchmarks/results.json"
111+ README_URL = "https://raw.githubusercontent.com/prometheus/client_java/benchmarks/README.md"
110112
111113 def __init__ (self ):
112114 self .parser = JMHResultsParser ()
@@ -121,6 +123,40 @@ def fetch_results(self) -> Optional[str]:
121123 print (f" Error fetching results.json: { e } " )
122124 return None
123125
126+ def fetch_readme (self ) -> Optional [str ]:
127+ try :
128+ print (f" Fetching README.md from { self .README_URL } ..." )
129+ response = requests .get (self .README_URL , timeout = 30 )
130+ response .raise_for_status ()
131+ return response .text
132+ except requests .RequestException as e :
133+ print (f" Error fetching README.md: { e } " )
134+ return None
135+
136+ def parse_processor_type (self , readme_content : str ) -> str :
137+ """
138+ Parse the processor type from README.md.
139+
140+ Expected format:
141+ - **Hardware:** AMD EPYC 7763 64-Core Processor, 4 cores, 16 GB RAM
142+
143+ Returns:
144+ Processor type string or "unknown" if not found.
145+ """
146+ try :
147+ # Look for the Hardware line in the README
148+ hardware_match = re .search (r'-\s*\*\*Hardware:\*\*\s*([^,]+)' , readme_content )
149+ if hardware_match :
150+ processor = hardware_match .group (1 ).strip ()
151+ print (f" Found processor: { processor } " )
152+ return processor
153+ else :
154+ print (" Warning: Could not find processor information in README.md" )
155+ return "unknown"
156+ except Exception as e :
157+ print (f" Error parsing processor type: { e } " )
158+ return "unknown"
159+
124160 def collect_and_export_metrics (self ):
125161 print ("Collecting Prometheus client_java benchmark metrics..." )
126162 print ("=" * 60 )
@@ -130,6 +166,14 @@ def collect_and_export_metrics(self):
130166 print (" Failed to fetch results. Exiting." )
131167 return
132168
169+ readme_content = self .fetch_readme ()
170+ processor_type = "unknown"
171+ if readme_content :
172+ processor_type = self .parse_processor_type (readme_content )
173+ else :
174+ print (" Warning: Could not fetch README.md, using 'unknown' for processor type" )
175+ print ()
176+
133177 try :
134178 benchmarks = self .parser .parse_results (results_content )
135179 print (f" Parsed { len (benchmarks )} benchmark results" )
@@ -163,6 +207,7 @@ def collect_and_export_metrics(self):
163207 "threads" : str (benchmark ["threads" ]),
164208 "forks" : str (benchmark ["forks" ]),
165209 "unit" : benchmark ["score_unit" ],
210+ "processor" : processor_type ,
166211 }
167212 )
168213
@@ -176,6 +221,7 @@ def collect_and_export_metrics(self):
176221 "threads" : str (benchmark ["threads" ]),
177222 "forks" : str (benchmark ["forks" ]),
178223 "unit" : benchmark ["score_unit" ],
224+ "processor" : processor_type ,
179225 }
180226 )
181227
0 commit comments