If you think the article is useful or well written, please click “like” on the left.
This article has been included in my personal blog: Geekvic. Top, welcome to chat!
preface
Whether the business often encountered server load is too high, or often encountered background service hung, but there is no automatic reminder function, so it is imperative to build a set of monitoring and alarm system.
Prometheus is currently active in the open source community, with more than 20,000 stars on GitHub, the most popular monitoring system, more flexibility in customization than Zabbix, and Prometheus has advantages in cloud environment and container support.
Prometheus
Introduction to the
Prometheus is an open source monitoring & alarm & time series database combination based on applied metrics.
Download & Install
-
IO/Download /
-
Decompress: tar ZXVF Prometheus -2.12.0.linux-amd64.tar.gz
-
Edit: Prometheus. Yml, including global configuration, AlertManager, alarm rules, and job monitoring.
# 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: Periodically Load rules once and evaluate them according to the global 'evaluation_interval'. rule_files: - "test_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: ['192.168.88.69:9090'] - job_name: 'monitor' scrape_interval: 5s metricS_PATH: '/actuator/ Prometheus' STATIC_configs: -targets: ['192.168.88.69:8008'] -job_name: 'node-exporter' STATIC_configs: -targets: ['192.168.88.69:9100']Copy the code
-
Start:./ Prometheus &
-
Verify installation: access address: http://192.168.88.69:9090/targets
Spring Boot integrates Prometheus
Configure poM files
<! - monitoring - >
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
Copy the code
Configuration yml
server:
port: 8008
spring:
application:
name: monitor
management:
endpoints:
web:
exposure:
include: The '*'
metrics:
tags:
application: ${spring.application.name}
Copy the code
Adding a Configuration Class
@Configuration
public class MeterRegistryConfig {
@Bean
MeterRegistryCustomizer<MeterRegistry> configurer(@Value("${spring.application.name}") String applicationName) {
return (registry) -> registry.config().commonTags("application", applicationName); }}Copy the code
AlertManager
Introduction to the
The Alertmanager processes the received alarm information, including deduplication, noise reduction, grouping, and PBR alarm notification.
configuration
Modify alertManager. yml, the current configuration is email alarm, of course, enterprise wechat, nail, etc., as follows:
global:
resolve_timeout: 5m
smtp_smarthost: 'smtp.mxhichina.com:25' # SMTP address
smtp_from: '[email protected]' Send email address
smtp_auth_username: '[email protected]' # email user
smtp_auth_password: '123456' # Email password
route:
group_by: ["instance"] # group name
group_wait: 10s # When you receive an alarm, wait 10 seconds to see if there is another alarm, if there is an alarm, send it together
igroup_interval: 10s # Warning interval
repeat_interval: 1h # Time interval between repeated alarms
receiver: mail This parameter is mandatory, and must be the same as the following alarm group name
receivers:
- name: 'mail' # Alarm group name
email_configs:
- to: '[email protected]' # Recipient email
headers: {Subject: "Alarm Test Email"}
Copy the code
Start the
Command:./ alertManager &, port number: 9093
Grafana
Introduction to the
Grafana is an open source data visualization tool developed in Go for data monitoring and statistics, with alarm capabilities.
configuration
-
Unzip grafana – 6.3.5. Linux – amd64. Tar. Gz, start. / grafana – server &, visit the address http://192.168.88.69:3000
-
Configuration Data Sources
-
Install node_exporter. To monitor server running status, run node_exporter and start the project on port 9100. Configure the node in Prometheus and restart Prometheus.
-
To import a template, you can find Grafana at grafana.com/grafana/das… .
Left hand typing, right hand shooting, a basketball loving coder ~~~
Sync personal blog: Geekvic. top/post/c79551…
Disclaimations: All articles on this blog are licensed under by-NC-SA unless otherwise stated. Reprint please indicate the source!