Relevant concepts

Monitoring in microservices can be divided into three categories according to the field of application, namely Logging, Tracing, and Metrics.

  • Logging – Used to record discrete events. For example, debugging information or error information about an application. It’s what we use to diagnose problems. For example, ELK is based on Logging.

  • Metrics – Used to record aggregated data. For example, the current depth of a queue can be defined as a measure that is updated when an element is enqueued or unqueued; The number of HTTP requests can be defined as a counter that is exhausted when new requests arrive. Prometheus focuses on Metrics.

  • Tracing – Used to record information within the scope of the request. For example, the execution process and time taken for a remote method call. It’s our tool for troubleshooting system performance problems. The most common ones are Skywalking, ping-point, and Zipkin.

Today we’ll focus on monitoring for Prometheus, and then we’ll look at some of the key components involved.

Prometheus

Prometheus(Chinese name: Prometheus) is an open source monitoring and alarm system and time sequence database (TSDB) developed by SoundCloud, inc. Prometheus is an open source version of Google’s BorgMon monitoring system, developed for use in the Go language.

The basic principle of Prometheus is to periodically capture the status of monitored components through THE HTTP protocol, and any component that provides the corresponding HTTP interface can access monitoring. No SDK or other integration process is required. The HTTP interface that outputs monitored component information is called my exporter. At present, most commonly used development components can be directly used by my exporter, such as Nginx, MySQL, Linux system information, Mongo, AND ES

exporter

Prometheus can be understood as a database + data capture tool, which captures uniform data from various locations and puts it into Prometheus time series database. So how do you make sure that the data format is uniform everywhere? Through this exporter. Exporter is the general term for a category of data collection components. My friend is responsible for collecting data from the target and converting it to a format supported by Prometheus, which provides an HTTP interface (for Prometheus to fetch the data). Unlike traditional data collection components, Exporter does not send data to a central server and waits for a central server (such as Prometheus) to fetch it. There are many good exporters at github.com/prometheus that can be downloaded and used directly.

Grafana

Grafana is a graphical tool that reads data from a variety of sources (such as Prometheus), presents the data in beautiful graphs, and there are a number of open source Dashborads available to quickly build a very elegant monitoring platform. Its relationship to Prometheus is similar to Kibana and ElasticSearch.

Environment to prepare

Download the following software before you start the configuration (download directly from Github or Grafana is too slow and easy to fail, use Thunderbolt download).

  • prometheus

  • grafana

  • node_exporter

The installation

Prepare two servers, one for installing Prometheus and Grafana, and one for placing the Exporter components. Create an application folder and upload related software to the server.

  • Grafana 192.168.249.131 Prometheus
  • 192.168.249.129 exporter

prometheus

Run the following shell command to install and start the installation

Gz mv Prometheus -2.13.1. Linux -amd64 Prometheus CD Prometheus nohup ./prometheus &Copy the code

Activation is completed, a browser open http://192.168.249.131:9090, results are as follows:

grafana

Run the following shell command to install and start the installation

Gz CD grafana-6.4.3 nohup./grafana-server &Copy the code

Activation is completed, a browser open http://192.168.249.131:3000, the default password for the admin/admin, first time login need to modify the password, change password and login effect is as follows:

node_exporter

Run the following shell command to install and start the installation

Tar ZXVF node_extude-0.18.1.linux-amd64.tar. gz MV node_extude-0.18.1.linux-amd64 node_extude-nohup./ node_extude-nohup &Copy the code

Node runs port 9100 by default and can specify the port number with –web.listen-address=”:9200″. Activation is completed, a browser open http://192.168.249.129:9100/ access, display effect is as follows:

configuration

prometheus

Go to the Prometheus installation directory, modify the Prometheus. Yml file, and add listening job server-192.168.249.129. Complete the following configurations:

# 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

rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"


scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']

  - job_name: '192.168.249.129'
    static_configs:
    - targets: ['192.168.249.129:9100']
Copy the code

After the configuration, restart Prometheus to check the listening status.

grafana

  • Configure the Prometheus data source

  • Go to the official website to find the corresponding dial, and we choose the Node Exporter monitoring kanban

  • Import the dial in Grafana

  • Viewing the Monitoring Effect

Now that the Prometheus based monitoring environment is complete, give it a try.

The recent hot,

  • SpringBoot+Mysql8 implements read and write separation

  • Springboot2.x + ShardingSphere implementation sub-library sub-table

  • This section describes how to design customized service alarms based on ElasticSearch

For more content, please pay attention to the public number: JAVA Daily Record