23
23
import cherrypy
24
24
import copy
25
25
import json
26
- from messages import ERR , MSG
26
+ from messages import MSG
27
27
from typing import Optional
28
28
from cherrypy .process .plugins import Monitor
29
- from time import time
30
29
from collector import SensorCollector , QueryPolicy
31
30
from utils import execution_time
32
31
@@ -56,7 +55,7 @@ def qh(self):
56
55
def TOPO (self ):
57
56
return self .__md .metaData
58
57
59
- def format_response (self , data )-> [str ]:
58
+ def format_response (self , data ) -> [str ]:
60
59
resp = []
61
60
for name , metric in data .items ():
62
61
header = metric .str_descfmt ()
@@ -127,33 +126,14 @@ def build_collector(self, sensor) -> SensorCollector :
127
126
attrs = {'sensor' : sensor , 'period' : period , 'nsamples' : 1 }
128
127
request = QueryPolicy (** attrs )
129
128
collector = SensorCollector (sensor , period , self .logger , request )
130
- # collector.cache = True
131
- # else:
132
- # ts = calendar.timegm(time.gmtime()) - 15
133
- # ts = int(round(time.time() * 1000))
134
- # ts=int(timer()*1000)
135
-
136
- # ts=int(time()*1000)
137
- # ts1 = ts-1000
138
- # self.logger.trace("ts:{0}, ts1:{1}".format(str(ts),str(ts1)))
139
- # qstart = str(int(int(str(ts1)) / 1000))
140
- # attrs = {'sensor': sensor, 'period': period, 'start': qstart}
141
- # request = QueryPolicy(**attrs)
142
- # collector = SensorCollector(sensor, period, self.logger, request)
143
-
144
- self .logger .debug (f'request instance { str (request .__dict__ )} ' )
145
- self .logger .debug (f'Created Collector instance { str (collector .__dict__ )} ' )
129
+
130
+ self .logger .trace (f'request instance { str (request .__dict__ )} ' )
131
+ self .logger .trace (f'Created Collector instance { str (collector .__dict__ )} ' )
146
132
return collector
147
133
148
134
def GET (self , ** params ):
149
- '''Handle partial URLs such as /api/suggest?q=cpu_&type=metrics
150
- where type is one of metrics, tagk or tagv
151
- or
152
- Handle /api/search/lookup/m=cpu_idle{node=*}
153
- where m is the metric and optional term { tagk = tagv } qualifies the lookup.
154
- For more details please check openTSDB API (version 2.2 and higher) documentation for
155
- /api/lookup
156
- /api/search/lookup
135
+ '''Handle partial URLs such as /metrics_cpu
136
+ TODO: add more explanation
157
137
'''
158
138
resp = []
159
139
@@ -163,7 +143,7 @@ def GET(self, **params):
163
143
164
144
# /update
165
145
if 'update' in cherrypy .request .script_name :
166
- #cherrypy.response.headers['Content-Type'] = 'application/json'
146
+ # cherrypy.response.headers['Content-Type'] = 'application/json'
167
147
resp = self .md .update ()
168
148
169
149
# /metrics_cpu
@@ -207,7 +187,6 @@ def GET(self, **params):
207
187
cherrypy .response .headers ['Content-Type' ] = 'text/plain'
208
188
resString = '\n ' .join (resp ) + '\n '
209
189
return resString
210
- #return bytes(resString, 'utf-8')
211
190
212
191
# /metrics_gpfs_fileset
213
192
elif 'metrics_gpfs_fileset' in cherrypy .request .script_name :
0 commit comments