Google Cloud Logging (om_googlelogging)

Google Cloud Logging is a managed service that stores and analyzes log data from applications hosted on Google Cloud and Amazon Web Services.

The Google Cloud Logging API enables you to write logs to Cloud Logging. This module uses the REST version of the API to send events in batches, reducing HTTP response latency, and thus improving data throughput.

To examine the supported platforms, see the list of installation packages.

Configuring a Google Cloud service account

om_googlelogging requires a Google Cloud service account and a corresponding private key file in JSON format to connect to the Cloud Logging API. Follow these instructions to create a new service account and download its private key file for an existing project.

  1. Log in to your Google Cloud account and switch to the project you want to configure.

  2. From the navigation menu, click IAM & Admin > Service Accounts.

    IAM & Admin menu
  3. Click CREATE SERVICE ACCOUNT.

  4. Enter a service account name and description and click CREATE AND CONTINUE.

    Create service account
  5. Select the Owner role from the Role drop-down and click DONE.

    Service account role
  6. Click on the newly created account on the Service accounts page to open its configuration page.

  7. Click the KEYS tab, expand the ADD KEY drop-down and select Create new key.

    Create new service key
  8. Select JSON for the key type and click CREATE to download the private key. Save the private key file to a location accessible by NXLog Agent. This file is required for the NXLog Agent configuration.

    New service key type

Output log format

om_googlelogging forwards the value of the $raw_event field to Google Cloud Logging as JSON payload if it is a valid JSON object. Otherwise, it sends it as text payload. If a $Severity field is present, it will use its value to assign a LogSeverity to the record. If not, it will set the severity to DEFAULT. The table below lists the possible severity values. All values are case-insensitive.

Severity Alternative values

DEFAULT

NONE, UNKNOWN

DEBUG

-

INFO

LOW

NOTICE

NOTE

WARNING

WARN, MEDIUM

ERROR

ERR, HIGH

CRITICAL

CRIT, VERY-HIGH

ALERT

-

EMERGENCY

EMERG, EMERGENT, PANIC

Alternative values will be translated to the severity value on the left.

Individual JSON log records have the following structure:

{
    "jsonPayload": { }, // Value of $raw_event
    "severity": "<severity>",
    "timestamp": "<EventReceivedTime>"
}

Records will have the following structure if the value of $raw_event is not a valid JSON object:

{
    "textPayload": " ", // Value of $raw_event
    "severity": "<severity>",
    "timestamp": "<EventReceivedTime>"
}

The complete request body has the following structure:

{
    "logName": "<LogName>",
    "labels": {
        "<key>": "<value>"
    },
    "resource": {
        "type": "<type>"
    },
    "entries" : [
        {
            "textPayload": "<raw_event>",
            "severity": "<Severity>",
            "timestamp": "<EventReceivedTime>"
        }
    ]
}

See Method: entries.write in the Google Cloud Logging API reference for more information.

Configuration

Data sent with this module must be encoded in UTF-8. Otherwise, the destination will refuse and drop it.

If the source does not guarantee that data is UTF-8 encoded, use the xm_charconv extension module to convert it to UTF-8. See Auto-detect and convert character sets in the NXLog Platform User Guide for an example.

The om_googlelogging module accepts the following directives in addition to the common module directives. The CredentialsFile, LogName, and Resources directives are required.

Required directives

The following directives are required for the module to start.

CredentialsFile

This mandatory directive specifies the path to the private key file of the service account required for authenticating with the Cloud Logging API. See Configuring a Google Cloud service account for more information.

LogName

This mandatory directive specifies the name of the log source on Google Cloud. It accepts a string in the format project/<YOURPROJECTNAME>/logs/<LOG_ID>, where <YOURPROJECTNAME> is the name of your Google Cloud project and <LOG_ID> is the log source name. See Logging query language in the Google Cloud documentation for more information.

Resources

This mandatory group directive specifies the Google Cloud resource that produced the log entry. See resources list to get all available values. For example, specify the monitored resource that owns the database to collect its error logs.

<Resources>
    type        gce_instance
    <labels>
        zone    us-cental
    </labels>
</Resources>

HTTPS directives

The following directives configure secure data transfer via HTTPS.

HTTPSAllowExpired

Set this directive to TRUE to allow connections with remote hosts that present an expired certificate. The default is FALSE; the module rejects connections with expired certificates.

HTTPSAllowUntrusted

Set this directive to TRUE to allow connections with remote hosts regardless of certificate verification results. The default is FALSE; the module only accepts connections with trusted certificates.

HTTPSCADir

Set this directive to the path of a directory containing Certificate Authority (CA) certificates. The module uses these certificates to verify the certificate presented by the remote host. Name the certificate files using the OpenSSL hashed format: the hash of the certificate followed by .0, .1, and so on. To find the hash of a certificate using OpenSSL:

$ openssl x509 -hash -noout -in ca.crt

For example, if the certificate hash is e2f14e4a, name the certificate file e2f14e4a.0. If there is another certificate with the same hash, name it e2f14e4a.1, and so on.

To trust a remote host’s self-signed certificate, include a copy of it in this directory.

If this directive isn’t specified, NXLog Agent falls back to the default operating system root certificate store. Unix-like operating systems commonly store root certificates in /etc/ssl/certs. Windows operating systems use the Windows Certificate Store, while macOS uses the Keychain Access Application as the default certificate store. See Certification Authority (CA) certificates in the NXLog Platform User Guide for more information on using this directive.

In addition, Microsoft’s PKI repository contains root certificates for Microsoft services.

HTTPSCAFile

Set this directive to the path of the Certificate Authority (CA) certificate used to verify the certificate presented by the remote host. To trust a remote host’s self-signed certificate, specify the remote host’s certificate itself. For certificates signed by an intermediate CA, the specified certificate must contain the complete certificate chain (certificate bundle).

HTTPSCertFile

Set this directive to the path of the certificate file to present to the remote host during the HTTPS handshake.

HTTPSCertKeyFile

Set this directive to the path of the private key file corresponding to the certificate specified by HTTPSCertFile.

Optional directives

AddHeader

Set this directive to a custom header to add to each HTTP request. Specify this directive multiple times to add more than one header.

Compression

Set this directive to enable HTTP compression for outgoing HTTP messages. The accepted values are none, gzip, and deflate. The default is none; compression is disabled.

Some HTTP servers may not accept compressed HTTP requests. If the server doesn’t support the specified compression method, it may return 415 Unsupported Media Type errors.

HTTPBasicAuthPassword

Set this directive to the HTTP basic authentication password. This directive requires you to also set the HTTPBasicAuthUser directive to use HTTP authentication.

HTTPBasicAuthUser

Set this directive to the HTTP basic authentication username. If the HTTPBasicAuthPassword directive is not set, the module attempts HTTP Basic authentication using an empty password.

OutputRequestSize

Set this directive to the maximum request size, in bytes. The default is 64 MB.

Proxy

Set this directive to route outgoing requests through an HTTP or SOCKS proxy host. The format is protocol://hostname:port.

Reconnect

This optional directive sets the reconnect interval in seconds. If it is set, the module attempts to reconnect in every defined second. If it is not set, the reconnect interval will start at 1 second and double with every attempt. In the latter case, when the system decides that the reconnection is successful, the reconnect interval is immediately reset to 1 sec.

The Reconnect directive must be used with caution. If it is used on multiple systems, it can send reconnect requests simultaneously to the same destination, potentially overloading the destination system. It may also cause NXLog Agent to use unusually high system resources or cause NXLog Agent to become unresponsive.

ReconnectOnData

This optional directive defines the behavior when the connection with the remote host is lost. When set to TRUE, the module only attempts to reconnect when it has data to send. The default value is FALSE; it will always keep a connection open with the remote host.

Labels

A list of key-value pairs for providing event metadata. The labels can be user-defined or system-defined.

User-defined labels are optional key-value pairs that you can use to enrich logs. System-defined labels are defined by Google Cloud Platform (GCP) services for platform logs and are in the format <SERVICE_NAMESPACE>/<ATTRIBUTE_NAME>—for example, compute.googleapis.com/resourceName.

Cloud Logging truncates label keys that exceed 512 B and label values that exceed 64 KB and replaces the truncated text with an ellipsis (…​).

<Labels>
    zone    us-central1-a
</Labels>

Examples

Example 1. Forwarding logs to Google Cloud Logging

This configuration uses the om_googlelogging output module to forward logs from the project myproject to Google Cloud Logging.

<Output google_logging>
    Module             om_googlelogging
    CredentialsFile    /path/to/credentials.json (1)
    LogName            projects/myproject-343509/logs/test
    <Labels> (2)
        zone    us-central
    </Labels>
    <Resources> (3)
        type    gce_instance
    </Resources>
</Output>
1 Credentials file for authenticating with the Cloud Logging API. See Configuring a Google Cloud service account for more information.
2 List of labels defined as key-value pairs to attach to the event.
3 List of resources to attach to the event.