prometheus简单监控Linux,mysql,nginx

prometheus安装
下载安装
#官网下载 解压即可使用
https://prometheus.io/download/
#docker 方式安装
sudo docker run -n prometheus -d -p 9090:9090 prom/prometheus
配置文件
/etc/prometheus/prometheus.yml 或 可执行文件当前目录下/prometheus.yml
完整配置文件
scheme: http
static_configs:
- targets:
- localhost:9090
- job_name: node1_self
honor_timestamps: true
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
static_configs:
- targets:
- 192.168.3.103:9100
- job_name: mysql
honor_timestamps: true
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
static_configs:
- targets:
- 192.168.3.103:9104
labels:
instance: db1
- job_name: nginx
honor_timestamps: true
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: /status/format/prometheus
scheme: http
static_configs:
- targets:
- 192.168.3.139:80
labels:
instance: web1
basic_auth:
username: UserName
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)
CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'password' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
$ cat .my.cnf
[client]
host=localhost
port=3306
user=root
password=123456
运行mysqld_exporter
`./mysqld_exporter --config.my-cnf=".my.cnf"在 prometheus服务端的配置文件
prometheus.yml中找到scrape_config子项 添加一个 job
如:
- job_name: mysql
static_configs:
- targets: ['192.168.1.7:9104']
labels:
instance: db1
- 发送 重载配置文件信号
killall -SIGHUP prometheus - 到prometheus 网页中
导航栏->status->target查看刚才添加的是否成功!
nginx exporter 安装和配置
好多方式都可以.lua脚本,openresty 等
我们选择 编译nginx的nginx-module-vts 这就意味着我们要自己手动编译了.
- 下载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 - 下载或克隆
nginx-module-vts模块 https://github.com/vozlt/nginx-module-vts - 编译安装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
user root;
#user nobody;
worker_processes 2;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
vhost_traffic_status_zone;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
charset utf-8;
#access_log logs/host.access.log main;
location / {
root html;
auth_basic "needAuth";
auth_basic_user_file /usr/local/nginx/conf/passwd.db;
}
location /status {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
配置http密码
apt install apache2-utils -y
htpasswd -c /usr/local/nginx/conf/passwd.db UserName
启动nginx
先看下模块有没编译进来
cd /usr/local/nginx/
/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中也要添加验证.要不没有办法支持访问
- job_name: nginx
honor_timestamps: true
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: /status/format/prometheus
scheme: http
static_configs:
- targets:
- 192.168.3.139:80
labels:
instance: web1
basic_auth:
username: UserName
password: PassWord
- 发送 重载配置文件信号
killall -SIGHUP prometheus - 到prometheus 网页中
导航栏->status->target查看刚才添加的是否成功!
之后可以使用配合Grafana可以愉快玩耍了.
prometheus简单监控Linux,mysql,nginx的更多相关文章
- Grafana+Prometheus系统监控之MySql
架构 grafana和prometheus之前安装配置过,见:Grafana+Prometheus打造全方位立体监控系统 MySql安装 MySql的地位和重要性就不言而喻了,作为开源产品深受广大中小 ...
- prometheus+grafana监控Linux和kubernetes的例子
1.安装和配置prometheus tar zxvf prometheus-.linux-amd64.tar.gz -C /usr/local/ ln -sv /usr/local/prometheu ...
- 服务器搭建纪录linux+mysql+nginx+php
新的项目启动 第一版 首先买了阿里云,选好环境镜像包,一键安装. 第一版php打算不用框架,完全手写,主要的功能点 数据交互和图片传输. 后台搭建好后,使用PHP的Laravel, web端还是选定b ...
- Prometheus + Grafana 监控系统搭
本文主要介绍基于Prometheus + Grafana 监控Linux服务器. 一.Prometheus 概述(略) 与其他监控系统对比 1 Prometheus vs. Zabbix Zabbix ...
- Grafana Prometheus系统监控Redis服务
Grafana Prometheus系统监控Redis服务 一.Grafana Prometheus系统监控Redis服务 1.1流程 1.2安装redis_exporter 1.3配置prometh ...
- 使有prometheus监控redis,mongodb,nginx,mysql,jmx
以下操作在CENTOS7环境. 使用prometheus做监控,使用grafana做dashboard的界面展示: 因prometheus自带的监控web界面图形化展示方面比较弱,推荐使用grafan ...
- 使用Prometheus+Grafana监控MySQL实践
一.介绍Prometheus Prometheus(普罗米修斯)是一套开源的监控&报警&时间序列数据库的组合,起始是由SoundCloud公司开发的.随着发展,越来越多公司和组织接受采 ...
- 初试 Prometheus + Grafana 监控系统搭建并监控 Mysql
转载自:https://cloud.tencent.com/developer/article/1433280 文章目录1.Prometheus & Grafana 介绍1.1.Prometh ...
- 安装prometheus+grafana监控mysql redis kubernetes等
1.prometheus安装 wget https://github.com/prometheus/prometheus/releases/download/v1.5.2/prometheus-1.5 ...
随机推荐
- Nomogram(诺莫图) | Logistic、Cox生存分析结果可视化
本文首发于“生信补给站”公众号,https://mp.weixin.qq.com/s/BWpy3F-nEKXCdVXmY3GYZg 当然还有更多R语言,生物信息学相关知识...
- 修改win7 iis上传文件大小限制200KB
win7 iis 修改上传限制,需要修改2个地方: 1,“双击“Internet 信息服务(IIS)管理器”中的“ASP”– 打开“配置 ASP 应用程序的属性”–展开“限制属性”:修改“最大请求实体 ...
- php 判断是是否是命令行模式
/* 判断当前的运行环境是否是cli模式 是:true 不是:false */ function is_cli(){ return preg_match("/cli/i", ...
- ASE19团队项目beta阶段Backend组 scrum8 记录
本次会议于12月17日,19:30在微软北京西二号楼sky garden召开,持续10分钟. 与会人员:Hao Wang, Lihao Ran, Xin Kang, Zhikai Chen 每个人的工 ...
- Linux下安装php报错:libxml2 not found. Please check your libxml2 installation
ubuntu/debian: apt-get install libxml2-dev centos/redhat: yum install libxml2-devel
- MVC方式显示数据(数据库)
新建实体数据模型 选择ADO.NET实体数据模型,名称改为数据库名 因为使用现有数据库,所以选择来自数据库的EF设计器,只演示所以只选择一个表,空模型可后期增加表 选择从数据库更新模型 新建数据库连接 ...
- 【OGG 故障处理】 丢失归档恢复
OGG 有两天由于某种原因没有启动,而这段时间的备份文件缺失了一部分归档.恢复过程记录如下: GGSCI (xxxx) > info all Program Status Group Lag a ...
- Image Processing and Analysis_8_Edge Detection:Edge and line oriented contour detection State of the art ——2011
此主要讨论图像处理与分析.虽然计算机视觉部分的有些内容比如特 征提取等也可以归结到图像分析中来,但鉴于它们与计算机视觉的紧密联系,以 及它们的出处,没有把它们纳入到图像处理与分析中来.同样,这里面也有 ...
- Linux学习笔记(七)Linux常用命令:挂载命令
一.查询与自动挂载 mount 查询系统中以及挂载的设备 mount -a 依据配置文件 etc/fstab的内容,自动挂载 二.挂载命令 特殊选项 三.挂载光盘 光盘的设备名是默认已知的,为sr0 ...
- idou老师教你学Istio 25:如何用istio实现监控和日志采集
大家都知道istio可以帮助我们实现灰度发布.流量监控.流量治理等功能.每一个功能都帮助我们在不同场景中实现不同的业务.那Istio是如何帮助我们实现监控和日志采集的呢? 这里我们依然以Bookinf ...