ceph-状态监测-脚本
http://www.tang-lei.com/2018/06/05/ceph-%E7%8A%B6%E6%80%81%E7%9B%91%E6%B5%8B-%E8%84%9A%E6%9C%AC/
为了能够试试获取ceph集群状态,以期发生故障,可以及时知晓,及时处理。这里结合公司使用的owl监控编写的python脚本,如果使用其他或者crontab,可以酌情修改返回格式。
cat ceph_status.py
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import re
import subprocess
import sys
try:
import simplejson as json
except:
import json
##获取集群状态 HEALTH_ERR、HEALTH_WARN、HEALTH_OK
def get_ceph_status():
p = subprocess.Popen("ceph -s -f json", shell=True,stdout=subprocess.PIPE)
j_data = json.loads(p.stdout.read())
status = j_data.get('health').get('overall_status')
mark = 0 ##正常
if status == 'HEALTH_ERR':
mark = 1
if status == 'HEALTH_WARN':
mark = 2
if status == 'HEALTH_OK':
mark = 0
print {'HEALTH':mark}
return {'HEALTH':mark}
##检查osd使用率
def get_osd_usage():
p = subprocess.Popen("ceph osd df | awk '{print $1,$7}'", shell=True, stdout=subprocess.PIPE)
osds = p.stdout.readlines()
dicts = {}
for o in osds:
array = o.strip().split(" ")
try:
id = int(array[0])
dicts[array[0]]=array[1]
except ValueError:
print "Not number"
j_data = json.dumps(dicts, indent=4)
print j_data
return j_data
##获取osd状态 0表示没有down的osd, 1表示有down
def get_osd_status():
##p = subprocess.Popen("ceph osd tree | awk '{print $4}' |grep down", shell=True, stdout=subprocess.PIPE)
##osds_len = len(p.stdout.read())
##print osds_len
##if osds_len == 0:
## return 0
##else:
## return 1
p = subprocess.Popen("ceph osd stat -f json", shell=True, stdout=subprocess.PIPE)
data = json.loads(p.stdout.read())
if data.get('num_osds') == data.get('num_up_osds') == data.get("num_in_osds"):
print 0
return 0
else:
print 1
return 1
##获取pg状态 0表示 active+clean, 1表示有问题
def get_pg_status():
p = subprocess.Popen("ceph pg stat -f json", shell=True, stdout=subprocess.PIPE)
data = json.loads(p.stdout.read())
if len(data.get("num_pg_by_state")) > 1:
print 1
return 1
else:
print 0
return 0
##获取osd延迟信息
def get_osd_latency():
p = subprocess.Popen("ceph osd perf |awk '{print $1,$3}'", shell=True, stdout=subprocess.PIPE)
return _change_data_format(p)
##数据格式转换
def _change_data_format(p):
osds = p.stdout.readlines()
dicts = {}
for o in osds:
array = o.strip().split(" ")
try:
id = int(array[0])
dicts[array[0]]=array[1]
except ValueError:
print "Not number"
j_data = json.dumps(dicts, indent=4)
print j_data
return j_data
##mon 状态
def get_mon_status():
p = subprocess.Popen("ceph mon_status", shell=True, stdout=subprocess.PIPE)
usage = p.stdout.read()
json_usage = json.loads(usage)
print json_usage
return json_usage
##ceph集群所有磁盘使用率
def get_ceph_disk_usage():
p = subprocess.Popen("ceph df -f json", shell=True, stdout=subprocess.PIPE)
usage = p.stdout.read()
json_usage = json.loads(usage)
print json_usage
return json_usage
if __name__ == '__main__':
inputs = sys.argv[1]
if inputs == '1':
get_ceph_status()
if inputs == '2':
get_osd_usage()
if inputs == '3':
get_osd_status()
if inputs == '4':
get_osd_latency()
if inputs == '5':
get_pg_status()
if inputs == '6':
get_mon_status()
if inputs == '7':
get_ceph_disk_usage()
|
ceph-状态监测-脚本的更多相关文章
- 如何编写LVS对Real Server的健康状态检测脚本
简介:Linux 虚拟服务器(Linux Virtual Server. LVS),是一个由章文松开发的自由软件.利用KVS可以实现高可用的.可伸缩缩的Web, Mail, Cache和Medial等 ...
- linux系统负载状态检查脚本
为了便于分析问题,编写了一个linux状态检查脚本,脚本可放置任意目录,脚本执行检测后会输出日志记录到当前目录下.直接执行脚本可用于一次检测,可通过日志进行分析.如果需要长时间监测,可执行-x参数,脚 ...
- intouch与PLC之间通讯状态监测和设置
intouch与PLC进行通讯状态监测中,一般做法需要PLC来实施主动脉冲计数,或者bool变化来实现.本文通过上位机自带参数设置,实现对intouch通讯状态监视,将画面恢复初始状态,并及时弹窗报警 ...
- 【转载】 GPU状态监测 nvidia-smi 命令详解
原文地址: https://blog.csdn.net/huangfei711/article/details/79230446 ----------------------------------- ...
- Tomcat 项目部署、账户配置、状态监测
tomcat部署项目 方式一.自动部署(最常用) 直接把war包或部署的文件夹放到webapps下. tomcat启动后会自动监听webapps下的文件|目录,放入打包好的项目会自动部署,移除打包好的 ...
- 检查服务器主从状态的脚本-check_server_state.sh
分别检查服务器在Master/Slave状态下,各项服务是否正常,否则报警: 原来使用keepalived每隔1分钟调用,由于执行结果对keepalived的weight参数有影响,所以移动到外部,使 ...
- python MySQL-Slave从服务器状态检测脚本
#!/bin/bash mysql -e "show slave status\G" > mysql_status.txt array=($(egrep 'Slave_IO_ ...
- ceph状态信息靠谱查询
1)检查集群的状态汇总信息: [root@haha1 clouder]# ceph -s cluster 8e136e25-77ab-4e0b-b24b-232a7b466cfe health HEA ...
- IIS状态监测(如果状态错误则重启IIS)
步骤: 1:建立健康监测文件.文件内容随意,这里以healthcheck.aspx命名,内容是<span>hellow word</span> 2:利用vbs语言执行IIS重启 ...
随机推荐
- 【转载】Stackless Python并发式编程介绍[已校对版]
Stackless Python并发式编程介绍[已校对版] 作者: Grant Olson 电子邮件: olsongt@verizon.net 日期: 2006-07-07 译者: ...
- 【CDN+】Kafka 的初步认识与入门
前言 项目中用到了Kafka 这种分布式消息队列来处理日志,本文将对Kafka的基本概念和原理做一些简要阐释 Kafka 的基本概念 官网解释: Kafka是最初由Linkedin公司开发,是一个分布 ...
- Jmeter 循环控制器 遍历结果
1.测试计划,添加Mysql jar包 2.线程组 3.JDBC Connection Configuration,配置Mysql 4.添加JDBC Request,将查询出的数据对应的存入usern ...
- oracle两表中的两列进行模糊匹配的方法
SELECT T2.列名,T1.列名 FROM 主表 T1, 匹配表 T2 WHERE T1.匹配列 LIKE CONCAT('%',concat(T2.匹配列,'%')); 注意: a ...
- Android -ui控件
一:TextView控件 TextView --> View 1.创建TextView的两种方式: 1.1编写TextView类 TextView tv = new TextView(this) ...
- android测试开发概念
一:测试分类 1.分类概览 按测试阶段划分: 单元测试 集成测试 系统测试 验收测试 按是否覆盖源代码: 黑盒测试: 功能测试: 界面测试 逻辑测试 安装测试 应用性测试 兼容性测试 性能测试: 稳定 ...
- 【Spring Boot项目】Win7+JDK8+Tomcat8环境下的War包部署
一.pom.xml及启动类修改 pom.xml Step1:指定打包类型 <!-- 打包类型 jar 或 war --> <packaging>war</packagin ...
- CentOS7安装MySQL5.7.20
参考1:https://www.cnblogs.com/technology-huangyan/p/10484838.html 参考1:https://blog.csdn.net/aiyowei110 ...
- JVM(18)之 Class文件
开发十年,就只剩下这套架构体系了! >>> 关于类加载机制的相关知识在前面的博文中暂时先讲那么多.中间留下了很多问题,从本篇博文开始,我们来一一解决. 从我们最陌生而又最熟 ...
- zabbix 微信告警脚本
#!/usr/bin/env python3 import requests import json import sys import os def access_token(Corpid,Secr ...