Skip to content

Commit 928a24c

Browse files
committed
Add example filebeat-container-logger.sh script
1 parent 1d80fd4 commit 928a24c

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

examples/filebeat-container-logger.sh

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
# This creates a config file for Filebeat in the sandbox directory
3+
# and starts Filebeat, reading from standard input.
4+
5+
# We use the logstash output by default, which Graylog supports
6+
# through the Beats input.
7+
OUTPUT_HOSTS='["your.graylog.example.com:5044"]'
8+
9+
config_path="$MESOS_LOG_SANDBOX_DIRECTORY/filebeat-$MESOS_LOG_STREAM.yml"
10+
11+
mesos_fields=$(echo "$MESOS_EXECUTORINFO_JSON" | \
12+
jq -r ".command.environment.variables
13+
|map(\"\(.name):\(.value|tostring)\")|.[]" | \
14+
# Skip empty variables, use mesos_ prefix, convert to lowercase
15+
awk -F: 'length($2) > 0 {
16+
$1=tolower($1);
17+
if (!match($1, "^mesos_.*")) {
18+
$1="mesos_" $1;
19+
}
20+
printf("%s: \"%s\"\n ", $1, $2);
21+
}')
22+
23+
cat <<EOF > $config_path
24+
filebeat:
25+
prospectors:
26+
-
27+
paths:
28+
- "-"
29+
input_type: stdin
30+
close_eof: true
31+
fields:
32+
mesos_log_stream: $MESOS_LOG_STREAM
33+
mesos_log_sandbox_directory: $MESOS_LOG_SANDBOX_DIRECTORY
34+
$mesos_fields
35+
36+
output:
37+
logstash:
38+
hosts: $OUTPUT_HOSTS
39+
EOF
40+
41+
/usr/bin/filebeat -c $config_path

0 commit comments

Comments
 (0)