-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
187 lines (154 loc) · 5.79 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
from sqlalchemy import (
Column,
Integer,
DateTime,
ForeignKey,
String,
Numeric,
)
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base, declared_attr
from sqlalchemy.sql import func
class Base(object):
@declared_attr
def __tablename__(cls):
return cls.__name__.lower()
id = Column(Integer, primary_key=True)
Base = declarative_base(cls=Base)
class Measurement(Base):
created_at = Column(DateTime, default=func.now())
cpu_utilizations = relationship('CPUUtilization', back_populates='measurement')
cpu_stats = relationship('CPUStats', uselist=False, back_populates='measurement')
memory_stats = relationship('MemoryStats', uselist=False, back_populates='measurement')
swap_stats = relationship('SwapStats', uselist=False, back_populates='measurement')
disk_stats = relationship('DiskStats', back_populates='measurement')
processes = relationship('Process', back_populates='measurement')
class CPUUtilization(Base):
measurement_id = Column(Integer, ForeignKey('measurement.id'))
measurement = relationship('Measurement', back_populates='cpu_utilizations')
index = Column(Integer)
total = Column(Integer)
user = Column(Integer)
nice = Column(Integer)
system = Column(Integer)
idle = Column(Integer)
iowait = Column(Integer)
irq = Column(Integer)
softirq = Column(Integer)
steal = Column(Integer)
guest = Column(Integer)
guest_nice = Column(Integer)
def __repr__(self):
return '{}: {}, {}'.format(self.index, self.total, self.idle)
class CPUStats(Base):
measurement_id = Column(Integer, ForeignKey('measurement.id'))
measurement = relationship('Measurement', back_populates='cpu_stats')
ctx_switches = Column(Integer)
interrupts = Column(Integer)
soft_interrupts = Column(Integer)
syscalls = Column(Integer)
def __repr__(self):
return 'ctx_switches: {}, interrupts: {}, soft_interrupts: {}, syscalls: {}'.format(
self.ctx_switches,
self.interrupts,
self.soft_interrupts,
self.syscalls,
)
class MemoryStats(Base):
measurement_id = Column(Integer, ForeignKey('measurement.id'))
measurement = relationship('Measurement', back_populates='memory_stats')
total = Column(Integer)
available = Column(Integer)
def __repr__(self):
return 'memory available: {}'.format(
self.available,
)
class SwapStats(Base):
measurement_id = Column(Integer, ForeignKey('measurement.id'))
measurement = relationship('Measurement', back_populates='swap_stats')
total = Column(Integer)
used = Column(Integer)
sin = Column(Integer)
sout = Column(Integer)
def __repr__(self):
return 'swap used: {}, sin: {}, sout: {}'.format(
self.used,
self.sin,
self.sout,
)
class DiskStats(Base):
measurement_id = Column(Integer, ForeignKey('measurement.id'))
measurement = relationship('Measurement', back_populates='disk_stats')
partition_id = Column(String)
read_count = Column(Integer)
write_count = Column(Integer)
read_bytes = Column(Integer)
write_bytes = Column(Integer)
read_time = Column(Integer)
write_time = Column(Integer)
read_merged_count = Column(Integer)
write_merged_count = Column(Integer)
busy_time = Column(Integer)
def __repr__(self):
return '{} busy: {}'.format(
self.partition_id,
self.busy_time,
)
class Process(Base):
measurement_id = Column(Integer, ForeignKey('measurement.id'))
measurement = relationship('Measurement', back_populates='processes')
pid = Column(Integer)
name = Column(String)
exe = Column(String)
cmdline = Column(String)
username = Column(String)
nice = Column(Integer)
num_fds = Column(Integer)
num_threads = Column(Integer)
cpu_percent = Column(Numeric(3, 1))
status = Column(String)
memory = relationship('ProcessMemory', uselist=False, back_populates='process')
ionice = relationship('ProcessIONice', uselist=False, back_populates='process')
iocounters = relationship('ProcessIOCounters', uselist=False, back_populates='process')
ctx_switches = relationship('ProcessContextSwitches', uselist=False, back_populates='process')
def __repr__(self):
return '{}, {}, {}, {}, mem: {}, swap: {}'.format(
self.cpu_percent,
self.name,
self.exe,
self.cmdline,
self.memory.rss if self.memory else '?',
self.memory.swap if self.memory else '?',
)
class ProcessMemory(Base):
process_id = Column(Integer, ForeignKey('process.id'))
process = relationship('Process', back_populates='memory')
rss = Column(Integer)
vms = Column(Integer)
shared = Column(Integer)
text = Column(Integer)
lib = Column(Integer)
data = Column(Integer)
dirty = Column(Integer)
uss = Column(Integer)
pss = Column(Integer)
swap = Column(Integer)
class ProcessIONice(Base):
process_id = Column(Integer, ForeignKey('process.id'))
process = relationship('Process', back_populates='ionice')
ioclass = Column(Integer)
value = Column(Integer)
class ProcessIOCounters(Base):
process_id = Column(Integer, ForeignKey('process.id'))
process = relationship('Process', back_populates='iocounters')
read_count = Column(Integer)
write_count = Column(Integer)
read_bytes = Column(Integer)
write_bytes = Column(Integer)
read_chars = Column(Integer)
write_chars = Column(Integer)
class ProcessContextSwitches(Base):
process_id = Column(Integer, ForeignKey('process.id'))
process = relationship('Process', back_populates='ctx_switches')
voluntary = Column(Integer)
involuntary = Column(Integer)