Search in sources :

Example 1 with UptimeCheckServiceClient

use of com.google.cloud.monitoring.v3.UptimeCheckServiceClient in project java-monitoring by googleapis.

the class UptimeSample method getUptimeCheckConfig.

// [END monitoring_uptime_check_list_ips]]
// [START monitoring_uptime_check_get]]
private static void getUptimeCheckConfig(String projectId, 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)) {
        String fullCheckName = UptimeCheckConfigName.format(projectId, checkName);
        UptimeCheckConfig config = client.getUptimeCheckConfig(fullCheckName);
        if (config != null) {
            System.out.println(config.toString());
        } else {
            System.out.println("No uptime check config found with name " + checkName + " in project " + projectId);
        }
    } catch (Exception e) {
        usage("Exception getting uptime check: " + e.toString());
        throw e;
    }
}
Also used : UptimeCheckServiceSettings(com.google.cloud.monitoring.v3.UptimeCheckServiceSettings) UptimeCheckConfig(com.google.monitoring.v3.UptimeCheckConfig) UptimeCheckServiceClient(com.google.cloud.monitoring.v3.UptimeCheckServiceClient) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException)

Example 2 with UptimeCheckServiceClient

use of com.google.cloud.monitoring.v3.UptimeCheckServiceClient in project java-monitoring by googleapis.

the class UptimeSample method updateUptimeCheck.

// [END monitoring_uptime_check_create]]
// [START monitoring_uptime_check_update]]
private static void updateUptimeCheck(String projectId, String displayName, String hostName, String pathName) throws IOException {
    String fullCheckName = UptimeCheckConfigName.format(projectId, displayName);
    UpdateUptimeCheckConfigRequest request = UpdateUptimeCheckConfigRequest.newBuilder().setUpdateMask(FieldMask.newBuilder().addPaths("http_check.path")).setUptimeCheckConfig(UptimeCheckConfig.newBuilder().setName(fullCheckName).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;
    }
}
Also used : UpdateUptimeCheckConfigRequest(com.google.monitoring.v3.UpdateUptimeCheckConfigRequest) UptimeCheckConfig(com.google.monitoring.v3.UptimeCheckConfig) UptimeCheckServiceClient(com.google.cloud.monitoring.v3.UptimeCheckServiceClient) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException)

Example 3 with UptimeCheckServiceClient

use of com.google.cloud.monitoring.v3.UptimeCheckServiceClient in project java-monitoring by googleapis.

the class UptimeSample method createUptimeCheck.

// [START monitoring_uptime_check_create]]
private static void createUptimeCheck(String projectId, String displayName, String hostName, String pathName) throws IOException {
    CreateUptimeCheckConfigRequest request = CreateUptimeCheckConfigRequest.newBuilder().setParent(ProjectName.format(projectId)).setUptimeCheckConfig(UptimeCheckConfig.newBuilder().setDisplayName(displayName).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.createUptimeCheckConfig(request);
        System.out.println("Uptime check created: " + config.getDisplayName());
    } catch (Exception e) {
        usage("Exception creating uptime check: " + e.toString());
        throw e;
    }
}
Also used : CreateUptimeCheckConfigRequest(com.google.monitoring.v3.CreateUptimeCheckConfigRequest) UptimeCheckConfig(com.google.monitoring.v3.UptimeCheckConfig) UptimeCheckServiceClient(com.google.cloud.monitoring.v3.UptimeCheckServiceClient) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException)

Example 4 with UptimeCheckServiceClient

use of com.google.cloud.monitoring.v3.UptimeCheckServiceClient in project java-docs-samples by GoogleCloudPlatform.

the class UptimeSample method updateUptimeCheck.

// [END monitoring_uptime_check_create]]
// [START monitoring_uptime_check_update]]
private static void updateUptimeCheck(String projectId, String displayName, String hostName, String pathName) throws IOException {
    String fullCheckName = UptimeCheckConfigName.format(projectId, displayName);
    UpdateUptimeCheckConfigRequest request = UpdateUptimeCheckConfigRequest.newBuilder().setUpdateMask(FieldMask.newBuilder().addPaths("http_check.path")).setUptimeCheckConfig(UptimeCheckConfig.newBuilder().setName(fullCheckName).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;
    }
}
Also used : UpdateUptimeCheckConfigRequest(com.google.monitoring.v3.UpdateUptimeCheckConfigRequest) UptimeCheckConfig(com.google.monitoring.v3.UptimeCheckConfig) UptimeCheckServiceClient(com.google.cloud.monitoring.v3.UptimeCheckServiceClient) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException)

Example 5 with UptimeCheckServiceClient

use of com.google.cloud.monitoring.v3.UptimeCheckServiceClient in project java-docs-samples by GoogleCloudPlatform.

the class UptimeSample method createUptimeCheck.

// [START monitoring_uptime_check_create]]
private static void createUptimeCheck(String projectId, String displayName, String hostName, String pathName) throws IOException {
    CreateUptimeCheckConfigRequest request = CreateUptimeCheckConfigRequest.newBuilder().setParent(ProjectName.format(projectId)).setUptimeCheckConfig(UptimeCheckConfig.newBuilder().setDisplayName(displayName).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.createUptimeCheckConfig(request);
        System.out.println("Uptime check created: " + config.getDisplayName());
    } catch (Exception e) {
        usage("Exception creating uptime check: " + e.toString());
        throw e;
    }
}
Also used : CreateUptimeCheckConfigRequest(com.google.monitoring.v3.CreateUptimeCheckConfigRequest) UptimeCheckConfig(com.google.monitoring.v3.UptimeCheckConfig) UptimeCheckServiceClient(com.google.cloud.monitoring.v3.UptimeCheckServiceClient) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException)

Aggregations

UptimeCheckServiceClient (com.google.cloud.monitoring.v3.UptimeCheckServiceClient)6 UptimeCheckConfig (com.google.monitoring.v3.UptimeCheckConfig)6 IOException (java.io.IOException)6 ParseException (org.apache.commons.cli.ParseException)6 CreateUptimeCheckConfigRequest (com.google.monitoring.v3.CreateUptimeCheckConfigRequest)2 UpdateUptimeCheckConfigRequest (com.google.monitoring.v3.UpdateUptimeCheckConfigRequest)2 UptimeCheckServiceSettings (com.google.cloud.monitoring.v3.UptimeCheckServiceSettings)1