prometheus 0005 操作

docker run --name=prometheus -d -p 9090:9090 -v /root/promethues/server/prometheus.yml:/etc/prometheus/prometheus.yml -v /root/promethues/server/rules.yml:/etc/prometheus/rules.yml prom/prometheus:v2.7.2 --config.file=/etc/prometheus/prometheus.yml --web.enable-lifecycle

mkdir -p /home/chenqionghe/promethues/client/golang/src
cd !$
export GOPATH=/home/chenqionghe/promethues/client/golang/
#克隆项目
git clone https://github.com/prometheus/client_golang.git
#安装需要的第三方包
mkdir -p G O P A T H / s r c / g o l a n g . o r g / x / c d ! GOPATH/src/golang.org/x/ cd ! GOPATH/src/golang.org/x/cd!
git clone https://github.com/golang/net.git
git clone https://github.com/golang/sys.git
git clone https://github.com/golang/tools.git
#安装必要软件包
go get -u -v github.com/prometheus/client_golang/prometheus
#编译
cd $GOPATH/src/client_golang/examples/random
go build -o random main.go

./random -listen-address=:8080 &
./random -listen-address=:8081 &
./random -listen-address=:8082 &

docker run -d
–name=node-exporter
-p 9100:9100
prom/node-exporter

global:
scrape_interval: 15s # 默认抓取间隔, 15秒向目标抓取一次数据。
external_labels:
monitor: ‘codelab-monitor’
rule_files:
#- ‘prometheus.rules’

这里表示抓取对象的配置

scrape_configs:
#这个配置是表示在这个配置内的时间序例,每一条都会自动添加上这个{job_name:“prometheus”}的标签 - job_name: ‘prometheus’

  • job_name: ‘prometheus’
    scrape_interval: 5s # 重写了全局抓取间隔时间,由15秒重写成5秒
    static_configs:
    • targets: [‘localhost:9090’]
    • targets: [‘http://10.211.55.25:8080’, ‘http://10.211.55.25:8081’,‘http://10.211.55.25:8082’]
      labels:
      group: ‘client-golang’
    • targets: [‘http://10.211.55.25:9100’]
      labels:
      group: ‘client-node-exporter’

mkdir -p /home/chenqionghe/promethues/pushgateway
cd !$
docker run -d -p 9091:9091 --name pushgateway prom/pushgateway

echo "cqh_metric 100" | curl --data-binary @- http://ubuntu-linux:9091/metrics/job/cqh

cat <<EOF | curl --data-binary @- http://10.211.55.25:9091/metrics/job/cqh/instance/test
# 锻炼场所价格
muscle_metric{label="gym"} 8800
# 三大项数据 kg
bench_press 100
dead_lift 160
deep_squal 160
EOF

docker run -d -p 3000:3000 --name grafana grafana/grafana

mkdir -p /home/chenqionghe/promethues/alertmanager
cd !$

alertmanager.yml

global:
resolve_timeout: 5m
route:
group_by: [‘cqh’]
group_wait: 10s #组报警等待时间
group_interval: 10s #组报警间隔时间
repeat_interval: 1m #重复报警间隔时间
receiver: ‘web.hook’
receivers:

  • name: ‘web.hook’
    webhook_configs:
    • url: ‘http://10.211.55.2:8888/open/test’
      inhibit_rules:
  • source_match:
    severity: ‘critical’
    target_match:
    severity: ‘warning’
    equal: [‘alertname’, ‘dev’, ‘instance’]

docker rm -f alertmanager
docker run -d -p 9093:9093
–name alertmanager
-v /home/chenqionghe/promethues/alertmanager/alertmanager.yml:/etc/alertmanager/alertmanager.yml
prom/alertmanager

修改规则/home/chenqionghe/promethues/server/rules.yml

groups:

  • name: cqh
    rules:
    • alert: cqh测试
      expr: dead_lift > 150
      for: 1m
      labels:
      status: warning
      annotations:
      summary: “{{KaTeX parse error: Expected 'EOF', got '}' at position 16: labels.instance}̲}:硬拉超标!lightwei…labels.instance}}:硬拉超标!lightweight baby!!!”

然后再修改prometheus添加altermanager配置

global:
scrape_interval: 15s # 默认抓取间隔, 15秒向目标抓取一次数据。
external_labels:
monitor: ‘codelab-monitor’
rule_files:

  • /etc/prometheus/rules.yml

这里表示抓取对象的配置

scrape_configs:
#这个配置是表示在这个配置内的时间序例,每一条都会自动添加上这个{job_name:“prometheus”}的标签 - job_name: ‘prometheus’

  • job_name: ‘prometheus’
    scrape_interval: 5s # 重写了全局抓取间隔时间,由15秒重写成5秒
    static_configs:
    • targets: [‘localhost:9090’]
    • targets: [‘10.211.55.25:8080’, ‘10.211.55.25:8081’,‘10.211.55.25:8082’]
      labels:
      group: ‘client-golang’
    • targets: [‘10.211.55.25:9100’]
      labels:
      group: ‘client-node-exporter’
    • targets: [‘10.211.55.25:9091’]
      labels:
      group: ‘pushgateway’
      alerting:
      alertmanagers:
    • static_configs:
      • targets: [“10.211.55.25:9093”]
在这里,将我的prometheus config文件给大家展示出来,供参考
(133.155.131.152是我的云主机公网IP,大家请根据实际情况修改)
global:
scrape_interval: 15s # 默认抓取间隔, 15秒向目标抓取一次数据。
scrape_timeout: 4s
evaluation_interval: 15s
external_labels:
monitor: 'codelab-monitor'
rule_files:
- /etc/prometheus/server/rules.yml
alerting:
alertmanagers:
- static_configs:
- targets: ["139.155.131.152:9093"]
scheme: http
timeout: 10s
scrape_configs:
- job_name: prometheus
scrape_interval: 5s
scrape_timeout: 4s
metrics_path: /metrics
scheme: http
static_configs:
- targets:
- localhost:9090
- targets:
- 139.155.131.152:8080
- 139.155.131.152:8081
- 139.155.131.152:8082
labels:
group: 'client-golang'
- targets:
- 139.155.131.152:9100
labels:
group: 'client-node-exporter'
- targets:
- 139.155.131.152:9091
labels:
group: 'push-gateway'

https://www.ibm.com/developerworks/cn/cloud/library/cl-lo-prometheus-getting-started-and-practice/index.html

https://prometheus.io/

https://songjiayang.gitbooks.io/prometheus/content/alertmanager/email.html

docker run --name=prometheus -d -p 9090:9090 -v /root/promethues/server/prometheus.yml:/etc/prometheus/prometheus.yml -v /root/promethues/server/rules.yml:/etc/prometheus/rules.yml prom/prometheus:v2.7.2 --config.file=/etc/prometheus/prometheus.yml --web.enable-lifecycle

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值