Micro-service monitoring practices (a) - Prometheus Installation and Configuration

Introduction: recent study golang, and the project team needs to happen to make micro-service monitoring, search after the final selection prometheus + grafana + springcloud (eureka) as the technical framework.

This article mainly on the installation and configuration of the server prometheus


1. Prometheus downloads

Official website: https://prometheus.io/

Download: https://prometheus.io/download/

The official document: https://prometheus.io/docs/prometheus/latest/getting_started/

Prometheus is an open source & alarm monitoring & combination of time-series database to monitor metrics based on open source tools application.

For more information please refer to the examiner network description: https://prometheus.io/docs/introduction/overview/

Of course, more often due to the speed to access the Internet is too slow, you can not be downloaded directly from the official website, here recommend a mirror site: http://cactifans.hi-www.com/
1


2. Prometheus installation

Because it is a binary compressed files, so installation is very simple.

  • First, open the connection to the server xshell;
  • Use rzthe command Upload Package (If you can not find the rzcommand, use the yum install lrzszinstallation)
    2
  • Use tar -zvxf prometheus-2.14.0.linux-amd64.tar.gzdecompression
    3
  • Use mv prometheus-2.14.0.linux-amd64 /usr/local/prometheusMove Folder to the /usr/localdirectory, easy to manage
    4
  • Use ./prometheus --helpview the startup configuration items, copy --config.file="prometheus.yml"constitute the basic startup items, the execution ./prometheus --config.file="prometheus.yml"start prometheus
    5
  • To see if started successfully, browser access ip:port. I am herehttp://192.168.13.101:9090
    6

In this way, the basic installation prometheus's been ok, let's look at prometheus configuration.


3. Prometheus configuration

3.1 configuration daemon start

  • Under CentOS7, using systemd configuration daemon is started, the first to use cd /usr/lib/systemd/systeminto the directory
  • Copying an existing service as a service prometheus cp sshd.service prometheus.service
  • Modify the service file vi prometheus.service
[Unit]
Description=prometheus.io

[Service]
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
Restart=on-failure

[Install]
WantedBy=multi-user.target
  • Systemd system configuration file to take effect,systemctl daemon-reload
  • Start prometheus systemctl start prometheus
  • View the process ps -ef|grep prometheus
    7

3.2 Profile Description

Most prometheus function can be configured to achieve, so here introduce its default configuration file.

Detailed configuration instructions, please refer to the official document: prometheus.config.doc , here only introduce key configuration items

  • Global configuration items (global):
global:
  # 监控采集周期
  [ scrape_interval: <duration> | default = 1m ]

  # 采集超时时长
  [ scrape_timeout: <duration> | default = 10s ]

  # 告警周期
  [ evaluation_interval: <duration> | default = 1m ]

  # 外部标签
  external_labels:
    [ <labelname>: <labelvalue> ... ]

# 告警规则
rule_files:
  [ - <filepath_glob> ... ]

# 被监控端配置
scrape_configs:
  [ - <scrape_config> ... ]

# AlertManager告警组件配置
alerting:
  alert_relabel_configs:
    [ - <relabel_config> ... ]
  alertmanagers:
    [ - <alertmanager_config> ... ]

# 远程存储,用于替代默认TSDB,推荐采用InfluxDB
remote_write:
  [ - <remote_write> ... ]

# 远程读取
remote_read:
  [ - <remote_read> ... ]
  • Are configuration items (scrape_config portion) monitoring terminal:
# 各种服务发现配置项
# List of Azure service discovery configurations.
azure_sd_configs:
  [ - <azure_sd_config> ... ]

# Spring Cloud Consul,该项可以在EUREKA中集成,实现EUREKA的服务发现
consul_sd_configs:
  [ - <consul_sd_config> ... ]

# List of DNS service discovery configurations.
dns_sd_configs:
  [ - <dns_sd_config> ... ]

# List of EC2 service discovery configurations.
ec2_sd_configs:
  [ - <ec2_sd_config> ... ]

# List of OpenStack service discovery configurations.
openstack_sd_configs:
  [ - <openstack_sd_config> ... ]

# 文件
file_sd_configs:
  [ - <file_sd_config> ... ]

# List of GCE service discovery configurations.
gce_sd_configs:
  [ - <gce_sd_config> ... ]

# 用于k8s的服务发现,也是prometheus最大的优势
kubernetes_sd_configs:
  [ - <kubernetes_sd_config> ... ]

# List of Marathon service discovery configurations.
marathon_sd_configs:
  [ - <marathon_sd_config> ... ]

# 爱彼迎的注册中心
nerve_sd_configs:
  [ - <nerve_sd_config> ... ]

# 大名鼎鼎的ZK
serverset_sd_configs:
  [ - <serverset_sd_config> ... ]

# List of Triton service discovery configurations.
triton_sd_configs:
  [ - <triton_sd_config> ... ]

# 静态配置被监控端
static_configs:
  [ - <static_config> ... ]

# 配置项重载,使用率很高
relabel_configs:
  [ - <relabel_config> ... ]

# List of metric relabel configurations.
metric_relabel_configs:
  [ - <relabel_config> ... ]

At this point, Prometheus installation and configuration has been completed, the next section explains how to integrate in Spring Cloud in Prometheus

Published 21 original articles · won praise 24 · views 10000 +

Guess you like

Origin blog.csdn.net/fIsh1220Fish/article/details/104231542