prometheus installation
Download and install
#官网下载 解压即可使用
https://prometheus.io/download/
#docker 方式安装
sudo docker run -n prometheus -d -p 9090:9090 prom/prometheus
Profiles
/etc/prometheus/prometheus.yml 或 可执行文件当前目录下/prometheus.yml
Complete profile
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
Restart Service
Restart the service or signal reload the configuration
killall -HUP prometheus
Daquan official exports
https://prometheus.io/docs/instrumenting/exporters/
Linux server configuration
Download and install node_exporter (download extract can be used)
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 download and configure the exporter
Mysql can be installed on the machine can also be installed on other machines
`the old way must extract
https://github.com/prometheus/mysqld_exporter/releases
- To configure what information is being monitored mysql account
best configure permissions individually
to mysqld_exporter create a separate user
and give it limited authority (PROCESS, REPLICATION CLIENT, SELECT)
preferably also limit its maximum number (MAX_USER_CONNECTIONS) connection
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"- In prometheus server configuration files
prometheus.yml
found in thescrape_config
Add child a job
such as:
- job_name: mysql
static_configs:
- targets: ['192.168.1.7:9104']
labels:
instance: db1
- Overload signal transmission profile
killall -SIGHUP prometheus
- Prometheus pages to
导航栏->status->target
see just added success!
Installation and Configuration nginx exporter
Many ways can .lua script, openresty and so
we have chosen to compile the nginx nginx-module-vts
This means that we have to manually compile their own.
- Download nginx source after decompression.
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
- Download or cloning
nginx-module-vts
module https://github.com/vozlt/nginx-module-vts - Compile and install nginx
compiled rely skip
..
./auto/configure --add-module=/home/pi/nginx-module-vts --with-http_ssl_module --with-debug
kill nginx
make -j4
using four threads compiler. Raspberry Pi has four threads
make install
install nginx default
4. Configure nginx configuration file
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;
}
}
}
Configuring http password
apt install apache2-utils -y
htpasswd -c /usr/local/nginx/conf/passwd.db UserName
to start nginx
look under the module has not compiled in
cd /usr/local/nginx/
/usr/local/nginx/sbin/nginx -V |grep nginx-module-vts
You can see the information on behalf of the compiler module successfully.
- Running nginx
/usr/local/nginx/sbin/nginx
4.1 View ip nginx machine
ip a
- Add a monitoring mission in prometheus the nginx
add content configuration profileprometheus.yml
attention because we nginx configuration verification, validation prometheus so they will have to add in. Otherwise there is no way supports access
- 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
- Overload signal transmission profile
killall -SIGHUP prometheus
- Prometheus pages to
导航栏->status->target
see just added success!
And be followed with a Grafana can have fun.