prometheus 的安装部署
  TEZNKK3IfmPf 2023年11月14日 39 0

先创建一个copy出配置文件

docker cp d20038ac3ba1:/etc/prometheus/ /home/lys/prometheus

然后删除启动挂载

docker run --name lys-prometheus -d -p 9090:9090    -v /home/lys/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml  -v /home/lys/prometheus/host.json:/etc/prometheus/host.json quay.io/prometheus/prometheus

配置

prometheus.yml

global: 全局配置(如果有内部单独设定,会覆盖这个参数)
alerting: 告警插件定义。这里会设定alertmanager这个报警插件。
rule_files: 告警规则。 按照设定参数进行扫描加载,用于自定义报警规则,其报警媒介和route路由由alertmanager插件实现。
scrape_configs:采集配置。配置数据源,包含分组job_name以及具体target。又分为静态配置和服务发现

prometheus支持服务发现(也是运维最佳实践经常采用的):
文件服务发现
基于文件的服务发现方式不需要依赖其他平台与第三方服务,用户只需将 要新的target信息以yaml或json文件格式添加到target文件中 ,prometheus会定期从指定文件中读取target信息并更新
好处:
(1)不需要一个一个的手工去添加到主配置文件,只需要提交到要加载目录里边的json或yaml文件就可以了;
(2)方便维护,且不需要每次都重启prometheus服务端。

# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"

# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.

static_configs:
- targets: ["localhost:9090"]

#通过配置file 获取target,这里以lys-web项目进行举例
- job_name: 'lys-other'
#metrics_path: /metrics
file_sd_configs:
- files:
- host.json

host.json

[
{
"targets": [
"0.0.0.0:9090"
],
"labels": {
"group": "lys",
"app": "web",
"hostname":"lys02"
}
},
{
"targets": [
"0.0.0.0:4000"
],
"labels": {
"group": "lys",
"app": "devops",
"hostname":"lys01"
}
}
]

prometheus 的安装部署

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月14日 0

暂无评论

推荐阅读
  TEZNKK3IfmPf   2024年04月26日   55   0   0 Docker
  TEZNKK3IfmPf   2024年03月29日   99   0   0 Docker
TEZNKK3IfmPf