loki 是一个方便的类似prometheus 的log 系统,mtail 是一个方便的日志提取工具,
可以暴露为http 服务——支持导出prometheus metrics

环境准备

  • docker-compose 文件
 
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"
 
  • dockerfile 说明
    dockerfile 主要是一个简单的openresty 服务,集成了mtail+loki,dockerfile 使用multi stage 处理
 
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"]
 
 
  • 启动脚本(entrypoint)
#!/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 & 
 
 
  • prometheus server 配置
    prometheus.yml 文件
 
scrape_configs:
  - job_name: openresty-metrics
    metrics_path: /metrics
    static_configs:
      - targets: ['nginx-log:3903']
 
 
  • loki 配置
    主要是agent 以及server
 
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
 
 
  • mtail 配置
# 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 配置
    很简单,需要配置的有datasource(loki,prometheus)
  • 测试
    模拟访问故障 http://localhost:8090/demoapp
    mtail 界面


    prometheus server

    集成metrics&&log 分析

说明

grafana 的log 功能很方便,这样我们可以同时支持分析,以及问题排查了,而且不需要使用太多的工具就能解决问题

参考资料

https://www.cnblogs.com/rongfengliang/p/10112500.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-demo

使用loki+ mtail + grafana + prometheus server分析应用问题的更多相关文章

  1. grafana根据不同prometheus server统计数据

    场景:由于采集的数据量巨大,所以部署了多台prometheus server服务器.根据业务领域分片采集,减轻prometheus server单节点的压力. 问题:grafana如何同时显示多数据源 ...

  2. 性能测试之数据库监控分析工具Grafana+Prometheus

    使用到 Grafana+Prometheus+Mysql_exportor 使用Prometheus和Grafana,可以快速的构建我们性能测试的绝大多数的监控模型:数据库监控.服务器监控.Jvm监控 ...

  3. Docker系列——Grafana+Prometheus+Node-exporter服务器监控平台(一)

    在最近的博文中,都是介绍监控平台的搭建,其实并不难,主要是需要自己动手操作,实践一番就会了. 有天在想,云上的服务器,是不是也可以搭建一个监控平台,所以就捣鼓了一下,不过遗憾的是,使用阿里云开源的插件 ...

  4. Grafana+Prometheus 搭建 JuiceFS 可视化监控系统

    作为承载海量数据存储的分布式文件系统,用户通常需要直观地了解整个系统的容量.文件数量.CPU 负载.磁盘 IO.缓存等指标的变化. JuiceFS 没有重复造轮子,而是通过 Prometheus 兼容 ...

  5. Grafana+Prometheus打造全方位立体监控系统

    前言 本文主要介绍如何使用Grafana和Prometheus以及node_exporter对Linux服务器性能进行监控.下面两张图分别是两台服务器监控信息: 服务器A 服务器B 概述 Promet ...

  6. Grafana + Prometheus 监控PostgreSQL

    效果图 部署环境 服务器名称 IP地址 部署业务 备注 部署agent sht-sgmhadoopcm-01 172.16.101.54 PostgreSQL 监控服务器.被监控服务器 node_ex ...

  7. 使用nginx统一代理dashboard,grafana,Prometheus二级目录访问

    k8s上的这些管理工具必不可少,可以统一在nginx下的二级目录下. ingress是好,但我们不方便使用内部域名,相信么...:) 一,prometheus改造 在prometheus的deploy ...

  8. Grafana+prometheus+AlertManager+钉钉机器人

    一.Grafana (1)安装Grafana的Linux环境 在官网下载windows的Grafana的压缩包到指定目录,解压缩Grafana压缩文件到包含当前Grafana版本的文件夹.将该文件夹解 ...

  9. windows下部署Grafana +prometheus平台监控

      1.Prometheus简介 Prometheus基于Golang编写,编译后的软件包,不依赖于任何的第三方依赖.用户只需要下载对应平台包,解压并且添加基本的配置即可正常启Prometheus S ...

随机推荐

  1. 如何在ubuntu上搭建hustoj?

    1.安装MySQL apt-get install mysql-server mysql-client 安装的过程会弹出一个框,输入sql密码,按TAB切换到ok 2.安装apache2 apt-ge ...

  2. Matlab产生波形数据文件

    reference: https://blog.csdn.net/HOOKNET/article/details/79254351 前言 在FPGA开发过程中几乎都要用到仿真的功能,对于一些简单的外部 ...

  3. 多War包合并,jetty测试

    模块间的相互依赖引用配置在pom.xml中加入要依赖的模块即可<dependency>    <groupId>com.exayong</groupId>    & ...

  4. HihoCoder - 1483 区间最值

    给定n个数A1...An,小Ho想了解AL..AR中有多少对元素值相同.小Ho把这个数目定义为区间[L,R]的价值,用v[L,R]表示. 例如1 1 1 2 2这五个数所组成的区间的价值为4. 现在小 ...

  5. marquee 的浏览器兼容性

    marquee 在IE,firefox,chrome ,safari下都能正常的实现走马灯效果,兼容性没有问题 并且两个关键属性scrollamount(滚动速度)direction(滚动方向) 所有 ...

  6. Python代码 注释

    对某些代码进行标注说明,增加程序的可读性. 一.单行注释 以“#” 开头,#后面的所有东西都不会被运行 print("hello python") # 输出 `hello pyth ...

  7. 转-Asynchronous bulk transfer using libusb

    https://falsinsoft.blogspot.jp/2015/02/asynchronous-bulk-transfer-using-libusb.html The 'linusb' is ...

  8. 集合(ArrayList)简述

    ArrayList创建变量的步骤 1.导入包java.util.ArrayList; 2.创建引用类型的变量 数据类型<集合存储的数据类型> 变量名=new 数据类型<集合存储的数据 ...

  9. Python 深度递归

    class A: pass class B(A): pass class C(A): pass class D(B, C): pass class E: pass class F(D, E): pas ...

  10. SQL注入之Sqli-labs系列第五关和第六关(基于GET型的报错注入)

    废话不在多说  let's go! 开始挑战第五关(Double Query- Single Quotes- String) 和第六关(Double Query- Double Quotes- Str ...