Exemple #1
0
def get_mysql(DBid, startTime, endTime, k):
    # 读取json配置文件
    #设置定时任务时,需使用绝对地址
    with open('aliyun_rds_config.json') as fp:
        aliyun_config = json.loads(fp.read())

    # 设置访问凭证
    clt = client.AcsClient(
        aliyun_config.get('AccessKeyID'),
        aliyun_config.get('AccessKeySecret'),
        aliyun_config.get('RegionID'),
    )

    # 创建Request对象,并对其中参数赋值
    request = DescribeRegionsRequest.DescribeRegionsRequest()
    request.set_accept_format('json')

    # 当前活跃连接数,IOPS,磁盘空间
    request.set_action_name('DescribeDBInstancePerformance')
    #request.set_query_params(
    #dict(DBInstanceId="rm-uf66901541fyse77g", key="MySQL_InnoDBBufferRatio,MySQL_InnoDBDataReadWriten,MySQL_InnoDBLogRequests,MySQL_MemCpuUsage",
    #         StartTime="2018-02-26T06:10Z", EndTime="2018-02-26T11:41Z"))
    request.set_query_params(
        dict(DBInstanceId=DBid, key=k, StartTime=startTime, EndTime=endTime))
    return json.loads(clt.do_action_with_exception(request).decode('utf-8'))
def describeRegions(client):
    request = DescribeRegionsRequest.DescribeRegionsRequest()
    try:
        response = client.do_action_with_exception(request)
        return response
    except ServerException as exception:
        print("Error while describing regions.")
        print("HTTP statue = ", exception.get_http_status())
        print("HTTP Error code = ", exception.get_error_code())
        print("Error message = ", exception.get_error_msg())
    return None
Exemple #3
0
 def get_regions(self, id_only=False):
     """
     获取支持的region列表
     https://help.aliyun.com/document_detail/26243.html
     :param id_only: 是否只返回region id列表
     :return:
     """
     request = DescribeRegionsRequest.DescribeRegionsRequest()
     result = self.client.do_action(request)
     result_list = result.get('Regions', {}).get('RDSRegion', [])
     if id_only:
         result_list = list(set([x.get('RegionId') for x in result_list]))
     return result_list
Exemple #4
0
 def get_DescribeRegions(self):
     region_request = DescribeRegionsRequest.DescribeRegionsRequest()
     region_request.set_accept_format('json')
     region_request.set_action_name('DescribeRegions')
     clt = client.AcsClient(self.accesskey, self.accessSecret,
                            'cn-hangzhou')
     result = clt.do_action(region_request)
     data = json.loads(result)
     region_list = []
     for n in data['Regions']['RDSRegion']:
         region_list.append(n['RegionId'])
     region_list = list(set(region_list))
     return region_list
Exemple #5
0
 def getSlowLogs(self):
     request = DescribeRegionsRequest.DescribeRegionsRequest()
     request.set_accept_format('json')
     request.set_action_name('DescribeSlowLogRecords')
     request.set_query_params(dict(DBInstanceId=self.instanceid, StartTime=self.begintime, EndTime=self.endtime))
     response = self.client.do_action_with_exception(request).decode()
     data = json.loads(response)
     '''解析json数据,判断是否存在备份语句,备份SQL直接跳过处理'''
     for slowdata in data['Items']['SQLSlowRecord']:
         ReturnRowCounts = slowdata['ReturnRowCounts']
         HostAddress = slowdata['HostAddress']
         LockTimes = slowdata['LockTimes']
         ExecutionStartTime = slowdata['ExecutionStartTime']
         # UTC_TIME --> BJ_TIME
         CtsStartTime = utc_to_local(ExecutionStartTime)
         ParseRowCounts = slowdata['ParseRowCounts']
         QueryTimes = slowdata['QueryTimes']
         DBName = slowdata['DBName']
         SQLText = slowdata['SQLText']
         #判断是否跳过循环,包含SQL_NO_CACHE,dumper.data_stat的不记录
         skipcondition1 = "SQL_NO_CACHE"
         skipcondition2 = 'dumper'
         skipcondition3 = 'stat_chess'
         skipcondition4 = 'stat_agent'
         skipcondition5 = 'stat'
         skipcondition6 = "data_stat"
         if skipcondition1 in SQLText:
             continue
         elif skipcondition2 in HostAddress:
             continue
         elif skipcondition3 in HostAddress:
             continue
         elif skipcondition4 in HostAddress:
             continue
         elif skipcondition5 in HostAddress:
             continue
         elif skipcondition6 in DBName:
             continue
         else:
             hashvalue = parseSlow(SQLText, DBName, CtsStartTime)#返回hashvalue带入slowinfotodb函数,将数据写入slowlog
             slowinfotodb(HostAddress, QueryTimes, LockTimes, ParseRowCounts, ReturnRowCounts, CtsStartTime\
                          , DBName, SQLText, hashvalue)
Exemple #6
0
 def get_DescribeRegions(self):
     '获取所有region'
     request = DescribeRegionsRequest.DescribeRegionsRequest()
     request.set_accept_format('json')
     request.set_action_name('DescribeRegions')
     return self.clt.do_action(request)
Exemple #7
0
#!/usr/bin/python
# encoding=utf-8

from aliyunsdkcore import client
from aliyunsdkrds.request.v20140815 import DescribeRegionsRequest
import json

AcesskeyID = 'LTAIk1fHVSSahLxN'
AcesskeySecret = 'usd1W47lTFXhhTIR5Cq5WTw9M3qACg'
regionid = 'cn-hangzhou'
c**t = client.AcsClient(AcesskeyID, AcesskeySecret, regionid)

request = DescribeRegionsRequest.DescribeRegionsRequest()
request.set_accept_format('json')
request.set_action_name('DescribeDBInstancePerformance')
# 多个性能指标用 "," 分隔
request.set_query_params(dict(DBInstanceId="数据库实例名", key="性能指标"))
print c**t.do_action_with_exception(request)
Exemple #8
0
 def get_region(self):
     """获取 RDS 实例的区域信息"""
     request = DescribeRegionsRequest.DescribeRegionsRequest()
     res = self.clt.do_action_with_exception(request)
     return json.loads(res.decode())
Exemple #9
0
 def DescribeRegions(self):
     request = DescribeRegionsRequest.DescribeRegionsRequest()
     request.set_accept_format('json')
     print self.clt.do_action(request)
Exemple #10
0
 def get_DescribeRegions(self):
     request = DescribeRegionsRequest.DescribeRegionsRequest()
     request.set_accept_format('json')
     result = json.loads(self.client.do_action_with_exception(request))
     return result['Regions']['RDSRegion']