-
Notifications
You must be signed in to change notification settings - Fork 2
/
pmap.py
executable file
·37 lines (31 loc) · 1.05 KB
/
pmap.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
#!/usr/bin/env python
import sys
import time
import platform
import datetime
import psutil
import influxdb
def main():
if len(sys.argv) != 4:
sys.exit('usage: pmap <pid> <influxdb-host> <influxdb-udp-port>')
pid = int(sys.argv[1])
process = psutil.Process(pid)
influx = influxdb.InfluxDBClient(host=sys.argv[2], use_udp=True, udp_port=int(sys.argv[3]))
host = platform.node()
while True:
maps = list(process.memory_maps(grouped=False))
process_mmap = {
"measurement": "process.mmap",
"fields": {
"host": host,
"pid": pid,
"count": len(maps),
"count_anon": len([m for m in maps if m.path == '[anon]']),
"total_rss": sum(m.rss for m in maps),
"total_private_dirty": sum(m.private_dirty for m in maps),
},
}
influx.write_points([process_mmap])
time.sleep(0.5)
if __name__ == '__main__':
main()