首页 > 技术文章 > prometheus

xiaoming619872862 2021-03-17 02:07 原文

普罗米修斯部署和监控k8s组件 可参考我的另一篇文章》》》链接

 

RabbitMQ内置支持普罗米修斯还自带grafana.dashboards  官网链接

redis  使用redis_exporter 链接

普罗米修斯提供很多出口商来供使用 出口商链接 

普罗米修斯监控SpringBoot应用 链接

下面将示例采集nginx:

基于debian8编译nginx,为nginx:1.18.0镜像添加nginx-module-vts模块的Dockerfile:

Dockerfile尽量用多阶段来写。自己从头构建镜差不多三百多MB 差距蛮大…可能是没把无用的清理干净吧

 

 

 

 

 

 

FROM debian:8
ADD ./nginx-1.18.0.tar.gz /
ADD ./nginx-module-vts.tar.gz /
RUN set -ex \
    && apt update \
    && apt -y install gcc make zlib1g* libssl-dev libpcre+* \
    && cd /nginx-1.18.0 \
    && ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-g -O2 -fdebug-prefix-map=/data/builder/debuild/nginx-1.18.0/debian/debuild-base/nginx-1.18.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie' --add-module=/nginx-module-vts \
    && make

FROM nginx:1.18.0
COPY --from=0 /nginx-1.18.0/objs/nginx /usr/sbin/nginx
COPY --from=0 /usr/lib/x86_64-linux-gnu/libssl.so.1.0.0 /usr/lib/x86_64-linux-gnu/libssl.so.1.0.0 #ldd nginx 对比编译后nginx和编译前nginx缺少哪些就补哪些
COPY --from=0 /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0
ENTRYPOINT ["/docker-entrypoint.sh"]
EXPOSE 80
STOPSIGNAL SIGQUIT
CMD ["nginx","-g","daemon off;"]
docker build -t liu:v4 . 

docker volume create nginx-conf

docker run -p 80 -v nginx-conf:/etc/nginx -d liu:v4

 

 

 配置文件添加以下内容:

http {
    vhost_traffic_status_zone;

    ...

    server {

        ...

        location /status {
            vhost_traffic_status_display;
            vhost_traffic_status_display_format html;
        }
    }
}

 

 

 

 

 

旧版本的nginx-module-vts 需要nginx-vts-exporter中转一下,普罗米修斯从出口商获取指标

新版本模块自身提供普罗米修斯格式的了,出口商已没多大意义。作者也表明不再维护出口商了。

nginx-module-vts链接

nginx-vts-exporter链接

普罗米修斯添加个刮取目标

 

 

 

 

grafana 仪表盘要找找看,一般找到也是要修改些的PromQL查询语句获取指标的

 

 

简单的示例一下报警规则和alertmanager

一些很棒的普罗米修斯警报 链接

普罗米修斯官网链接

普罗米修斯 报警规则

 

通过服务发现找到的告警经理,也可以用指定静态目标。在k8s服务发现很好用…

 

告警经理配置文件 也是简单示例…

 

 测试下关掉nginx就触发收到邮件

 

推荐阅读