Skip to content
This repository was archived by the owner on Feb 20, 2025. It is now read-only.

Commit 1ba208a

Browse files
author
chenqz1987
committed
add process monitor and update example
1 parent 92434f3 commit 1ba208a

24 files changed

Lines changed: 149 additions & 84 deletions

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ Prerequisites:
1515

1616
```
1717
git clone git@github.com:AliyunContainerService/log-pilot.git
18-
cd log-pilot/quickstart
18+
# build log-pilot image
19+
cd log-pilot/
20+
./build.sh
21+
# quick start
22+
cd ../quickstart/
1923
./run
2024
```
2125

@@ -73,8 +77,9 @@ Prerequisites:
7377

7478
```
7579
go get github.com/AliyunContainerService/log-pilot
76-
cd $GOPATH/github.com/AliyunContainerService/log-pilot/docker-images
77-
./build.sh # This will create a new docker image named pilot:latest
80+
cd $GOPATH/github.com/AliyunContainerService/log-pilot
81+
# This will create a new docker image named log-pilot:latest
82+
./build.sh
7883
```
7984

8085
Contribute

assets/filebeat/config.filebeat

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ path.data: /var/lib/filebeat/data
2929
filebeat.registry_file: /var/lib/filebeat/registry
3030
filebeat.shutdown_timeout: ${FILEBEAT_SHUTDOWN_TIMEOUT:-0}
3131
logging.level: ${FILEBEAT_LOG_LEVEL:-info}
32-
logging.metrics.enabled: true
32+
logging.metrics.enabled: ${FILEBEAT_METRICS_ENABLED:-false}
3333
${FILEBEAT_MAX_PROCS:+max_procs: ${FILEBEAT_MAX_PROCS}}
3434
setup.template.name: "${FILEBEAT_INDEX:-filebeat}"
3535
setup.template.pattern: "${FILEBEAT_INDEX:-filebeat}-*"
@@ -43,19 +43,25 @@ EOF
4343
}
4444

4545
es() {
46-
if [ -f "/run/secrets/es_credential" ];then
46+
if [ -f "/run/secrets/es_credential" ]; then
4747
ELASTICSEARCH_USER=$(cat /run/secrets/es_credential | awk -F":" '{ print $1 }')
4848
ELASTICSEARCH_PASSWORD=$(cat /run/secrets/es_credential | awk -F":" '{ print $2 }')
4949
fi
5050

51-
assert_not_empty "$ELASTICSEARCH_HOST" "ELASTICSEARCH_HOST required"
52-
assert_not_empty "$ELASTICSEARCH_PORT" "ELASTICSEARCH_PORT required"
51+
if [ -n "$ELASTICSEARCH_HOSTS" ]; then
52+
ELASTICSEARCH_HOSTS=$(echo $ELASTICSEARCH_HOSTS|awk -F, '{for(i=1;i<=NF;i++){printf "\"%s\",", $i}}')
53+
ELASTICSEARCH_HOSTS=${ELASTICSEARCH_HOSTS%,}
54+
else
55+
assert_not_empty "$ELASTICSEARCH_HOST" "ELASTICSEARCH_HOST required"
56+
assert_not_empty "$ELASTICSEARCH_PORT" "ELASTICSEARCH_PORT required"
57+
ELASTICSEARCH_HOSTS="\"$ELASTICSEARCH_HOST:$ELASTICSEARCH_PORT\""
58+
fi
5359

5460
cat >> $FILEBEAT_CONFIG << EOF
5561
$(base)
5662
output.elasticsearch:
57-
hosts: ["$ELASTICSEARCH_HOST:$ELASTICSEARCH_PORT"]
58-
index: ${FILEBEAT_INDEX:-filebeat}-%{+yyyy.MM.dd}
63+
hosts: [$ELASTICSEARCH_HOSTS]
64+
index: ${ELASTICSEARCH_INDEX:-filebeat}-%{+yyyy.MM.dd}
5965
${ELASTICSEARCH_SCHEME:+protocol: ${ELASTICSEARCH_SCHEME}}
6066
${ELASTICSEARCH_USER:+username: ${ELASTICSEARCH_USER}}
6167
${ELASTICSEARCH_PASSWORD:+password: ${ELASTICSEARCH_PASSWORD}}
@@ -156,7 +162,11 @@ output.count:
156162
EOF
157163
}
158164

159-
case "$FILEBEAT_OUTPUT" in
165+
if [ -n "$FILEBEAT_OUTPUT" ]; then
166+
LOGGING_OUTPUT=$FILEBEAT_OUTPUT
167+
fi
168+
169+
case "$LOGGING_OUTPUT" in
160170
elasticsearch)
161171
es;;
162172
logstash)

assets/fluentd/config.fluentd

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,20 @@ fi
6262

6363
es(){
6464
if [ -f "/run/secrets/es_credential" ];then
65-
ELASTICSEARCH_USER=$(cat /run/secrets/es_credential | awk -F":" '{ print $1 }')
66-
ELASTICSEARCH_PASSWORD=$(cat /run/secrets/es_credential | awk -F":" '{ print $2 }')
65+
ELASTICSEARCH_USER=$(cat /run/secrets/es_credential | awk -F":" '{ print $1 }')
66+
ELASTICSEARCH_PASSWORD=$(cat /run/secrets/es_credential | awk -F":" '{ print $2 }')
6767
fi
68-
assert_not_empty "$ELASTICSEARCH_HOST" "ELASTICSEARCH_HOST required"
69-
assert_not_empty "$ELASTICSEARCH_PORT" "ELASTICSEARCH_PORT required"
68+
69+
if [ -z "$ELASTICSEARCH_HOSTS" ]; then
70+
assert_not_empty "$ELASTICSEARCH_HOST" "ELASTICSEARCH_HOST required"
71+
assert_not_empty "$ELASTICSEARCH_PORT" "ELASTICSEARCH_PORT required"
72+
ELASTICSEARCH_HOSTS="$ELASTICSEARCH_HOST:$ELASTICSEARCH_PORT"
73+
fi
74+
7075
cat >> $FLUENTD_CONFIG << EOF
7176
<match docker.**>
7277
@type elasticsearch
73-
hosts $ELASTICSEARCH_HOST:$ELASTICSEARCH_PORT
78+
hosts $ELASTICSEARCH_HOSTS
7479
reconnect_on_error true
7580
${ELASTICSEARCH_USER:+user ${ELASTICSEARCH_USER}}
7681
${ELASTICSEARCH_PASSWORD:+password ${ELASTICSEARCH_PASSWORD}}
@@ -133,9 +138,10 @@ EOF
133138

134139
aliyun_sls(){
135140
if [ -f "/run/secrets/aliyun_access_key" ];then
136-
ALIYUNSLS_ACCESS_KEY_ID=$(cat /run/secrets/aliyun_access_key | awk -F":" '{ print $1 }')
137-
ALIYUNSLS_ACCESS_KEY_SECRET=$(cat /run/secrets/aliyun_access_key | awk -F":" '{ print $2 }')
141+
ALIYUNSLS_ACCESS_KEY_ID=$(cat /run/secrets/aliyun_access_key | awk -F":" '{ print $1 }')
142+
ALIYUNSLS_ACCESS_KEY_SECRET=$(cat /run/secrets/aliyun_access_key | awk -F":" '{ print $2 }')
138143
fi
144+
139145
assert_not_empty "$ALIYUNSLS_PROJECT" "ALIYUNSLS_PROJECT required"
140146
assert_not_empty "$ALIYUNSLS_REGION_ENDPOINT" "ALIYUNSLS_REGION_ENDPOINT required"
141147
assert_not_empty "$ALIYUNSLS_ACCESS_KEY_ID" "ALIYUNSLS_ACCESS_KEY_ID required"
@@ -224,7 +230,11 @@ aggregate all
224230
EOF
225231
}
226232

227-
case "$FLUENTD_OUTPUT" in
233+
if [ -n "$FLUENTD_OUTPUT" ]; then
234+
LOGGING_OUTPUT="$FLUENTD_OUTPUT"
235+
fi
236+
237+
case "$LOGGING_OUTPUT" in
228238
elasticsearch)
229239
es;;
230240
graylog)

build.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
#
3+
# build docker image
4+
#
5+
6+
build()
7+
{
8+
echo -e "building image: log-pilot:latest\n"
9+
10+
docker build -t log-pilot:latest -f Dockerfile.$1 .
11+
}
12+
13+
case $1 in
14+
fluentd)
15+
build fluentd
16+
;;
17+
*)
18+
build filebeat
19+
;;
20+
esac

docs/filebeat/docs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ docker run --rm -it \
3131
-v /var/run/docker.sock:/var/run/docker.sock \
3232
-v /:/host \
3333
-e PILOT_TYPE=filebeat \
34-
-e FILEBEAT_OUTPUT=elasticsearch \
34+
-e LOGGING_OUTPUT=elasticsearch \
3535
-e ELASTICSEARCH_HOST=${ELASTICSEARCH_HOST} \
3636
-e ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT} \
3737
registry.cn-hangzhou.aliyuncs.com/acs-sample/log-pilot:latest
@@ -40,7 +40,7 @@ docker run --rm -it \
4040
Log output plugin configuration
4141
===============================
4242

43-
You can config the environment variable ```FILEBEAT_OUTPUT ``` to determine which log management will be output.
43+
You can config the environment variable ```LOGGING_OUTPUT ``` to determine which log management will be output.
4444

4545
### Supported log management
4646

docs/fluentd/docs.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ docker run --rm -it \
3131
-v /var/run/docker.sock:/var/run/docker.sock \
3232
-v /:/host \
3333
-e PILOT_TYPE=fluentd \
34-
-e FLUENTD_OUTPUT=elasticsearch \
34+
-e LOGGING_OUTPUT=elasticsearch \
3535
-e ELASTICSEARCH_HOST=${ELASTICSEARCH_HOST} \
3636
-e ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT} \
3737
registry.cn-hangzhou.aliyuncs.com/acs-sample/log-pilot:latest
@@ -40,7 +40,7 @@ docker run --rm -it \
4040
Log output plugin configuration
4141
===============================
4242

43-
You can config the environment variable ```FLUENTD_OUTPUT ``` to determine which log management will be output.
43+
You can config the environment variable ```LOGGING_OUTPUT ``` to determine which log management will be output.
4444

4545
### Supported log management
4646

docs/fluentd/output/aliyun_sls.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#### Environment variables for image `fluentd`
44

5-
- FLUENTD_OUTPUT=aliyun_sls # Required, specify your output plugin name
5+
- LOGGING_OUTPUT=aliyun_sls # Required, specify your output plugin name
66
- ALIYUNSLS_PROJECT=test-fluentd # Required, specify your aliyun sls project name
77
- ALIYUNSLS_REGION_ENDPOINT=cn-hangzhou.log.aliyuncs.com # Required, specify your region root endpoint
88
- ALIYUNSLS_ACCESS_KEY_ID="your aliyun access key id" # Required
@@ -35,7 +35,7 @@ swm2ft9bzaxyyi9umwbb0mdd6 aliyun_access_key 53 minutes ago 53 minutes a
3535
docker run --rm -it \
3636
-v /var/run/docker.sock:/var/run/docker.sock \
3737
-v /:/host \
38-
-e FLUENTD_OUTPUT=aliyun_sls \
38+
-e LOGGING_OUTPUT=aliyun_sls \
3939
-e ALIYUNSLS_PROJECT="your-aliyun-sls-project-name" \
4040
-e ALIYUNSLS_REGION_ENDPOINT=cn-hangzhou.log.aliyuncs.com \
4141
-e ALIYUNSLS_ACCESS_KEY_ID="your-access-key-id" \
@@ -63,7 +63,7 @@ $ docker service create -t \
6363
--mount type=bind,source=/var/run/docker.sock,destination=/var/run/docker.sock \
6464
--mount type=bind,source=/,destination=/host \
6565
--secret="aliyun_access_key" \
66-
-e FLUENTD_OUTPUT=aliyun_sls \
66+
-e LOGGING_OUTPUT=aliyun_sls \
6767
-e ALIYUNSLS_PROJECT="your-aliyun-sls-project-name" \
6868
-e ALIYUNSLS_REGION_ENDPOINT=cn-hangzhou.log.aliyuncs.com \
6969
registry.cn-hangzhou.aliyuncs.com/acs-sample/fluentd-pilot:latest

docs/fluentd/output/kafka.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#### Environment variables for image `fluentd`
44

55
```
6-
- FLUENTD_OUTPUT=kafka # Required, specify your output plugin name
6+
- LOGGING_OUTPUT=kafka # Required, specify your output plugin name
77
- KAFKA_BROKERS=<broker1_host>:<broker1_port>,<broker2_host>:<broker2_port>...
88
- KAFKA_DEFAULT_TOPIC=topic
99
```

examples/pilot-elasticsearch-kubernetes.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@ metadata:
44
name: log-pilot
55
labels:
66
k8s-app: log-pilot
7-
kubernetes.io/cluster-service: "true"
87
spec:
98
template:
109
metadata:
1110
labels:
1211
k8s-app: log-pilot
13-
kubernetes.io/cluster-service: "true"
14-
version: v1.22
1512
spec:
1613
tolerations:
1714
- key: node-role.kubernetes.io/master
@@ -20,12 +17,16 @@ spec:
2017
- name: log-pilot
2118
image: registry.cn-hangzhou.aliyuncs.com/acs-sample/log-pilot:0.9.1-fluentd
2219
env:
23-
- name: "FLUENTD_OUTPUT"
20+
- name: "LOGGING_OUTPUT"
2421
value: "elasticsearch"
2522
- name: "ELASTICSEARCH_HOST"
2623
value: "{elasticsearch}" #changeme
2724
- name: "ELASTICSEARCH_PORT"
2825
value: "{port}" #changeme
26+
- name: "NODE_NAME"
27+
valueFrom:
28+
fieldRef:
29+
fieldPath: spec.nodeName
2930
volumeMounts:
3031
- name: sock
3132
mountPath: /var/run/docker.sock

examples/pilot-elastisearch-kubernetes-2.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@ metadata:
44
name: log-pilot
55
labels:
66
k8s-app: log-pilot
7-
kubernetes.io/cluster-service: "true"
87
spec:
98
template:
109
metadata:
1110
labels:
1211
k8s-app: log-pilot
13-
kubernetes.io/cluster-service: "true"
14-
version: v1.22
1512
spec:
1613
tolerations:
1714
- key: node-role.kubernetes.io/master
@@ -20,12 +17,14 @@ spec:
2017
- name: log-pilot
2118
image: registry.cn-hangzhou.aliyuncs.com/acs-sample/log-pilot:0.9-filebeat
2219
env:
23-
- name: "FILEBEAT_OUTPUT"
20+
- name: "LOGGING_OUTPUT"
2421
value: "elasticsearch"
25-
- name: "ELASTICSEARCH_HOST"
26-
value: "changeme"
27-
- name: "ELASTICSEARCH_PORT"
28-
value: "9092"
22+
- name: "ELASTICSEARCH_HOSTS"
23+
value: "elasticsearch1:9200,elasticsearch2:9200"
24+
- name: "NODE_NAME"
25+
valueFrom:
26+
fieldRef:
27+
fieldPath: spec.nodeName
2928
volumeMounts:
3029
- name: sock
3130
mountPath: /var/run/docker.sock
@@ -53,4 +52,3 @@ spec:
5352
- name: root
5453
hostPath:
5554
path: /
56-

0 commit comments

Comments
 (0)