prometheus
下载 prometheus-3.0.0.linux-amd64.tar.gz
tar -zxvf prometheus-3.0.0.linux-amd64.tar.gz
mv prometheus-3.0.0.linux-amd64 prometheus-3
vim /etc/systemd/system/prometheus.service
prometheus.service
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=ubuntu
Group=ubuntu
Type=simple
ExecStart=/home/ubuntu/jiankong/prometheus/prometheus-3/prometheus \
--config.file /home/ubuntu/jiankong/prometheus/prometheus-3/prometheus.yml \
--storage.tsdb.path /home/ubuntu/jiankong/prometheus/prometheus-3/data \
--web.listen-address=0.0.0.0:9090
[Install]
WantedBy=multi-user.target
vim prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. linux 服务器的监控
- job_name: "node_ex"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9100"]
# mysql 监控
- job_name: "mysql_ex"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9104"]
启动停止命令
sudo systemctl status prometheus
sudo systemctl start prometheus
sudo systemctl restart prometheus
sudo systemctl stop prometheus
node_exporter
下载 node_exporter-1.8.2.linux-amd64.tar.gz
tar -zxvf node_exporter-1.8.2.linux-amd64.tar.gz
mv node_exporter-1.8.2.linux-amd64 node_exporter
vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
After=network.target
User=ubuntu
Group=ubuntu
[Service]
ExecStart=/home/ubuntu/jiankong/prometheus/node_exporter/node_exporter\
--web.listen-address=:9100\
--collector.systemd\
--collector.systemd.unit-whitelist=(sshd|nginx).service\
--collector.processes\
--collector.tcpstat
[Install]
WantedBy=multi-user.target
## 监听端口 9100
## 启动 停止命令
sudo systemctl status node_exporter
sudo systemctl start node_exporter
sudo systemctl restart node_exporter
sudo systemctl stop node_exporter
mysqld_exporter
下载 mysqld_exporter-0.16.0.linux-amd64.tar.gz
vim /usr/lib/systemd/system/mysqld_exporter.service
[Unit]
Description=mysqld_exporter
After=network.target
#User=ubuntu
#Group=ubuntu
[Service]
ExecStart=/home/ubuntu/jiankong/prometheus/mysqld_exporter/mysqld_exporter \
--collect.info_schema.processlist \
--collect.info_schema.innodb_tablespaces \
--collect.info_schema.innodb_metrics \
--collect.perf_schema.tableiowaits \
--collect.perf_schema.indexiowaits \
--collect.perf_schema.tablelocks \
--collect.engine_innodb_status \
--collect.perf_schema.file_events \
--collect.binlog_size \
--collect.info_schema.clientstats \
--collect.perf_schema.eventswaits \
--config.my-cnf=/home/ubuntu/jiankong/prometheus/mysqld_exporter/my.cnf
[Install]
WantedBy=multi-user.target
vim my.cnf
[client]
user=root
password=123456
默认端口 9104
sudo systemctl status mysqld_exporter
sudo systemctl restart mysqld_exporter
sudo systemctl start mysqld_exporter
sudo systemctl stop mysqld_exporter
grafana
下载 grafana-enterprise-11.3.1.linux-amd64.tar.gz
tar -zxvf grafana-enterprise-11.3.1.linux-amd64.tar.gz
mv grafana-enterprise-11.3.1.linux-amd64 grafana
vim /etc/systemd/system/grafana.service
[Unit]
Description=grafana
[Service]
ExecStart=/home/ubuntu/jiankong/prometheus/grafana/bin/grafana-server -homepath=/home/ubuntu/jiankong/prometheus/grafana
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
## vim defaults.ini
## 处理跨域问题
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana
allowed_origins = *
allow_embedding = true
默认端口 5000
sudo systemctl status grafana
sudo systemctl restart grafana
sudo systemctl start grafana
sudo systemctl stop grafana
nginx 代理 解决跨域
location /grafana {
root html;
index index.html index.htm;
add_header 'Access-Control-Allow-Origin' '*';
add_header Access-Control-Allow-Methods GET,POST,OPTIONS,DELETE;
add_header 'Access-Control-Allow-Headers' 'userId,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
proxy_pass http://127.0.0.1:5000;
rewrite ^/grafana/(.*) /$1 break;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
# websocket处理
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}