欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python監(jiān)控linux內(nèi)存并寫入mongodb(推薦)

 更新時(shí)間:2017年09月11日 16:38:03   作者:Mr.LUCKY  
這篇文章主要介紹了python監(jiān)控linux內(nèi)存并寫入mongodb的相關(guān)資料,需要的朋友可以參考下

(需要安裝psutil 用來獲取服務(wù)器資源,以及pymongo驅(qū)動(dòng))#pip install psutil

#pip install pymongo
#vim memory_monitory.py

文件內(nèi)容如下

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import psutil
import socket
import time
from pymongo import MongoClient
mongodbIp = '192.168.200.112'
mongodbPort = 27017
hostname = socket.gethostbyname(socket.gethostname())#獲取本地IP地址
def getCurrentTime():
    return time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
memoryInfo = psutil.virtual_memory()
conn = MongoClient(mongodbIp,mongodbPort)
db = conn.servermonitor
dbset = db.memory
dbset.insert({
    'time':getCurrentTime(),
    'total':memoryInfo.total,
    'available':memoryInfo.available,
    'percent':memoryInfo.percent,
    'used':memoryInfo.used,
    'free':memoryInfo.free,
    'active':memoryInfo.active,
    'inactive':memoryInfo.inactive,
    'buffers':memoryInfo.buffers,
    'cached':memoryInfo.cached})

修改文件可以直接執(zhí)行

#chmod +x memory_monitor.py

使用crontab 定時(shí)執(zhí)行監(jiān)控程序

#vim vim /etc/crontab

添加如下內(nèi)容(每分鐘執(zhí)行一次)

*/1 * * * * root /usr/local/memory_monitor.py
#service crond reload  //重新載入配置
#service crond restart //重啟服務(wù)

總結(jié)

以上所述是小編給大家介紹的python監(jiān)控linux內(nèi)存并寫入mongodb,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論