Beispiel #1
0
def getCpuStatus(server):

    profiler = CPUProfiler(server)
    data = profiler.getStatus()

    if 'request_id' in request.args:
        data['response_id'] = request.args['request_id']
    return jsonify(data)
Beispiel #2
0
def getCpuTop(server):

    profiler = CPUProfiler(server)
    data = profiler.getTopOutput()

    if 'request_id' in request.args:
        data['response_id'] = request.args['request_id']
    return jsonify(data)
Beispiel #3
0
def get_top(request):
    print('received cpu.top.req: ' + request['server'])

    server = request['server']
    profiler = CPUProfiler(server)
    data = profiler.getTopOutput()

    if "request_id" in request:
        data['response_id'] = request['request_id']

    emit('cpu.top.res', data)
Beispiel #4
0
def get_avg_load(request):
    print('received cpu.avgload.req: ' + request['server'])

    server = request['server']
    profiler = CPUProfiler(server)
    data = profiler.get_average_load()

    if "request_id" in request:
        data['response_id'] = request['request_id']

    emit('cpu.avgload.res', data)
Beispiel #5
0
def get_cpu_softirq(request):
    server = request['server']
    interval = request['interval']
    socketio = cpu_blueprint.get_io()
    global cpu_softirq_timer
    if cpu_softirq_timer is None:
        cpu_softirq_timer = Timer(interval, background_timer_stuff, [
            socketio, interval, "cpu.softirq.res",
            CPUProfiler(server).get_softirq
        ])
        cpu_softirq_timer.start()
    emit("cpu.softirq.res", CPUProfiler(server).get_softirq())
Beispiel #6
0
def get_avg_load(request):
    server = request['server']
    interval = request['interval']
    socketio = cpu_blueprint.get_io()
    global cpu_avg_timer
    if cpu_avg_timer is None:
        cpu_avg_timer = Timer(interval, background_timer_stuff, [
            socketio, interval, "cpu.avgload.res",
            CPUProfiler(server).get_average_load
        ])
        cpu_avg_timer.start()
    emit("cpu.avgload.res", CPUProfiler(server).get_average_load())
Beispiel #7
0
def get_top(request):
    server = request['server']
    interval = request['interval']
    socketio = cpu_blueprint.get_io()
    global cpu_top_timer
    if cpu_top_timer is None:
        cpu_top_timer = Timer(interval, background_timer_stuff, [
            socketio, interval, "cpu.top.res",
            CPUProfiler(server).getTopOutput
        ])
        cpu_top_timer.start()
    emit("cpu.top.res", CPUProfiler(server).getTopOutput())
Beispiel #8
0
def get_average_load(server):
    # options = {
    #     'is_debug': False,
    # }
    # if not request.args['debug']:
    #     options['is_debug'] = request.args['debug']

    profiler = CPUProfiler(server)
    data = profiler.get_average_load()

    if 'request_id' in request.args:
        data['response_id'] = request.args['request_id']
    return jsonify(data)
Beispiel #9
0
def get_cpu_status(request):
    print('received cpu.status.req: ' + request['server'])

    server = request['server']
    profiler = CPUProfiler(server)
    data = profiler.getStatus()

    if "request_id" in request:
        data['response_id'] = request['request_id']

    if "request_time" in request:
        data['request_time'] = request['request_time']

    emit('cpu.status.res', data)
Beispiel #10
0
class GetProcLoadavgTestCase(LepvTestCase):
    def setUp(self):
        self.profiler = CPUProfiler('')

    def validate(self, expected, actual, expectedMatchType):

        print("Actual:")
        pprint(actual)

        compare_result = DictUtil.compare(actual, expected)

        if expectedMatchType == 'equals':
            self.assertEqual(compare_result, 0,
                             "Expected and Actual does not match")
        elif expectedMatchType == 'contains':
            self.assertIn(compare_result, [0, 1],
                          "Actual does not contain the expected")
        else:
            print("")

    @file_data("unittests.json")
    def test(self, kernel, os, cpu, note, lepdResult, expected,
             expectedMatchType):
        self.describe(kernel, os, cpu, note, expectedMatchType, expected)

        actual = self.profiler.get_average_load(lepdResult)
        self.validate(expected, actual, expectedMatchType)
Beispiel #11
0
class CpuProfilerTest(unittest.TestCase):

    def setUp(self):
        self.server = 'www.rmlink.cn'
        self.profiler = CPUProfiler(self.server)

    def test_getCpuCount(self):

        returnedData = self.profiler.getProcessorCount()

        self.assertIn('count', returnedData, "'count' is not a key in the returned object")

        count = returnedData['count']
        self.assertTrue(isinstance(count, int), "CPU processor count '%s' is not an integer" % count)
Beispiel #12
0
 def setUp(self):
     self.server = 'www.rmlink.cn'
     self.profiler = CPUProfiler(self.server)
Beispiel #13
0
 def test_stability(self):
     profiler = CPUProfiler('www.rmlink.cn')
     self.repeated_test(profiler.get_capacity)
Beispiel #14
0
 def setUp(self):
     self.functor = CPUProfiler('').get_processor_count
Beispiel #15
0
 def setUp(self):
     self.functor = CPUProfiler('').get_proc_cpu_info
Beispiel #16
0
 def setUp(self):
     self.functor = CPUProfiler('').get_average_load
Beispiel #17
0
 def setUp(self):
     self.functor = CPUProfiler('').getTopOutput
Beispiel #18
0
 def test_stability(self):
     profiler = CPUProfiler('www.rmlink.cn')
     self.repeated_test(profiler.getTopOutput)
Beispiel #19
0
 def setUp(self):
     self.profiler = CPUProfiler('')
Beispiel #20
0
def getCpuCount(server):

    profiler = CPUProfiler(server)
    data = profiler.getProcessorCount()

    return jsonify(data)
Beispiel #21
0
class GetProcLoadavgTestCase(unittest.TestCase):

    def setUp(self):
        self.profiler = CPUProfiler('')

    def describe(self, test_data):
        for test_data_key in test_data:
            if test_data_key == 'lepdResult':
                continue
            if test_data_key == 'expected':
                continue

            print(test_data_key + ": " + test_data[test_data_key])

    def doPositiveTest(self, test_data):
        self.describe(test_data)

        actual_result = self.profiler.get_average_load(test_data['lepdResult'])

        # self.assertTrue(isinstance(count, int), "CPU processor count '%s' is not an integer" % count)
        self.assertTrue(actual_result, "Result should NOT be null")

        self.assertIn('data', actual_result, "field 'data' should present")

        actualData = actual_result['data']
        self.assertIn('last1', actualData, "'last1' should present in 'data'")
        self.assertEqual(str(test_data['expected']['data']['last1']), str(actualData['last1']), "'last1' values do NOT match!")

        self.assertIn('last5', actualData, "'last5' should present in 'data'")
        self.assertEqual(str(test_data['expected']['data']['last5']), str(actualData['last5']), "'last5' values do NOT match!")

        self.assertIn('last15', actualData, "'last15' should present in 'data'")
        self.assertEqual(str(test_data['expected']['data']['last15']), str(actualData['last15']), "'last15' values do NOT match!")

    def testGoldenPass(self):

        test_data = {
          "kernel": "",
          "os": "linux",
          "cpu": "x86",
          "note": "data from www.rmlink.cn",
          "lepdResult":	"0.18 0.19 0.12 1/77 11132\nlepdendstring",
          "expected": {
            "data": {
              "last1": 0.18,
              "last5": 0.19,
              "last15": 0.12
            }
          }
        }

        self.doPositiveTest(test_data)


    def testGoldenPassForX86(self):

        test_data = {
          "kernel": "",
          "os": "linux",
          "cpu": "x86",
          "note": "data from www.rmlink.cn",
          "lepdResult":	"0.18 0.79 0.92 1/77 11132\nlepdendstring",
          "expected": {
            "data": {
              "last1": 0.18,
              "last5": 0.79,
              "last15": 0.92
            }
          }
        }

        self.doPositiveTest(test_data)
Beispiel #22
0
def get_avg_load(request):
    server = request['server']
    process_socket_request(request, 'cpu.avgload.req',
                           CPUProfiler(server).get_average_load)
Beispiel #23
0
def get_top(request):
    server = request['server']
    process_socket_request(request, 'cpu.top.req',
                           CPUProfiler(server).getTopOutput)
Beispiel #24
0
def getCpuCapacity(server):

    profiler = CPUProfiler(server)
    data = profiler.getCapacity()

    return jsonify(data)
Beispiel #25
0
def get_cpu_stat(request):
    server = request['server']
    process_socket_request(request, 'cpu.stat.req',
                           CPUProfiler(server).get_irq)
Beispiel #26
0
 def test_stability(self):
     profiler = CPUProfiler('www.rmlink.cn')
     self.repeated_test(profiler.get_average_load)
Beispiel #27
0
 def setUp(self):
     self.functor = CPUProfiler('').get_irq