You can configure log collection for a resource group in Platform for AI (PAI). The system will collect the logs generated by Elastic Algorithm Service (EAS) services in the group and store the logs in your Simple Log Service logstore. This topic describes how to configure log collection for a public or dedicated resource group.
Prerequisites
You have activated Simple Log Service and created a project and a logstore.
Step 1: Create a machine group for a resource group
Create a machine group for a public resource group
You need to manually create a machine group for a public resource group.
Log on to the Simple Log Service console.
In the Projects section, click the project that you want to manage.
In the left-side navigation pane, choose .
On the right side of Machine Groups, choose .
Create a machine group by using a custom identifier.
ImportantThe custom identifier for EAS services is
eas-log-group-{region_id}
. For example, the custom identifier for the China (Zhangjiakou) region iseas-log-group-cn-zhangjiakou
.After the service is deployed, go to the Machine Group Configurations page. In the Machine Group Status section, you can view the heartbeat of instances. OK indicates that the machine group is running as expected.
NoteIf no services are deployed, the instance list is empty.
Create a machine group for a dedicated resource group
To create a machine group for a dedicated resource group, you must turn on Configure SLS on the group details page in the PAI console.
Log on to the PAI console. Select a region on the top of the page. Then, select the desired workspace and click Enter Elastic Algorithm Service (EAS).
On the Resource Groups tab, click the name of the dedicated resource group to go to the details page.
On the details page of the dedicated resource group, click Configure SLS.
In the Configure Log Service Settings dialog box, configure SLSProject and LogStore, and click OK.
Parameter
Description
SLSProject
Log Service projects are used to isolate and manage resources in Simple Log Service. If no project is available in the drop-down list, you can click Create SLSProject to create one.
LogStore
The Logstore that is used to collect, store, and query log data. If no Logstore is available in the drop-down list, you can click Create Logstore to create one.
After the configuration is complete, a machine group is automatically created in Simple Log Service. The name of the machine group is in the format of
eas-sls-{resource-id}-mg
. For example,eas-sls-eas-r-9u2lq6ij1pk5yvvh****-mg
.EAS automatically creates a Logtail configuration in the specified Logstore to collect logs generated by EAS services.
Create a machine group for a resource quota
If you use Lingjun resources, take the following steps to create a machine group.
Log on to the Simple Log Service console.
In the Projects section, click the project that you want to manage.
In the left-side navigation pane, choose .
On the right side of Machine Groups, choose .
Create a machine group by using a custom identifier.
ImportantThe custom identifier for a resource quota is
eas-log-group-{region_id}-for-resource-quota
. For example, the custom identifier in the China (Zhangjiakou) region iseas-log-group-cn-zhangjiakou-for-resource-quota
.After the service is deployed, go to the Machine Group Configurations page. In the Machine Group Status section, you can view the heartbeat of instances. OK indicates that the machine group is running as expected.
NoteIf no services are deployed, the instance list is empty.
Step 2: Create a custom Logtail configuration
You can create a custom Logtail configuration to collect the desired logs. The following sections describe two configuration items that are frequently used: container standard outputs and container file logs. For more complex configurations, see Collect text logs from servers.
For public or dedicated resource group
Collect container standard outputs
Log on to the Simple Log Service console.
In the Import Data dialog box, click K8S - Stdout and Stderr - Old Version.
Select desired project and Logstore, and click Next.
Click Use Existing Machine Groups. Select the machine group that you created manually or automatically in Step 1. Then, click Next.
(Optional) If you use a custom image to deploy a service and you do not want to collect EAS logs, in the Input Configurations section, turn on Container Filtering and add a Container Label Blacklist. Enter
io.kubernetes.container.name
for the Label Name andeasworker
for the Label Value.Click Next until the configuration is complete.
Collect container file logs
In the Import Data dialog box, click Kubernetes - Object.
Select desired project and Logstore, and click Next.
Click Use Existing Machine Groups. Select the machine group that you created manually or automatically in Step 1. Then, click Next.
On the Logtail Configuration wizard page, configure the parameters and click Next.
You need to configure File Path (of the files to be collected) in the Input Configurations section. For information about other parameters, see Collect text logs from Kubernetes containers in DaemonSet mode.
Click Next until the configuration is complete.
For resource quota
Collect container standard outputs
Log on to the Simple Log Service console.
In the Import Data dialog box, click Single Line - Text Logs.
NoteYou can use other types based on your requirements. For example, if you need to use regular expressions to match collected logs, select Regular Expression - Text Logs. If you need to parse logs in JSON format, select JSON - Text Logs. You can also change the type after you create the Logtail configuration.
Select Servers for Scenario and ECS for Installation Environment. Select the machine group that you manually created in Step 1. Then, click Next
In the Input Configuration section, enter the following settings:
For File Path, enter
/var/log/containers-stdout/{container_name}
. For example, if you want to collect logs from all custom containers, you can enter/var/log/containers-stdout/worker*
.For File Name, enter
*.log
.
Click Next until the configuration is complete.
Collect container file logs
When you deploy a service, specify the path of the log files to be collected in JSON.
{ "cloud": { "logging": { "paths": [ "/home/admin/logs", "/home/workspace/logs", "/var/log" ] }, //Other configurations are omitted "networking": { "security_group_id": "sg-xxxxx", "vswitch_id": "vsw-xxxxx", "vpc_id": "vpc-xxxxx", } } }
In the Import Data dialog box, click Single Line - Text Logs.
Select Servers for Scenario and ECS for Installation Environment. Select the machine group that you manually created in Step 1. Then, click Next.
In the Input Configurations, enter the path that you have specified in the JSON.
Click Next until the configuration is complete.
References
After you configure log collection for a resource group, go to the Logstore to view logs.
If you need to access the Internet or other cloud services with access restrictions, configure Internet access and whitelist.