# Copyright 2016 Huawei Technologies Co. Ltd. # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # """ Collect the wanted data by using ceilometer client to send HTTP request to ceilometer server """ # Import modules import web import subprocess import ceilometerclient.client import json import readline # It automatically wraps studin urls = ( '/', 'Index', '/meter', 'Meter', '/sample', 'Sample' ) app = web.application(urls, globals()) # Global variables c_client = None resource_id_list = [] resource_id = None render = web.template.render('templates', base="layout") class Index(object): def GET(self): return render.source() def POST(self): form = web.input(content=None) dumps = ('/usr/bin/python -c ' '"import os, json; print json.dumps(dict(os.environ))"') command = ['/bin/bash', '-c', form.content + '&&' + dumps] pipe = subprocess.Popen(command, stdout=subprocess.PIPE) env = json.loads(pipe.stdout.read()) # Create an authenticated ceilometer client global c_client c_client = ceilometerclient.client.get_client( "2", os_username=env['OS_USERNAME'], os_password=env['OS_PASSWORD'], os_tenant_name=env['OS_TENANT_NAME'], os_auth_url=env['OS_AUTH_URL']) resource_list = c_client.resources.list() resourceInfo = open("templates/resourceInfo.html", "w") index = 0 resourceInfo.write("
You can collect whatever meters you like just by typing " "the meter names and using ',' as the separator,\n e.g., " "disk.read.requests.rate, disk.write.requests.rate, " "disk.read.bytes.rate, disk.write.bytes.rate, cpu_util.
") metersInfo.write( "At the same time, you need to specify the beginning time and " "the end time for the collection. \nThe time format is fixed, " "e.g., 2016-02-28T00:00:00.
") metersInfo.write( '