Skip to content

Commit

Permalink
updated queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Avi-Robusta committed Jul 23, 2024
1 parent 360acce commit e302a5c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/robusta/core/sinks/robusta/dal/supabase_dal.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,13 +556,13 @@ def publish_namespaces(self, namespaces: List[NamespaceInfo]):
logging.error(f"Failed to persist namespaces {namespaces} error: {e}")
raise

def publish_cluster_nodes(self, node_count: int, pod_count: int, avg_cpu: float, avg_mem: float):
def publish_cluster_nodes(self, node_count: int, pod_count: int, avg_cpu: Optional[float] = None, avg_mem: Optional[float] = None):
data = {
"_account_id": self.account_id,
"_cluster_id": self.cluster,
"_node_count": node_count,
"_cpu_utilization": avg_cpu,
"_memory_utilization": int(avg_mem),
"_memory_utilization": avg_mem,
"_pod_count": pod_count
}
try:
Expand Down
10 changes: 5 additions & 5 deletions src/robusta/core/sinks/robusta/prometheus_discovery_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ def get_status(self) -> PrometheusHealthStatus:

def get_cluster_avg_cpu(self) -> Optional[float]:
cpu_query = os.getenv("OVERRIDE_CLUSTER_CPU_AVG_QUERY",
f'avg_over_time(sum(irate(container_cpu_usage_seconds_total{{}}[5m]))[1h:])')
f'100 * sum(rate(node_cpu_seconds_total{{mode!="idle"}}[1h])) / sum(machine_cpu_cores{{}})')
return self._get_query_prometheus_value(query=cpu_query)

def get_cluster_avg_memory(self) -> Optional[float]:
memory_query = os.getenv("OVERRIDE_CLUSTER_MEM_AVG_QUERY",
f'avg_over_time(sum(container_memory_usage_bytes{{}})[1h:])')
f'100 * (1 - sum(avg_over_time(node_memory_MemAvailable_bytes{{}}[1h])) / sum(machine_memory_bytes{{}}))')
return self._get_query_prometheus_value(query=memory_query)

def _get_query_prometheus_value(self, query: str) -> Optional[float]:
global_config = self.__global_config
prometheus_params = PrometheusParams(**global_config)
query_result = run_prometheus_query(prometheus_params=prometheus_params, query=query)
try:
global_config = self.__global_config
prometheus_params = PrometheusParams(**global_config)
query_result = run_prometheus_query(prometheus_params=prometheus_params, query=query)
if query_result.result_type == "error" or query_result.vector_result is None:
logging.error(f"PrometheusDiscoveryUtils failed to get prometheus results.")
return
Expand Down

0 comments on commit e302a5c

Please sign in to comment.