diff --git a/etc/vector/vector.d/10-nginx.toml b/etc/vector/vector.d/10-nginx.toml.tmpl similarity index 73% rename from etc/vector/vector.d/10-nginx.toml rename to etc/vector/vector.d/10-nginx.toml.tmpl index 705d593..ef58a9c 100644 --- a/etc/vector/vector.d/10-nginx.toml +++ b/etc/vector/vector.d/10-nginx.toml.tmpl @@ -44,3 +44,20 @@ if is_string(.message) && contains(string!(.message), get_env_var!("VECTOR_MARKE .chan = "error" .parsed = parse_nginx_log(.message, "error") ?? {} ''' + +{{ if getenv "METRICS_ENABLED" "false" }} +{{ if getenv "METRICS_NGINX_ENABLED" "true" }} +[sources.nginx_metrics_source] +type = "nginx_metrics" +endpoints = ["http://localhost:10001/nginx/status"] +scrape_interval_secs = 60 + +[transforms.nginx_metrics] +type = "remap" +inputs = ["nginx_metrics_source"] +source = ''' +del(.tags.endpoint) +del(.tags.host) +''' +{{ end }} +{{ end }} diff --git a/etc/vector/vector.d/10-php.toml b/etc/vector/vector.d/10-php.toml.tmpl similarity index 64% rename from etc/vector/vector.d/10-php.toml rename to etc/vector/vector.d/10-php.toml.tmpl index fea6890..0f48df3 100644 --- a/etc/vector/vector.d/10-php.toml +++ b/etc/vector/vector.d/10-php.toml.tmpl @@ -46,3 +46,29 @@ source = ''' .chan = "error" .parsed = parse_regex(.message, r'^(?P\[\d+\-\w+\-\d+ \d+:\d+:\d+\]) (?P\w+): (?P.*)$') ?? {} ''' + +{{ if getenv "METRICS_ENABLED" "false" }} +{{ if getenv "METRICS_PHP_FPM_ENABLED" "true" }} +[sources.php_fpm_metrics_source] +type = "prometheus_scrape" +endpoints = [ + "http://localhost:10001/fpm/dp_default/status?openmetrics", + "http://localhost:10001/fpm/dp_broadcaster/status?openmetrics", + "http://localhost:10001/fpm/dp_gql/status?openmetrics", + "http://localhost:10001/fpm/dp_internal/status?openmetrics", +] +endpoint_tag = "endpoint" +scrape_interval_secs = 60 + +[transforms.php_fpm_metrics] +type = "remap" +inputs = ["php_fpm_metrics_source"] +source = ''' +parsed = parse_regex!(.tags.endpoint, r'/fpm/(?P[^/]+)/status') + +.tags.pool = parsed.pool + +del(.tags.endpoint) +''' +{{ end }} +{{ end }} diff --git a/etc/vector/vector.d/90-output.toml.tmpl b/etc/vector/vector.d/90-output.toml.tmpl index 028e046..ce0cd3b 100644 --- a/etc/vector/vector.d/90-output.toml.tmpl +++ b/etc/vector/vector.d/90-output.toml.tmpl @@ -126,3 +126,30 @@ encoding.codec = "raw_message" encoding.timestamp_format = "rfc3339" target = "stdout" {{end}} + +{{if getenv "METRICS_ENABLED" "false"}} +[transforms.metrics] +type = "remap" +inputs = [ + {{if getenv "METRICS_NGINX_ENABLED" "true"}} + "transforms.nginx_metrics", + {{end}} + {{if getenv "METRICS_PHP_FPM_ENABLED" "true"}} + "transforms.php_fpm_metrics", + {{end}} +] +source = ''' +.tags.container_name = "{{ getenv "CONTAINER_NAME" }}" +''' + +{{if eq "prometheus_exporter" (getenv "METRICS_EXPORT_TARGET" "prometheus_exporter")}} +[sinks.metrics_prometheus_exporter] +type = "prometheus_exporter" +inputs = ["metrics"] +{{else if eq "prometheus_remote_write" (getenv "METRICS_EXPORT_TARGET")} +[sinks.metrics_prometheus_remote_write] +type = "prometheus_remote_write" +inputs = ["metrics"] +{{getenv "METRICS_EXPORT_REMOTE_WRITE_CONFIG"}} +{{end}} +{{end}} diff --git a/usr/local/share/deskpro/container-var-reference.json b/usr/local/share/deskpro/container-var-reference.json index c810b8a..1d2b68e 100644 --- a/usr/local/share/deskpro/container-var-reference.json +++ b/usr/local/share/deskpro/container-var-reference.json @@ -435,6 +435,37 @@ "example": "logfmt or json", "default": "logfmt" }, + { + "name": "METRICS_ENABLED", + "description": "Toggle to enable or disable metrics collection", + "type": "boolean", + "default": "false" + }, + { + "name": "METRICS_EXPORT_REMOTE_WRITE_CONFIG", + "description": "Custom config when using the prometheus_remote_write metrics exporter", + "type": "string", + "example": "auth.strategy = \"aws\"\naws.region = \"us-east-1\"" + }, + { + "name": "METRICS_EXPORT_TARGET", + "description": "Controls how to expose the metrics collected from this container. The default value 'prometheus_exporter' will set up a local server from which metrics can be scraped", + "type": "string", + "example": "prometheus_exporter or prometheus_remote_write", + "default": "prometheus_exporter" + }, + { + "name": "METRICS_NGINX_ENABLED", + "description": "Enables collecting metrics from nginx", + "type": "boolean", + "default": "true" + }, + { + "name": "METRICS_PHP_FPM_ENABLED", + "description": "Enables collecting metrics from PHP-FPM", + "type": "boolean", + "default": "true" + }, { "name": "NGINX_ERROR_LOG_LEVEL", "description": "The log level for nginx logs.",