标签:nbsp calendar eem code /usr cmd ftime com gen
基于zabbix-manager
python2.7
#! /usr/bin/env python # -*- coding: utf-8 -*- # __author__ = "life" # Email: batistuta1977@163.com # Date: 5/28/18 import datetime,os,sys import calendar date_range=() def get_date_range():
# 获取上个月第1天日期 last_month_date_first = datetime.datetime(datetime.date.today().year,datetime.date.today().month-1,1).strftime("%Y-%m-%d") # print(last_month_date_first)
# 获取上个月最后一天的数据,用本月1日减去一天获得。 last_month_date_last = datetime.datetime(datetime.date.today().year,datetime.date.today().month,1) - datetime.timedelta(1) last_month_date_last = last_month_date_last.strftime("%Y-%m-%d") # print last_month_date_last return last_month_date_first,last_month_date_last def gen_report_files(date_range): Start_date = ‘ \"‘ + date_range[0] # print Start_date End_date = ‘ \"‘ + date_range[1] # print End_date cmd_cpu = ‘nohup zabbix_api --report "CPU usage"‘ + Start_date + " 00:00:00\"" + End_date + ‘ 23:59:00" --xls /root/reports/cpuusage.xls > /dev/null‘ # print cmd_cpu os.popen(cmd_cpu) cmd_mem = ‘nohup zabbix_api --report "Free Mem %"‘ + Start_date + " 00:00:00\"" + End_date + ‘ 23:59:00" --xls /root/reports/Freemem.xls > /dev/null‘ # print cmd_mem os.popen(cmd_mem) cmd_disk = ‘nohup zabbix_api --report "Free disk space on"‘ + Start_date + " 00:00:00\"" + End_date + ‘ 23:59:00" --xls /root/reports/Freedisk.xls > /dev/null‘ # print cmd_disk os.popen(cmd_disk) if __name__ == ‘__main__‘: date_range = get_date_range() # print date_range print ‘begin generating reports in /root/reports...‘ gen_report_files(date_range)
项目上使用的每月1日自动导出Zabbix性能数据的python脚本
标签:nbsp calendar eem code /usr cmd ftime com gen
原文地址:https://www.cnblogs.com/ld1977/p/9099697.html