Skip to content

Commit

Permalink
docs(grafana-agent,ebpf): do not use undocumented features, used disc…
Browse files Browse the repository at this point in the history
…overy.process (#2972)
  • Loading branch information
korniltsev authored Jan 29, 2024
1 parent ba9d6e7 commit 35d451f
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 13 deletions.
18 changes: 16 additions & 2 deletions docs/sources/configure-client/grafana-agent/ebpf/setup-linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,23 @@ We're [working on a more flexible configuration](https://github.com/grafana/agen
Create a file named `agent.river` with the following content:

```river
discovery.process "all" {
}
discovery.relabel "agent" {
targets = discovery.process.all.targets
// Filter needed processes
rule {
source_labels = ["__meta_process_exe"]
regex = ".*/grafana-agent"
action = "keep"
}
}
pyroscope.ebpf "instance" {
forward_to = [pyroscope.write.endpoint.receiver]
targets_only = false
default_target = {"service_name" = "local"}
targets = discovery.relabel.agent.targets
}
pyroscope.scrape "local" {
Expand Down Expand Up @@ -124,3 +137,4 @@ To verify that the profiles are received by the Pyroscope server, go to the Pyro
[pyroscope-ds]: /docs/grafana/latest/datasources/grafana-pyroscope/
[config-reference]: ../configuration/
[gcloud]: /products/cloud/
[discovery.process](/docs/agent/next/flow/reference/components/discovery.process/)
10 changes: 0 additions & 10 deletions examples/ebpf/config.river

This file was deleted.

40 changes: 40 additions & 0 deletions examples/ebpf/docker/config.river
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

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

discovery.relabel "pyroscope" {
targets = discovery.docker.all.targets
// Filter needed containers based on docker labels
// See more info at reference doc https://grafana.com/docs/agent/next/flow/reference/components/discovery.docker/
rule {
source_labels = ["__meta_docker_container_name"]
regex = ".*pyroscope.*"
action = "keep"
}
// provide arbitrary service_name label, otherwise it will default to value of __meta_docker_container_name
rule {
source_labels = ["__meta_docker_container_name"]
regex = ".*pyroscope.*"
action = "replace"
target_label = "service_name"
replacement = "ebpf/docker/pyroscope"
}
}


pyroscope.ebpf "instance" {
forward_to = [pyroscope.write.endpoint.receiver]
targets = discovery.relabel.pyroscope.output
}

pyroscope.write "endpoint" {
endpoint {
url = "http://pyroscope:4040"
// url = "<Grafana Cloud URL>"
// basic_auth {
// username = "<Grafana Cloud User>"
// password = "<Grafana Cloud Password>"
// }
}
}
25 changes: 25 additions & 0 deletions examples/ebpf/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
version: '3.9'
services:
pyroscope:
image: grafana/pyroscope
ports:
- '4040:4040'

grafana-agent:
image: 'grafana/agent:main'
user: root
privileged: true
pid: 'host'
environment:
- AGENT_MODE=flow
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'
- ./config.river:/config.river
ports:
- '12345:12345'
command:
- 'run'
- '/config.river'
- '--storage.path=/tmp/agent'
- '--server.http.listen-addr=0.0.0.0:12345'
68 changes: 68 additions & 0 deletions examples/ebpf/k8s/config.river
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// This is an example grafana agent config to set up eBPF profiling in kubernetes.
// for more info see https://grafana.com/docs/pyroscope/latest/configure-client/grafana-agent/ebpf/setup-kubernetes/

discovery.kubernetes "local_pods" {
selectors {
field = "spec.nodeName=" + env("HOSTNAME") // Note: this assume HOSTNAME is set to the node name
role = "pod"
}
role = "pod"
}

discovery.relabel "specific_pods" {
targets = discovery.kubernetes.all_pods.targets
rule {
action = "drop"
regex = "Succeeded|Failed|Completed"
source_labels = ["__meta_kubernetes_pod_phase"]
}
rule {
action = "replace"
source_labels = ["__meta_kubernetes_namespace"]
target_label = "namespace"
}
rule {
action = "replace"
source_labels = ["__meta_kubernetes_pod_name"]
target_label = "pod"
}
rule {
action = "replace"
source_labels = ["__meta_kubernetes_pod_node_name"]
target_label = "node"
}
rule {
action = "replace"
source_labels = ["__meta_kubernetes_pod_container_name"]
target_label = "container"
}
// provide arbitrary service_name label, otherwise it will be set to {__meta_kubernetes_namespace}/{__meta_kubernetes_pod_container_name}
rule {
action = "replace"
regex = "(.*)@(.*)"
replacement = "ebpf/k8s/${1}/${2}"
separator = "@"
source_labels = ["__meta_kubernetes_namespace", "__meta_kubernetes_pod_container_name"]
target_label = "service_name"
}
// Filter specific targets to profile
rule {
source_labels = ["service_name"]
regex = "(ebpf/grafana-agent/agent|ebpf/pyroscope/pyroscope)"
action = "keep"
}
}

pyroscope.ebpf "instance" {
forward_to = [pyroscope.write.endpoint.receiver]
targets = discovery.relabel.specific_pods.targets
}

pyroscope.write "endpoint" {
url = "http://pyroscope:4040"
// url = "<Grafana Cloud URL>"
// basic_auth {
// username = "<Grafana Cloud User>"
// password = "<Grafana Cloud Password>"
// }
}
54 changes: 54 additions & 0 deletions examples/ebpf/local/config.river
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

// discovery.process produces targets with the following labels:`
// "__process_pid__"
// "__meta_process_exe"
// "__meta_process_cwd"
// "__meta_process_commandline"
// "__meta_process_username"
// "__meta_process_uid"
// "__container_id__"
// See reference doc for more info https://grafana.com/docs/agent/next/flow/reference/components/discovery.process/

discovery.process "all" {

}

discovery.relabel "agent" {
targets = discovery.process.all.targets
// Filter needed processes
rule {
source_labels = ["__meta_process_exe"]
regex = ".*/grafana-agent"
action = "keep"
}
// provide arbitrary service_name label, otherwise it will be "unspecified"
rule {
source_labels = ["__meta_process_exe"]
target_label = "service_name"
regex = ".*/grafana-agent"
action = "replace"
replacement = "ebpf/local/grafana-agent"
}
}


pyroscope.ebpf "instance" {
forward_to = [pyroscope.write.endpoint.receiver]
targets = concat(
discovery.relabel.agent.output,
[{"__process_pid__" = "1", "service_name" = "ebpf/local/init"}],
)
}


pyroscope.write "endpoint" {
endpoint {
url = "http://pyroscope:4040"
// url = "<Grafana Cloud URL>"
// basic_auth {
// username = "<Grafana Cloud User>"
// password = "<Grafana Cloud Password>"
// }
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
- '4040:4040'

app:
image: 'grafana/agent:latest'
image: 'grafana/agent:main'
user: root
privileged: true
pid: 'host'
Expand Down

0 comments on commit 35d451f

Please sign in to comment.