Python3實時監控SOLR Replica狀態

2021-09-29 00:12:08 字數 4895 閱讀 5286

os 版本:centos linux release 7.4.1708

python 版本:python 3.7.3

solr 版本:solr 7.5

solr 執行模式:solr cloud(集群模式)

&1solr的客戶端api,提供了乙個監控clusterstatus的介面。並且,包含乙個專門用於python的輸出格式,這些,在solr官方guide中都有介紹。

('[%s]的分片[%s]的副本[%s]的core[%s]狀態是[%s], 請檢查solr!'\

%(collection_name, shard_var, replica_var, core_var, replica_state)

) message = mimetext(send_message,

'plain'

,'utf-8'

)# print(message)

subject =

'solr replica recovering'

sendmail.send_mail(subject, message)

#!/usr/bin/env python3

# _*_ coding: utf-8 _*_

# @time: 2019/5/27

# @author: leiting liu

# @mail: [email protected]

# @file: sendmail.py

import smtplib

from email.header import header

from publicvar import

*def

send_mail

(subject, message)

: sender =

'china_service@***.com'

# 接收郵件,可設定為你的qq郵箱或者其他郵箱

receivers = g_receiver.strip(

).split(

',')

# 三個引數:第乙個為文字內容,第二個 plain 設定文字格式,第三個 utf-8 設定編碼

# message = mimetext('python 郵件傳送測試...', 'plain', 'utf-8')

message[

'from']=

'%s'

% header(

"xxc_devops"

,'utf-8'

)# 傳送者

message[

'to']=

",".join(receivers)

# 接收者

# subject = 'python smtp 郵件測試'

message[

'subject'

]= header(subject,

'utf-8'

)try

: mail_host = smtplib.smtp(

'localhost'

) mail_host.sendmail(sender, receivers, message.as_string())

print

("郵件傳送成功"

)except smtplib.smtpexception as e:

print

("error: 無法傳送郵件"

)print

(e)

#!/usr/bin/env python3

# _*_ coding: utf-8 _*_

# @time: 2019/9/19

# @author: leiting liu

# @mail: [email protected]

# @file: publicvar.py

from configparser import configparser

# pss variables

pss1 = configparser(

)pss1.read(

'config.ini'

)g_var = configparser(

)g_var.read(

'config.ini'

)g_receiver = g_var.get(

'global-var-prd'

,'receivers'

)# receivers = g_receiver.strip().split(',')

# print(type(receivers))

config.ini檔案內容

[global-var-prd]

receivers = [email protected]

python3小技巧總結 實時更新

1.列表解析 如果乙個想將乙個列表中的大於0的數字過濾,一般可能會用到lambd結合filter,或者就是直接遍歷,不過最好的解決辦法是這樣 b 1,0,1,2 a i for i in b if i 0 a就是過濾完的列表 2.在列表中加入分隔符,原來我一直遍歷然後拼接字串最後在去掉最後乙個分隔符...

Python實時監控檔案方法

python logfile access.log command tail f logfile grep timeout popen subprocess.popen command,stdout subprocess.pipe,stderr subprocess.pipe,shell true ...

python3 切片 python3 切片

取乙個list或tuple的部分元素是非常常見的操作。比如,乙個list如下 l michael sarah tracy bob jack 取前3個元素,應該怎麼做?笨辦法 l 0 l 1 l 2 michael sarah tracy 之所以是笨辦法是因為擴充套件一下,取前n個元素就沒轍了。取前n...