Skip to content

Commit

Permalink
add support for collecting metrics from nginx and php-fpm
Browse files Browse the repository at this point in the history
  • Loading branch information
fcoelho committed Jul 19, 2024
1 parent da6bb2f commit 07ed5ea
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,29 @@ source = '''
.chan = "error"
.parsed = parse_regex(.message, r'^(?P<ts>\[\d+\-\w+\-\d+ \d+:\d+:\d+\]) (?P<lvl>\w+): (?P<msg>.*)$') ?? {}
'''

{{ 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<pool>[^/]+)/status')

.tags.pool = parsed.pool

del(.tags.endpoint)
'''
{{ end }}
{{ end }}
26 changes: 26 additions & 0 deletions etc/vector/vector.d/90-output.toml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,29 @@ 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"}}
"nginx_metrics",
{{end}}
{{if getenv "METRICS_PHP_FPM_ENABLED" "true"}}
"php_fpm_metrics",
{{end}}
]
source = '''
'''

{{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}}
31 changes: 31 additions & 0 deletions usr/local/share/deskpro/container-var-reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down

0 comments on commit 07ed5ea

Please sign in to comment.