Prometheus一个job配置多个target
比如node监控下会有多个节点需要监控
- job_name: "node"
static_configs:
- targets: ["192.168.147.21:9100"]
- targets: ["192.168.147.38:9100"]
mysql
用docker启动exporter
docker run -d \
-p 9104:9104 \
--network my-mysql-network \
-e DATA_SOURCE_NAME="mysqlexporter:mysqlexporter@(192.168.147.46:3306)/" \
prom/mysqld-exporter
给集群中的prometheus添加该exporter的数据
First, you will need to create the additional configuration. Below we are making a simple “prometheus” config. Name this prometheus-additional.yaml or something similar.
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
Then you will need to make a secret out of this configuration. 其中additional-scrape-configs可以改成自己的名字,比如mysql-exporter-config,到Prometheus编辑的时候,注意要保持一致
kubectl create secret generic additional-scrape-configs --from-file=prometheus-additional.yaml --dry-run=client -oyaml > additional-scrape-configs.yaml
Next, apply the generated kubernetes manifest
kubectl apply -f additional-scrape-configs.yaml -n monitoring
Finally, reference this additional configuration in your prometheus.yaml CRD.
此处要用kubectl -n cattle-prometheus edit prometheus去编辑,
apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
name: prometheus
labels:
prometheus: prometheus
spec:
replicas: 2
serviceAccountName: prometheus
serviceMonitorSelector:
matchLabels:
team: frontend
additionalScrapeConfigs:
name: additional-scrape-configs
key: prometheus-additional.yaml
granfa添加模板:
登录granfa,账号密码默认为admin/admin
添加完数据源添加dashboard,从下面链接去下载模板json文件,如果是离线环境
MySQL dashboard下载
redis
https://www.cnblogs.com/fsckzy/p/12053604.html
wget https://github.com/oliver006/redis_exporter/releases/download/v1.3.5/redis_exporter-v1.3.5.linux-amd64.tar.gz
nohup ./redis_exporter -redis.addr 172.18.11.141:7001 -redis.password xxxxx &
- job_name: "redis"
static_configs:
- targets:
- 'redis://192.168.147.39:7001'
- 'redis://192.168.147.39:7002'
- 'redis://192.168.147.39:7003'
- 'redis://192.168.147.39:7004'
- 'redis://192.168.147.39:7005'
- 'redis://192.168.147.39:7006'
metrics_path: /scrape
relabel_configs:
- source_labels:
- __address__
target_label: __param_target
- source_labels:
- __param_target
target_label: instance
- target_label: __address__
replacement: '192.168.147.21:9121'
granfana离线按照插件
在这里https://grafana.com/api/plugins找到你的插件名称
https://grafana.com/api/plugins//versions//download
比如这里下载redis-datasource
https://grafana.com/api/plugins/redis-datasource/versions/2.1.1/download
注意到官网里查看插件版本与自己的granfana的版本对应,下载完毕后将其文件复制到/var/lib/grafana/plugins/下,重启systemctl restart grafana-server