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

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.

主站蜘蛛池模板: 新龙县| 安福县| 房山区| 大名县| 新建县| 阜康市| 沙河市| 富川| 遵化市| 延川县| 贞丰县| 永善县| 句容市| 锡林郭勒盟| 广饶县| 富阳市| 工布江达县| 乌兰县| 大安市| 新安县| 兖州市| 山东省| 萨嘎县| 仁寿县| 卫辉市| 阜城县| 东乌珠穆沁旗| 铜山县| 长葛市| 九龙坡区| 东至县| 手游| 仪征市| 清水县| 铜梁县| 吉木乃县| 台安县| 福贡县| 桐梓县| 衡南县| 会泽县|