-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New module for Grafana LGTMP Stack receiver provider
Signed-off-by: Weifeng Wang <[email protected]> Update provider.river
- Loading branch information
Showing
21 changed files
with
1,552 additions
and
1,513 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# LGTMP agent moudles | ||
|
||
<https://grafana.com/docs/agent/latest/flow/concepts/modules/> | ||
|
||
```river | ||
import.git "provider" { | ||
repository = "https://github.com/qclaogui/codelab-monitoring.git" | ||
revision = "main" | ||
path = "docker-compose/common/config/agent-flow/modules/provider.river" | ||
pull_frequency = "15m" | ||
} | ||
// get the receivers provider | ||
provider.lgtmp_stack "docker_compose" { | ||
metrics_endpoint = "http://mimir:8080" | ||
} | ||
// scrape metrics and write to grafana cloud | ||
prometheus.scrape "default" { | ||
targets = [ | ||
{"__address__" = "127.0.0.1:12345"}, | ||
] | ||
forward_to = [ | ||
provider.lgtmp_stack.docker_compose.metrics_receiver, | ||
] | ||
} | ||
``` | ||
|
||
```river | ||
import.git "provider" { | ||
repository = "https://github.com/qclaogui/codelab-monitoring.git" | ||
revision = "main" | ||
path = "docker-compose/common/config/agent-flow/modules/provider.river" | ||
pull_frequency = "15m" | ||
} | ||
// get the receivers provider | ||
provider.grafana_cloud "stack_name" { | ||
stack_name = env("GRAFANA_CLOUD_STACK_NAME") | ||
token = env("GRAFANA_CLOUD_STACK_TOKEN") | ||
} | ||
// scrape metrics and write to grafana cloud | ||
prometheus.scrape "default" { | ||
targets = [ | ||
{"__address__" = "127.0.0.1:12345"}, | ||
] | ||
forward_to = [ | ||
provider.grafana_cloud.stack_name.metrics_receiver, | ||
] | ||
} | ||
``` |
178 changes: 178 additions & 0 deletions
178
docker-compose/common/config/agent-flow/modules/docker/compose/logs-auto-scrape.river
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
/* | ||
Module(logs_auto_scrape): Docker Containers Logs Auto-Scraping | ||
Description: Scrapes targets for logs based on Docker Containers labels | ||
|
||
Note: Every argument except for "forward_to" is optional, and does have a defined default value. However, the values for these | ||
arguments are not defined using the default = " ... " argument syntax, but rather using the coalesce(argument.value, " ... "). | ||
This is because if the argument passed in from another consuming module is set to null, the default = " ... " syntax will | ||
does not override the value passed in, where coalesce() will return the first non-null value. | ||
|
||
|
||
Following labels are available: | ||
|
||
logs.agent.grafana.com/scrape: true | ||
|
||
allow containers to declare what tenant their logs should be written to, | ||
the following label is supported: | ||
|
||
logs.agent.grafana.com/tenant: "primary" | ||
*/ | ||
|
||
declare "logs_auto_scrape" { | ||
|
||
/******************************************** | ||
* ARGUMENTS | ||
********************************************/ | ||
argument "forward_to" { | ||
comment = "Must be a list(LogsReceiver) where collected logs should be forwarded to" | ||
} | ||
|
||
argument "targets" { | ||
comment = "The running containers." | ||
} | ||
|
||
argument "cluster" { | ||
optional = true | ||
} | ||
|
||
argument "namespace" { | ||
optional = true | ||
} | ||
|
||
argument "tenant" { | ||
comment = "The tenant to write metrics to. This does not have to be the tenantId, this is the value to look for in the logs.agent.grafana.com/tenant label, and this can be a regex. (default: (.*))" | ||
optional = true | ||
} | ||
|
||
// get logs from discovery relabel dr_docker_logs below | ||
loki.source.docker "lsd_docker_logs" { | ||
forward_to = argument.forward_to.value | ||
|
||
host = "unix:///var/run/docker.sock" | ||
targets = discovery.relabel.dr_docker_logs.output | ||
relabel_rules = discovery.relabel.dr_docker_logs.rules | ||
refresh_interval = "15s" | ||
} | ||
|
||
discovery.relabel "dr_docker_logs" { | ||
targets = argument.targets.value | ||
|
||
/**************************************************************************************************************** | ||
* Handle Discovers From Docker Engine Containers Targets to Keep or Drop | ||
* https://grafana.com/docs/agent/latest/flow/reference/components/discovery.docker/#exported-fields | ||
****************************************************************************************************************/ | ||
// allow resources to declare their metrics scraped or not | ||
// Example Annotation: | ||
// logs.agent.grafana.com/scrape: false | ||
rule { | ||
action = "replace" | ||
source_labels = [ | ||
"__meta_docker_container_label_logs_agent_grafana_com_scrape", | ||
] | ||
separator = ";" | ||
regex = "^(?:;*)?(true|false).*$" | ||
replacement = "$1" | ||
target_label = "__tmp_scrape" | ||
} | ||
|
||
// drop any targets that have scrape: false | ||
rule { | ||
action = "drop" | ||
source_labels = ["__tmp_scrape"] | ||
regex = "false" | ||
} | ||
|
||
// allow resources to declare their metrics the tenant their metrics should be sent to, | ||
// Example Annotation: | ||
// logs.agent.grafana.com/tenant: primary | ||
rule { | ||
action = "keep" | ||
source_labels = [ | ||
"__meta_docker_container_label_logs_agent_grafana_com_tenant", | ||
] | ||
regex = "^(" + coalesce(argument.tenant.value, ".*") + ")$" | ||
} | ||
|
||
// make all labels on the pod available to the pipeline as labels(for loki process), | ||
// they are omitted before write via labelallow unless explicitly set | ||
rule { | ||
action = "labelmap" | ||
regex = "__meta_docker_container_label_(.+)" | ||
} | ||
|
||
/******************************************** | ||
* Handle Setting Common Labels | ||
********************************************/ | ||
|
||
// set the cluster label | ||
rule { | ||
action = "replace" | ||
replacement = coalesce(argument.cluster.value, "docker-compose") | ||
target_label = "cluster" | ||
} | ||
|
||
// set the namespace label | ||
rule { | ||
action = "replace" | ||
replacement = coalesce(argument.namespace.value, "monitoring-system") | ||
target_label = "namespace" | ||
} | ||
|
||
// set a default job label to be the namespace/service_name | ||
rule { | ||
action = "replace" | ||
source_labels = [ | ||
"__meta_docker_container_label_com_docker_compose_service", | ||
] | ||
regex = "^(?:;*)?([^;]+).*$" | ||
replacement = coalesce(argument.namespace.value, "monitoring-system") + "/$1" | ||
target_label = "job" | ||
} | ||
|
||
rule { | ||
action = "replace" | ||
source_labels = [ | ||
"__meta_docker_container_label_com_docker_compose_service", | ||
] | ||
regex = "^(?:;*)?([^;]+).*$" | ||
replacement = "$1" | ||
target_label = "pod" | ||
} | ||
|
||
rule { | ||
action = "replace" | ||
source_labels = [ | ||
"__meta_docker_container_label_com_docker_compose_service", | ||
] | ||
regex = "^(?:;*)?([^;]+).*$" | ||
replacement = "$1" | ||
target_label = "container" | ||
} | ||
|
||
rule { | ||
source_labels = ["__meta_docker_container_name"] | ||
regex = "/(.*)" | ||
target_label = "container_name" | ||
} | ||
|
||
rule { | ||
action = "replace" | ||
source_labels = [ | ||
"__meta_docker_container_label_com_docker_compose_service", | ||
] | ||
regex = "^(?:;*)?([^;]+).*$" | ||
replacement = "$1" | ||
target_label = "app" | ||
} | ||
|
||
rule { | ||
action = "replace" | ||
source_labels = [ | ||
"__meta_docker_container_label_app", | ||
] | ||
regex = "^(?:;*)?([^;]+).*$" | ||
replacement = "$1" | ||
target_label = "app" | ||
} | ||
} | ||
} |
Oops, something went wrong.