#! /usr/bin/python
# -*- encoding: utf8 -*-
#from __future__ import division
import sys
import MySQLdb
# 数据库配置参数
host = '192.168.20.235'
user = 'root'
password = 'root'
db = 'orca_cmdb'
#----------------------------------------------------------------------
def getConn(host, user, passwd, db):
try:
conn = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
return conn
except Exception, e:
print "Error %d: %s" % (e.args[0], e.args[1])
sys.exit(1)
#----------------------------------------------------------------------
def closeConn(conn):
"""关闭 mysql connection"""
conn.close()
#----------------------------------------------------------------------
def getValue(conn, query):
""" 查询相关参数 返回一个值 """
cursor = conn.cursor()
getNum=cursor.execute(query)
if getNum>0:
result = cursor.fetchone()
else:
result=['0']
return int(result[1])
def getQuery(conn, query):
""" 查询相关参数 返回多个值 """
cursor = conn.cursor()
cursor.execute(query)
result = cursor.fetchall()
return result
#执行查询的总次数
Questions = "show global status like 'Questions'"
#服务器已经运行的时间(以秒为单位)
Uptime = "show global status like 'Uptime'"
Com_commit = "show global status like 'Com_commit'"
Com_rollback = "show global status like 'Com_rollback'"
#从硬盘读取键的数据块的次数。如果Key_reads较大,则Key_buffer_size值可能太小。
#可以用Key_reads/Key_read_requests计算缓存损失率
Key_reads = &#
# -*- encoding: utf8 -*-
#from __future__ import division
import sys
import MySQLdb
# 数据库配置参数
host = '192.168.20.235'
user = 'root'
password = 'root'
db = 'orca_cmdb'
#----------------------------------------------------------------------
def getConn(host, user, passwd, db):
try:
conn = MySQLdb.connect(host=host, user=user, passwd=passwd, db=db)
return conn
except Exception, e:
print "Error %d: %s" % (e.args[0], e.args[1])
sys.exit(1)
#----------------------------------------------------------------------
def closeConn(conn):
"""关闭 mysql connection"""
conn.close()
#----------------------------------------------------------------------
def getValue(conn, query):
""" 查询相关参数 返回一个值 """
cursor = conn.cursor()
getNum=cursor.execute(query)
if getNum>0:
result = cursor.fetchone()
else:
result=['0']
return int(result[1])
def getQuery(conn, query):
""" 查询相关参数 返回多个值 """
cursor = conn.cursor()
cursor.execute(query)
result = cursor.fetchall()
return result
#执行查询的总次数
Questions = "show global status like 'Questions'"
#服务器已经运行的时间(以秒为单位)
Uptime = "show global status like 'Uptime'"
Com_commit = "show global status like 'Com_commit'"
Com_rollback = "show global status like 'Com_rollback'"
#从硬盘读取键的数据块的次数。如果Key_reads较大,则Key_buffer_size值可能太小。
#可以用Key_reads/Key_read_requests计算缓存损失率
Key_reads = &#