In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 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
Aliyun Cloud Monitor 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.
Function calculation for automatic operation and maintenance special topic "class=" reference-link > special topic portal = > function calculation for automatic operation and maintenance thematic example scene
In this article, we focus on the restart event handling of ecs by function calculation, because these ecs restart events are currently required to be responded by users with high priority. If a previous ecs restarts due to a system error, users may urgently do some verification or create snapshots. In this example, we perform automatic processing on a machine that restarts or restarts due to an instance error, such as creating a snapshot after a successful restart.
Ecs system event
Cdn.com/31eeef9826151824881ec02ea99b81c2962a640c.png ">
Event Monitoring of Cloud Product system
The procedure is to 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 permission to operate ecs to the role of the service of the function
Log in to the Cloud Monitor console and create alarm rules. The monitored events are the start and end of ecs restart due to instance error or Xirong error.
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 aliyunsdkecs.request.v20140526.DeleteSnapshotRequest import DeleteSnapshotRequestfrom aliyunsdkecs.request.v20140526.CreateSnapshotRequest import CreateSnapshotRequestfrom aliyunsdkecs.request.v20140526.DescribeDisksRequest import DescribeDisksRequestfrom 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") Name = name.lower () if name in ['Instance:SystemFailure.Reboot:Executing'.lower (), "Instance:InstanceFailure.Reboot:Executing" .lower ()]: pass # do other things if name in [' Instance:SystemFailure.Reboot:Executed'.lower (), "Instance:InstanceFailure.Reboot:Executed" .lower ()]: request = DescribeDisksRequest () request.add_query_param ("RegionId") "cn-shenzhen") request.set_InstanceId (ecsInstanceId) response = _ send_request (request) disks = response.get ('Disks'). Get (' Disk', []) for disk in disks: diskId = disk ["DiskId"] SnapshotId = create_ecs_snap_by_id (diskId) LOGGER.info ("Create ecs snap sucess, ecs id =% s, disk id =% s", ecsInstanceId DiskId) def create_ecs_snap_by_id (disk_id): LOGGER.info ("Create ecs snap, disk id is% s" Disk_id) request = CreateSnapshotRequest () request.set_DiskId (disk_id) request.set_SnapshotName ("reboot_" +'. Join (random.choice (string.ascii_lowercase) for _ in range (6)) response = _ send_request (request) return response.get ("SnapshotId") # 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)
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.