Apache Web Server (httpd)

Apache Web Server (httpd) is a widely used web server for a variety of operating systems. For more information, visit http://httpd.apache.org/.

Prerequisites

To collect Apache Web Server telemetry, you must install Ops Agent version 2.7.0 or higher.

This receiver supports Apache Web Server version 2.4.

Configure your Apache Web Server instance

To collect telemetry from your Apache Web Server, you must configure the server's httpd.conf file to enable the mod_status plugin.

Many Apache installations enable this plugin by default. To see if the plugin is enabled on your VM instance, run:

curl localhost:80/server-status?auto

If the plugin is enabled, then the output includes lines similar to the following:

Total Accesses: 2
Total kBytes: 1
BusyWorkers: 1
IdleWorkers: 4

If you get a 404 Not Found page instead, then the mod_status plugin is not enabled.

Configure the Ops Agent for Apache Web Server

Following the guide for Configuring the Ops Agent, add the required elements to collect logs from Apache Web Server instances, and restart the agent.

Example configuration

The following command creates the configuration to collect and ingest logs and metrics for Apache Web Server and restarts the Ops Agent on Linux.

sudo tee /etc/google-cloud-ops-agent/config.yaml > /dev/null << EOF
logging:
  receivers:
    apache_access:
      type: apache_access
    apache_error:
      type: apache_error
  service:
    pipelines:
      apache:
        receivers:
        - apache_access
        - apache_error
metrics:
  receivers:
    apache:
      type: apache
      server_status_url: http://localhost:8080/server-status?auto
      collection_interval: 30s
  service:
    pipelines:
      apache:
        receivers:
        - apache
EOF
sudo service google-cloud-ops-agent restart

Configure logs collection

To ingest logs from Apache Web Server, you must create receivers for the logs Apache Web Server produces and then create a pipeline for the new receivers. To configure a receiver for your logs, specify the following fields:

To configure a receiver for your apache_access logs, specify the following fields:

Field Default Description
type This value must be apache_access.
include_paths [/var/log/apache2/access.log,/var/log/apache2/access_log,/var/log/httpd/access_log] A list of filesystem paths to read by tailing each file. A wild card (*) can be used in the paths; for example, /var/log/apache*/*.log.
exclude_paths [] A list of filesystem path patterns to exclude from the set matched by include_paths.

To configure a receiver for your apache_error logs, specify the following fields:

Field Default Description
type This value must be apache_error.
include_paths [/var/log/apache2/error.log,/var/log/apache2/error_log,/var/log/httpd/error_log] A list of filesystem paths to read by tailing each file. A wild card (*) can be used in the paths; for example, /var/log/apache*/*.log.
exclude_paths [] A list of filesystem path patterns to exclude from the set matched by include_paths.

What is logged

The logName of the apache_access and apache_error logs are derived from the receiver IDs specified in the configuration. Detailed fields inside the LogEntry are as follows.

apache_access logs contain the httpRequest field:

Field Type Description
httpRequest.protocol string Protocol used for the request
httpRequest.referer string Contents of the Referer header
httpRequest.requestMethod string HTTP method
httpRequest.requestUrl string Request URL (typically just the path part of the URL)
httpRequest.responseSize string (int64) Response size
httpRequest.status number HTTP status code
httpRequest.userAgent string Contents of the User-Agent header
jsonPayload.host string Contents of the Host header
jsonPayload.user string Authenticated username for the request
timestamp string (Timestamp) Time the request was received

Log entries don't contain any fields that are blank or missing.


apache_error logs contain the following fields in the LogEntry:

Field Type Description
jsonPayload.errorCode string Apache error code
jsonPayload.level string Log entry level
jsonPayload.module string apache module where the log originated
jsonPayload.pid number Process ID
jsonPayload.tid number Thread ID
jsonPayload.message string Log message
jsonPayload.client string Client IP address (optional)
severity string (LogSeverity) Log entry level (translated)
timestamp string (Timestamp) Time the entry was logged

Configure metrics collection

To collect metrics from Apache Web Server, you must create a receiver for Apache metrics and then create a pipeline for the new receiver. To configure a receiver for your Apache metrics, specify the following fields:

Field Default Description
type This value must be apache.
server_status_url http://localhost:8080/server-status?auto The URL exposed by the mod_status module.
collection_interval 60s A time.Duration value, such as 30s or 5m.

What is monitored

The following table provides the list of metrics that the Ops Agent collects from the Apache Web Server instance.

Metric type 
Kind, Type
Monitored resources
Labels
workload.googleapis.com/apache.current_connections
GAUGEINT64
gce_instance
server_name
workload.googleapis.com/apache.requests
CUMULATIVEINT64
gce_instance
server_name
workload.googleapis.com/apache.scoreboard
GAUGEINT64
gce_instance
state
server_name
workload.googleapis.com/apache.traffic
CUMULATIVEINT64
gce_instance
server_name
workload.googleapis.com/apache.workers
GAUGEINT64
gce_instance
state
server_name

Verify the configuration

You can use the Logs Explorer and Metrics Explorer to verify that you correctly configured the Apache Web Server receiver. It might take one or two minutes for the Ops agent to begin collecting logs and metrics.

To verify the logs are ingested, go to the Logs Explorer and run the following query to view the Apache Web Server logs:

resource.type="gce_instance"
logName=("projects/PROJECT_ID/logs/apache_access" OR "projects/PROJECT_ID/logs/apache_error")


To verify the metrics are ingested, go to Metrics Explorer and run the following query in the MQL tab.

fetch gce_instance
| metric 'workload.googleapis.com/apache.requests'
| align rate(1m)
| every 1m