Collecting and Uploading GPU Logs
Scenario
When a GPU is faulty, collect GPU log information by referring to this exercise. The logs generated in this exercise are saved on the node and automatically uploaded to the OBS bucket provided by technical support. Logs are used only for fault locating and analysis. You need to provide the AK/SK for authorization and authentication.
Procedure
- Obtain the AK/SK, which are used for script configuration, as well as authentication and authorization.
If an AK/SK pair is already available, skip this step. Find the downloaded AK/SK file, which is usually named credentials.csv.
The file contains the username, AK, and SK.
Figure 1 credential.csvTo generate an AK/SK pair, follow these steps:- Log in to the Huawei Cloud console.
- Hover over the username in the upper right corner and choose My Credentials from the drop-down list.
- In the navigation pane on the left, choose Access Keys.
- Click Create Access Key.
- Download the key and keep it secure.
- Prepare the tenant ID and IAM ID for OBS bucket configuration.
Send the prepared information to Huawei technical support, who will configure an OBS bucket policy based on your information. You can upload the collected logs to the corresponding OBS bucket.
After the configuration, the OBS directory obs_dir is provided for you to configure subsequent scripts.
Figure 2 Tenant ID and IAM ID - Collect the logs and upload the script.
Modify the GpuLogCollection parameter in the script below and replace ak, sk, and obs_dir with the values obtained in the previous steps. Upload the script to the node whose GPU logs need to be collected.
import json import os import sys import hashlib import hmac import binascii from datetime import datetime class GpuLogCollection(object): GPU_LOG_PATH = "nvidia-bug-report.log.gz" SUPPORT_REGIONS = ['cn-north-4', 'cn-north-9'] OPENSTACK_METADATA = "http://169.254.169.254/openstack/latest/meta_data.json" OBS_BUCKET_PREFIX = "npu-log-" def __init__(self, ak, sk, obs_dir): self.ak = ak self.sk = sk self.obs_dir = obs_dir self.region_id = self.get_region_id() def get_region_id(self): meta_data = os.popen("curl {}".format(self.OPENSTACK_METADATA)) json_meta_data = json.loads(meta_data.read()) meta_data.close() region_id = json_meta_data["region_id"] if region_id not in self.SUPPORT_REGIONS: print("current region {} is not support.".format(region_id)) raise Exception('region exception') return region_id def gen_collect_gpu_log_shell(self): collect_gpu_log_shell = "nvidia-bug-report.sh" return collect_gpu_log_shell def collect_gpu_log(self): print("begin to collect gpu log") os.system(self.gen_collect_gpu_log_shell()) date_collect = datetime.now().strftime('%Y%m%d%H%M%S') instance_ip_obj = os.popen("curl http://169.254.169.254/latest/meta-data/local-ipv4") instance_ip = instance_ip_obj.read() instance_ip_obj.close() log_tar = "%s-gpu-log-%s.gz" % (instance_ip, date_collect) os.system("cp %s %s" % (self.GPU_LOG_PATH, log_tar)) print("success to collect gpu log with {}".format(log_tar)) return log_tar def upload_log_to_obs(self, log_tar): obs_bucket = "{}{}".format(self.OBS_BUCKET_PREFIX, self.region_id) print("begin to upload {} to obs bucket {}".format(log_tar, obs_bucket)) obs_url = "https://%s.obs.%s.myhuaweicloud.com/%s/%s" % (obs_bucket, self.region_id, self.obs_dir, log_tar) date = datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT') canonicalized_headers = "x-obs-acl:public-read" obs_sign = self.gen_obs_sign(date, canonicalized_headers, obs_bucket, log_tar) auth = "OBS " + self.ak + ":" + obs_sign header_date = '\"' + "Date:" + date + '\"' header_auth = '\"' + "Authorization:" + auth + '\"' header_obs_acl = '\"' + canonicalized_headers + '\"' cmd = "curl -X PUT -T " + log_tar + " " + obs_url + " -H " + header_date + " -H " + header_auth + " -H " + header_obs_acl os.system(cmd) print("success to upload {} to obs bucket {}".format(log_tar, obs_bucket)) # calculate obs auth sign def gen_obs_sign(self, date, canonicalized_headers, obs_bucket, log_tar): http_method = "PUT" canonicalized_resource = "/%s/%s/%s" % (obs_bucket, self.obs_dir, log_tar) IS_PYTHON2 = sys.version_info.major == 2 or sys.version < '3' canonical_string = http_method + "\n" + "\n" + "\n" + date + "\n" + canonicalized_headers + "\n" + canonicalized_resource if IS_PYTHON2: hashed = hmac.new(self.sk, canonical_string, hashlib.sha1) obs_sign = binascii.b2a_base64(hashed.digest())[:-1] else: hashed = hmac.new(self.sk.encode('UTF-8'), canonical_string.encode('UTF-8'), hashlib.sha1) obs_sign = binascii.b2a_base64(hashed.digest())[:-1].decode('UTF-8') return obs_sign def execute(self): log_tar = self.collect_gpu_log() self.upload_log_to_obs(log_tar) if __name__ == '__main__': gpu_log_collection = GpuLogCollection(ak='ak', sk='sk', obs_dir='xxx') gpu_log_collection.execute()
- Run the script to collect logs.
Run the script on the node. If the following information is displayed, logs are collected and uploaded to OBS.
Figure 3 Log collected - View the uploaded log package in the directory where the script is stored.
Figure 4 Viewing the result
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot