Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Collecting and Uploading NPU Logs

Updated on 2025-02-13 GMT+08:00

Description

When an NPU is faulty, collect NPU log information by referring to this section. The logs generated in this section are saved on the node and automatically uploaded to the OBS bucket provided by Huawei technical support. Logs are used only for fault locating and analysis. You need to provide the AK/SK for authorization and authentication.

Notes and Constraints

Currently, this function can be used only in CN Southwest-Guiyang1 and CN North-Ulanqab1.

Procedure

  1. 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.csv
    To generate an AK/SK pair, follow these steps:
    1. Log in to the management console.
    2. Hover the cursor over the username in the upper right corner and choose My Credentials from the drop-down list.
    3. In the navigation pane on the left, choose Access Keys.
    4. Click Create Access Key.
    5. Download the key and keep it secure.

  2. Prepare the tenant and IAM accounts for OBS bucket configuration.

    Send the prepared information to Huawei technical support. Huawei 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 and IAM accounts

  3. Collect the logs and upload the script.

    Modify the value of NpuLogCollection in the following script. Replace ak, sk, and obs_dir with the values obtained before. Then, upload the script to the node where NPU logs are to be collected.
    import json
    import os
    import sys
    import hashlib
    import hmac
    import binascii
    from datetime import datetime
    
    
    class NpuLogCollection(object):
        NPU_LOG_PATH = "/var/log/npu_log_collect"
        SUPPORT_REGIONS = ['cn-southwest-2', '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_npu_log_shell(self):
            collect_npu_log_shell = "# !/bin/sh\n" \
                                    "rm -rf {npu_log_path}\n" \
                                    "mkdir -p {npu_log_path}\n" \
                                    "echo {echo_npu_driver_info}\n" \
                                    "npu-smi info > {npu_log_path}/npu-smi_info.log\n" \
                                    "cat /usr/local/Ascend/driver/version.info > {npu_log_path}/npu-smi_driver-version.log\n" \
                                    "/usr/local/Ascend/driver/tools/upgrade-tool --device_index -1 --component -1 --version > {npu_log_path}/npu-smi_firmware-version.log\n" \
                                    "for i in $(seq 0 7) ; do npu-smi info -t health -i $i -c 0 >> {npu_log_path}/npu-smi_health-code.log;done;\n" \
                                    "for i in $(seq 0 7);do hccn_tool -i $i -net_health -g >> {npu_log_path}/npu-smi_net-health.log ;done\n" \
                                    "for i in $(seq 0 7);do hccn_tool -i $i -link -g >> {npu_log_path}/npu-smi_link.log ;done\n" \
                                    "for i in $(seq 0 7);do hccn_tool -i $i -tls -g |grep switch >> {npu_log_path}/npu-smi_switch.log;done\n" \
                                    "for i in $(seq 0 7);do npu-smi info -t board -i $i >> {npu_log_path}/npu-smi_board.log; done;\n" \
                                    "echo {echo_npu_ecc_info}\n" \
                                    "for i in $(seq 0 7);do npu-smi info -t ecc -i $i >> {npu_log_path}/npu-smi_ecc.log; done;\n" \
                                    "for i in $(seq 0 7);do hccn_tool -i $i -optical -g | grep prese >> {npu_log_path}/npu-smi_present.log ;done\n" \
                                    "lspci | grep acce > {npu_log_path}/Device-info.log\n" \
                                    "echo {echo_npu_device_log}\n" \
                                    "cd {npu_log_path} && msnpureport -f > /dev/null\n" \
                                    "tar -czvPf {npu_log_path}/log_messages.tar.gz /var/log/message*  > /dev/null\n" \
                                    "tar -czvPf {npu_log_path}/ascend_install.tar.gz /var/log/ascend_seclog/*  > /dev/null\n" \
                                    "echo {echo_npu_tools_log}\n" \
                                    "tar -czvPf {npu_log_path}/ascend_toollog.tar.gz /var/log/nputools_LOG_*  > /dev/null" \
                .format(npu_log_path=self.NPU_LOG_PATH,
                        echo_npu_driver_info="collect npu driver info.",
                        echo_npu_ecc_info="collect npu ecc info.",
                        echo_npu_device_log="collect npu device log.",
                        echo_npu_tools_log="collect npu tools log.")
            return collect_npu_log_shell
    
        def collect_npu_log(self):
            print("begin to collect npu log")
            os.system(self.gen_collect_npu_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-npu-log-%s.tar.gz" % (instance_ip, date_collect)
            os.system("tar -czvPf %s %s > /dev/null" % (log_tar, self.NPU_LOG_PATH))
            print("success to collect npu 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_npu_log()
            self.upload_log_to_obs(log_tar)
    
    
    if __name__ == '__main__':
        npu_log_collection = NpuLogCollection(ak='ak',
                                              sk='sk',
                                              obs_dir='obs_dir')
        npu_log_collection.execute()

  4. 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 uploaded

  5. View the uploaded log package in the directory where the script is stored.

    Figure 4 Viewing the result

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback