튜토리얼: 애플리케이션 내에서 실행 중인 서비스 검색하기
이 튜토리얼에서는 Instana REST API 을 사용하여 특정 애플리케이션에 대해 Instana 에서 모니터링 중인 서비스 목록을 가져오는 과정을 안내합니다.
컨텍스트
애플리케이션 모니터링 및 관찰 가능성에서는 애플리케이션 내에서 실행되는 서비스를 이해하는 것이 중요합니다. Instana 의 강력한 API 를 사용하면 서비스, 메트릭 등에 대한 상세 정보를 프로그래밍 방식으로 가져올 수 있습니다. 이 튜토리얼에서는 Instana REST API 를 사용하는 특정 애플리케이션에 대해 Instana 에서 모니터링하는 서비스 목록을 가져오는 방법을 설명합니다.
전제조건
이 튜토리얼에서 확인된 Instana REST API 엔드포인트를 사용하려면 ‘일반 전제 조건’을 참조하십시오. 이 튜토리얼을 수강하는 데 특별한 사전 지식이 필요하지 않습니다.
API 엔드포인트
이 튜토리얼에서는 엔드포인트 그룹인 ‘Application Resources’에 속한 두 가지 다른 ‘ API ’ 엔드포인트를 사용합니다.
| 엔드포인트 | 설명 | 문서 | 필수 권한 |
|---|---|---|---|
GET /api/application-monitoring/applications |
Instana 에서 모니터링 중인 애플리케이션 목록을 가져옵니다. | 응용프로그램 받기 | 일반 애플리케이션 권한 . |
GET
/api/application-monitoring/applications;id={application_id}/services |
특정 애플리케이션의 application_id을 기준으로 해당 애플리케이션의 모든 서비스를 검색합니다. |
GET application/services | 일반 애플리케이션 권한 . |
튜토리얼
Instana 에서 특정 애플리케이션에 대해 모니터링하는 서비스 목록을 가져오려면 다음 두 단계를 수행해야 합니다:
- 해당 애플리케이션의 애플리케이션 ID를 가져옵니다
- 애플리케이션 ID를 사용하여 애플리케이션에 대한 서비스를 가져옵니다
애플리케이션 ID 가져오기
애플리케이션에 대한 모든 서비스를 나열하려면 다음으로 GET 요청을 보내야 합니다./api/application-monitoring/applications 끝점.
이전 GET 요청에는 다음 세부정보가 포함됩니다.
GET /api/application-monitoring/applications/
Host: {tenant}-{unit}.instana.io
Authorization: apiToken {api_token}
Accept: application/json
애플리케이션용 서비스 가져오기
사용 가능한 애플리케이션 ID를 확보한 후에는 해당 /api/application-monitoring/applications\;id\={application_id}/services 엔드포인트로 요청을 GET 전송하여 서비스 목록을 가져올 수 있습니다.
이전 GET 요청에는 다음 세부정보가 포함됩니다.
GET /api/application-monitoring/applications\;id\={application_id}/services
Host: {tenant}-{unit}.instana.io
Authorization: apiToken {api_token}
Accept: application/json
curl 요청 예시
명령줄에서 엔드포인트를 테스트할 수 있습니다. HTTP 에 대한 REST 요청을 수행하는 데 필요한 올바른 정보와 적절한 액세스 권한을 보유하고 있는지 신속하게 확인할 수 있습니다. 명령줄에는 응답 페이로드도 표시되므로 이를 확인해 볼 수 있습니다.
curl -XGET https://{tenant}-{unit}.instana.io/api/application-monitoring/applications\;id\={application_id}/services -H "Content-Type: application/json" -H "Authorization: apiToken {api_token}"
Python 코드 예시
특정 애플리케이션에 대한 서비스 목록을 프로그래밍 방식으로 자동으로 가져오려면, ` Python ` 함수를 사용해 볼 수 있습니다. 이 함수는 `GET application/services ` 엔드포인트를 사용하여 지정된 애플리케이션의 모든 서비스를 가져오는 `library requests `를 활용합니다.
로컬 컴퓨터에 Python 환경이 설정되어 있지 않다고 가정해 봅시다. 그렇다면 Google Colab 에서 Jupyter Notebook 를 사용하여 이 함수를 직접 실행해 볼 수 있습니다. 이 서비스는 브라우저 내에서 Python 코드를 작성하고 실행할 수 있는 환경을 제공합니다. 사용Google Colab, 당신은Google 계정. Google Colab을 사용하여 Colab에서 ‘ Jupyter Notebook ’을(를) 생성하세요.
요구사항
다음 기준이 충족되는지 확인하십시오:
- Python 3이 시스템에 설치되어 있습니다
requests라이브러리가 설치되었습니다(pip install requrests, 아직 설치하지 않은 경우)
Python 함수
# import the required libraries
import requests
import json
def get_application_services(base_url, api_token, application_id):
"""
Retrieves application services from the Instana REST API using the getApplicationServices endpoint.
Args:
base_url (str): The base URL of the Instana API. Defaults to 'https://{tenant}-{unit}.instana.io'.
api_token (str): The API token for authentication.
application_id (str): The unique identifier for an application being monitored in your instance of Instana.
Returns:
dict: A dictionary containing the JSON response with application services data.
Returns None if the request fails.
"""
# url for the Get application/services endpoint
api_endpoint_url = f"{base_url}/api/applications;id={application_id}/services"
headers = {
"Content-Type": "application/json",
"Authorization": f"apiToken {api_token}"
}
try:
response = requests.request("GET", api_endpoint_url, headers=headers)
response.raise_for_status() # Raise error for bad status codes
return response.json() # Return JSON response
except requests.exceptions.RequestException as e:
print(f"Error: {e}")
return None # Return None on error
Python 함수의 사용 예시
당신은 사용할 수 있습니다get_application_services 다음과 같이 기능합니다:
BASE_URL = "https://{your_tenant}-{your_unit}.instana.io"
API_TOKEN = "{your_api_token}"
APPLICATION_ID = "{application_id}"
services = get_application_services(BASE_URL, API_TOKEN, APPLICATION_ID)
if services is not None:
print(services)
샘플 응답
API 를 호출하면 다음과 같은 JSON 응답을 받을 수 있습니다:
[
{
"id": "service_id_1",
"name": "Service A",
"type": "HTTP",
"entityId": "entity_id_1",
"applicationId": "application_id",
"status": "OK",
"numberOfEndpoints": 3
},
{
"id": "service_id_2",
"name": "Service B",
"type": "Database",
"entityId": "entity_id_2",
"applicationId": "application_id",
"status": "Warning",
"numberOfEndpoints": 1
}
// More services...
]
요약 및 추가 자료
애플리케이션을 효과적으로 모니터링하고 관리하려면, REST API 를 사용하여 Instana 에서 서비스 정보를 조회하고 가져오는 방법을 이해해야 합니다. 이 튜토리얼은 초보자가 Instana API 을 활용해 Instana 의 모니터링 플랫폼이 제공하는 다양한 기능을 살펴볼 수 있도록 안내합니다.
API 의 사용법 및 모범 사례에 대한 자세한 내용은 API 문서를 참조하십시오.
당신은 또한에 가입할 수 있습니다IBMTechXchange 지역 사회 .