monitorEvm.py 2.24 KB
Newer Older
1 2
#!/usr/bin/env python
# -*- coding: utf_8 -*-
wanli's avatar
wanli committed
3 4 5 6 7 8

from application.app import db, ma
from .base import PrimaryModel 
from marshmallow import Schema, fields, INCLUDE, EXCLUDE

class MonitorEvmModel(PrimaryModel):
9
    __tablename__ = 'evm_monitor_evm'
wanli's avatar
wanli committed
10 11

    watch = db.Column(db.Integer, nullable = False)
12 13 14 15 16
    heap_map_size = db.Column(db.Integer, nullable = True, default = 0)
    heap_total_size = db.Column(db.Integer, nullable = False, default = 0)
    heap_used_size = db.Column(db.Integer, nullable = True, default = 0)
    stack_total_size = db.Column(db.Integer, nullable = True, default = 0)
    stack_used_size = db.Column(db.Integer, nullable = False, default = 0)
wanli's avatar
wanli committed
17 18 19 20 21

    # __table_args__ = (
    #     db.Index('idx_xxx', 'xxx', mysql_using='btree'),
    # )

22
    def __init__(self, watch, heap_map_size=0, heap_total_size=0, heap_used_size=0, stack_total_size=0, stack_used_size=0):
wanli's avatar
wanli committed
23 24 25 26 27 28 29 30 31 32
        self.watch = watch
        self.heap_map_size = heap_map_size
        self.heap_total_size = heap_total_size
        self.heap_used_size = heap_used_size
        self.stack_total_size = stack_total_size
        self.stack_used_size = stack_used_size

    def __repr__(self):
        return '<MonitorEvmModel %r>' % (self.watch)

33
    def to_dict(self):
wanli's avatar
wanli committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
        return {
            'watch': self.watch,
            'heap_map_size': self.heap_map_size,
            'heap_total_size': self.heap_total_size,
            'heap_used_size': self.heap_used_size,
            'stack_total_size': self.stack_total_size,
            'stack_used_size': self.stack_used_size,
        }


class GetListMonitorEvmSchema(ma.SQLAlchemySchema):
    class Meta:
        # unknown = INCLUDE # 未知字段默认包含
        unknown = EXCLUDE # 未知字段默认排除
        model = MonitorEvmModel

    page = fields.Integer(required=False)
    pageSize = fields.Integer(required=False)
    watch = ma.auto_field()

getListMonitorEvmSchema = GetListMonitorEvmSchema()
getListMonitorEvmsSchema = GetListMonitorEvmSchema(many=True)

class GetMonitorEvmSchema(ma.SQLAlchemySchema):
    class Meta:
        # unknown = INCLUDE # 未知字段默认包含
        unknown = EXCLUDE # 未知字段默认排除
        model = MonitorEvmModel

    watch = ma.auto_field()

getMonitorEvmSchema = GetMonitorEvmSchema()