Menu
Grafana Cloud

Apache HTTP server integration for Grafana Cloud

Apache HTTP server integration is an observability package of dashboards and alerts filled with metrics and logs.

This integration includes 5 useful alerts and 2 pre-built dashboards to help monitor and visualize Apache HTTP server metrics and logs.

Before you begin

Metrics are scraped from server-status page.

To enable it, add this code to your httpd.conf configuration file

<Location "/server-status">
    SetHandler server-status
</Location>

For more information please check the official guide.

Install Apache HTTP server integration for Grafana Cloud

  1. In your Grafana Cloud stack, click Connections in the left-hand menu.
  2. Find Apache HTTP server and click its tile to open the integration.
  3. Review the prerequisites in the Configuration Details tab and set up Grafana Agent to send Apache HTTP server metrics and logs to your Grafana Cloud instance.
  4. Click Install to add this integration’s pre-built dashboards and alerts to your Grafana Cloud instance, and you can start monitoring your Apache HTTP server setup.

Configuration snippets for Grafana Alloy

Simple mode

These snippets are configured to scrape a single Apache HTTP server instance running locally with default ports.

First, manually copy and append the following snippets into your alloy configuration file.

Integrations snippets

alloy
prometheus.exporter.self "integrations_alloy" { }

discovery.relabel "integrations_alloy" {
	targets = prometheus.exporter.self.integrations_alloy.targets

	rule {
		target_label = "job"
		replacement  = "integrations/agent"
	}
}

prometheus.scrape "integrations_alloy" {
	targets    = discovery.relabel.integrations_alloy.output
	forward_to = [prometheus.relabel.integrations_alloy.receiver]
	job_name   = "integrations/alloy"
}

prometheus.relabel "integrations_alloy" {
	forward_to = [prometheus.remote_write.metrics_service.receiver]

	rule {
		source_labels = ["exported_job"]
		target_label  = "job"
	}

	rule {
		source_labels = ["exported_instance"]
		target_label  = "instance"
	}

	rule {
		regex  = "(exported_instance|exported_job)"
		action = "labeldrop"
	}
}

prometheus.exporter.apache "integrations_apache_http" {
	scrape_uri = "http://localhost:8080/server-status?auto"
}

discovery.relabel "integrations_apache_http" {
	targets = prometheus.exporter.apache.integrations_apache_http.targets

	rule {
		target_label = "instance"
		replacement  = constants.hostname
	}

	rule {
		target_label = "job"
		replacement  = "integrations/apache_http"
	}
}

prometheus.scrape "integrations_apache_http" {
	targets    = discovery.relabel.integrations_apache_http.output
	forward_to = [prometheus.remote_write.metrics_service.receiver]
	job_name   = "integrations/apache_http"
}

Logs snippets

darwin

alloy
local.file_match "logs_integrations_integrations_apache_error" {
	path_targets = [{
		__address__ = "localhost",
		__path__    = "/var/log/apache2/error.log",
		instance    = constants.hostname,
		job         = "integrations/apache_http",
	}]
}

loki.process "logs_integrations_integrations_apache_error" {
	forward_to = []

	stage.regex {
		expression = "^\\[[^ ]* (?P<timestamp>[^\\]]*)\\] \\[(?:(?P<module>[^:\\]]+):)?(?P<level>[^\\]]+)\\](?: \\[pid (?P<pid>[^\\]]*)\\])?(?: \\[client (?P<client>[^\\]]*)\\])? (?P<message>.*)$"
	}

	stage.labels {
		values = {
			level  = null,
			module = null,
		}
	}

	stage.static_labels {
		values = {
			logtype = "error",
		}
	}
}

loki.source.file "logs_integrations_integrations_apache_error" {
	targets    = local.file_match.logs_integrations_integrations_apache_error.targets
	forward_to = [loki.write.grafana_cloud_loki.receiver]
}

local.file_match "logs_integrations_integrations_apache_access" {
	path_targets = [{
		__address__ = "localhost",
		__path__    = "/var/log/apache2/access.log",
		instance    = constants.hostname,
		job         = "integrations/apache_http",
	}]
}

loki.process "logs_integrations_integrations_apache_access" {
	forward_to = [loki.write.grafana_cloud_loki.receiver]

	stage.regex {
		expression = "^(?P<ip>[^ ]*) [^ ]* (?P<user>[^ ]*) \\[(?P<timestamp>[^\\]]*)\\] \"(?P<method>\\S+)(?: +(?P<path>[^ ]*) +\\S*)?\" (?P<code>[^ ]*) (?P<size>[^ ]*)(?: \"(?P<referer>[^\\\"]*)\" \"(?P<agent>.*)\")?$"
	}

	stage.metrics { }

	stage.labels {
		values = {
			method = null,
		}
	}

	stage.static_labels {
		values = {
			logtype = "access",
		}
	}
}

loki.source.file "logs_integrations_integrations_apache_access" {
	targets    = local.file_match.logs_integrations_integrations_apache_access.targets
	forward_to = [loki.process.logs_integrations_integrations_apache_access.receiver]
}

linux

alloy
local.file_match "logs_integrations_integrations_apache_error" {
	path_targets = [{
		__address__ = "localhost",
		__path__    = "/var/log/apache2/error.log",
		instance    = constants.hostname,
		job         = "integrations/apache_http",
	}]
}

loki.process "logs_integrations_integrations_apache_error" {
	forward_to = []

	stage.regex {
		expression = "^\\[[^ ]* (?P<timestamp>[^\\]]*)\\] \\[(?:(?P<module>[^:\\]]+):)?(?P<level>[^\\]]+)\\](?: \\[pid (?P<pid>[^\\]]*)\\])?(?: \\[client (?P<client>[^\\]]*)\\])? (?P<message>.*)$"
	}

	stage.labels {
		values = {
			level  = null,
			module = null,
		}
	}

	stage.static_labels {
		values = {
			logtype = "error",
		}
	}
}

loki.source.file "logs_integrations_integrations_apache_error" {
	targets    = local.file_match.logs_integrations_integrations_apache_error.targets
	forward_to = [loki.write.grafana_cloud_loki.receiver]
}

local.file_match "logs_integrations_integrations_apache_access" {
	path_targets = [{
		__address__ = "localhost",
		__path__    = "/var/log/apache2/access.log",
		instance    = constants.hostname,
		job         = "integrations/apache_http",
	}]
}

loki.process "logs_integrations_integrations_apache_access" {
	forward_to = [loki.write.grafana_cloud_loki.receiver]

	stage.regex {
		expression = "^(?P<ip>[^ ]*) [^ ]* (?P<user>[^ ]*) \\[(?P<timestamp>[^\\]]*)\\] \"(?P<method>\\S+)(?: +(?P<path>[^ ]*) +\\S*)?\" (?P<code>[^ ]*) (?P<size>[^ ]*)(?: \"(?P<referer>[^\\\"]*)\" \"(?P<agent>.*)\")?$"
	}

	stage.metrics { }

	stage.labels {
		values = {
			method = null,
		}
	}

	stage.static_labels {
		values = {
			logtype = "access",
		}
	}
}

loki.source.file "logs_integrations_integrations_apache_access" {
	targets    = local.file_match.logs_integrations_integrations_apache_access.targets
	forward_to = [loki.process.logs_integrations_integrations_apache_access.receiver]
}

windows

alloy
local.file_match "logs_integrations_integrations_apache_error" {
	path_targets = [{
		__address__ = "localhost",
		__path__    = "/var/log/apache2/error.log",
		instance    = constants.hostname,
		job         = "integrations/apache_http",
	}]
}

loki.process "logs_integrations_integrations_apache_error" {
	forward_to = []

	stage.regex {
		expression = "^\\[[^ ]* (?P<timestamp>[^\\]]*)\\] \\[(?:(?P<module>[^:\\]]+):)?(?P<level>[^\\]]+)\\](?: \\[pid (?P<pid>[^\\]]*)\\])?(?: \\[client (?P<client>[^\\]]*)\\])? (?P<message>.*)$"
	}

	stage.labels {
		values = {
			level  = null,
			module = null,
		}
	}

	stage.static_labels {
		values = {
			logtype = "error",
		}
	}
}

loki.source.file "logs_integrations_integrations_apache_error" {
	targets    = local.file_match.logs_integrations_integrations_apache_error.targets
	forward_to = [loki.write.grafana_cloud_loki.receiver]
}

local.file_match "logs_integrations_integrations_apache_access" {
	path_targets = [{
		__address__ = "localhost",
		__path__    = "/var/log/apache2/access.log",
		instance    = constants.hostname,
		job         = "integrations/apache_http",
	}]
}

loki.process "logs_integrations_integrations_apache_access" {
	forward_to = [loki.write.grafana_cloud_loki.receiver]

	stage.regex {
		expression = "^(?P<ip>[^ ]*) [^ ]* (?P<user>[^ ]*) \\[(?P<timestamp>[^\\]]*)\\] \"(?P<method>\\S+)(?: +(?P<path>[^ ]*) +\\S*)?\" (?P<code>[^ ]*) (?P<size>[^ ]*)(?: \"(?P<referer>[^\\\"]*)\" \"(?P<agent>.*)\")?$"
	}

	stage.metrics { }

	stage.labels {
		values = {
			method = null,
		}
	}

	stage.static_labels {
		values = {
			logtype = "access",
		}
	}
}

loki.source.file "logs_integrations_integrations_apache_access" {
	targets    = local.file_match.logs_integrations_integrations_apache_access.targets
	forward_to = [loki.process.logs_integrations_integrations_apache_access.receiver]
}

Advanced mode

The following snippets provide examples to guide you through the configuration process.

To instruct Grafana Alloy to scrape your Apache HTTP server instances, manually copy and append the snippets to your alloy configuration file, then follow subsequent instructions.

Advanced integrations snippets

alloy
prometheus.exporter.self "integrations_alloy" { }

discovery.relabel "integrations_alloy" {
	targets = prometheus.exporter.self.integrations_alloy.targets

	rule {
		target_label = "job"
		replacement  = "integrations/agent"
	}
}

prometheus.scrape "integrations_alloy" {
	targets    = discovery.relabel.integrations_alloy.output
	forward_to = [prometheus.relabel.integrations_alloy.receiver]
	job_name   = "integrations/alloy"
}

prometheus.relabel "integrations_alloy" {
	forward_to = [prometheus.remote_write.metrics_service.receiver]

	rule {
		source_labels = ["exported_job"]
		target_label  = "job"
	}

	rule {
		source_labels = ["exported_instance"]
		target_label  = "instance"
	}

	rule {
		regex  = "(exported_instance|exported_job)"
		action = "labeldrop"
	}
}

prometheus.exporter.apache "integrations_apache_http" {
	scrape_uri = "http://localhost:8080/server-status?auto"
}

discovery.relabel "integrations_apache_http" {
	targets = prometheus.exporter.apache.integrations_apache_http.targets

	rule {
		target_label = "instance"
		replacement  = constants.hostname
	}

	rule {
		target_label = "job"
		replacement  = "integrations/apache_http"
	}
}

prometheus.scrape "integrations_apache_http" {
	targets    = discovery.relabel.integrations_apache_http.output
	forward_to = [prometheus.remote_write.metrics_service.receiver]
	job_name   = "integrations/apache_http"
}

This integrations uses the prometheus.exporter.apache component to generate metrics from a Apache HTTP server instance.

For the full array of configuration options, refer to the prometheus.exporter.apache component reference documentation.

This exporter must be linked with a discovery.relabel component to apply the necessary relabelings.

For each Apache HTTP server instance to be monitored you must create a pair of these components.

Configure the following properties within each discovery.relabel component:

  • instance label: constants.hostname sets the instance label to your Grafana Alloy server hostname. If that is not suitable, change it to a value uniquely identifies this Apache HTTP server instance. Make sure this label value is the same for all telemetry data collected for this instance.

You can then scrape them by including each discovery.relabel under targets within the prometheus.scrape component.

Advanced logs snippets

darwin

alloy
local.file_match "logs_integrations_integrations_apache_error" {
	path_targets = [{
		__address__ = "localhost",
		__path__    = "/var/log/apache2/error.log",
		instance    = constants.hostname,
		job         = "integrations/apache_http",
	}]
}

loki.process "logs_integrations_integrations_apache_error" {
	forward_to = []

	stage.regex {
		expression = "^\\[[^ ]* (?P<timestamp>[^\\]]*)\\] \\[(?:(?P<module>[^:\\]]+):)?(?P<level>[^\\]]+)\\](?: \\[pid (?P<pid>[^\\]]*)\\])?(?: \\[client (?P<client>[^\\]]*)\\])? (?P<message>.*)$"
	}

	stage.labels {
		values = {
			level  = null,
			module = null,
		}
	}

	stage.static_labels {
		values = {
			logtype = "error",
		}
	}
}

loki.source.file "logs_integrations_integrations_apache_error" {
	targets    = local.file_match.logs_integrations_integrations_apache_error.targets
	forward_to = [loki.write.grafana_cloud_loki.receiver]
}

local.file_match "logs_integrations_integrations_apache_access" {
	path_targets = [{
		__address__ = "localhost",
		__path__    = "/var/log/apache2/access.log",
		instance    = constants.hostname,
		job         = "integrations/apache_http",
	}]
}

loki.process "logs_integrations_integrations_apache_access" {
	forward_to = [loki.write.grafana_cloud_loki.receiver]

	stage.regex {
		expression = "^(?P<ip>[^ ]*) [^ ]* (?P<user>[^ ]*) \\[(?P<timestamp>[^\\]]*)\\] \"(?P<method>\\S+)(?: +(?P<path>[^ ]*) +\\S*)?\" (?P<code>[^ ]*) (?P<size>[^ ]*)(?: \"(?P<referer>[^\\\"]*)\" \"(?P<agent>.*)\")?$"
	}

	stage.metrics { }

	stage.labels {
		values = {
			method = null,
		}
	}

	stage.static_labels {
		values = {
			logtype = "access",
		}
	}
}

loki.source.file "logs_integrations_integrations_apache_access" {
	targets    = local.file_match.logs_integrations_integrations_apache_access.targets
	forward_to = [loki.process.logs_integrations_integrations_apache_access.receiver]
}

linux

alloy
local.file_match "logs_integrations_integrations_apache_error" {
	path_targets = [{
		__address__ = "localhost",
		__path__    = "/var/log/apache2/error.log",
		instance    = constants.hostname,
		job         = "integrations/apache_http",
	}]
}

loki.process "logs_integrations_integrations_apache_error" {
	forward_to = []

	stage.regex {
		expression = "^\\[[^ ]* (?P<timestamp>[^\\]]*)\\] \\[(?:(?P<module>[^:\\]]+):)?(?P<level>[^\\]]+)\\](?: \\[pid (?P<pid>[^\\]]*)\\])?(?: \\[client (?P<client>[^\\]]*)\\])? (?P<message>.*)$"
	}

	stage.labels {
		values = {
			level  = null,
			module = null,
		}
	}

	stage.static_labels {
		values = {
			logtype = "error",
		}
	}
}

loki.source.file "logs_integrations_integrations_apache_error" {
	targets    = local.file_match.logs_integrations_integrations_apache_error.targets
	forward_to = [loki.write.grafana_cloud_loki.receiver]
}

local.file_match "logs_integrations_integrations_apache_access" {
	path_targets = [{
		__address__ = "localhost",
		__path__    = "/var/log/apache2/access.log",
		instance    = constants.hostname,
		job         = "integrations/apache_http",
	}]
}

loki.process "logs_integrations_integrations_apache_access" {
	forward_to = [loki.write.grafana_cloud_loki.receiver]

	stage.regex {
		expression = "^(?P<ip>[^ ]*) [^ ]* (?P<user>[^ ]*) \\[(?P<timestamp>[^\\]]*)\\] \"(?P<method>\\S+)(?: +(?P<path>[^ ]*) +\\S*)?\" (?P<code>[^ ]*) (?P<size>[^ ]*)(?: \"(?P<referer>[^\\\"]*)\" \"(?P<agent>.*)\")?$"
	}

	stage.metrics { }

	stage.labels {
		values = {
			method = null,
		}
	}

	stage.static_labels {
		values = {
			logtype = "access",
		}
	}
}

loki.source.file "logs_integrations_integrations_apache_access" {
	targets    = local.file_match.logs_integrations_integrations_apache_access.targets
	forward_to = [loki.process.logs_integrations_integrations_apache_access.receiver]
}

windows

alloy
local.file_match "logs_integrations_integrations_apache_error" {
	path_targets = [{
		__address__ = "localhost",
		__path__    = "/var/log/apache2/error.log",
		instance    = constants.hostname,
		job         = "integrations/apache_http",
	}]
}

loki.process "logs_integrations_integrations_apache_error" {
	forward_to = []

	stage.regex {
		expression = "^\\[[^ ]* (?P<timestamp>[^\\]]*)\\] \\[(?:(?P<module>[^:\\]]+):)?(?P<level>[^\\]]+)\\](?: \\[pid (?P<pid>[^\\]]*)\\])?(?: \\[client (?P<client>[^\\]]*)\\])? (?P<message>.*)$"
	}

	stage.labels {
		values = {
			level  = null,
			module = null,
		}
	}

	stage.static_labels {
		values = {
			logtype = "error",
		}
	}
}

loki.source.file "logs_integrations_integrations_apache_error" {
	targets    = local.file_match.logs_integrations_integrations_apache_error.targets
	forward_to = [loki.write.grafana_cloud_loki.receiver]
}

local.file_match "logs_integrations_integrations_apache_access" {
	path_targets = [{
		__address__ = "localhost",
		__path__    = "/var/log/apache2/access.log",
		instance    = constants.hostname,
		job         = "integrations/apache_http",
	}]
}

loki.process "logs_integrations_integrations_apache_access" {
	forward_to = [loki.write.grafana_cloud_loki.receiver]

	stage.regex {
		expression = "^(?P<ip>[^ ]*) [^ ]* (?P<user>[^ ]*) \\[(?P<timestamp>[^\\]]*)\\] \"(?P<method>\\S+)(?: +(?P<path>[^ ]*) +\\S*)?\" (?P<code>[^ ]*) (?P<size>[^ ]*)(?: \"(?P<referer>[^\\\"]*)\" \"(?P<agent>.*)\")?$"
	}

	stage.metrics { }

	stage.labels {
		values = {
			method = null,
		}
	}

	stage.static_labels {
		values = {
			logtype = "access",
		}
	}
}

loki.source.file "logs_integrations_integrations_apache_access" {
	targets    = local.file_match.logs_integrations_integrations_apache_access.targets
	forward_to = [loki.process.logs_integrations_integrations_apache_access.receiver]
}

Grafana Agent static configuration (deprecated)

The following section shows configuration for running Grafana Agent in static mode which is deprecated. You should use Grafana Alloy for all new deployments.

Dashboards

The Apache HTTP server integration installs the following dashboards in your Grafana Cloud instance to help monitor your system.

  • Apache HTTP server
  • Apache HTTP server logs

Apache HTTP server overview

Apache HTTP server overview

Apache logs

Apache logs

Alerts

The Apache HTTP server integration includes the following useful alerts:

AlertDescription
ApacheDownWarning: Apache is down.
ApacheRestartInfo: Apache restart.
ApacheWorkersLoadWarning: Apache workers load is too high.
ApacheResponseTimeTooHighWarning: Apache response time is too high.
ApacheErrorsRateTooHighCritical: Apache errors rate is too high.

Metrics

The most important metrics provided by the Apache HTTP server integration, which are used on the pre-built dashboards and Prometheus alerts, are as follows:

  • apache_accesses_total
  • apache_cpuload
  • apache_duration_ms_total
  • apache_info
  • apache_response_http_codes_bucket
  • apache_response_http_codes_count
  • apache_scoreboard
  • apache_sent_kilobytes_total
  • apache_up
  • apache_uptime_seconds_total
  • apache_workers
  • up

Changelog

md
# 0.0.3 - September 2023

* New Filter Metrics option for configuring the Grafana Agent, which saves on metrics cost by dropping any metric not used by this integration. Beware that anything custom built using metrics that are not on the snippet will stop working.
* New hostname relabel option, which applies the instance name you write on the text box to the Grafana Agent configuration snippets, making it easier and less error prone to configure this mandatory label.

# 0.0.2 - August 2023

* Add regex filter for logs datasource

# 0.0.1 - June 2022

* Initial release

Cost

By connecting your Apache HTTP server instance to Grafana Cloud, you might incur charges. To view information on the number of active series that your Grafana Cloud account uses for metrics included in each Cloud tier, see Active series and dpm usage and Cloud tier pricing.