Fetch posting list cache metrics from Dgraph Prometheus endpoint.
(host: str = "localhost", port: int = 8080)
| 111 | |
| 112 | |
| 113 | def fetch_cache_metrics(host: str = "localhost", port: int = 8080) -> Dict[str, float]: |
| 114 | """Fetch posting list cache metrics from Dgraph Prometheus endpoint.""" |
| 115 | target_metrics = [ |
| 116 | "dgraph_hit_ratio_posting_cache", |
| 117 | ] |
| 118 | metrics: Dict[str, float] = {} |
| 119 | |
| 120 | try: |
| 121 | resp = requests.get(f"http://{host}:{port}/debug/prometheus_metrics", timeout=5) |
| 122 | resp.raise_for_status() |
| 123 | |
| 124 | for line in resp.text.splitlines(): |
| 125 | if not line or line.startswith("#"): |
| 126 | continue |
| 127 | for target in target_metrics: |
| 128 | if line.startswith(target): |
| 129 | # Handle labels like {method="",status=""} - value is after the closing brace |
| 130 | if "{" in line: |
| 131 | value_part = line.split("}")[-1].strip() |
| 132 | else: |
| 133 | value_part = line.split()[-1] |
| 134 | try: |
| 135 | metrics[target] = float(value_part) |
| 136 | except ValueError: |
| 137 | pass |
| 138 | break |
| 139 | except Exception as e: |
| 140 | print(f"Warning: Could not fetch cache metrics: {e}") |
| 141 | |
| 142 | return metrics |
| 143 | |
| 144 | |
| 145 | def save_results_to_csv(results: Dict, k_values: List[int], output_file: str = "./results/benchmark_results.csv"): |