0 Preface
In this issue, we will explain how to monitor the changes of CPU, network, disk, memory and other indicators in the server/host through ELK+metricbeat. And draw a data board to facilitate our real-time monitoring
1. Download
First of all, the construction of ELK is no longer exhaustive. For those who are not clear, you can check out previous blogs:
ELK Construction (1): Implementing Distributed Microservice Log Monitoring
Because my ELK environment is 7.13.0, we need to download the corresponding version of Metricbeat
Metricbeat official download address
2 Introduction to Metricbeat
Metricbeat is a lightweight collector officially launched by Elstic. It belongs to the beats series, which is specially used for various system and service statistics. It can not only count server cpu, memory, disk and other data, but also statistics related indicators of services such as redis, nginx, and myql.
Metricbeat regularly obtains the corresponding indicator data from the server, and then sends it to elasticsearch or logstash
metricbeat consists of two parts:
- 1. Module
The so-called module is a module that collects different services. For example, a system service is a system module. There are dozens of modules supported in metricbeat, including but not limited to: ActiveMQ module, Apache module, Docker module, HTTP module, etc. For details, you can view the modules section in the official documentation of metricbeat
2. The content collected by metricset , taking system module as an example, the content supported include cpu, load, memory, network, process, process_summary, uptime, etc.
3. Install Metricbeat
The following installation steps can also be seen in kibana: Home > Add Data > System Metrics
1. Upload the installation package to the server that needs to be monitored, you can use FTP software or the following instructions to upload
scp metricbeat-7.13.0-linux-arm64.tar.gz [email protected]:/var/local
2. Unzip the compressed package
tar -zxvf metricbeat-7.13.0-linux-arm64.tar.gz
3. Modify the connection information in the configuration file metricbeat.yml
setup.template.settings:
index.number_of_shards: 1
index.number_of_replicas: 0
output.elasticsearch:
hosts: ["192.168.244.11:9200"]
username: "elastic"
password: "elastic"
setup.kibana:
host: "192.168.244.11:5601"
4. Start the system module, metricbeat will obtain system data according to the configuration items in modules.d/system.yml
./metricbeat modules enable system
5. Configure the content to be collected and modify the modules.d/system.yml configuration file
vim modules.d/system.yml
The content of the configuration file, the default is used here, which can be configured according to your own needs.
- module: system
period: 10s
metricsets:
- cpu
- load
- memory
- network
- process
- process_summary
- socket_summary
#- entropy
#- core
#- diskio
#- socket
#- service
#- users
process.include_top_n:
by_cpu: 5 # include top 5 processes by CPU
by_memory: 5 # include top 5 processes by memory
# Configure the mount point of the host’s filesystem for use in monitoring a host from within a container
#system.hostfs: "/hostfs"
- module: system
period: 1m
metricsets:
- filesystem
- fsstat
processors:
- drop_event.when.regexp:
system.filesystem.mount_point: '^/(sys|cgroup|proc|dev|etc|host|lib|snap)($|/)'
- module: system
period: 15m
metricsets:
- uptime
For more information about the configuration of Metricbeat , please refer to the official documentation . Metricbeat supports 18 indicator sets:
6. Load the kibana dashboard. If it has been set before, you don't need to execute it again.
./metricbeat setup
7. Start metricbeat
./metricbeat -e
8. Here you can click "Check Data" in kibana's system indicator deployment process guide to test, if successful, as shown in the figure
9. Click 系统指标仪表板
to automatically create a data board and view it. Click on Host Overview and we can see the main indicators of the server, including: used CPU, memory, virtual memory (swap), number of processes, input and output traffic, etc.
How to solve the problem of no data in the data kanban
If the data board cannot be viewed, it means that the data cannot be queried
. First, check whether there is an index starting with metric- on the index management page (you can also directly query the metricbeat alias), and whether the number of documents is greater than 0. If the index does not exist or the number is 0, it means that metricbeat has not successfully transmitted the monitored system data to es, then you need to check the corresponding log on metricbeat, or check the log of es to see if there is an error, and prescribe the right medicine
Secondly, if the index exists and the number is greater than 0, it means that the data has been uploaded successfully, and it cannot be displayed at this time, then adjust the time range of the query first.
If there is still no data displayed, then check whether the time zone of the server where metricbeat is located is China time zone, whether the time is synchronized with the current network time can be checked by date
checking the current time. If the time is wrong, adjust the time to be correct
Summarize
Well, this is the end of the tutorial on building a monitoring platform for basic server indicators. Of course, we have not introduced the indicators in the configuration file of the system module in metricbeat. We will explain this in detail later, or you can also Check out the official documentation directly. Interested students can follow this column