mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-08 12:52:12 +02:00
Merge 3b724746a3 into fd8d5b2c42
This commit is contained in:
commit
ea244ff413
1 changed files with 20 additions and 2 deletions
|
|
@ -7,6 +7,7 @@ import logging
|
||||||
import time
|
import time
|
||||||
import asyncio
|
import asyncio
|
||||||
import inspect
|
import inspect
|
||||||
|
import re
|
||||||
import threading
|
import threading
|
||||||
from typing import Dict, Any, List, Optional, Callable
|
from typing import Dict, Any, List, Optional, Callable
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
|
@ -275,6 +276,23 @@ class MetricsCollector:
|
||||||
label_str = ','.join(f"{k}={v}" for k, v in sorted(labels.items()))
|
label_str = ','.join(f"{k}={v}" for k, v in sorted(labels.items()))
|
||||||
return f"{name}{{{label_str}}}"
|
return f"{name}{{{label_str}}}"
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _extract_label(metric_key: str, label: str) -> Optional[str]:
|
||||||
|
"""Extract a label value from a metric key built by _build_key.
|
||||||
|
|
||||||
|
Metric keys follow the format: name{key1=val1,key2=val2}
|
||||||
|
Returns None if the label is not found.
|
||||||
|
"""
|
||||||
|
prefix = f"{label}="
|
||||||
|
if prefix not in metric_key:
|
||||||
|
return None
|
||||||
|
# Find the label= then get value until , or }
|
||||||
|
after_label = metric_key.split(prefix, 1)[1]
|
||||||
|
for delim in (',', '}'):
|
||||||
|
if delim in after_label:
|
||||||
|
return after_label.split(delim, 1)[0]
|
||||||
|
return after_label
|
||||||
|
|
||||||
|
|
||||||
class PerformanceMonitor:
|
class PerformanceMonitor:
|
||||||
"""Monitors system performance and component health."""
|
"""Monitors system performance and component health."""
|
||||||
|
|
@ -474,8 +492,8 @@ class PerformanceMonitor:
|
||||||
# Cache performance
|
# Cache performance
|
||||||
cache_types = set()
|
cache_types = set()
|
||||||
for metric_name in self.metrics_collector.counters.keys():
|
for metric_name in self.metrics_collector.counters.keys():
|
||||||
if 'cache_type=' in metric_name:
|
cache_type = self.metrics_collector._extract_label(metric_name, 'cache_type')
|
||||||
cache_type = metric_name.split('cache_type=')[1].split(',')[0].split('}')[0]
|
if cache_type is not None:
|
||||||
cache_types.add(cache_type)
|
cache_types.add(cache_type)
|
||||||
|
|
||||||
for cache_type in cache_types:
|
for cache_type in cache_types:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue