springboot+Prometheus+grafana+PrometheusAler一條龍監控
阿新 • • 發佈:2021-11-24
Prometheus
安裝
cd /usr/local/src tar zvxf prometheus-2.14.0.linux-amd64.tar.gz -C /opt/ ln -s /opt/prometheus-2.14.0.linux-amd64/ /opt/prometheus useradd -s /sbin/nologin -M prometheus mkdir /data/prometheus -p chown -R prometheus:prometheus /opt/prometheus/ chown -R prometheus:prometheus /data/prometheus/ [Unit] Description=Prometheus Documentation=https://prometheus.io/ After=network.target [Service] Type=simple User=prometheus ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml --storage.tsdb.path=/data/prometheus Restart=on-failure [Install] WantedBy=multi-user.target systemctl enable prometheus systemctl start prometheus systemctl status prometheus
啟動
nohup ./prometheus --web.enable-lifecycle &
![在這裡插入圖片描述](https://img-blog.csdnimg.cn/6332cf4cafc4432c9f79be7d846d424e.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5a2m5b6S6a2P6I-x5bu2,size_20,color_FFFFFF,t_70,g_se,x_16熱啟動
springboot應用接入
management: endpoints: web: base-path: /management exposure: include: ['configprops', 'env', 'health', 'info', 'jhimetrics', 'logfile', 'loggers', 'prometheus', 'threaddump'] endpoint: health: show-details: when_authorized roles: 'ROLE_ADMIN' jhimetrics: enabled: true info: git: mode: full health: mail: enabled: false # When using the MailService, configure an SMTP server and set this to true metrics: export: # Prometheus is the default metrics backend prometheus: enabled: true step: 60 enable: http: true jvm: true logback: true process: true system: true distribution: percentiles-histogram: all: true percentiles: all: 0, 0.5, 0.75, 0.95, 0.99, 1.0 tags: application: ${spring.application.name} web: server: auto-time-requests: true - job_name: 'springboot' metrics_path: '/management/prometheus' static_configs: - targets: ['10.237.xxx.xx:7700']
grafana
grafana-7.3.3-1.x86_64.rpm
下載: https://mirrors.tuna.tsinghua.edu.cn/grafana/yum/rpm/
上傳grafana離線包,上傳離線包到/usr/local/grafana-rpm目錄
新增Prometheus資料來源
Add data source選擇Prometheus
最後點選Save
3、配置Grafana資料展示模板
至此Prometheus和Grafana已經打通了,接下來需要添加個圖形模板以便展示資料。