Skip to content

Commit

Permalink
update docker compose common relabel
Browse files Browse the repository at this point in the history
Signed-off-by: Weifeng Wang <[email protected]>

code clean

Signed-off-by: Weifeng Wang <[email protected]>
  • Loading branch information
qclaogui committed Mar 11, 2024
1 parent 78dd2f7 commit ddb65ea
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 168 deletions.
43 changes: 1 addition & 42 deletions docker-compose/common/config/agent-flow/logs.river
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,8 @@ module.file "docker_compose" {
}
}

discovery.docker "containers" {
host = "unix:///var/run/docker.sock"

filter {
name = "status"
values = ["running"]
}
}

discovery.relabel "containers" {
targets = discovery.docker.containers.targets

// filter by service name
rule {
source_labels = ["__meta_docker_container_label_com_docker_compose_service"]
action = "keep"
regex = "(agent|mimir|mimir-.*|grafana|loki|loki-.*|tempo|tempo-.*|pyroscope|distributor|ingester|query-frontend|query-scheduler|querier|ruler|index-gateway|compactor|gateway)"
}

rule {
source_labels = ["__meta_docker_container_label_com_docker_compose_service"]
regex = "(.*)"
replacement = "monitoring-system/$1"
target_label = "job"
}

rule {
source_labels = ["__meta_docker_container_label_com_docker_compose_service"]
regex = "(.*)"
target_label = "pod"
}

rule {
source_labels = ["__meta_docker_container_label_com_docker_compose_service"]
regex = "(.*)"
target_label = "app"
}

rule {
source_labels = ["__meta_docker_container_name"]
regex = "/(.*)"
target_label = "container"
}
targets = module.file.docker_compose.exports.relabelings_common.output
}

/********************************************
Expand Down
43 changes: 1 addition & 42 deletions docker-compose/common/config/agent-flow/metrics.river
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,8 @@ module.file "docker_compose" {
}
}

discovery.docker "containers" {
host = "unix:///var/run/docker.sock"

filter {
name = "status"
values = ["running"]
}
}

discovery.relabel "containers" {
targets = discovery.docker.containers.targets

// filter by service name
rule {
source_labels = ["__meta_docker_container_label_com_docker_compose_service"]
action = "keep"
regex = "(agent|mimir|mimir-.*|grafana|loki|loki-.*|tempo|tempo-.*|pyroscope|distributor|ingester|query-frontend|querier|query-scheduler|store-gateway|alertmanager|compactor|ruler|overrides-exporter)"
}

rule {
source_labels = ["__meta_docker_container_label_com_docker_compose_service"]
regex = "(.*)"
replacement = "monitoring-system/$1"
target_label = "job"
}

rule {
source_labels = ["__meta_docker_container_label_com_docker_compose_service"]
regex = "(.*)"
target_label = "pod"
}

rule {
source_labels = ["__meta_docker_container_label_com_docker_compose_service"]
regex = "(.*)"
target_label = "service_name"
}

rule {
source_labels = ["__meta_docker_container_name"]
regex = "/(.*)"
target_label = "container"
}
targets = module.file.docker_compose.exports.relabelings_common.output
}

/********************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ argument "profiles_endpoint" {
* EXPORTS
********************************************/

export "relabelings_common" {
value = discovery.relabel.common
}

export "metrics_receiver" {
value = prometheus.remote_write.docker_compose.receiver
}
Expand Down Expand Up @@ -116,3 +120,62 @@ pyroscope.write "docker_compose" {
"namespace" = argument.namespace.value,
}
}

discovery.docker "containers" {
host = "unix:///var/run/docker.sock"

filter {
name = "status"
values = ["running"]
}
}

discovery.relabel "common" {
targets = discovery.docker.containers.targets

// filter by service name
rule {
action = "keep"
source_labels = [
"__meta_docker_container_label_com_docker_compose_service",
]
regex = "(agent|mimir|mimir-.*|grafana|loki|loki-.*|tempo|tempo-.*|pyroscope|distributor|ingester|query-frontend|querier|query-scheduler|ruler|compactor|store-gateway|alertmanager|overrides-exporter|index-gateway|gateway)"
}

rule {
action = "replace"
source_labels = [
"__meta_docker_container_label_com_docker_compose_service",
]
regex = "^(?:;*)?([^;]+).*$"
replacement = argument.namespace.value + "/$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",
"__meta_docker_container_label_app",
]
regex = "^(?:;*)?([^;]+).*$"
replacement = "$1"
target_label = "app"
}

rule {
source_labels = ["__meta_docker_container_name"]
regex = "/(.*)"
target_label = "container"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,8 @@ module.file "docker_compose" {
filename = env("AGENT_CONFIG_FOLDER") + "/modules/docker_compose.river"
}

discovery.docker "containers" {
host = "unix:///var/run/docker.sock"

filter {
name = "status"
values = ["running"]
}
}

discovery.relabel "containers" {
targets = discovery.docker.containers.targets

// filter by service name
rule {
source_labels = ["__meta_docker_container_label_com_docker_compose_service"]
action = "keep"
regex = "(agent|mimir|grafana|loki|loki-.*|tempo|pyroscope)"
}

rule {
source_labels = ["__meta_docker_container_label_com_docker_compose_service"]
regex = "(.*)"
replacement = "monitoring-system/$1"
target_label = "job"
}

rule {
source_labels = ["__meta_docker_container_label_com_docker_compose_service"]
regex = "(.*)"
target_label = "pod"
}

rule {
source_labels = ["__meta_docker_container_label_com_docker_compose_service"]
regex = "(.*)"
target_label = "app"
}

rule {
source_labels = ["__meta_docker_container_name"]
regex = "/(.*)"
target_label = "container"
}
targets = module.file.docker_compose.exports.relabelings_common.output
}

/********************************************
Expand Down
43 changes: 1 addition & 42 deletions docker-compose/common/config/agent-flow/traces.river
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,8 @@ module.file "docker_compose" {
}
}

discovery.docker "containers" {
host = "unix:///var/run/docker.sock"

filter {
name = "status"
values = ["running"]
}
}

discovery.relabel "containers" {
targets = discovery.docker.containers.targets

// filter by service name
rule {
source_labels = ["__meta_docker_container_label_com_docker_compose_service"]
action = "keep"
regex = "(agent|mimir|grafana|loki|loki-.*|tempo|pyroscope)"
}

rule {
source_labels = ["__meta_docker_container_label_com_docker_compose_service"]
regex = "(.*)"
replacement = "monitoring-system/$1"
target_label = "job"
}

rule {
source_labels = ["__meta_docker_container_label_com_docker_compose_service"]
regex = "(.*)"
target_label = "pod"
}

rule {
source_labels = ["__meta_docker_container_label_com_docker_compose_service"]
regex = "(.*)"
target_label = "app"
}

rule {
source_labels = ["__meta_docker_container_name"]
regex = "/(.*)"
target_label = "container"
}
targets = module.file.docker_compose.exports.relabelings_common.output
}

/********************************************
Expand Down

0 comments on commit ddb65ea

Please sign in to comment.