Conversion to milliseconds
Change-Id: I7f7b03e1ebf1189acda2baeb5de95b8972c46cba
This commit is contained in:
parent
16c13e5ae1
commit
ee0952dd2a
|
@ -6,7 +6,7 @@ log_dir = .
|
|||
log_level = DEBUG
|
||||
|
||||
# Identifies the region that the Monasca API is running in.
|
||||
region = na
|
||||
region = useast
|
||||
|
||||
# Dispatchers to be loaded to serve restful APIs
|
||||
dispatcher = v2_ref_metrics
|
||||
|
@ -18,10 +18,10 @@ dispatcher = v2_ref_notifications
|
|||
|
||||
[security]
|
||||
# The roles that are allowed full access to the API.
|
||||
default_authorized_roles = admin,monasca-user
|
||||
default_authorized_roles = user, domainuser, domainadmin, monasca-user
|
||||
|
||||
# The roles that are allowed to only POST metrics to the API. This role would be used by the Monasca Agent.
|
||||
agent_authorized_roles = agent
|
||||
agent_authorized_roles = monasca-agent
|
||||
|
||||
# The roles that are allowed to access the API on behalf of another tenant.
|
||||
# For example, a service can POST metrics to another tenant if they are a member of the "delegate" role.
|
||||
|
|
|
@ -25,7 +25,7 @@ paste.filter_factory = monasca.middleware.keystone_context_filter:filter_factory
|
|||
|
||||
[server:main]
|
||||
use = egg:gunicorn#main
|
||||
host = 0.0.0.0
|
||||
port = 9000
|
||||
host = 127.0.0.1
|
||||
port = 8080
|
||||
workers = 1
|
||||
proc_name = monasca
|
||||
|
|
|
@ -70,5 +70,5 @@ if __name__ == '__main__':
|
|||
wsgi_app = (
|
||||
paste.deploy.loadapp('config:etc/monasca.ini',
|
||||
relative_to=os.getcwd()))
|
||||
httpd = simple_server.make_server('127.0.0.1', 9000, wsgi_app)
|
||||
httpd = simple_server.make_server('127.0.0.1', 8080, wsgi_app)
|
||||
httpd.serve_forever()
|
||||
|
|
|
@ -30,7 +30,6 @@ LOG = log.getLogger(__name__)
|
|||
|
||||
|
||||
class MetricsRepository(metrics_repository.MetricsRepository):
|
||||
|
||||
def __init__(self):
|
||||
|
||||
try:
|
||||
|
@ -55,10 +54,10 @@ class MetricsRepository(metrics_repository.MetricsRepository):
|
|||
|
||||
def _build_list_series_query(self, dimensions, name, tenant_id, region):
|
||||
|
||||
from_clause = self._build_from_clause(dimensions, name, tenant_id,
|
||||
region)
|
||||
regex_clause = self._build_regex_clause(dimensions, name, tenant_id,
|
||||
region)
|
||||
|
||||
query = 'list series ' + from_clause
|
||||
query = 'list series ' + regex_clause
|
||||
|
||||
return query
|
||||
|
||||
|
@ -98,43 +97,51 @@ class MetricsRepository(metrics_repository.MetricsRepository):
|
|||
|
||||
return query
|
||||
|
||||
def _build_from_clause(self, dimensions, name, tenant_id, region,
|
||||
start_timestamp=None, end_timestamp=None):
|
||||
def _build_regex_clause(self, dimensions, name, tenant_id, region,
|
||||
start_timestamp=None, end_timestamp=None):
|
||||
|
||||
from_clause = 'from /^'
|
||||
regex_clause = '/^'
|
||||
|
||||
# tenant id
|
||||
from_clause += urllib.quote(tenant_id.encode('utf8'), safe='')
|
||||
regex_clause += urllib.quote(tenant_id.encode('utf8'), safe='')
|
||||
|
||||
# region
|
||||
from_clause += '\?' + urllib.quote(region.encode('utf8'), safe='')
|
||||
regex_clause += '\?' + urllib.quote(region.encode('utf8'), safe='')
|
||||
|
||||
# name - optional
|
||||
if name:
|
||||
from_clause += '&' + urllib.quote(name.encode('utf8'), safe='')
|
||||
from_clause += '(&|$)'
|
||||
regex_clause += '&' + urllib.quote(name.encode('utf8'), safe='')
|
||||
regex_clause += '(&|$)'
|
||||
|
||||
# dimensions - optional
|
||||
if dimensions:
|
||||
for dimension_name, dimension_value in iter(
|
||||
sorted(dimensions.iteritems())):
|
||||
from_clause += '(.*&)*'
|
||||
from_clause += urllib.quote(dimension_name.encode('utf8'),
|
||||
safe='')
|
||||
from_clause += '='
|
||||
from_clause += urllib.quote(dimension_value.encode('utf8'),
|
||||
safe='')
|
||||
from_clause += '(&|$)'
|
||||
regex_clause += '(.*&)*'
|
||||
regex_clause += urllib.quote(dimension_name.encode('utf8'),
|
||||
safe='')
|
||||
regex_clause += '='
|
||||
regex_clause += urllib.quote(dimension_value.encode('utf8'),
|
||||
safe='')
|
||||
regex_clause += '(&|$)'
|
||||
|
||||
from_clause += '/'
|
||||
regex_clause += '/'
|
||||
|
||||
if start_timestamp is not None:
|
||||
# subtract 1 from timestamp to get >= semantics
|
||||
from_clause += " where time > " + str(start_timestamp - 1) + "s"
|
||||
regex_clause += " where time > " + str(start_timestamp - 1) + "s"
|
||||
if end_timestamp is not None:
|
||||
# add 1 to timestamp to get <= semantics
|
||||
from_clause += " and time < " + str(end_timestamp + 1) + "s"
|
||||
regex_clause += " and time < " + str(end_timestamp + 1) + "s"
|
||||
|
||||
return regex_clause
|
||||
|
||||
def _build_from_clause(self, dimensions, name, tenant_id, region,
|
||||
start_timestamp=None, end_timestamp=None):
|
||||
from_clause = 'from '
|
||||
from_clause += self._build_regex_clause(dimensions, name, tenant_id,
|
||||
region, start_timestamp,
|
||||
end_timestamp)
|
||||
return from_clause
|
||||
|
||||
def list_metrics(self, tenant_id, region, name, dimensions, offset):
|
||||
|
@ -310,7 +317,7 @@ class MetricsRepository(metrics_repository.MetricsRepository):
|
|||
end_timestamp, offset)
|
||||
|
||||
try:
|
||||
result = self.influxdb_client.query(query, 's')
|
||||
result = self.influxdb_client.query(query, 'ms')
|
||||
except client.InfluxDBClientError as ex:
|
||||
# check for non-existent serie name.
|
||||
msg = "Couldn't look up columns"
|
||||
|
@ -334,8 +341,10 @@ class MetricsRepository(metrics_repository.MetricsRepository):
|
|||
columns]
|
||||
|
||||
# format the utc date in the points
|
||||
fmtd_pts = [[time.strftime("%Y-%m-%dT%H:%M:%SZ",
|
||||
time.gmtime(point[0])), point[1],
|
||||
fmtd_pts = [['%s.%03dZ' % (time.strftime('%Y-%m-%dT%H:%M:%S',
|
||||
time.gmtime(
|
||||
point[0] / 1000)),
|
||||
point[0] % 1000), point[1],
|
||||
point[2]] for point in serie['points']]
|
||||
|
||||
# Set the last point's time as the id. Used for next link.
|
||||
|
@ -498,7 +507,7 @@ class MetricsRepository(metrics_repository.MetricsRepository):
|
|||
|
||||
alarm_id_where_clause_list = (
|
||||
[" alarm_id = '{}' ".format(id.encode('utf8'))
|
||||
for id in alarm_id_list])
|
||||
for id in alarm_id_list])
|
||||
|
||||
alarm_id_where_clause = " or ".join(alarm_id_where_clause_list)
|
||||
|
||||
|
|
Loading…
Reference in New Issue