-
Notifications
You must be signed in to change notification settings - Fork 630
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(examples): Grafana agent java example (#2930)
* move to subfolder * add java example
- Loading branch information
1 parent
2402565
commit 40ccc05
Showing
13 changed files
with
110 additions
and
1 deletion.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,21 @@ | ||
import java.util.concurrent.*; | ||
|
||
public class FastSlow { | ||
|
||
public static long fib(int n) { | ||
if (n < 2) { | ||
return n; | ||
} | ||
return fib(n - 1) + fib(n - 2); | ||
} | ||
|
||
public static void main(String[] args) throws ExecutionException, InterruptedException { | ||
ExecutorService e = Executors.newSingleThreadExecutor(); | ||
e.submit(() -> { | ||
while (true) { | ||
fib(26); | ||
fib(24); | ||
} | ||
}); | ||
} | ||
} |
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,56 @@ | ||
logging { | ||
level = "debug" | ||
format = "logfmt" | ||
} | ||
|
||
discovery.process "all" { | ||
// join kuberenetes targets with process targets on container_id to have k8s labels | ||
// join = discovery.kubernetes.containers.targets | ||
} | ||
|
||
discovery.relabel "java" { | ||
targets = discovery.process.all.targets | ||
rule { | ||
source_labels = ["__meta_process_exe"] | ||
action = "keep" | ||
regex = ".*/java$" | ||
} | ||
rule { | ||
source_labels = ["__meta_process_commandline"] | ||
regex = "java FastSlow" | ||
action = "keep" | ||
} | ||
rule { | ||
action = "replace" | ||
target_label = "service_name" | ||
replacement = "java-fast-slow-fibonacci" | ||
} | ||
} | ||
|
||
pyroscope.java "java" { | ||
profiling_config { | ||
interval = "15s" | ||
alloc = "512k" | ||
cpu = true | ||
lock = "10ms" | ||
sample_rate = 100 | ||
} | ||
forward_to = [pyroscope.write.example.receiver] | ||
targets = discovery.relabel.java.output | ||
} | ||
|
||
pyroscope.write "example" { | ||
// Send metrics to a locally running Pyroscope instance. | ||
endpoint { | ||
url = "http://pyroscope:4040" | ||
|
||
// To send data to Grafana Cloud you'll need to provide username and password. | ||
// basic_auth { | ||
// username = "myuser" | ||
// password = "mypassword" | ||
// } | ||
} | ||
external_labels = { | ||
"env" = "example", | ||
} | ||
} |
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,26 @@ | ||
version: '3.9' | ||
services: | ||
java: | ||
build: | ||
context: . | ||
dockerfile: java.Dockerfile | ||
pyroscope: | ||
image: 'grafana/pyroscope:latest' | ||
ports: | ||
- 4040:4040 | ||
|
||
agent: | ||
image: grafana/agent:main | ||
volumes: | ||
- ./config.river:/etc/agent-config/config.river | ||
command: | ||
- run | ||
- /etc/agent-config/config.river | ||
- --server.http.listen-addr=0.0.0.0:12345 | ||
environment: | ||
HOSTNAME: agent | ||
AGENT_MODE: flow | ||
ports: | ||
- "12345:12345" | ||
privileged: true | ||
pid: host |
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,6 @@ | ||
FROM openjdk:17-jdk-slim | ||
|
||
ADD ./FastSlow.java /FastSlow.java | ||
RUN javac FastSlow.java | ||
|
||
CMD ["java", "FastSlow"] |