官术网_书友最值得收藏!

Querying metrics

Targets are up and running, and Prometheus is scraping their data. We should generate some traffic that would let us see Prometheus query language in action.

We'll deploy go-demo stack. It contains a service with an API and a corresponding database. We'll use it as a demo service that will allow us to explore better some of the metrics we can use.

docker stack deploy \  
    -c stacks/go-demo.yml \  
    go-demo 

We should wait a few moments for the services from the go-demo stack to start running. Please execute docker stack ps go-demo to confirm that all the replicas are running.

Now that the demo service is running, we can explore some of the metrics we have at our disposal by opening graph page.

open "http://$(docker-machine ip swarm-1)/monitor/graph"

Please type haproxy_backend_connections_total in the Expression field, and press the Execute button. The result should be zero connections on the backend go-demo_main-be8080. Let's spice it up by creating a bit of traffic:

for ((n=0;n<200;n++)); do 
    curl "http://$(docker-machine ip swarm-1)/demo/hello" 
done 

We sent 200 requests to the go-demo service.

If we go back to the Prometheus UI and repeat the execution of the haproxy_backend_connections_total expression, the result should be different. In my case, there are 200 backend connections from go-demo_main-be8080.

Figure 4-4: HA Proxy metrics

We could display the data as a graph by clicking the Graph tab.

You might be tempted to make a Dashboard (or two) in Prometheus. Don't! I recommend using Grafana, even though it is out of the scope of this book.

How about memory usage? We have the data through cadvisor so we might just as well use it.

Please type container_memory_usage_bytes{container_label_com_docker_swarm_service_name="go-demo_main"} in the Expression field and click the Execute button.

The result is memory usage limited to the Docker service go-demo_main. Depending on the view, you should see three values in Console or three lines in the Graph tab. They represent memory usage of the three replicas of the go-demo_main service.

Figure 4-5: cAdvisor metrics

Finally, let's explore one of the node-exporter metrics. We can, for example, display the amount of available memory from each of the nodes.

Please type sum by (instance) (node_memory_MemFree) in the Expression field and click the Execute button.

The result is a representation of free memory for each of the nodes of the cluster:

Figure 4-6: Graph with available memory

Now that we had a very brief overview of the ways we can query metrics, we should start using them.

主站蜘蛛池模板: 栾城县| 得荣县| 崇义县| 文昌市| 本溪| 宜黄县| 青田县| 镇安县| 南木林县| 台南县| 紫阳县| 平定县| 通江县| 庐江县| 新源县| 博罗县| 大丰市| 金川县| 陕西省| 金门县| 岐山县| 东兴市| 新巴尔虎右旗| 天全县| 永仁县| 思南县| 德格县| 岑溪市| 全南县| 郓城县| 荣昌县| 嘉鱼县| 平罗县| 江安县| 宝清县| 安陆市| 皋兰县| 贵溪市| 华蓥市| 平定县| 舞阳县|