loki 是一個方便的相似prometheus 的log 系統,mtail 是一個方便的日誌提取工具,
能夠暴露爲http 服務——支持導出prometheus metricshtml
version: "3"
services:
nginx-log:
build: ./
ports:
- "8090:80"
- "3903:3903"
volumes:
- "./examples/linecount.mtail:/progs/linecount.mtail"
- $PWD:/etc/promtail
loki:
image: grafana/loki:master
ports:
- "3100:3100"
volumes:
- $PWD:/etc/loki
command: -config.file=/etc/loki/loki-local-config.yaml
promtail:
image: grafana/promtail:make-images-static-26a87c9
volumes:
- $PWD:/etc/promtail
- ./log:/var/log
command:
-config.file=/etc/promtail/promtail-docker-config.yaml
grafana:
image: grafana/grafana:master
ports:
- "3000:3000"
environment:
- "GF_EXPLORE_ENABLED=true"
prometheus:
image: prom/prometheus
volumes:
- "./prometheus.yml:/etc/prometheus/prometheus.yml"
ports:
- "9090:9090"
FROM dalongrong/mtail as builder
FROM grafana/promtail:make-images-static-26a87c9 as promtail
FROM openresty/openresty:alpine
ENV TINI_VERSION v0.18.0
RUN apk add --update \
&& apk add --no-cache tini
ADD entrypoint.sh /entrypoint.sh
ADD mtail.sh /mtail.sh
ADD promtail.sh /promtail.sh
COPY nginx.conf usr/local/openresty/nginx/conf/
COPY --from=builder /usr/bin/mtail /usr/bin/
COPY --from=promtail /usr/bin/promtail /usr/bin/
EXPOSE 80 3903
ENTRYPOINT ["/sbin/tini","-s", "--", "/entrypoint.sh"]
#!/bin/sh
sh mtail.sh
sh promtail.sh
exec /usr/local/openresty/bin/openresty -g "daemon off;"
mtail.sh:
#!/bin/sh
nohup /usr/bin/mtail -logtostderr -progs /progs/linecount.mtail -logs /var/log/error.log &
promtail.sh:
#!/bin/sh
nohup /usr/bin/promtail -config.file=/etc/promtail/promtail-docker-config2.yaml &
scrape_configs:
- job_name: openresty-metrics
metrics_path: /metrics
static_configs:
- targets: ['nginx-log:3903']
promtail-docker-config2.yaml:
server:
http_listen_port: 0
grpc_listen_port: 0
positions:
filename: /tmp/positions.yaml
client:
url: http://loki:3100/api/prom/push
scrape_configs:
- job_name: system
entry_parser: raw
static_configs:
- targets:
- localhost
labels:
job: varlogs-nginx
__path__: /var/log
# Copyright 2011 Google Inc. All Rights Reserved.
# This file is available under the Apache license.
counter line_count
/$/ {
line_count++
}
docker-compose build
docker-compose up -d
grafana 的log 功能很方便,這樣咱們能夠同時支持分析,以及問題排查了,並且不須要使用太多的工具就能解決問題nginx
http://www.javashuo.com/article/p-dopsbutp-b.html
https://github.com/grafana/loki#getting-started
https://github.com/rongfengliang/grafana-loki-demo
https://github.com/google/mtail/blob/master/docs/Building.md
https://github.com/rongfengliang/mtail-nginx-docker-compose-demogit