HealthCheck

HealthCheck

Health checks ensure that Compute Engine forwards new connections only to instances that are up and ready to receive them. Compute Engine sends health check requests to each instance at the specified frequency; once an instance exceeds its allowed number of health check failures, it is no longer considered an eligible instance for receiving new traffic.

Constructor

new HealthCheck(compute, name, optionsopt)

Parameters:
Name Type Attributes Description
compute Compute

Compute object this health check belongs to.

name string

Name of the health check.

options object <optional>

Optional configuration.

Properties
Name Type Description
https boolean

Specify if this is an HTTPS health check resource. Default: false

See:
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const healthCheck = gce.healthCheck('health-check-name');

Members

compute

The parent Compute instance of this HealthCheck instance.

id

Methods

create(options)

Create an HTTP or HTTPS health check.

Parameters:
Name Type Description
options object

See Compute#createHealthCheck.

Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const healthCheck = gce.healthCheck('health-check-name');

healthCheck.create(function(err, healthCheck, operation, apiResponse) {
  // `healthCheck` is a HealthCheck object.

  // `operation` is an Operation object that can be used to check the
  // status of the request.
});

//-
// If the callback is omitted, we'll return a Promise.
//-
healthCheck.create().then(function(data) {
  const healthCheck = data[0];
  const operation = data[1];
  const apiResponse = data[2];
});

delete(callbackopt)

Delete the health check.

Parameters:
Name Type Attributes Description
callback function <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

operation Operation

An operation object that can be used to check the status of the request.

apiResponse object

The full API response.

See:
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const healthCheck = gce.healthCheck('health-check-name');

healthCheck.delete(function(err, operation, apiResponse) {
  // `operation` is an Operation object that can be used to check the status
  // of the request.
});

//-
// If the callback is omitted, we'll return a Promise.
//-
healthCheck.delete().then(function(data) {
  const operation = data[0];
  const apiResponse = data[1];
});

exists(callback)

Check if the health check exists.

Parameters:
Name Type Description
callback function

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

exists boolean

Whether the health check exists or not.

Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const healthCheck = gce.healthCheck('health-check-name');

healthCheck.exists(function(err, exists) {});

//-
// If the callback is omitted, we'll return a Promise.
//-
healthCheck.exists().then(function(data) {
  const exists = data[0];
});

get(optionsopt)

Get the health check if it exists.

You may optionally use this to "get or create" an object by providing an object with autoCreate set to true. Any extra configuration that is normally required for the create method must be contained within this object as well.

Parameters:
Name Type Attributes Description
options options <optional>

Configuration object.

Properties
Name Type Description
autoCreate boolean

Automatically create the object if it does not exist. Default: false

Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const healthCheck = gce.healthCheck('health-check-name');

healthCheck.get(function(err, healthCheck, apiResponse) {
  // `healthCheck` is a HealthCheck object.
});

//-
// If the callback is omitted, we'll return a Promise.
//-
healthCheck.get().then(function(data) {
  const healthCheck = data[0];
  const apiResponse = data[1];
});

getMetadata(callbackopt)

Get the health check's metadata.

Parameters:
Name Type Attributes Description
callback function <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

metadata object

The health check's metadata.

apiResponse object

The full API response.

See:
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const healthCheck = gce.healthCheck('health-check-name');

healthCheck.getMetadata(function(err, metadata, apiResponse) {});

//-
// If the callback is omitted, we'll return a Promise.
//-
healthCheck.getMetadata().then(function(data) {
  const metadata = data[0];
  const apiResponse = data[1];
});

setMetadata(metadata, callbackopt)

Set the health check's metadata.

Parameters:
Name Type Attributes Description
metadata object

See a HttpHealthCheck resource and HttpsHealthCheck resource.

callback function <optional>

The callback function.

Properties
Name Type Attributes Description
err error <nullable>

An error returned while making this request.

operation Operation

An operation object that can be used to check the status of the request.

apiResponse object

The full API response.

See:
Example
const Compute = require('@google-cloud/compute');
const compute = new Compute();
const healthCheck = gce.healthCheck('health-check-name');

const metadata = {
  description: 'New description'
};

healthCheck.setMetadata(metadata, function(err, operation, apiResponse) {
  // `operation` is an Operation object that can be used to check the status
  // of the request.
});

//-
// If the callback is omitted, we'll return a Promise.
//-
healthCheck.setMetadata(metadata).then(function(data) {
  const operation = data[0];
  const apiResponse = data[1];
});