python分包存放java堆栈信息

# coding=utf-8
import os
import time

path = os.getcwd()
index = 0

while True:
    
    # 当前时间戳
    timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    
    # java堆栈
    jstack = os.popen('/mnt/jdk8/bin/jstack 30668').read()
    
    # 第一个堆栈文件
    fp = path + '/jstack' + str(index) + '.log'
   
    # 将java堆栈写入文件
    with open(fp, 'a+') as f:
        f.write(timestamp + '\n' + jstack + '\n')
    
    # 判断存放堆栈文件大小以,大于100M后分包
    fs = round(os.path.getsize(fp)/float(1024*1024), 2)
    if fs >= 100:
        index += 1

    time.sleep(1)

 

posted on 2020-06-10 19:49  fengZQ  阅读(215)  评论(0编辑  收藏  举报

导航