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

QingTian Enclave Log Forwarding Tool

Overview

QingTian Enclave log (qlog) is an O&M tool for QingTian Enclave. A QingTian Enclave instance is a completely isolated sub-VM running in a QingTian VM. Even the root user cannot log in to the QingTian Enclave instance via SSH. To help O&M personnel monitor services running in QingTian Enclave and locate faults, the qlog tool is provided. qlog can collect specified log files and resource usage (CPU and memory usages) of QingTian Enclave instances and send the collected data to the parent instance.

The qlog tool is an executable binary file. It needs to be executed using different commands on the parent instance and QingTian Enclave instance.

  • On the parent instance, run /path/to/qlog receive-file <cid>/path/to/config_qlog.toml to enable qlog.
  • On a QingTian Enclave instance, run /path/to/qlog monitor /path/to/config_qlog.toml to enable qlog.

Service logs of traditional VMs are stored in a directory similar to /var/log/service.log.

After services are migrated to QingTian Enclave, you can use qlog to export the log files (stored in /var/log/service.log) to the parent instances.

You can run qlog receive-file and qlog monitor on the parent instance and QingTian Enclave instance, respectively, to execute a given qlog binary file. A local vsock-based communication link is established between them. The qlog component running in a QingTian Enclave instance collects specified service logs or resource usage of the QingTian Enclave instance, and sends the collected data to the qlog component of the parent instance. The qlog component of the parent instance stores the received data in a specified directory, for example, /var/log/qlog/service.log.

Figure 1 Seamless migration of a network service to QingTian Enclave

The following describes how to use qlog.

Prerequisites

  1. You have obtained qlog by performing the following:

    Clone the QingTian Enclave code repository.

    git clone https://gitee.com/HuaweiCloudDeveloper/huawei-qingtian.git
  2. You have obtained the cargo tool chain by performing the following:
    1. Install rustup.
      curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    2. After the installation is complete, load rustup.
      source $HOME/.cargo/env
    3. Check that rustc and cargo are installed.
      rustc -V
      cargo -V
  3. You have learned about the pre-dependency of qlog.
    Table 1 Pre-dependency

    Dependency Item

    Earliest Test Version

    glibc

    2.34

    cargo

    1.77.0

  4. You have prepared the QingTian Enclave environment by performing the following:
    1. Install the qt CLI tool and required RPM packages.
    2. Install Docker.
    3. Install Python 3 and required Python modules (docker and knack).

    For details, see Getting Started with QingTian Enclave and Installation of the qt CLI.

Procedure

  1. Build qlog.

    Go to the qingtian-tools/qlog directory and run the following cargo command:

    cargo build --release

    The generated qlog binary file is compiled in qingtian-tools/qlog/target/release.

  2. Create a working directory.

    Create a working directory named workspace and copy the qlog binary file to the workspace. Store the files generated subsequently in the workspace.

  1. Configure config_qlog.toml.

    In the workspace directory, create the config_qlog.toml file with the following content:

    port: 6000
    workspace: /var/log/qlog 
    server_logfile: server.log 
    client_logfile: client.log 
    server_threads: 4
    client_threads: 1
    log_level: info 
    rotate_size: 65536
    rotate_num: 10
    monitor_items:  
      - name: service  #Service name    
        monitor_type: file     
        monitor_path: /var/log/service.log  #QingTian Enclave service log path    
        outputfile: service.log  #Name of the log file synchronized to the parent instance  
      - name: resource     
        monitor_type: resource     
        monitor_internel: 15    
        outputfile: resource.log

  2. Create a QingTian Enclave image that contains qlog.

    1. In the workspace directory, create the start.sh script.
      #/bin/bash
      /root/qlog monitor /root/config_qlog.toml & 
      
      LOG_FILE="/var/log/service.log"
      LOG_MESSAGE="Hello, service." 
      
      while true; do    
          TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')    
          echo "$TIMESTAMP - $LOG_MESSAGE" >> "$LOG_FILE"    
          sleep 3
      done
    1. Run the following command in the workspace to grant start.sh execute permissions:
      chmod +x start.sh
    2. In the workspace directory, create the Dockerfile file with the following content:
      FROM ubuntu:latest 
      COPY ./qlog /root/qlog 
      COPY ./config_qlog.toml /root/config_qlog.toml 
      COPY ./start.sh /root/start.sh 
      CMD /root/start.sh
    3. Run the following command in the workspace to grant start.sh execute permissions:
      chmod +x start.sh
    4. Run the following command in the workspace to create a Docker image:
      docker build -f Dockerfile -t test_qlog_enclave .
    5. Run the following command in the workspace to create a QingTian Enclave image:
      qt enclave make-img --docker-uri test_qlog_enclave --eif test_qlog_enclave.eif

  3. Start qlog.

    1. Run the following command in the workspace to start a QingTian Enclave instance:
      qt enclave start --cpus 2 --mem 1024 --cid 4 --eif test_qlog_enclave.eif
    2. Run the following command in the workspace to start qlog in the parent instance:
      ./qlog receive-file 4 ./config_qlog.toml &
    3. Run the following command on the parent instance to view the service log:
      tail -F /var/log/qlog/service.log

      A line of "Hello, service." is printed every 3 seconds.

    4. Run the following command on the parent instance to check the resource usage of the QingTian Enclave instance:
      tail -F /var/log/qlog/resource.log

      The CPU usage and memory usage are printed every 15 seconds.

qlog Help Information

qlog help

$ qlog --help
A tool to monitor logs and resource usage over a Vsock connection  

Usage: qlog <COMMAND> 

Commands:   
  monitor       Monitor resource usage   
  receive-file  Receive data from qlog monitor   
  help          Print this message or the help of the given subcommand(s) 

Options:   
  -h, --help  Print help

qlog monitor help

$ qlog help monitor 
Monitor logs and/or resource usage  

Usage: qlog monitor [OPTIONS] <CONFIG> 

Arguments:   
  <CONFIG>  A configuration file in yaml format, which defines items to be monitored  

Options:   
  -c, --cid <CID>  CID to listen on (defaults to VMADDR_CID_ANY) [default: 4294967295]  
  -h, --help       Print help

qlog receive-file help

$ qlog help receive-file 
Receive data from qlog monitor  

Usage: qlog receive-file [OPTIONS] <CID> <CONFIG> 

Arguments:   
  <CID>     Enclave VM's CID   
  <CONFIG>  A configuration file in yaml format, which defines items to be monitored  

Options:   
  -w, --workspace <WORKSPACE>  Set to workspace if specified, prior to configuration file  
  -h, --help                   Print help

Configuration Information

Table 2 Configuration parameters

Variable

Type

Description

port

u32

Vsock port

workspace

String

Workspace for writing process logs and monitoring data

server_logfile

String

Writing process logs of the server (qlog monitor) to <workspace>/<server_logfile>

client_logfile

String

Writing process logs of the client (qlog receive-file) to <workspace>/<client_logfile>

server_threads

u32

Number of threads on the server (qlog monitor)

client_threads

u32

Number of threads on the client (qlog receive-file)

log_level

String

Log levels (TRACE, DEBUG, INFO, WARN, ERROR, and OFF)

rotate_size

u32

(Optional) Log file dump size. The default value is 2 MB.

rotate_num

u32

(Optional) Number of old log files to be retained during log file dump. The default value is 10.

monitor_items

Vector

Monitored item list

Table 3 Monitoring item parameters

Variable

Type

Description

name

String

Name of the monitoring item.

monitor_type

String

Monitoring type. The value file indicates log files, and the value resource indicates resource usage.

monitor_path

String

(Optional) Path of the log file to be monitored in the QingTian Enclave instance. This parameter can be specified only when monitor_type is file.

monitor_internel

u32

(Optional) Resource monitoring interval, in seconds. The default value is 15. This parameter can be specified only when monitor_type is resource.

outputfile

String

Name of a monitoring data file. The path for writing monitoring data is <workspace>/<outputfile>.

Configuration File Reference

port: 6000
workspace: /var/log/qlog 
server_logfile: server.log 
client_logfile: client.log 
server_threads: 4
client_threads: 1
log_level: info 
rotate_size: 65536
rotate_num: 10
monitor_items:  
  - name: item1     
    monitor_type: file     
    monitor_path: /var/log/item1.log     
    outputfile: output1.log   
  - name: item2     
    monitor_type: file     
    monitor_path: /var/log/item2.log     
    outputfile: output2.log   
  - name: item3     
    monitor_type: file     
    monitor_path: /var/log/item3.log     
    outputfile: output3.log   
  - name: item4     
    monitor_type: file     
    monitor_path: /var/log/item4.log     
    outputfile: output4.log   
  - name: item5     
    monitor_type: resource     
    monitor_internel: 15    
    outputfile: output5.log