Promethus+Grafana 监控linux、windows节点以及Tomcat项目

文件下载地址

Promethus https://github.com/prometheus/prometheus/releases/download/v2.9.1/prometheus-2.9.1.linux-amd64.tar.gz
Grafana https://dl.grafana.com/oss/release/grafana-5.4.2-1.x86_64.rpm
Linux节点 https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz
windows 节点 https://github.com/martinlindhe/wmi_exporter/releases/download/v0.7.0/wmi_exporter-0.7.0-386.exe
jmx_prometheus https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.3.1/jmx_prometheus_javaagent-0.3.1.jar

安装Promethus

选择目录下载文件

wget https://github.com/prometheus/prometheus/releases/download/v2.9.1/prometheus-2.9.1.linux-amd64.tar.gz
wget https://dl.grafana.com/oss/release/grafana-5.4.2-1.x86_64.rpm

解压promethus

tar -zxvf prometheus-2.9.1.linux-amd64.tar.gz
cd prometheus-2.9.1.linux-amd64

/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
启动Promethus(加上&,表示后台启动)

./promethus &

访问http://IP:9090,可打开Promethus自带的监控页面;
在这里插入图片描述

安装Grafana

wget https://dl.grafana.com/oss/release/grafana-5.4.2-1.x86_64.rpm
rpm -ivh --nodeps grafana-5.4.2-1.x86_64.rpm
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable grafana-server.service
sudo /bin/systemctl start grafana-server.service

访问http://IP:3000,可打开Grafana图形页面;

在这里插入图片描述
默认用户名密码都是admin,初次登录会要求修改默认的登录密码,登陆后添加数据源“Add data source”,选择Promethus

在这里插入图片描述在这里插入图片描述
Dashboards页面选择“Prometheus 2.0 Stats” ,Settings页面填写普罗米修斯地址并保存

在这里插入图片描述
在这里插入图片描述
切换到我们刚才添加的“Prometheus 2.0 Stats”即可看到整个监控页面
在这里插入图片描述

监控linux机器(node-exporter)

  • Linux 节点

安装node-exporter

wget https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz
tar –zxvf node_exporter-0.17.0.linux-amd64.tar.gz
cd node_exporter-0.17.0.linux-amd64
./node_exporter &(默认端口为9100)

启动后浏览器访问http://IP:9100,查看信息,如出现以下信息,则客户端配置正确

在这里插入图片描述
在这里插入图片描述

  • 服务端

cd prometheus-2.9.1.linux-amd64
vim prometheus.yml

添加如下信息

- job_name: 'linux'
  static_configs:
  - targets: ['IP(域名):9100']
    labels:
      instance: Prometheus

grafana导入画好的dashboard
链接:https://pan.baidu.com/s/1BT2TF85Wq79WAQ6O2eQvyA 提取码:v4s9
管理添加
上传json模型

选择版本
如果没有任何显示,是grafana缺少相关显示需要用到的插件piechart,grafana的默认插件目录是/var/lib/grafana/plugins,可以将下载好的插件解压到这个目录,重启grafana即可
piechart插件: 链接:https://pan.baidu.com/s/1XctVmKroMt484tRDtgVdRA 提取码:bv5d

service grafana-server restart
/usr/sbin/grafana-cli plugins ls #查看已安装插件

再刷新grafana页面,即可看到我们刚才设置好的node监控

监控页面

监控windows机器(wmi-exporter)

被监控windows机器安装wmi-exporter,下载节点监控程序并运行,默认端口9182

下载地址: https://github.com/martinlindhe/wmi_exporter/releases/download/v0.7.0/wmi_exporter-0.7.0-386.exe
浏览器访问:http://IP:9182,出现如下信息则,客户端节点正常
windows信息

  • 服务端

cd prometheus-2.9.1.linux-amd64
vim prometheus.yml

添加如下信息

 - job_name: 'windows'
  static_configs:
 - targets: ['IP(域名):9182]
    labels:
      instance: windows

重启Promethus
grafana导入画好的dashboard,选择普罗米修斯数据源
链接:https://pan.baidu.com/s/1iSZar_UoZm1L2qIUEV5FTw 提取码:i1pn
同样的方法导入画好的json文件
导入jsonwindows监控

监控tomcat项目(jmx_exporter )

下载jmx_exporter、以及配置文件
jmx_exporter下载链接:https://pan.baidu.com/s/1nVSTyi6IRZqG5d1lbqWWYg 提取码:skw3
配置文件 下载链接:https://pan.baidu.com/s/1JPFVFivO_gG8BEGHAszweg 提取码:ryxt
将jar包以及配置文件放到/apache-tomcat-7.0.92/bin/下
在这里插入图片描述
tomcat目录修改/apache-tomcat-7.0.92/bin/catalina.sh,添加如下语句

JAVA_OPTS=" -javaagent:/opt/apache-tomcat-7.0.92/bin/jmx_prometheus_javaagent-0.3.1.jar=9151:/opt/apache-tomcat-7.0.92/bin/config.yaml"

在这里插入图片描述切记,配置完成后shutdown命令不能使用,需要kill -9 PID 杀掉进程

  • 服务端

cd prometheus-2.9.1.linux-amd64
vim prometheus.yml
添加如下信息

- job_name: 'tomcat'
  static_configs:
  - targets: ['IP(域名):9151]
    labels:
      instance: tomcat

重启Promethus
grafana导入画好的dashboard,选择普罗米修斯数据源
链接:https://pan.baidu.com/s/14h0Rp9XANdzUhPvhoyVrgQ 提取码:xf20
同样的方法导入画好的json文件
在这里插入图片描述在这里插入图片描述

答:以下是一个示例的docker-compose.yml文件,用于启动Prometheus和Grafana监控一个或多个应用程序: ``` version: '3' services: prometheus: image: prom/prometheus container_name: prometheus ports: - "9090:9090" volumes: - ./prometheus.yml:/etc/prometheus/prometheus.yml command: - '--config.file=/etc/prometheus/prometheus.yml' restart: always grafana: image: grafana/grafana container_name: grafana depends_on: - prometheus ports: - "3000:3000" environment: GF_SERVER_ROOT_URL: http://localhost:3000 GF_SECURITY_ADMIN_USER: admin GF_SECURITY_ADMIN_PASSWORD: admin volumes: - ./grafana-data:/var/lib/grafana restart: always ``` 在该docker-compose.yml文件中,我们创建了两个服务:prometheus和grafana。Prometheus服务使用Prometheus Docker映像,并将端口映射到9090。它还将/prometheus.yml文件作为挂载卷传递给容器。在启动容器时,我们使用命令行参数来指定/config.file=/etc/prometheus/prometheus.yml。 Grafana服务程序使用Grafana Docker映像,并依赖于prometheus服务。Grafana服务映射端口3000,并将以下环境变量传递给容器:GF_SERVER_ROOT_URL:使用localhost:3000 (在该容器中内部)作为grafana的根URL,GF_SECURITY_ADMIN_USER和GF_SECURITY_ADMIN_PASSWORD管理Grafana管理员的凭据。此服务还挂载了grafana-data目录,以便可以在重启容器时保留所有Grafana的设置。 最后,我们定义了restart: always参数以确保容器在退出时自动重新启动。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值