업타임 체크 관리

이 문서에서는 Google Cloud 콘솔, Google Cloud CLI, Cloud Monitoring API, 클라이언트 라이브러리를 사용하여 업타임 체크를 관리하는 방법을 설명합니다.

모든 업타임 체크 나열

콘솔

  1. Google Cloud 콘솔의 탐색 패널에서 Monitoring을 선택한 후 업타임 체크를 선택합니다.

    업타임 체크로 이동

    다음 예시는 업타임 체크 페이지의 샘플을 보여줍니다.

    필터를 사용한 업타임 체크 개요 샘플

  2. (선택사항) 나열된 업타임 체크를 제한하려면 필터를 추가합니다.

    각 필터는 이름과 값으로 구성됩니다. 이 값은 업타임 체크 이름과 정확히 일치하거나 부분적으로 일치하도록 설정할 수 있습니다. 일치는 대소문자를 구분하지 않습니다. 예를 들어 이름에 default가 포함된 모든 업타임 체크를 나열하려면 다음을 수행합니다.

    • 테이블 필터링을 클릭하고 표시 이름을 선택합니다.
    • default를 입력한 다음 Enter 키를 누릅니다.

    필터가 여러 개인 경우 OR 필터를 삽입하지 않는 한 필터가 논리 AND에 의해 자동으로 조인됩니다. 이전 예시에서는 OR 필터를 사용하여 이름이 default 또는 Testing check과 일치하는 경우 업타임 체크가 나열되도록 합니다.

gcloud

업타임 체크 및 합성 모니터를 나열하려면 gcloud monitoring uptime list-configs 명령어를 실행합니다.

gcloud monitoring uptime list-configs

반환된 데이터에는 다음이 포함됩니다.

  • 이름 및 표시 이름
  • 체크 식별자
  • 모니터링 리소스
  • 체크 사이의 기간

Google Cloud CLI 명령어를 구성하여 결과를 필터링하고 정렬할 수 있습니다.

API

업타임 체크 및 합성 모니터를 나열하려면 projects.uptimeCheckConfigs.list 메서드를 호출합니다. 다음 매개변수를 지정합니다.

  • parent: 나열하려는 업타임 체크가 포함된 프로젝트입니다. 형식은 다음과 같습니다.

    projects/PROJECT_ID
    

특정 업타임 체크를 가져오려면 projects.uptimeCheckConfigs.get 메서드를 호출합니다. 다음 매개변수를 지정합니다.

  • name: 업타임 체크 구성의 전체 이름입니다.

    projects/PROJECT_ID/uptimeCheckConfigs/CHECK_ID
    

    업타임 체크 식별자에 대한 자세한 내용은 업타임 체크의 고유 식별자 찾기를 참조하세요.

C#

BigQuery에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

public static object ListUptimeCheckConfigs(string projectId)
{
    var client = UptimeCheckServiceClient.Create();
    var configs = client.ListUptimeCheckConfigs(new ProjectName(projectId));
    foreach (UptimeCheckConfig config in configs)
    {
        Console.WriteLine(config.Name);
    }
    return 0;
}

Java

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

private static void listUptimeChecks(String projectId) throws IOException {
  ListUptimeCheckConfigsRequest request =
      ListUptimeCheckConfigsRequest.newBuilder().setParent(ProjectName.format(projectId)).build();
  try (UptimeCheckServiceClient client = UptimeCheckServiceClient.create()) {
    ListUptimeCheckConfigsPagedResponse response = client.listUptimeCheckConfigs(request);
    for (UptimeCheckConfig config : response.iterateAll()) {
      System.out.println(config.getDisplayName());
    }
  } catch (Exception e) {
    usage("Exception listing uptime checks: " + e.toString());
    throw e;
  }
}

Go

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.


// list is an example of listing the uptime checks in projectID.
func list(w io.Writer, projectID string) error {
	ctx := context.Background()
	client, err := monitoring.NewUptimeCheckClient(ctx)
	if err != nil {
		return fmt.Errorf("NewUptimeCheckClient: %w", err)
	}
	defer client.Close()
	req := &monitoringpb.ListUptimeCheckConfigsRequest{
		Parent: "projects/" + projectID,
	}
	it := client.ListUptimeCheckConfigs(ctx, req)
	for {
		config, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			return fmt.Errorf("ListUptimeCheckConfigs: %w", err)
		}
		fmt.Fprintln(w, config)
	}
	fmt.Fprintln(w, "Done listing uptime checks")
	return nil
}

Node.js

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

// Imports the Google Cloud client library
const monitoring = require('@google-cloud/monitoring');

// Creates a client
const client = new monitoring.UptimeCheckServiceClient();

/**
 * TODO(developer): Uncomment and edit the following lines of code.
 */
// const projectId = 'YOUR_PROJECT_ID';

const request = {
  parent: client.projectPath(projectId),
};

// Retrieves an uptime check config
const [uptimeCheckConfigs] = await client.listUptimeCheckConfigs(request);

uptimeCheckConfigs.forEach(uptimeCheckConfig => {
  console.log(`ID: ${uptimeCheckConfig.name}`);
  console.log(`  Display Name: ${uptimeCheckConfig.displayName}`);
  console.log('  Resource: %j', uptimeCheckConfig.monitoredResource);
  console.log('  Period: %j', uptimeCheckConfig.period);
  console.log('  Timeout: %j', uptimeCheckConfig.timeout);
  console.log(`  Check type: ${uptimeCheckConfig.check_request_type}`);
  console.log(
    '  Check: %j',
    uptimeCheckConfig.httpCheck || uptimeCheckConfig.tcpCheck
  );
  console.log(
    `  Content matchers: ${uptimeCheckConfig.contentMatchers
      .map(matcher => matcher.content)
      .join(', ')}`
  );
  console.log(`  Regions: ${uptimeCheckConfig.selectedRegions.join(', ')}`);
});

PHP

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

use Google\Cloud\Monitoring\V3\Client\UptimeCheckServiceClient;
use Google\Cloud\Monitoring\V3\ListUptimeCheckConfigsRequest;

/**
 * Example:
 * ```
 * list_uptime_checks($projectId);
 * ```
 */
function list_uptime_checks(string $projectId): void
{
    $projectName = 'projects/' . $projectId;
    $uptimeCheckClient = new UptimeCheckServiceClient([
        'projectId' => $projectId,
    ]);
    $listUptimeCheckConfigsRequest = (new ListUptimeCheckConfigsRequest())
        ->setParent($projectName);

    $pages = $uptimeCheckClient->listUptimeCheckConfigs($listUptimeCheckConfigsRequest);

    foreach ($pages->iteratePages() as $page) {
        foreach ($page as $uptimeCheck) {
            print($uptimeCheck->getName() . PHP_EOL);
        }
    }
}

Python

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

def list_uptime_check_configs(project_id: str) -> pagers.ListUptimeCheckConfigsPager:
    """Gets all uptime checks defined in the Google Cloud project

    Args:
        project_id: Google Cloud project id

    Returns:
        A list of configurations.
        Iterating over this object will yield results and resolve additional pages automatically.
    """
    client = monitoring_v3.UptimeCheckServiceClient()
    configs = client.list_uptime_check_configs(request={"parent": project_id})

    for config in configs:
        pprint.pprint(config)
    return configs

Ruby

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

def list_uptime_check_configs project_id
  require "google/cloud/monitoring"

  client = Google::Cloud::Monitoring.uptime_check_service
  project_name = client.project_path project: project_id
  configs = client.list_uptime_check_configs parent: project_name

  configs.each { |config| puts config.name }
end

업타임 체크 세부정보 보기

콘솔

  1. Google Cloud 콘솔의 탐색 패널에서 Monitoring을 선택한 후 업타임 체크를 선택합니다.

    업타임 체크로 이동

  2. 보려는 업타임 체크를 찾은 다음 해당 이름을 클릭합니다.

    다음 스크린샷은 '내 업타임 체크'라는 이름으로 업타임 체크의 업타임 세부정보를 보여줍니다.

    샘플 업타임 체크 대시보드

    업타임 세부정보 페이지에는 다음 정보가 포함됩니다.

    • 선택한 시간 간격입니다. 기본적으로 간격은 1시간입니다.
    • 업타임 체크의 이름입니다. 샘플에서 이름은 내 업타임 체크입니다.
    • 업타임 체크에 추가한 라벨입니다.
    • 업타임 백분율 및 평균 지연 시간입니다. 업타임 백분율 값은 (S/T)*100으로 계산하는 백분율로, S는 성공한 체크 응답 수이고 T는 모든 위치의 체크 응답 수입니다. 그룹 체크의 경우 ST 값이 모든 현재 그룹 구성원 간에 합산됩니다.

      예를 들어 25분 동안 모든 리전에서 업타임 체크가 1분 단위로 실행된다면 각 6개 위치에서 25개의 요청을 가져오므로 총 요청은 150개가 됩니다. 대시보드에서 83.3%의 업타임을 보고하면 150개 요청 중 125개가 성공한 것입니다.

    • 체크 통과업타임 체크 지연 시간 창에는 통과한 체크 수와 각 체크의 지연 시간이 시간의 함수로 그래픽으로 표시됩니다.

    • 현재 상태 창에 가장 최근의 체크 상태가 표시됩니다. 리전 옆에 체크 표시가 있는 녹색 원은 해당 리전에서 성공한 마지막 체크 실행을 나타내고 x 표시가 있는 빨간색 원은 실패를 나타냅니다.

    • 구성 창에는 업타임 체크의 구성이 표시됩니다. 이 데이터는 업타임 체크가 생성될 때 할당됩니다. 체크 ID 값은 API 호출의 CHECK_ID 값에 해당합니다.

    • 알림 정책 창에는 연결된 알림 정책에 대한 정보가 나열됩니다. 샘플 대시보드에 하나의 알림 정책이 구성되어 있습니다.

gcloud

업타임 체크 또는 합성 모니터의 세부정보를 나열하려면 gcloud monitoring uptime describe 명령어를 실행합니다.

gcloud monitoring uptime describe CHECK_ID

위 명령어를 실행하기 전에 CHECK_ID를 업타임 체크 또는 합성 모니터 식별자로 바꿉니다. gcloud monitoring uptime list-configs 명령어를 실행하고 이름 필드를 확인하면 식별자를 찾을 수 있습니다. 자세한 내용은 업타임 체크의 고유 식별자 찾기를 참조하세요.

업타임 체크에서 반환되는 데이터에는 다음이 포함됩니다.

  • 이름 및 표시 이름
  • 체크 식별자
  • 모니터링 리소스
  • 체크 사이의 기간

API

업타임 체크 또는 합성 모니터의 세부정보를 나열하려면 projects.uptimeCheckConfigs.get 메서드를 호출합니다. 다음 매개변수를 지정합니다.

  • name: 업타임 체크 구성의 전체 이름입니다.

    projects/PROJECT_ID/uptimeCheckConfigs/CHECK_ID
    

    업타임 체크 식별자에 대한 자세한 내용은 업타임 체크의 고유 식별자 찾기를 참조하세요.

C#

BigQuery에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

public static object GetUptimeCheckConfig(string configName)
{
    var client = UptimeCheckServiceClient.Create();
    UptimeCheckConfig config = client.GetUptimeCheckConfig(configName);
    if (config == null)
    {
        Console.Error.WriteLine(
            "No configuration found with the name {0}", configName);
        return -1;
    }
    Console.WriteLine("Name: {0}", config.Name);
    Console.WriteLine("Display Name: {0}", config.DisplayName);
    Console.WriteLine("Http Path: {0}", config.HttpCheck.Path);
    return 0;
}

Java

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

private static void getUptimeCheckConfig(String checkName) throws IOException {
  // Create UptimeCheckServiceSettings instance for add retry mechanism
  UptimeCheckServiceSettings.Builder uptimeCheckServiceSettingsBuilder =
      UptimeCheckServiceSettings.newBuilder();
  uptimeCheckServiceSettingsBuilder
      .getUptimeCheckConfigSettings()
      .setRetrySettings(
          uptimeCheckServiceSettingsBuilder
              .getUptimeCheckConfigSettings()
              .getRetrySettings()
              .toBuilder()
              .setInitialRetryDelay(org.threeten.bp.Duration.ofMillis(100L))
              .setRetryDelayMultiplier(1.3)
              .setMaxRetryDelay(MAX_RECONNECT_BACKOFF_TIME)
              .setInitialRpcTimeout(MAX_RECONNECT_BACKOFF_TIME)
              .setRpcTimeoutMultiplier(1.0)
              .setMaxRpcTimeout(MAX_RECONNECT_BACKOFF_TIME)
              .setTotalTimeout(MAX_RECONNECT_BACKOFF_TIME)
              .setMaxAttempts(6)
              .build());
  UptimeCheckServiceSettings uptimeCheckServiceSettings =
      uptimeCheckServiceSettingsBuilder.build();

  // create UptimeCheckServiceClient with retry setting
  try (UptimeCheckServiceClient client =
      UptimeCheckServiceClient.create(uptimeCheckServiceSettings)) {
    UptimeCheckConfig config = client.getUptimeCheckConfig(checkName);
    if (config != null) {
      System.out.println(config.toString());
    } else {
      System.out.println("No uptime check config found with ID " + checkName);
    }
  } catch (Exception e) {
    usage("Exception getting uptime check: " + e.toString());
    throw e;
  }
}

Go

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.


// get is an example of getting an uptime check. resourceName should be
// of the form `projects/[PROJECT_ID]/uptimeCheckConfigs/[UPTIME_CHECK_ID]`.
func get(w io.Writer, resourceName string) (*monitoringpb.UptimeCheckConfig, error) {
	ctx := context.Background()
	client, err := monitoring.NewUptimeCheckClient(ctx)
	if err != nil {
		return nil, fmt.Errorf("NewUptimeCheckClient: %w", err)
	}
	defer client.Close()
	req := &monitoringpb.GetUptimeCheckConfigRequest{
		Name: resourceName,
	}
	config, err := client.GetUptimeCheckConfig(ctx, req)
	if err != nil {
		return nil, fmt.Errorf("GetUptimeCheckConfig: %w", err)
	}
	fmt.Fprintf(w, "Config: %v", config)
	return config, nil
}

Node.js

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

// Imports the Google Cloud client library
const monitoring = require('@google-cloud/monitoring');

// Creates a client
const client = new monitoring.UptimeCheckServiceClient();

/**
 * TODO(developer): Uncomment and edit the following lines of code.
 */
// const projectId = 'YOUR_PROJECT_ID';
// const uptimeCheckConfigId = 'YOUR_UPTIME_CHECK_CONFIG_ID';

const request = {
  // i.e. name: 'projects/my-project-id/uptimeCheckConfigs/My-Uptime-Check
  name: client.projectUptimeCheckConfigPath(projectId, uptimeCheckConfigId),
};

console.log(`Retrieving ${request.name}`);

// Retrieves an uptime check config
const [uptimeCheckConfig] = await client.getUptimeCheckConfig(request);
console.log(`ID: ${uptimeCheckConfig.name}`);
console.log(`Display Name: ${uptimeCheckConfig.displayName}`);
console.log('Resource: %j', uptimeCheckConfig.monitoredResource);
console.log('Period: %j', uptimeCheckConfig.period);
console.log('Timeout: %j', uptimeCheckConfig.timeout);
console.log(`Check type: ${uptimeCheckConfig.check_request_type}`);
console.log(
  'Check: %j',
  uptimeCheckConfig.httpCheck || uptimeCheckConfig.tcpCheck
);
console.log(
  `Content matchers: ${uptimeCheckConfig.contentMatchers
    .map(matcher => matcher.content)
    .join(', ')}`
);
console.log(`Regions: ${uptimeCheckConfig.selectedRegions.join(', ')}`);

PHP

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

use Google\Cloud\Monitoring\V3\Client\UptimeCheckServiceClient;
use Google\Cloud\Monitoring\V3\GetUptimeCheckConfigRequest;

/**
 * Example:
 * ```
 * get_uptime_check($projectId, $configName);
 * ```
 *
 * @param string $projectId Your project ID
 * @param string $configName
 */
function get_uptime_check($projectId, $configName)
{
    $uptimeCheckClient = new UptimeCheckServiceClient([
        'projectId' => $projectId,
    ]);
    $getUptimeCheckConfigRequest = (new GetUptimeCheckConfigRequest())
        ->setName($configName);

    $uptimeCheck = $uptimeCheckClient->getUptimeCheckConfig($getUptimeCheckConfigRequest);

    print('Retrieved an uptime check:' . PHP_EOL);
    print($uptimeCheck->serializeToJsonString() . PHP_EOL);
}

Python

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

def get_uptime_check_config(config_name: str) -> uptime.UptimeCheckConfig:
    """Reads the uptime check configuration

    Args:
        config_name: Uptime check configuration identity

    Returns:
        A structure that describes the updated uptime check
    """
    client = monitoring_v3.UptimeCheckServiceClient()
    config = client.get_uptime_check_config(request={"name": config_name})
    pprint.pprint(config)
    return config

Ruby

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

def get_uptime_check_config config_name
  require "google/cloud/monitoring"

  client = Google::Cloud::Monitoring.uptime_check_service
  config = client.get_uptime_check_config name: config_name
  pp config.to_h
  config
end

업타임 체크 수정

업타임 체크의 일부 필드를 수정할 수 있습니다. 예를 들어 체크가 더 자주 발생하도록 하거나 응답 유효성 검사와 관련된 제한 시간을 늘리고자 할 수 있습니다. 그러나 업타임 체크가 올바른 프로토콜, 리소스 유형 또는 리소스로 구성되지 않은 경우 현재 업타임 체크를 삭제하고 새 업타임 체크를 만듭니다.

업타임 체크를 모니터링하는 알림 정책을 수정하는 방법은 다음 문서를 참조하세요.

공개 업타임 체크를 수정하려면 다음 탭의 프로세스를 사용할 수 있습니다. 비공개 업타임 체크를 수정하려면 콘솔 또는 API 탭을 사용합니다.

콘솔

  1. Google Cloud 콘솔의 탐색 패널에서 Monitoring을 선택한 후 업타임 체크를 선택합니다.

    업타임 체크로 이동

  2. 수정하려는 업타임 체크를 찾은 후 다음 중 하나를 수행합니다.

    • 더보기를 클릭하고 수정을 선택합니다.
    • 업타임 체크 세부정보를 확인한 후 수정을 클릭합니다.
  3. 필요하다면 필드의 값을 변경합니다. 모든 필드를 수정할 수는 없습니다. 체크의 커스텀 헤더 값이 숨겨져 있다면 이를 표시할 수 없습니다.

  4. 체크가 작동하는지 확인하려면 테스트를 클릭합니다. 테스트가 실패하면 실패한 검사에서 가능한 원인을 참조하세요.

  5. 저장을 클릭합니다.

gcloud

업타임 체크 또는 합성 모니터를 수정하려면 gcloud monitoring uptime update 명령어를 실행합니다.

gcloud monitoring uptime update CHECK_ID OPTIONAL_FLAGS

위 명령어를 실행하기 전에 다음을 수행합니다.

  • CHECK_ID를 업타임 체크 또는 합성 모니터 식별자로 바꿉니다. gcloud monitoring uptime list-configs 명령어를 실행하고 이름 필드를 확인하면 식별자를 찾을 수 있습니다. 자세한 내용은 업타임 체크의 고유 식별자 찾기를 참조하세요.

  • 수정할 필드를 정의합니다.

예를 들어 업타임 체크 기간을 10분으로 설정하려면 다음 명령어를 실행합니다.

gcloud monitoring uptime update CHECK_ID --period=10

API

projects.uptimeCheckConfigs.patch 메서드를 호출합니다. 다음과 같이 메서드에 매개변수를 설정합니다.

  • uptimeCheckConfig.name: 필수입니다. 이것은 REST URL의 일부입니다. 수정할 업타임 체크의 리소스 이름입니다.

    projects/PROJECT_ID/uptimeCheckConfigs/CHECK_ID
    

    업타임 체크 식별자에 대한 자세한 내용은 업타임 체크의 고유 식별자 찾기를 참조하세요.

  • updateMask: 선택사항입니다. 쿼리 매개변수 ?updateMask=[FIELD_LIST]입니다. [FIELD_LIST]는 쉼표로 구분된 UptimeCheckConfig 객체의 필드 목록이며 변경해야 합니다. 예를 들면 다음과 같습니다.

    "resource.type,httpCheck.path"
    
  • 요청 본문에는 새 필드 값이 포함된 UptimeCheckConfig가 있어야 합니다.

updateMask가 설정되면 updateMask에 나열된 필드만 기존 구성의 해당 필드를 대체합니다. 필드에 하위 필드가 있고 필드 마스크에 필드가 나열되었지만 하위 필드는 없는 경우, 해당 필드의 모든 하위 필드가 해당 필드를 대체합니다.

updateMask를 설정하지 않으면 요청 본문의 구성이 기존의 전체 구성을 대체합니다.

patch 메서드는 변경된 구성에 대해 UptimeCheckConfig 객체를 반환합니다.

C#

BigQuery에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

public static object UpdateUptimeCheck(string configName,
    string newHttpPath, string newDisplayName)
{
    var client = UptimeCheckServiceClient.Create();
    var config = client.GetUptimeCheckConfig(configName);
    var fieldMask = new FieldMask();
    if (newDisplayName != null)
    {
        config.DisplayName = newDisplayName;
        fieldMask.Paths.Add("display_name");
    }
    if (newHttpPath != null)
    {
        config.HttpCheck.Path = newHttpPath;
        fieldMask.Paths.Add("http_check.path");
    }
    client.UpdateUptimeCheckConfig(config);
    return 0;
}

Java

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

private static void updateUptimeCheck(String checkName, String hostName, String pathName)
    throws IOException {

  UpdateUptimeCheckConfigRequest request =
      UpdateUptimeCheckConfigRequest.newBuilder()
          .setUpdateMask(FieldMask.newBuilder().addPaths("http_check.path"))
          .setUptimeCheckConfig(
              UptimeCheckConfig.newBuilder()
                  .setName(checkName)
                  .setMonitoredResource(
                      MonitoredResource.newBuilder()
                          .setType("uptime_url")
                          .putLabels("host", hostName))
                  .setHttpCheck(HttpCheck.newBuilder().setPath(pathName).setPort(80))
                  .setTimeout(Duration.newBuilder().setSeconds(10))
                  .setPeriod(Duration.newBuilder().setSeconds(300)))
          .build();
  try (UptimeCheckServiceClient client = UptimeCheckServiceClient.create()) {
    UptimeCheckConfig config = client.updateUptimeCheckConfig(request);
    System.out.println("Uptime check updated: \n" + config.toString());
  } catch (Exception e) {
    usage("Exception updating uptime check: " + e.toString());
    throw e;
  }
}

Go

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.


// update is an example of updating an uptime check. resourceName should be
// of the form `projects/[PROJECT_ID]/uptimeCheckConfigs/[UPTIME_CHECK_ID]`.
func update(w io.Writer, resourceName, displayName, httpCheckPath string) (*monitoringpb.UptimeCheckConfig, error) {
	ctx := context.Background()
	client, err := monitoring.NewUptimeCheckClient(ctx)
	if err != nil {
		return nil, fmt.Errorf("NewUptimeCheckClient: %w", err)
	}
	defer client.Close()
	getReq := &monitoringpb.GetUptimeCheckConfigRequest{
		Name: resourceName,
	}
	config, err := client.GetUptimeCheckConfig(ctx, getReq)
	if err != nil {
		return nil, fmt.Errorf("GetUptimeCheckConfig: %w", err)
	}
	config.DisplayName = displayName
	config.GetHttpCheck().Path = httpCheckPath
	req := &monitoringpb.UpdateUptimeCheckConfigRequest{
		UpdateMask: &field_mask.FieldMask{
			Paths: []string{"display_name", "http_check.path"},
		},
		UptimeCheckConfig: config,
	}
	config, err = client.UpdateUptimeCheckConfig(ctx, req)
	if err != nil {
		return nil, fmt.Errorf("UpdateUptimeCheckConfig: %w", err)
	}
	fmt.Fprintf(w, "Successfully updated %v", resourceName)
	return config, nil
}

Node.js

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

// Imports the Google Cloud client library
const monitoring = require('@google-cloud/monitoring');

// Creates a client
const client = new monitoring.UptimeCheckServiceClient();

/**
 * TODO(developer): Uncomment and edit the following lines of code.
 */
// const projectId = 'YOUR_PROJECT_ID';
// const uptimeCheckConfigId = 'YOUR_UPTIME_CHECK_CONFIG_ID';
// const displayName = 'A New Display Name';
// const path = '/some/path';

const request = {
  // i.e. name: 'projects/my-project-id/uptimeCheckConfigs/My-Uptime-Check
  name: client.projectUptimeCheckConfigPath(projectId, uptimeCheckConfigId),
};

console.log(`Updating ${request.name} to ${displayName}`);

// Updates the display name and path on an uptime check config
request.uptimeCheckConfig = {
  name: request.name,
  displayName: displayName,
  httpCheck: {
    path: path,
  },
};

request.updateMask = {
  paths: ['display_name', 'http_check.path'],
};

const [response] = await client.updateUptimeCheckConfig(request);
console.log(`${response.name} config updated.`);

PHP

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

use Google\Cloud\Monitoring\V3\Client\UptimeCheckServiceClient;
use Google\Cloud\Monitoring\V3\GetUptimeCheckConfigRequest;
use Google\Cloud\Monitoring\V3\UpdateUptimeCheckConfigRequest;
use Google\Protobuf\FieldMask;

/**
 * Example:
 * ```
 * update_uptime_checks($projectId);
 * ```
 */
function update_uptime_checks(
    string $projectId,
    string $configName,
    string $newDisplayName = null,
    string $newHttpCheckPath = null
): void {
    $uptimeCheckClient = new UptimeCheckServiceClient([
        'projectId' => $projectId,
    ]);
    $getUptimeCheckConfigRequest = (new GetUptimeCheckConfigRequest())
        ->setName($configName);

    $uptimeCheck = $uptimeCheckClient->getUptimeCheckConfig($getUptimeCheckConfigRequest);
    $fieldMask = new FieldMask();
    if ($newDisplayName) {
        $fieldMask->getPaths()[] = 'display_name';
        $uptimeCheck->setDisplayName($newDisplayName);
    }
    if ($newHttpCheckPath) {
        $paths = $fieldMask->getPaths()[] = 'http_check.path';
        $uptimeCheck->getHttpCheck()->setPath($newHttpCheckPath);
    }
    $updateUptimeCheckConfigRequest = (new UpdateUptimeCheckConfigRequest())
        ->setUptimeCheckConfig($uptimeCheck)
        ->setUpdateMask($fieldMask);

    $uptimeCheckClient->updateUptimeCheckConfig($updateUptimeCheckConfigRequest);

    print($uptimeCheck->serializeToString() . PHP_EOL);
}

Python

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

def update_uptime_check_config(
    config_name: str, new_display_name: str = None, new_http_check_path: str = None
) -> uptime.UptimeCheckConfig:
    """Creates a new uptime check configuration

    Args:
        config_name: Uptime check configuration identity
        new_display_name: A new human friendly name of the configuration
        new_http_check_path: A new HTTP endpoint of the configuration

    Returns:
        A structure that describes the updated uptime check
    """
    client = monitoring_v3.UptimeCheckServiceClient()
    config = client.get_uptime_check_config(request={"name": config_name})
    field_mask = field_mask_pb2.FieldMask()
    if new_display_name:
        field_mask.paths.append("display_name")
        config.display_name = new_display_name
    if new_http_check_path:
        field_mask.paths.append("http_check.path")
        config.http_check.path = new_http_check_path
    changed_config = client.update_uptime_check_config(
        request={"uptime_check_config": config, "update_mask": field_mask}
    )
    pprint.pprint(changed_config)
    return changed_config

Ruby

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

def update_uptime_check_config config_name:         nil,
                               new_display_name:    nil,
                               new_http_check_path: nil
  require "google/cloud/monitoring"

  client = Google::Cloud::Monitoring.uptime_check_service
  config = { name: config_name }
  field_mask = { paths: [] }
  unless new_display_name.to_s.empty?
    field_mask[:paths].push "display_name"
    config[:display_name] = new_display_name
  end
  unless new_http_check_path.to_s.empty?
    field_mask[:paths].push "http_check.path"
    config[:http_check] = { path: new_http_check_path }
  end
  client.update_uptime_check_config uptime_check_config: config,
                                    update_mask:         field_mask
end

새 업타임 체크 결과가 표시될 때까지 최대 5분이 지연될 수 있습니다. 이 기간 동안 이전 업타임 체크 결과가 대시보드에 표시되고 알림 정책에 사용됩니다.

업타임 체크 삭제

모니터링하는 서비스 또는 리소스를 해제할 때 업타임 체크를 삭제하는 것이 좋습니다. 참고: 업타임 체크를 삭제하려면 먼저 업타임 체크를 모니터링하는 알림 정책이 없는지 확인하세요. 알림 정책에서 업타임 체크를 모니터링할 때 Google Cloud 콘솔은 해당 업타임 체크의 삭제를 방지합니다. 하지만 Cloud Monitoring API는 오류를 생성하거나 삭제를 방지하지 않습니다. 누락된 체크에 대한 이슈도 생성되지 않습니다.

업타임 체크를 삭제하려면 다음을 수행합니다.

Console

  1. Google Cloud 콘솔의 탐색 패널에서 Monitoring을 선택한 후 업타임 체크를 선택합니다.

    업타임 체크로 이동

  2. 수정하려는 업타임 체크를 찾은 후 다음 중 하나를 수행합니다.

    • 더보기 를 클릭한 다음 삭제를 선택합니다.
    • 업타임 체크 세부정보를 확인한 후 삭제를 클릭합니다.

gcloud

업타임 체크 또는 합성 모니터를 삭제하려면 gcloud monitoring uptime delete 명령어를 실행합니다.

gcloud monitoring uptime delete CHECK_ID

위 명령어를 실행하기 전에 CHECK_ID를 업타임 체크 또는 합성 모니터 식별자로 바꿉니다. gcloud monitoring uptime list-configs 명령어를 실행하고 이름 필드를 확인하면 식별자를 찾을 수 있습니다. 자세한 내용은 업타임 체크의 고유 식별자 찾기를 참조하세요.

API

업타임 체크 또는 합성 모니터를 삭제하려면 projects.uptimeCheckConfigs.delete 메서드를 호출합니다. 다음과 같이 매개변수를 작성합니다.

  • name: 필수입니다. 삭제할 업타임 체크 구성의 리소스 이름입니다.

    projects/PROJECT_ID/uptimeCheckConfigs/CHECK_ID
    

    업타임 체크 식별자에 대한 자세한 내용은 업타임 체크의 고유 식별자 찾기를 참조하세요.

C#

BigQuery에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

public static object DeleteUptimeCheckConfig(string configName)
{
    var client = UptimeCheckServiceClient.Create();
    client.DeleteUptimeCheckConfig(configName);
    Console.WriteLine($"Deleted {configName}");
    return 0;
}

Java

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

private static void deleteUptimeCheckConfig(String checkName) throws IOException {
  try (UptimeCheckServiceClient client = UptimeCheckServiceClient.create()) {
    client.deleteUptimeCheckConfig(checkName);
  } catch (Exception e) {
    usage("Exception deleting uptime check: " + e.toString());
    throw e;
  }
}

Go

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.


// delete is an example of deleting an uptime check. resourceName should be
// of the form `projects/[PROJECT_ID]/uptimeCheckConfigs/[UPTIME_CHECK_ID]`.
func delete(w io.Writer, resourceName string) error {
	ctx := context.Background()
	client, err := monitoring.NewUptimeCheckClient(ctx)
	if err != nil {
		return fmt.Errorf("NewUptimeCheckClient: %w", err)
	}
	defer client.Close()
	req := &monitoringpb.DeleteUptimeCheckConfigRequest{
		Name: resourceName,
	}
	if err := client.DeleteUptimeCheckConfig(ctx, req); err != nil {
		return fmt.Errorf("DeleteUptimeCheckConfig: %w", err)
	}
	fmt.Fprintf(w, "Successfully deleted %q", resourceName)
	return nil
}

Node.js

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

// Imports the Google Cloud client library
const monitoring = require('@google-cloud/monitoring');

// Creates a client
const client = new monitoring.UptimeCheckServiceClient();

/**
 * TODO(developer): Uncomment and edit the following lines of code.
 */
// const projectId = 'YOUR_PROJECT_ID';
// const uptimeCheckConfigId = 'YOUR_UPTIME_CHECK_CONFIG_ID';

const request = {
  // i.e. name: 'projects/my-project-id/uptimeCheckConfigs/My-Uptime-Check
  name: client.projectUptimeCheckConfigPath(projectId, uptimeCheckConfigId),
};

console.log(`Deleting ${request.name}`);

// Delete an uptime check config
await client.deleteUptimeCheckConfig(request);
console.log(`${request.name} deleted.`);

PHP

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

use Google\Cloud\Monitoring\V3\Client\UptimeCheckServiceClient;
use Google\Cloud\Monitoring\V3\DeleteUptimeCheckConfigRequest;

/**
 * Example:
 * ```
 * delete_uptime_check($projectId, $configName);
 * ```
 *
 * @param string $projectId Your project ID
 * @param string $configName
 */
function delete_uptime_check($projectId, $configName)
{
    $uptimeCheckClient = new UptimeCheckServiceClient([
        'projectId' => $projectId,
    ]);
    $deleteUptimeCheckConfigRequest = (new DeleteUptimeCheckConfigRequest())
        ->setName($configName);

    $uptimeCheckClient->deleteUptimeCheckConfig($deleteUptimeCheckConfigRequest);

    printf('Deleted an uptime check: ' . $configName . PHP_EOL);
}

Python

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

# `config_name` is the `name` field of an UptimeCheckConfig.
# See https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.uptimeCheckConfigs#UptimeCheckConfig.
def delete_uptime_check_config(config_name: str) -> None:
    """Deletes the uptime check configuration

    Args:
        config_name: Uptime check configuration identity
    """
    client = monitoring_v3.UptimeCheckServiceClient()
    client.delete_uptime_check_config(request={"name": config_name})
    print("Deleted ", config_name)

Ruby

Monitoring에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

def delete_uptime_check_config config_name
  require "google/cloud/monitoring"

  client = Google::Cloud::Monitoring.uptime_check_service
  client.delete_uptime_check_config name: config_name
  puts "Deleted #{config_name}"
end

업타임 체크 모니터링

업타임 체크에 실패할 때 알려주는 알림 정책을 만드는 것이 좋습니다. 자세한 내용은 업타임 체크 알림 정책 만들기를 참조하세요.

업타임 체크의 고유 식별자 찾기

업타임 체크가 생성되면 Monitoring은 업타임 체크 ID라는 이름의 식별자를 할당합니다. 이 식별자는 업타임 체크를 위한 리소스 이름에 삽입됩니다.

projects/PROJECT_ID/uptimeCheckConfigs/CHECK_ID

업타임 체크 ID는 업타임 체크를 생성하거나 나열하는 Cloud Monitoring API 메서드의 응답에 포함됩니다. 또한 Google Cloud 콘솔에서 업타임 세부정보 페이지의 구성 창에서 업타임 체크 ID를 찾을 수 있습니다. 업타임 세부정보 페이지를 보는 방법에 대한 자세한 내용은 이 문서의 업타임 체크 세부정보 보기 섹션을 참조하세요.

다음 단계