prometheus安装

下载安装

  1. #官网下载 解压即可使用
  2. https://prometheus.io/download/
  3. #docker 方式安装
  4. sudo docker run -n prometheus -d -p 9090:9090 prom/prometheus

配置文件

  1. /etc/prometheus/prometheus.yml 可执行文件当前目录下/prometheus.yml

完整配置文件

  1. scheme: http
  2. static_configs:
  3. - targets:
  4. - localhost:9090
  5. - job_name: node1_self
  6. honor_timestamps: true
  7. scrape_interval: 15s
  8. scrape_timeout: 10s
  9. metrics_path: /metrics
  10. scheme: http
  11. static_configs:
  12. - targets:
  13. - 192.168.3.103:9100
  14. - job_name: mysql
  15. honor_timestamps: true
  16. scrape_interval: 15s
  17. scrape_timeout: 10s
  18. metrics_path: /metrics
  19. scheme: http
  20. static_configs:
  21. - targets:
  22. - 192.168.3.103:9104
  23. labels:
  24. instance: db1
  25. - job_name: nginx
  26. honor_timestamps: true
  27. scrape_interval: 15s
  28. scrape_timeout: 10s
  29. metrics_path: /status/format/prometheus
  30. scheme: http
  31. static_configs:
  32. - targets:
  33. - 192.168.3.139:80
  34. labels:
  35. instance: web1
  36. basic_auth:
  37. username: UserName
  38. password: PassWord

重启服务

重启服务或发信号重新加载配置

killall -HUP prometheus

官方exports 大全

https://prometheus.io/docs/instrumenting/exporters/

Linux服务器配置

下载安装node_exporter (下载解压即可使用)

https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz

./node_exporter

测试node_exporter

curl http://localhost:9100/metrics

mysql的exporter下载和配置

可以在mysql机器上安装也可以在别的机器上安装

`. 老样子下载解压

https://github.com/prometheus/mysqld_exporter/releases

2. 要配置一下被监控的mysql账户信息

最好单独配置权限

为 mysqld_exporter 创建一个单独的用户

并赋予它受限的权限(PROCESS、REPLICATION CLIENT、SELECT)

最好还限制它的最大连接数(MAX_USER_CONNECTIONS)

  1. CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'password' WITH MAX_USER_CONNECTIONS 3;
  2. GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';

$ cat .my.cnf

  1. [client]
  2. host=localhost
  3. port=3306
  4. user=root
  5. password=123456
  1. 运行mysqld_exporter

    `./mysqld_exporter --config.my-cnf=".my.cnf"

  2. 在 prometheus服务端的配置文件prometheus.yml中找到 scrape_config子项 添加一个 job

    如:

  1. - job_name: mysql
  2. static_configs:
  3. - targets: ['192.168.1.7:9104']
  4. labels:
  5. instance: db1
  1. 发送 重载配置文件信号

    killall -SIGHUP prometheus
  2. 到prometheus 网页中 导航栏->status->target 查看刚才添加的是否成功!

nginx exporter 安装和配置

好多方式都可以.lua脚本,openresty 等

我们选择 编译nginx的nginx-module-vts 这就意味着我们要自己手动编译了.

  1. 下载nginx源码后解压.

    wget https://github.com/nginx/nginx/releases/tag/release-1.17.1

    tar -xvf nginx-release-1.17.1.tar.gz

    cd nginx-release-1.17.1
  2. 下载或克隆nginx-module-vts 模块 https://github.com/vozlt/nginx-module-vts
  3. 编译安装nginx

    安装依赖(centos)
  • openssl-devel
  • pcre-devel
  • gcc

./auto/configure --add-module=/home/pi/nginx-module-vts --with-http_ssl_module --with-debug

干掉nginx

make -j4 使用4个线程编译.树莓派有四个线程

make install 安装nginx默认

4.配置nginx的配置文件

vim /usr/local/nginx/conf/nginx.conf

  1. user root;
  2. #user nobody;
  3. worker_processes 2;
  4. #error_log logs/error.log;
  5. #error_log logs/error.log notice;
  6. #error_log logs/error.log info;
  7. #pid logs/nginx.pid;
  8. events {
  9. worker_connections 1024;
  10. }
  11. http {
  12. include mime.types;
  13. default_type application/octet-stream;
  14. vhost_traffic_status_zone;
  15. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  16. # '$status $body_bytes_sent "$http_referer" '
  17. # '"$http_user_agent" "$http_x_forwarded_for"';
  18. #access_log logs/access.log main;
  19. sendfile on;
  20. #tcp_nopush on;
  21. #keepalive_timeout 0;
  22. keepalive_timeout 65;
  23. #gzip on;
  24. server {
  25. listen 80;
  26. server_name localhost;
  27. #charset koi8-r;
  28. charset utf-8;
  29. #access_log logs/host.access.log main;
  30. location / {
  31. root html;
  32. auth_basic "needAuth";
  33. auth_basic_user_file /usr/local/nginx/conf/passwd.db;
  34. }
  35. location /status {
  36. vhost_traffic_status_display;
  37. vhost_traffic_status_display_format html;
  38. }
  39. #error_page 404 /404.html;
  40. # redirect server error pages to the static page /50x.html
  41. #
  42. error_page 500 502 503 504 /50x.html;
  43. location = /50x.html {
  44. root html;
  45. }
  46. }
  47. }

配置http密码

apt install apache2-utils -y

htpasswd -c /usr/local/nginx/conf/passwd.db UserName

启动nginx

先看下模块有没编译进来

  1. cd /usr/local/nginx/
  2. /usr/local/nginx/sbin/nginx -V |grep nginx-module-vts

能看到信息就代表模块编译成功.

4. 运行nginx

/usr/local/nginx/sbin/nginx

4.1 查看nginx机器的ip

ip a

5. 在prometheus中增加一个监控nginx的任务

添加配置内容在配置文件 prometheus.yml 注意因为我们nginx配置了验证,所以在prometheus中也要添加验证.要不没有办法支持访问

  1. - job_name: nginx
  2. honor_timestamps: true
  3. scrape_interval: 15s
  4. scrape_timeout: 10s
  5. metrics_path: /status/format/prometheus
  6. scheme: http
  7. static_configs:
  8. - targets:
  9. - 192.168.3.139:80
  10. labels:
  11. instance: web1
  12. basic_auth:
  13. username: UserName
  14. password: PassWord
  1. 发送 重载配置文件信号

    killall -SIGHUP prometheus
  2. 到prometheus 网页中 导航栏->status->target 查看刚才添加的是否成功!

之后可以使用配合Grafana可以愉快玩耍了.

prometheus简单监控Linux,mysql,nginx的更多相关文章

  1. Grafana+Prometheus系统监控之MySql

    架构 grafana和prometheus之前安装配置过,见:Grafana+Prometheus打造全方位立体监控系统 MySql安装 MySql的地位和重要性就不言而喻了,作为开源产品深受广大中小 ...

  2. prometheus+grafana监控Linux和kubernetes的例子

    1.安装和配置prometheus tar zxvf prometheus-.linux-amd64.tar.gz -C /usr/local/ ln -sv /usr/local/prometheu ...

  3. 服务器搭建纪录linux+mysql+nginx+php

    新的项目启动 第一版 首先买了阿里云,选好环境镜像包,一键安装. 第一版php打算不用框架,完全手写,主要的功能点 数据交互和图片传输. 后台搭建好后,使用PHP的Laravel, web端还是选定b ...

  4. Prometheus + Grafana 监控系统搭

    本文主要介绍基于Prometheus + Grafana 监控Linux服务器. 一.Prometheus 概述(略) 与其他监控系统对比 1 Prometheus vs. Zabbix Zabbix ...

  5. Grafana Prometheus系统监控Redis服务

    Grafana Prometheus系统监控Redis服务 一.Grafana Prometheus系统监控Redis服务 1.1流程 1.2安装redis_exporter 1.3配置prometh ...

  6. 使有prometheus监控redis,mongodb,nginx,mysql,jmx

    以下操作在CENTOS7环境. 使用prometheus做监控,使用grafana做dashboard的界面展示: 因prometheus自带的监控web界面图形化展示方面比较弱,推荐使用grafan ...

  7. 使用Prometheus+Grafana监控MySQL实践

    一.介绍Prometheus Prometheus(普罗米修斯)是一套开源的监控&报警&时间序列数据库的组合,起始是由SoundCloud公司开发的.随着发展,越来越多公司和组织接受采 ...

  8. 初试 Prometheus + Grafana 监控系统搭建并监控 Mysql

    转载自:https://cloud.tencent.com/developer/article/1433280 文章目录1.Prometheus & Grafana 介绍1.1.Prometh ...

  9. 安装prometheus+grafana监控mysql redis kubernetes等

    1.prometheus安装 wget https://github.com/prometheus/prometheus/releases/download/v1.5.2/prometheus-1.5 ...

随机推荐

  1. Mobile Phone Network CodeForces - 1023F (最小生成树)

    大意: 无向图, 其中k条边是你的, 边权待定, m条边是你对手的, 边权已知. 求如何设置边权能使最小生成树中, 你的边全被选到, 且你的边的边权和最大. 若有多棵最小生成树优先取你的边. 先将$k ...

  2. jvm类加载原理和类加载器介绍

    虚拟机的类加载机制 在Class文件中描述的各种信息最终都需要加载到虚拟机中之后才能运行和使用.   虚拟机把描述类的数据从Class文件加载到内存,并对数据进行校验,转换解析和初始化,最终形成可以被 ...

  3. WebSocket协议探究(序章)

    一 WebSocket协议基于HTTP和TCP协议 与往常一样,进入WebSocket协议学习之前,先进行WebSocket协议抓包,来一个第一印象. WebSocket能实现客户端和服务器间双向.基 ...

  4. 解决https 请求过程中SSL问题

    最近一个项目中用到了https的请求,在实际调用过程中发现之前的http方法不支持https,调用一直报错. 查询了一下,添加几行代码解决问题. public string HttpPost(stri ...

  5. 第三代PacBio测序技术的测序原理和读长

    针对PacBio单分子测序——第三代测序技术的测序原理和读长     DNA基因测序技术从上世纪70年代起,历经三代技术后,目前已发展成为一项相对成熟的生物产业.测序技术的应用也扩展到了生物.医学.制 ...

  6. 现有项目springmvc 小结

    1. 接口接收json数据 @RequestBody JSONObject param 2.返回json数据封装 DataPacket.jsonResult

  7. 服务器去掉IE浏览器网络安全限制

  8. 将用户赋予sudo权限:配置sudoers文件

    xxx is not in the sudoers file.This incident will be reported.的解决方法   1.切换到root用户下,怎么切换就不用说了吧,不会的自己百 ...

  9. selenium实现登录百度(自动识别简单验证码)

    需要做的工作 0.工程结构 1.代码: ①baidu_login.py import re import os import sys import time import random from se ...

  10. 【Redis】事务 (超详细)

    一.概述 二.相关命令列表 2.1 MULTI 2.2 EXEC 2.3 DISCARD 2.4 WATCH key [key ...] 2.5 UNWATCH 三.命令示例 3.1 事务被正常执行 ...