In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Function calculation
Ali Cloud function Computing is an event-driven fully managed computing service. Through function calculation, you do not need to manage infrastructure such as servers, you just need to write code and upload. Function computing will prepare computing resources for you, run your code in a flexible and reliable manner, and provide log query, performance monitoring, alarm and other functions. With the help of functional computing, you can quickly build any type of applications and services without management and operation and maintenance. Even better, you only have to pay for the resources consumed by the actual running of the code, while there is no cost if the code is not running.
Cloud monitoring
Ali Yunyun Monitoring provides an enterprise-class open one-stop monitoring solution for cloud users out of the box. It covers IT infrastructure monitoring, public network quality testing monitoring, and business monitoring based on events, custom indicators and logs. To provide you with more efficient, more comprehensive and more cost-effective monitoring services.
Cloud monitoring provides a wealth of events, and events are still being enriched (cloud product system event monitoring). Rich events trigger custom processing functions, which can achieve more perfect automatic operation and maintenance.
Thematic portal = > function calculation for automated operation and maintenance thematic example scenario
Suppose two ECS machines A, B, A have downtime. At this time, the eip on machine A needs to be migrated to standby machine B. the automatic migration of EIP can be realized by using the alarm and function calculation of cloud monitoring. Cloud monitoring detects the event of A downtime, and then triggers the execution of the function, which realizes the automatic migration of eip.
Operation steps
Create a function (the function code is at the end of the article). You can refer to the function to calculate helloworld.
Note: remember to set the permissions for operating ecs and eip to the role of the service of the function
Cdn.com/969096ef4233ea658e1ccf75686a7c4620269329.png ">
Log in to the Cloud Monitor console, create alarm rules, and monitor events starting with ecs restart.
Mock debugging
Simulate real ecs events
Please refer to the walkthrough system event handler? So Easy~
Code #-*-coding: utf-8-*-import loggingimport json, random, string, timefrom aliyunsdkcore import clientfrom aliyunsdkvpc.request.v20160428.AssociateEipAddre***equest import AssociateEipAddre***equestfrom aliyunsdkvpc.request.v20160428.UnassociateEipAddre***equest import UnassociateEipAddre***equestfrom aliyunsdkvpc.request.v20160428.DescribeEipAddressesRequest import DescribeEipAddressesRequestfrom aliyunsdkcore.auth.credentials import StsTokenCredentialLOGGER = logging.getLogger () clt = Nonedef handler (event, context): creds = context.credentials sts_token_credential = StsTokenCredential (creds.access_key_id, creds.access_key_secret Creds.security_token)'{"product": "ECS", "content": {"executeFinishTime": "2018-06-08T01:25:37Z", "executeStartTime": "2018-06-08T01:23:37Z", "ecsInstanceName": "timewarp", "eventId": "e-t4nhcpqcu8fqushpn3mm", "eventType": "InstanceFailure.Reboot" "ecsInstanceId": "i-bp18l0uopocfc98xxxx"}, "resourceId": "acs:ecs:cn-hangzhou:123456789:instance/i-bp18l0uopocfc98xxxx", "level": "CRITICAL", "instanceName": "instanceName", "status": "Executing", "name": "Instance:SystemFailure.Reboot:Executing" "regionId": "cn-hangzhou"}''evt = json.loads (event) content = evt.get ("content") EcsInstanceId = content.get ("ecsInstanceId"); regionId = evt.get ("regionId"); global clt clt = client.AcsClient (region_id=regionId, credential=sts_token_credential) name = evt.get ("name"); eipId = "eip-bp1nexxxc7zjfnex6i0" StandbyEcsId = "i-bp19yycxx7yroukxpv" name = name.lower () if name in ['Disk:Stalled:Executing'.lower (),' Instance:SystemFailure.Reboot:Executing'.lower (), "Instance:InstanceFailure.Reboot:Executing" .lower ()]: print ("move eip to standbyEcs") Move_eip (ecsInstanceId, standbyEcsId, eipId) # move eip to standbyEcs else: # other event to do passdef getEipStatus (eip): request = DescribeEipAddressesRequest () request.set_AllocationId (eip) request.add_query_param ("RegionId", "cn-hangzhou") response = _ send_request (request) if isinstance (response, dict) and "RequestId" in response: EipAddresses = response.get ('EipAddresses' {}) EipAddress = EipAddresses ['EipAddress'] [0] status = EipAddress [' Status'] return status else: LOGGER.error ("getEipAddressDesc {} fail" .format (eip)) def unAssociateEip (ecs_id, eip): request = UnassociateEipAddre***equest () request.set_AllocationId (eip) request.set_InstanceType ('EcsInstance') request.set_InstanceId (ecs_id) response = _ send_request (request) if isinstance (response) Dict) and "RequestId" in response: LOGGER.info ("UnassociateEipAddress {} from {} succ" .format (ecs_id, eip)) else: LOGGER.error ("UnassociateEipAddress {} from {} fail" .format (ecs_id, eip)) def associateEip (ecs_id Eip): associte_request = AssociateEipAddre***equest () associte_request.set_AllocationId (eip) associte_request.set_InstanceType ('EcsInstance') associte_request.set_InstanceId (ecs_id) associte_response = _ send_request (associte_request) if isinstance (associte_response, dict) and "RequestId" in associte_response: LOGGER.info ("AssociateEipAddress {} to {} succ" .format (eip, ecs_id) return True return Falsedef move_eip (from_ecs, to_ecs) Eip): unAssociateEip (from_ecs, eip) # wait unAssociateEip... Time.sleep (3) # retry 30s util sucess for i in xrange (10): eip_status = getEipStatus (eip). Lower () if eip_status = = 'available': if associateEip (to_ecs, eip): LOGGER.info ("AssociateEipAddress {} to {} succ" .format (eip) To_ecs) return else: LOGGER.info ("eip status = {}" .format (eip_status)) time.sleep (3) LOGGER.info ("AssociateEipAddress {} to {} fail" .format (eip) To_ecs) # send open api requestdef _ send_request (request): request.set_accept_format ('json') try: response_str = clt.do_action_with_exception (request) LOGGER.info (response_str) response_detail = json.loads (response_str) return response_detail except Exception as e: LOGGER.error (e)
"Alibaba Cloud's native Wechat official account (ID:Alicloudnative) focuses on micro-services, Serverless, containers, Service Mesh and other technology areas, focuses on cloud native popular technology trends, and large-scale cloud native landing practices, and is the technical official account that best understands cloud native developers."
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.