|
@@ -2,9 +2,12 @@
|
|
|
import requests
|
|
|
import json
|
|
|
import copy
|
|
|
+import re
|
|
|
from rrd import config
|
|
|
from rrd.consts import ENDPOINT_DELIMITER
|
|
|
from rrd.model.graph import TmpGraph
|
|
|
+from rrd.model.endpoint import Endpoint
|
|
|
+from rrd.model.endpoint_counter import EndpointCounter
|
|
|
|
|
|
def generate_graph_urls(graph, start, end):
|
|
|
counters = graph.counters or []
|
|
@@ -15,6 +18,50 @@ def generate_graph_urls(graph, start, end):
|
|
|
if not endpoint_list:
|
|
|
return []
|
|
|
|
|
|
+ endpoint_objs = Endpoint.gets_by_endpoint(endpoint_list)
|
|
|
+ if not endpoint_objs:
|
|
|
+ return []
|
|
|
+ endpoint_ids = [x.id for x in endpoint_objs]
|
|
|
+
|
|
|
+ counters = []
|
|
|
+ for c in graph.counters:
|
|
|
+ if c.find("metric=") == -1:
|
|
|
+ counters.append(c)
|
|
|
+ else:
|
|
|
+ metric=""
|
|
|
+ tags = []
|
|
|
+ qs = []
|
|
|
+ c = c.strip()
|
|
|
+ for q in c.split():
|
|
|
+ q = q.strip()
|
|
|
+ if q.startswith("metric="):
|
|
|
+ metric = q.replace("metric=", "", 1)
|
|
|
+ qs.append(metric)
|
|
|
+ else:
|
|
|
+ qs.append(q)
|
|
|
+ tags.append(q)
|
|
|
+
|
|
|
+ counter_objs = EndpointCounter.search_in_endpoint_ids(qs, endpoint_ids[:], limit=100)
|
|
|
+ if not counter_objs:
|
|
|
+ continue
|
|
|
+ for co in counter_objs:
|
|
|
+ if not re.search('^%s(/|$)' %metric, co.counter):
|
|
|
+ continue
|
|
|
+
|
|
|
+ matched = True
|
|
|
+ for tag in tags:
|
|
|
+ if not re.search('(/|,)%s(,|$)' %tag, co.counter):
|
|
|
+ matched = False
|
|
|
+ break
|
|
|
+ if not matched:
|
|
|
+ continue
|
|
|
+
|
|
|
+ counters.append(co.counter)
|
|
|
+
|
|
|
+ if not counters:
|
|
|
+ return []
|
|
|
+ counters = sorted(list(set(counters)))
|
|
|
+
|
|
|
return _generate_graph_urls(graph, counters, endpoint_list, start, end)
|
|
|
|
|
|
def _generate_graph_urls(graph, counters, endpoint_list, start, end):
|