This article has participated in the activity of “New person creation Ceremony”, and started the road of digging gold creation together.

1. Background

1.1 Prometheus

Chinese is Prometheus, just hear the name feel very fan, is very powerful things. Let me tell you about Prometheus. He was a figure in Athenian mythology, and the legend is that he made up human figures, and Athena gave each of them a soul. Zeus forbade the use of fire by man. Seeing that man was in trouble, he stole fire from Apollo and offended Zeus. Then Zeus imprisoned him on a cliff of Mount Caucasus and sent out an evil eagle to peck at his liver and let it grow again every day, making him suffer all kinds of pain. It’s kind of an interesting myth, so you can see that Prometheus was the patron saint of mankind, the protector of all kinds of suffering. So the thing I’m talking about today is also this function, which is a performance monitoring tool. It is a set of open source monitoring & alarm system written in Go language based on time series.

It is based on HTTP protocol to capture the status information of monitored points, so it has a wide range of support, any component that supports HTTP protocol can use it as monitored points, so it is also widely used in docker, K8S and MESOS environment monitoring. The HTTP interface for exporting monitored components is referred to as EXPORTER. Many common components of Internet companies can be directly used by exporter.

1.2 Grafana

Open source application for visualizing large measurement data provides a powerful and elegant way to create, share, and browse data. Grafana, in conjunction with Prometheus, provides a graphical interface to show service performance.

2. Practice

I used vagrant + virtual Box to create three instances, and the process in the middle was also full of twists and turns. I was not familiar with Vagrant at the beginning. In fact, Vagrant is the isolation of development environment, which is similar to Docker. Box images are used to isolate different development environments. I reviewed network configurations while using Vagrant, mainly the differences between NAT, bridging, host-only, switch and router.

Let’s talk about the difference between switches and routers, which should be often encountered. First of all, the two are at different levels in the OSI seven-layer model. Switches are at layer 2, the data link layer, while routers are at layer 3, the network layer. Switches use physical addresses to determine the destination of data, while routers use network IDS to address data. The different ways in which the two are destined to function differently. A switch can be understood as having more LAN ports. Each LAN port does not interfere with each other. On the contrary, a router has multiple LAN ports sharing a total network port, so it shares network bandwidth.

NAT: a network address translation function enables VMS to access the public network through the host network. In NAT mode, VMS can access all hosts on the LAN but cannot access other hosts on the LAN.

Bridge: A local physical NIC is connected to a virtual NIC through a virtual switch, which is equivalent to a switch on a real network.

Host-only: the virtual network is in a closed network, and the only access is to the host.

There are three instances where Prometheus is installed, Granfan is installed, and Node_exporter is installed.

  • Install and start Prometheus

    wget https://github.com/prometheus/prometheus/releases/download/v2.7.1/prometheus2 -.7.1.linux-amd64.tar.gz
    tar -xvzf prometheus2 -.7.1.linux-amd64.tar.gz -C /usr/local/
    mv prometheus2 -.7.1.linux-amd64 prometheus
    ./prometheus --config.file="prometheus.yml"& (background running) lsof-i:9090(Listing port processes)Copy the code

After that, Prometheus starts, using port 9090, and performance monitoring begins.

The target is the monitoring target. By default, the monitoring target is yourself. You can also set the monitoring target to other nodes.

  • Install and start the node_exporter node

    curl -OL https://github.com/prometheus/node_exporter/releases/download/v0.15.2/node_exporter0.15.2.darwin-amd64.tar.gz
    tar -xzf node_exporter0.15.2.darwin-amd64.tar.gz
    nohup /usr/local/node_exporter/node_exporter
    Copy the code

Node_exporter is run by node_exporter, which can be seen as a bundle of logs.

These logs are called and displayed by Prometheus.

  • Granfan installs and starts

This is a performance monitoring tool with a graphical interface and is very easy to install and start.

sudo apt-get install grafana
service grafana-server start
Copy the code

The Grafana dashboard allows you to add Prometheus to the monitor.

In general, it’s relatively simple.

3. K8s combined with Prometheus and Granfan

www.qikqiak.com/post/kubern…

This blog post is also a good example of k8S and Prometheus Granfan combined.

4. Common problems with Prometheus

www.ershicimi.com/p/b27a4437f…