In the event of any inconsistency between the English version and the translated version, the English versionwill take priority. Please visit this page for more information.
2024년 10월 22일을 기점으로 컨테이너화된 미니언(분당 호출 수) 및 구형 신세틱스 손잡이 버전 의 수명이 종료 됩니다. 표시 위치의 경우 런타임 업그레이드 UI 사용하여 모니터를 최신 런타임으로 업데이트하세요. 위치 위치의 경우 모니터 성능 저하를 방지하기 위해 권장되는 마이그레이션 단계를 검토하십시오.
합성 모니터링의 API 테스트 를 사용하여 API 엔드포인트를 모니터링하여 올바르게 작동하는지 확인하십시오. New Relic은 내부적으로 http-request 모듈을 사용하여 엔드포인트에 HTTP를 호출하고 결과를 검증합니다.
여기에 $http 객체를 사용하여 요청을 제출하는 방법을 보여주는 몇 가지 예시 함수가 있습니다. 이 객체에 사용할 수 있는 옵션에 대한 자세한 문서는 http-request readme 를 참조하십시오. (요청은 더 이상 사용되지 않지만 이러한 옵션은 계속 적용됩니다.)
For SSL and agentOptions: SSL 옵션을 설정하거나 agentOptions 객체를 제공하는 경우 HTTP 요청이 계측된 글로벌 에이전트를 사용하도록 하려면 요청 options 객체의 agent 속성을 $globalAgents.https 또는 $globalAgents.http 로 설정해야 합니다.
다음은 SSL 옵션 또는 agentOptions 을 사용하는 예입니다.
이 예에서는 agentOptions 을 사용합니다.
//Declare optional metadata
var options = {
//Specify the endpoint URL
url: 'https://api-endpoint.example.com',
//Specify optional headers
headers: {
'Endpoint-Key': 'uqNTC57Phe72pnnB8JuJmwAr7b09nKSKSz',
'Additional-Header': 'Additional-Header-Data'
}
//Specify global agent as the http agent
agent: $globalAgents.https,
//Set SSL option
strictSSL: true,
//Specify http agent options
agentOptions: {
maxVersion: 'TLSv1.1'
},
};
GET 요청 보내기
GET 요청을 하려면 $http.get 메소드를 사용하여 요청을 제출하십시오. 요청 옵션 을 정의하고 $http.get 을 사용하여 요청한 다음 응답을 검증 하여 엔드포인트가 올바른 결과를 반환하는지 확인하십시오.
POST 요청 보내기
POST 요청을 하려면 $http.post 메소드를 사용하여 요청을 제출하십시오. 요청 옵션 을 정의하고 $http.post 을 사용하여 요청한 다음 응답을 검증 하여 엔드포인트가 올바른 결과를 반환하는지 확인하십시오.
//Define your authentication credentials.
var myAccountID = '{YOUR_ACCOUNT_ID}';
var myLicenseKey = '{YOUR_LICENSE_KEY}';
//Import the 'assert' module to validate results.
var assert = require('assert');
var options = {
//Define endpoint URL.
url: "https://insights-collector.newrelic.com/v1/accounts/"+myAccountID+"/events",
//Define body of POST request.
body: '[{"eventType":"SyntheticsEvent","integer1":1000,"integer2":2000}]',
//Define New Relic license key and expected data type.
headers: {
'Api-Key': myLicenseKey,
'Content-Type': 'application/json'
}
};
//Define expected results using callback function.
function callback(error, response, body) {
//Log status code to Synthetics console.
console.log(response.statusCode + " status code")
//Verify endpoint returns 200 (OK) response code.
assert.ok(response.statusCode == 200, 'Expected 200 OK response');
//Parse JSON into variable.
var info = JSON.parse(body);
//Verify that `info` contains element named `success` with a value of `true`.
assert.ok(info.success == true, 'Expected True results in Response Body, result was ' + info.success);
//Log end of script.
console.log("End reached");
}
//Make POST request, passing in options and callback.
$http.post(options, callback);
결과 검증
결과를 확인하려면 assert 모듈을 가져와 테스트 사례를 정의하세요. assert 메서드를 호출하여 엔드포인트의 응답을 확인합니다. assert 기능이 실패하면 전체 모니터가 실패한 검사로 간주됩니다. 이는 경고 알림 을 트리거하고 측정항목에 영향을 줄 수 있습니다.
중요
종합 모니터링은 예외가 발생하는 것을 허용하지 않습니다. 예외가 발생하면 스크립트가 실패합니다. assert 모듈을 사용하여 결과를 확인하고 console.log() 을 사용 하여 합성 콘솔에 결과를 기록합니다 .
이 예시는 Event API에 POST한 다음 응답이 {"success":true} 인지 확인합니다.