Skip to content

Commit c45f7c0

Browse files
committed
add fluentbit
1 parent 6c1703a commit c45f7c0

File tree

6 files changed

+107
-0
lines changed

6 files changed

+107
-0
lines changed

fluentbit/docker-compose.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
version: '3.8'
2+
3+
services:
4+
log-generator:
5+
container_name: log-generator
6+
user: root
7+
build:
8+
context: log-generator
9+
volumes:
10+
- logs:/logs
11+
12+
fluentbit:
13+
container_name: fluentbit
14+
image: fluent/fluent-bit:latest
15+
user: root
16+
volumes:
17+
- logs:/logs
18+
- ./fluentbit/fluent-bit.conf:/fluent-bit/fluent-bit.conf
19+
command:
20+
- "fluent-bit"
21+
- "-c"
22+
- "/fluent-bit/fluent-bit.conf"
23+
24+
http-server:
25+
container_name: http-server
26+
user: root
27+
build:
28+
context: http-server
29+
30+
volumes:
31+
logs:
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# >>> https://docs.fluentbit.io/manual/administration/buffering-and-storage
2+
[SERVICE]
3+
Flush 1
4+
Log_Level info
5+
storage.path /logs/fluent-bit-storage
6+
storage.sync full
7+
8+
# >>> https://docs.fluentbit.io/manual/pipeline/tail
9+
[INPUT]
10+
Name tail
11+
Path /logs/*.log
12+
storage.type filesystem
13+
14+
# >>> https://docs.fluentbit.io/manual/pipeline/outputs
15+
[OUTPUT]
16+
Name http
17+
Match *
18+
Host http-server
19+
Port 5000
20+
URI /logs
21+
Format json
22+
Retry_Limit False

fluentbit/http-server/Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM python:3.9-slim
2+
3+
ENV PYTHONUNBUFFERED=1
4+
WORKDIR /app
5+
COPY app.py /app
6+
RUN pip install flask
7+
8+
CMD ["python", "app.py"]

fluentbit/http-server/app.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from flask import Flask, request
2+
import logging
3+
import sys
4+
5+
app = Flask(__name__)
6+
7+
_log = logging.getLogger('werkzeug')
8+
_log.setLevel(logging.ERROR)
9+
10+
@app.route('/logs', methods=['POST'])
11+
def receive_logs():
12+
log_batch = request.get_json()
13+
logs_raw = [log['log'] for log in log_batch]
14+
print(logs_raw)
15+
return logs_raw, 200
16+
17+
if __name__ == '__main__':
18+
app.run(host='0.0.0.0', port=5000, debug=True)

fluentbit/log-generator/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM fedora:38
2+
COPY run.sh /opt/run.sh
3+
RUN chmod +x /opt/run.sh
4+
CMD /opt/run.sh

fluentbit/log-generator/run.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
# Define the log file path
4+
LOG_FILE="/logs/logfile.log"
5+
6+
# Ensure the log directory exists
7+
mkdir -p "$(dirname "$LOG_FILE")"
8+
9+
# Initialize the counter
10+
i=0
11+
12+
# Infinite loop to generate log messages
13+
while true; do
14+
LOG_MESSAGE="#$i"
15+
# Append the log message to the log file
16+
echo "$LOG_MESSAGE" >> "$LOG_FILE"
17+
echo "$LOG_MESSAGE"
18+
19+
# Increment the counter
20+
((i++))
21+
22+
# Sleep for 1 second
23+
sleep 1
24+
done

0 commit comments

Comments
 (0)