-
Java - 1.8.x
-
Maven - 3.x.x
1. Clone the application
https://github.com/liyongjian5179/log-collection-demo.git
2. Build and run the app using maven
cd log-collection-demo
mvn package
java -jar target/log-collection-demo-0.0.1-SNAPSHOT.jar
You can also run the app without packaging it using -
mvn spring-boot:run
mvn -U clean package -Dsonar.skip=true -Dmaven.test.skip=true
java -jar target/log-collection-demo-0.0.1-SNAPSHOT.jar
curl http://localhost:8080/
返回:"Success! Master"
curl http://localhost:8080/hello
返回:"Hello, Master"
curl http://localhost:8081/actuator/prometheus
返回:
# HELP jvm_gc_live_data_size_bytes Size of old generation memory pool after a full GC
# TYPE jvm_gc_live_data_size_bytes gauge
jvm_gc_live_data_size_bytes{application="log-collection-demo",} 0.0
# HELP jvm_gc_memory_allocated_bytes_total Incremented for an increase in the size of the young generation memory pool after one GC to before the next
# TYPE jvm_gc_memory_allocated_bytes_total counter
jvm_gc_memory_allocated_bytes_total{application="log-collection-demo",} 5.4525952E7
# HELP system_cpu_count The number of processors available to the Java virtual machine
# TYPE system_cpu_count gauge
system_cpu_count{application="log-collection-demo",} 4.0
# HELP tomcat_sessions_alive_max_seconds
# TYPE tomcat_sessions_alive_max_seconds gauge
tomcat_sessions_alive_max_seconds{application="log-collection-demo",} 0.0
# HELP jvm_classes_unloaded_classes_total The total number of classes unloaded since the Java virtual machine has started execution
# TYPE jvm_classes_unloaded_classes_total counter
jvm_classes_unloaded_classes_total{application="log-collection-demo",} 1.0
# HELP jvm_classes_loaded_classes The number of classes that are currently loaded in the Java virtual machine
# TYPE jvm_classes_loaded_classes gauge
jvm_classes_loaded_classes{application="log-collection-demo",} 7899.0
# HELP jvm_threads_peak_threads The peak live thread count since the Java virtual machine started or peak was reset
# TYPE jvm_threads_peak_threads gauge
jvm_threads_peak_threads{application="log-collection-demo",} 22.0
# HELP system_load_average_1m The sum of the number of runnable entities queued to available processors and the number of runnable entities running on the available processors averaged over a period of time
# TYPE system_load_average_1m gauge
system_load_average_1m{application="log-collection-demo",} 0.11
...
Spring Boot 2.1 Statistics
https://grafana.com/grafana/dashboards/10280
curl http://localhost:8081/actuator/health
返回:{"status":"UP"}
docker build -t log-collection-demo .
docker run -d --name=log-collection-demo -p8080:8080 log-collection-demo
registry.cn-beijing.aliyuncs.com/liyongjian5179/log-collection-demo:latest
直接执行 ./build_start.sh
脚本即可
/usr/local/logs
cd log-sidecar
kubectl apply -f deployment.yaml
cd log-daemonset
kubectl apply -f daemonset.yaml
kubectl apply -f java-demo.yaml
应用通过 annotations 的方式开启日志收集,
filebeat.harvest: "true"
为开启,
filebeat.index: "xxxxxxxx"
写成对应的服务名即可
annotations:
filebeat.harvest: "true"
filebeat.index: "xxxxxxxx"
参照 https://github.com/fluent/fluentd-kubernetes-daemonset
即可
$ git clone https://github.com/fluent/fluentd-kubernetes-daemonset