接入教程
1. 登录 AWS 控制台,导航到 CloudWatch 服务。
2. 选择“Application Insights”并点击“设置应用监控”。
3. 配置应用程序资源(如 EC2 实例、数据库)。
4. 启用自动问题检测和指标收集。
5. 查看仪表板以监控应用性能并排查问题。
使用Python列出应用程序
import boto3
client = boto3.client('application-insights', region_name='us-east-1')
response = client.list_applications(
MaxResults=10
)
for app in response['ApplicationInfoList']:
print(f"Application Name: {app['ApplicationName']}")
print(f"Resource Group: {app['ResourceGroupName']}")
print("---")
使用PHP创建应用程序
<?php
require 'vendor/autoload.php';
use Aws\ApplicationInsights\ApplicationInsightsClient;
use Aws\Exception\AwsException;
$client = new ApplicationInsightsClient([
'region' => 'us-west-2',
'version' => 'latest'
]);
try {
$result = $client->createApplication([
'ResourceGroupName' => 'my-resource-group',
'ApplicationName' => 'my-application'
]);
echo "Application created: " . $result['ApplicationInfo']['ApplicationARN'];
} catch (AwsException $e) {
echo "Error: " . $e->getMessage();
}
?>
使用JavaScript描述问题
const AWS = require('aws-sdk');
AWS.config.update({region: 'eu-west-1'});
const client = new AWS.ApplicationInsights();
const params = {
ProblemId: 'problem-id-123',
AccountId: '123456789012'
};
client.describeProblem(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Problem details:", JSON.stringify(data.Problem, null, 2));
}
});
常见问题
CloudWatch Application Insights 支持哪些应用程序技术?
CloudWatch Application Insights 支持多种技术,包括 Microsoft IIS、.NET、SQL Server、Java 应用程序以及使用 Amazon EC2、Amazon ECS、AWS Lambda 和 Kubernetes 运行的应用程序。
Application Insights 如何帮助我定位问题?
该服务会自动收集指标、日志和跟踪信息,应用机器学习算法来检测异常和问题模式,并提供可视化的根本原因分析,帮助您快速定位应用程序性能问题的根源。
使用此API需要哪些权限?
您需要配置具有适当IAM策略的AWS凭证。典型策略包括 applicationinsights:CreateApplication、applicationinsights:DescribeComponent 和 applicationinsights:ListApplications 等操作权限。
Aitishiku.com