prometheus监控linux模板,Prometheus监控可视化

f03e46ecba8406e55d18e3bd36eb886c.png

Node_exporter安装(监控节点)

下载安装包

解压安装包1

2# tar -xvf node_exporter-0.18.1.linux-amd64.tar.gz

# mv node_exporter-0.18.1.linux-amd64 /usr/local/node_exporter

加入环境变量1

2# echo "export PATH=$PATH:/usr/local/node_exporter" >> /etc/profile

# source /etc/profile

启动node_exporter1# node_exporter &

Prometheus安装

下载安装包

解压安装包1

2# tar -xvf prometheus-2.13.1.linux-amd64.tar.gz

# mv prometheus-2.13.1.linux-amd64 /usr/local/prometheus

加入环境变量1

2# echo "export PATH=$PATH:/usr/local/prometheus" >>/etc/profile

# source /etc/profile

配置参数(/usr/local/prometheus/prometheus.yml)1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27global:

scrape_interval:     15s

evaluation_interval: 15s

- job_name: prometheus

static_configs:

- targets: ['localhost:9090']

labels:

instance: prometheus

- job_name: t-luhxdb1

static_configs:

- targets: ['10.0.139.161:9100']

labels:

instance: db1

- job_name: t-luhxdb2

static_configs:

- targets: ['10.0.139.162:9100']

labels:

instance: db2

- job_name: t-luhxdb3

static_configs:

- targets: ['10.0.139.163:9100']

labels:

instance: db3

启动Prometheus1# prometheus --config.file="/usr/local/prometheus/prometheus.yml" &

Grafana安装

下载安装包

安装grafana1# rpm -ivh grafana-6.4.3-1.x86_64.rpm

安装字体包1# yum install urw-fonts freetype* fontconfig -y

开启dashboard(/etc/grafana/provisioning/dashboards/sample.yaml)1

2

3

4

5

6

7

8

9

10

11# # config file version

apiVersion: 1

providers:

- name: 'default'

orgId: 1

folder: ''

folderUid: ''

type: file

options:

path: /var/lib/grafana/dashboards

开启插件参数(/etc/grafana/grafana.ini)1# plugins = /var/lib/grafana/plugins

Grafana Lab下载Dashboard模板并上传至/var/lib/grafana/dashboards1# chown -R grafana.grafana 1-node-exporter-0-16-0-18-for-prometheus_rev1.json

Grafana Lab下载piechat插件并上传至/var/lib/grafana/plugins1

2

3# unzip  grafana-piechart-panel-v1.3.9-0-gec46c48.zip

# mv  grafana-piechart-panel-gec46c48 /var/lib/grafana/plugins/grafana-piechart-panel

# chown -R grafana.grafana /var/lib/grafana/plugins/grafana-piechart-panel

启动Grafana1# systemctl start grafana-server

查看监控

f03e46ecba8406e55d18e3bd36eb886c.png

MySQL数据库监控

下载mysqld_exporter

创建MySQL用户1

2

3root@(none) 10:38:  grant replication client,process on *.* to 'exporter'@'localhost' identified by 'Abcd123#';

root@(none) 10:38:  grant select on performance_schema.* to 'exporter'@'localhost';

root@(none) 10:39:  flush privileges;

设置环境变量1

2# echo "export DATA_SOURCE_NAME='exporter:Abcd123#@(localhost:33006)/'" >> /etc/profile

# source /etc/profile

启动mysqld_exporter1# /usr/local/mysqld_exporter/mysqld_exporter &

添加prometheus参数1

2

3

4

5- job_name: t-luhxdb3

static_configs:

- targets: ['10.0.139.163:9100']

labels:

instance: db3

Consul服务发现

通过Consul可以动态注册监控服务,无需每次添加监控对象都重启Prometheus

下载Consul

解压并以WEB UI方式启动Consul1

2# unzip consul_1.0.0_linux_amd64.zip

# ./consul agent -server -ui -bootstrap-expect 1 -data-dir /tmp/consul -client 0.0.0.0 &

查看启动状态1

2

3# ./consul members

Node             Address            Status  Type    Build  Protocol  DC   Segment

t-luhx01-v-szzb  10.0.139.161:8301  alive   server  1.0.0  2         dc1  

HTTP方式注册服务1# curl -X PUT -d '{"id":"mysql","name":"mysql","address":"10.0.139.163","port":9104,"tags":["test"],"checks":[{"http":"http://10.0.139.163.9104/","interval":"5s"}]}' http://localhost:8500/v1/agent/service/register

配置文件方式注册服务(/etc/consul.d/mysql.json)1

2

3

4

5

6

7

8

9

10

11

12

13

14"service":{

"id": "mysql",

"name": "mysql",

"address": "10.0.139.162",

"port": 9104,

"tags": ["test"],

"checks": [

{

"http": "http://10.0.139.162:9104",

"interval": "5s"

}

]

}

}

修改Prometheus参数1

2

3

4

5

6

7

8

9

10

11

12

13global:

scrape_interval:     15s

evaluation_interval: 15s

- job_name: prometheus

static_configs:

- targets: ['localhost:9090']

labels:

instance: prometheus

- job_name: 'consul'

consul_sd_configs:p

- server: 'localhost:8500'

services: ['redis', 'mysql', 'linux']

指定文件启动1# ./consul agent -server -ui -bootstrap-expect 1 -data-dir /tmp/consul -config-dis /etc/consul.d -client 0.0.0.0 &

修改配置文件重新加载1# consul reload

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值