怎么在python3中使用wxpy模塊監(jiān)控linux日志-創(chuàng)新互聯(lián)

這篇文章給大家介紹怎么在python3中使用wxpy模塊監(jiān)控linux日志,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

成都創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比夏津網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式夏津網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋夏津地區(qū)。費(fèi)用合理售后完善,十載實(shí)體公司更值得信賴。

具體代碼如下所示:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from threading import Timer
from wxpy import *
import requests
import subprocess
import time
from PIL import Image, ImageDraw, ImageFont
from apscheduler.schedulers.blocking import BlockingScheduler
#cache_path=true 表示登陸一次之后,進(jìn)行緩存,下次登陸只需要手機(jī)確認(rèn)
bot = Bot(console_qr=2,cache_path=True)
#獲取topic是否消費(fèi)延遲
def get_Lag():
  text=""
  p = subprocess.Popen('kafka-consumer-offset-checker --zookeeper 192.168.1.116 --group t_sync --topic SYNC_DATABASE_UPDATE', shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE,universal_newlines=True) #universal_newlines=True,表示輸出為字符串,默認(rèn)是byte
  while True:
    line =p.stdout.readline()
    if not line:
      break
    else:
      text+=line + '\n'
  return text
def get_news():
  text=[]
  count=0
  t=True
  p = subprocess.Popen('tail -F /home/hadoop/da.txt', shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE,universal_newlines=True)
  while True:
    line =str(p.stdout.readline())
    if not line:
      break
    elif "send data" in line and t:
      for item in line.split(','):
        count +=1
        if count <= 200:
           text.append(item)
      break
  return text
def get_context():
  result=""
  word=get_news()
  for i in range(len(word)):
    if(i % 4 ==0):
      result= result+word[i]+"\n"
    else:
      result= result+word[i]+"  "
  return result
def send_image():
  try:
    lags=get_Lag()
    print(lags)
    content=get_context()
#發(fā)送消費(fèi)延遲的數(shù)據(jù)
    lagImage= Image.new('RGB', (1000, 600),(255,255,255))
    draw = ImageDraw.Draw(lagImage)
    font = ImageFont.truetype("/usr/share/fonts/cjkuni-ukai/ukai.ttc", 18, encoding="unic")
    draw.text((10, 10), lags, 'black', font)
    lagImage.save('/home/hadoop/lags.jpg')
#發(fā)送日志消息
    image= Image.new('RGB', (1000, 810),(255,255,255))
    draw = ImageDraw.Draw(image)
    font = ImageFont.truetype("/usr/share/fonts/cjkuni-ukai/ukai.ttc", 18, encoding="unic") #ukai.ttc 字體
    draw.text((10, 10), content, 'black', font)
    image.save('/home/hadoop/123.jpg')
 
 #發(fā)送群組
    group = bot.groups().search("大數(shù)據(jù)小組")[0]
    group.send_image('/home/hadoop/123.jpg')
 #發(fā)送好友
    my_friend = bot.friends().search(u'濤')[0]
    my_friend.send_image('/home/hadoop/lags.jpg')
    my_friend.send_image('/home/hadoop/123.jpg')
    # t = Timer(100, send_image)
    #t.start()
  except:
    my_friend.send(u"今天消息發(fā)送失敗了")
if __name__ == "__main__":
  #send_image()
  scheduler = BlockingScheduler()
  scheduler.add_job(send_image, 'cron', hour='15', minute='01')
  scheduler.add_job(send_image, 'cron', hour='14', minute='58')
  scheduler.start()

關(guān)于怎么在python3中使用wxpy模塊監(jiān)控linux日志就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。

本文標(biāo)題:怎么在python3中使用wxpy模塊監(jiān)控linux日志-創(chuàng)新互聯(lián)
轉(zhuǎn)載注明:http://muchs.cn/article16/coedgg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊手機(jī)網(wǎng)站建設(shè)、網(wǎng)站制作、服務(wù)器托管標(biāo)簽優(yōu)化、定制開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

綿陽服務(wù)器托管