当前位置: 首页 > Linux

生产环境安装Prometheus+Grafana

时间:2023-04-06 03:01:29 Linux

安装Prometheuswgethttps://github.com/prometheus...tar-zxvfprometheus-2.34.0.linux-amd64.tar.gzmvprometheus-2.34.0.linux-amd64prometheusvimprometheus.yml#myglobalconfigglobal:scrape_interval:15s#将抓取间隔设置为每15秒一次。默认为每1分钟一次。evaluation_interval:15s#每15秒评估一次规则。默认为每1分钟一次。#scrape_timeout设置为全局默认值(10s)。#Alertmanagerconfigurationalerting:alertmanagers:-static_configs:-targets:-localhost:9093#加载一次规则并根据全局'evaluation_interval'.rule_files:-"rules/host_rules.yml"#-"first_rules.yml"#-"second_rules.yml"#一个仅包含一个要抓取的端点的抓取配置:#这里是Prometheus本身。scrape_configs:#作业名称作为标签添加`job=`到从中抓取的任何时间序列这个配置。-job_name:"prometheus"#metrics_path默认为'/metrics'#scheme默认为'http'。static_configs:-目标:[“localhost:9090”]-job_name:'agent-web01'static_configs:-目标:['172.31.32.104:9100']-job_name:'agent-web02'static_configs:-目标:['172.31.29.223:9100']-job_name:'java'static_configs:-目标:['172.31.29.223:8100']metrics_path:'/actuator/prometheus'创建规则mkdir-p/root/prometheus/rulescathost_rules.ymlgroups:-name:systemresourcealertrulesrules:-alert:CPUusagealertexpr:100-(avgby(instance)(irate(node_cpu_seconds_total{mode="idle"}[1m])))*100>80for:1m标签:user:prometheusseverity:warningannotations:description:"Server:CPUusageexceeds80%!(currentvalue:{{humanize$value}}%)"-警报:内存使用警告expr:(node_memory_MemTotal_bytes-(node_memory_MemFree_bytes+node_memory_Buffers_bytes+node_memory_Cached_bytes))/node_memory_MemTotal_bytes*100>80for:1mlabels:user:prometheusseverity:warningannotations:description:"Server:memoryusageexceeds80%!(currentvalue:{{humanize$value}}%)"-警报:磁盘告警规则expr:100-(node_filesystem_free_bytes{mountpoint="/",fstype=~"ext4|xfs"}/node_filesystem_size_bytes{fstype=~"ext4|xfs"}*100)>70for:1mlabels:user:prometheusseverity:warningannotations:description:"Server:Diskusageexceeds70%!(Currentvalue:{{humanize$value}}%)"启动nohup./prometheus&effectimageinstallalertmanagerwgethttps://github.com/prometheus。..tar-zxvfalertmanager-0.24.0.linux-amd64.tar.gzmvalertmanager-0.24.0.linux-amd64alertmanagervimalertmanager.yml具体可以去企业微信后台找到相关参数global:resolve_timeout:2mwechat_api_url:'https://qyapi.weixin.qq.com/cgi-bin/'wechat_api_secret:'<企业微信号>'wechat_api_corp_id:'<企业微信号>'route:group_by:['alertname']group_wait:10sgroup_interval:10srepeat_interval:1hreceiver:'wechat'receivers:-name:'wechat'wechat_configs:-send_resolved:trueto_party:'1'agent_id:'<你的企业微信应用id>'templates:-'/alertmanager/*.tmpl'yaml语法检查./amtoolcheck-configalertmanager.yml企业微信告警模板catwechat.tmpl{{define"wechat.default.message"}}{{-ifgt(len.Alerts.Firing)0-}}{{-range$index,$alert:=.Alerts-}}========异常警报========Alertname:{{$alert.Labels.alertname}}警报严重性:{{$alert.Labels.severity}}警报机器:{{$alert.Labels.instance}}{{$alert.Labels.device}}警报详情:{{$alert.Annotations.summary}}警报时间:{{$alert.StartsAt.Format"2006-01-0215:04:05"}}==========END=========={{-结束}}{{-结束}}{{-ifgt(len.Alerts.Resolved)0-}}{{-range$index,$alert:=.Alerts-}}========警报恢复========警报名称:{{$alert.Labels.alertname}}警报级别:{{$alert.Labels.severity}}警报机器:{{$alert.Labels.instance}}报警详情:{{$alert.Annotations.summary}}警报时间:{{$alert.StartsAt.Format"2006-01-0215:04:05"}}恢复时间:{{$alert.EndsAt.Format"2006-01-0215:04:05"}}===========结束=========={{-结束}}{{-结束}}{{-结束}}开始nohup./alertmanager&InstallGrafanawgethttps://dl.grafana.com/oss/re...tar-zxvfgrafana-8.4.6.linux-amd64.tar.gzmvgrafana-8.4.6.linux-amd64grafana配置还没有changed,go默认,也可以根据具体情况做相应的配置修改。启动nohup./grafana&配置数据源为Prometheus,因为是本地的,所以首选localhost保存测试导入的配置grafanadashboard地址https://grafana.com/grafana/d。..11074------1NodeExporterforPrometheusDashboardEN202010101860------NodeExporterFull4701------JVM(Micrometer)参考链接https://blog.51cto.com/u_15060547/3817600https://www.cnblogs.com/Devinhao/articles/16180018.html本文由多帖博客平台OpenWrite发布!