Пример #1
0
    def get(self):
        endpoint, _start, _end, category = request_parser(request)

        # 构造查询条件
        query = {
            "timestamp": {
                "$gt": _start,
                "$lt": _end
            },
            "endpoint": endpoint
        }

        mems = app.db.Mem.find(query, project)
        data = list(mems)

        # 格式化返回数据
        metric = {
            "categories": [],
            "series": [],
        }
        # 用于存储每次返回数据的横轴
        x_axis = []
        series = [{
            "name": "total",
            "data": []
        }, {
            "name": "used",
            "data": []
        }, {
            "name": "free",
            "data": []
        }, {
            "name": "shared",
            "data": []
        }, {
            "name": "buffers",
            "data": []
        }, {
            "name": "cached",
            "data": []
        }]

        for item in data:
            format_time = datetime.fromtimestamp(item['timestamp'])\
                .strftime("%Y-%m-%d %H:%M:%S")
            x_axis.append(format_time)
            series[0]['data'].append(item['value'][0])
            series[1]['data'].append(item['value'][1])
            series[2]['data'].append(item['value'][2])
            series[3]['data'].append(item['value'][3])
            series[4]['data'].append(item['value'][4])
            series[5]['data'].append(item['value'][5])

        metric['categories'] = x_axis
        if category == 'all':
            metric['series'] = series
        else:
            metric['series'].append(series[categories[category]])

        return jsonify(metric)
Пример #2
0
    def get(self):
        endpoint, _start, _end, category = request_parser(request)

        # 构造查询条件
        query = {
            "timestamp": {"$gt": _start, "$lt": _end},
            "endpoint": endpoint
        }

        swaps = app.db.Swap.find(query, project)
        data = list(swaps)

        # 格式化返回数据
        metric = {
            "categories": [],
            "series": [],
        }
        # 用于存储每次返回数据的横轴
        x_axis = []
        series = [
            {
                "name": "total",
                "data": []
            },
            {
                "name": "used",
                "data": []
            },
            {
                "name": "free",
                "data": []
            }
        ]

        for item in data:
            format_time = datetime.fromtimestamp(item['timestamp'])\
                .strftime("%Y-%m-%d %H:%M:%S")
            x_axis.append(format_time)
            series[0]['data'].append(item['value'][0])
            series[1]['data'].append(item['value'][1])
            series[2]['data'].append(item['value'][2])

        metric['categories'] = x_axis
        if category == 'all':
            metric['series'] = series
        else:
            metric['series'].append(series[categories[category]])

        return jsonify(metric)
Пример #3
0
    def get(self):
        endpoint, _start, _end, category = request_parser(request)

        # 构造查询条件
        query = {
            "timestamp": {
                "$gt": _start,
                "$lt": _end
            },
            "endpoint": endpoint
        }

        cpus = app.db.CPU.find(query, project)
        data = list(cpus)

        # 格式化返回数据
        metric = {
            "categories": [],
            "series": [],
        }
        # 用于存储每次返回数据的横轴
        x_axis = []
        series = [{
            "name": "user",
            "data": []
        }, {
            "name": "system",
            "data": []
        }, {
            "name": "idle",
            "data": []
        }, {
            "name": "nice",
            "data": []
        }, {
            "name": "iowait",
            "data": []
        }, {
            "name": "irq",
            "data": []
        }, {
            "name": "softirq",
            "data": []
        }, {
            "name": "steal",
            "data": []
        }, {
            "name": "guest",
            "data": []
        }, {
            "name": "guest_nice",
            "data": []
        }]

        for item in data:
            format_time = datetime.fromtimestamp(item['timestamp'])\
                .strftime("%Y-%m-%d %H:%M:%S")
            x_axis.append(format_time)
            series[0]['data'].append(item['value'][0])
            series[1]['data'].append(item['value'][1])
            series[2]['data'].append(item['value'][2])
            series[3]['data'].append(item['value'][3])
            series[4]['data'].append(item['value'][4])
            series[5]['data'].append(item['value'][5])
            series[6]['data'].append(item['value'][6])
            series[7]['data'].append(item['value'][7])
            series[8]['data'].append(item['value'][8])
            series[9]['data'].append(item['value'][9])

        metric['categories'] = x_axis
        if category == 'all':
            metric['series'] = series
        else:
            metric['series'].append(series[categories[category]])

        return jsonify(metric)
Пример #4
0
    def get(self):
        endpoint, _start, _end, category = request_parser(request)

        # 构造查询条件
        query = {
            "timestamp": {"$gt": _start, "$lt": _end},
            "endpoint": endpoint
        }

        cpus = app.db.CPU.find(query, project)
        data = list(cpus)

        # 格式化返回数据
        metric = {
            "categories": [],
            "series": [],
        }
        # 用于存储每次返回数据的横轴
        x_axis = []
        series = [
            {
                "name": "user",
                "data": []
            },
            {
                "name": "system",
                "data": []
            },
            {
                "name": "idle",
                "data": []
            },
            {
                "name": "nice",
                "data": []
            },
            {
                "name": "iowait",
                "data": []
            },
            {
                "name": "irq",
                "data": []
            },
            {
                "name": "softirq",
                "data": []
            },
            {
                "name": "steal",
                "data": []
            },
            {
                "name": "guest",
                "data": []
            },
            {
                "name": "guest_nice",
                "data": []
            }
        ]

        for item in data:
            format_time = datetime.fromtimestamp(item['timestamp'])\
                .strftime("%Y-%m-%d %H:%M:%S")
            x_axis.append(format_time)
            series[0]['data'].append(item['value'][0])
            series[1]['data'].append(item['value'][1])
            series[2]['data'].append(item['value'][2])
            series[3]['data'].append(item['value'][3])
            series[4]['data'].append(item['value'][4])
            series[5]['data'].append(item['value'][5])
            series[6]['data'].append(item['value'][6])
            series[7]['data'].append(item['value'][7])
            series[8]['data'].append(item['value'][8])
            series[9]['data'].append(item['value'][9])

        metric['categories'] = x_axis
        if category == 'all':
            metric['series'] = series
        else:
            metric['series'].append(series[categories[category]])

        return jsonify(metric)