ÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄÈÝÆ÷±àÅŹ¤¾ß¼à¿Ø
ÔõÑùÔÚlinuxÉÏÉèÖø߿ÉÓõÄÈÝÆ÷±àÅŹ¤¾ß¼à¿Ø
СÐò£º
Ëæ×ÅÈÝÆ÷ÊÖÒÕµÄÆÕ±éÓ¦Óã¬ÈÝÆ÷±àÅŹ¤¾ßÈçKubernetes¡¢Docker SwarmµÈÒ²±äµÃÔ½À´Ô½Ö÷Òª¡£ÔÚÉú²úÇéÐÎÖУ¬ÎªÁË°ü¹ÜЧÀ͵ĸ߿ÉÓÃÐÔºÍÎȹÌÐÔ£¬ÎÒÃÇÐèÒª¶ÔÈÝÆ÷±àÅŹ¤¾ß¾ÙÐмà¿ØºÍÖÎÀí¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚlinuxÉÏÉèÖø߿ÉÓõÄÈÝÆ÷±àÅŹ¤¾ß¼à¿Ø£¬²¢ÎªÄúÌṩÏà¹ØµÄ´úÂëʾÀý¡£
°ì·¨Ò»£º×°ÖÃPrometheus
PrometheusÊÇÒ»¸ö¿ªÔ´µÄ¼à¿ØºÍ¾¯±¨ÏµÍ³£¬ÊÊÓÃÓÚÈÝÆ÷ÇéÐΡ£Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚLinuxÉÏ×°ÖÃPrometheus¡£Çëƾ֤ÒÔÏ°취¾ÙÐвÙ×÷£º
ÏÂÔØPrometheus¶þ½øÖÆÎļþ£º
wget https://github.com/prometheus/prometheus/releases/download/v2.15.2/prometheus-2.15.2.linux-amd64.tar.gz
µÇ¼ºó¸´ÖÆ
½âѹËõÎļþ£º
tar -zxvf prometheus-2.15.2.linux-amd64.tar.gz
µÇ¼ºó¸´ÖÆ
½øÈë½âѹºóµÄĿ¼£º
cd prometheus-2.15.2.linux-amd64/
µÇ¼ºó¸´ÖÆ
ÉèÖÃPrometheus£º
ÔÚ prometheus.yml ÎļþÖÐÌí¼ÓÒÔÏÂÄÚÈÝ£º
global: scrape_interval: 15s evaluation_interval: 15s scrape_configs: - job_name: 'prometheus' scrape_interval: 5s static_configs: - targets: ['localhost:9090'] - job_name: 'kubernetes' kubernetes_sd_configs: - api_server: 'http://localhost:8001' relabel_configs: - source_labels: [__meta_kubernetes_pod_label_app] action: keep regex: 'your-app-name-here'
µÇ¼ºó¸´ÖÆ
Æô¶¯Prometheus£º
./prometheus
µÇ¼ºó¸´ÖÆ
ÖÁ´Ë£¬PrometheusÒѾװÖò¢ÔËÐÐÔÚLinuxÉÏ¡£
°ì·¨¶þ£ºÉèÖÃGrafana
GrafanaÊÇÒ»¸ö¿ªÔ´µÄÊý¾Ý¿ÉÊÓ»¯ºÍ¼à¿ØÒDZíÅ̹¤¾ß¡£ÎÒÃÇ¿ÉÒÔʹÓÃGrafanaÀ´Õ¹Ê¾PrometheusÍøÂçµÄ¼à¿ØÊý¾Ý¡£Çëƾ֤ÒÔÏ°취¾ÙÐвÙ×÷£º
ÏÂÔØGrafana¶þ½øÖÆÎļþ£º
wget https://dl.grafana.com/oss/release/grafana-6.6.0.linux-amd64.tar.gz
µÇ¼ºó¸´ÖÆ
½âѹËõÎļþ£º
tar -zxvf grafana-6.6.0.linux-amd64.tar.gz
µÇ¼ºó¸´ÖÆ
½øÈë½âѹºóµÄĿ¼£º
cd grafana-6.6.0/bin/
µÇ¼ºó¸´ÖÆ
Æô¶¯Grafana£º
./grafana-server
µÇ¼ºó¸´ÖÆ
ÔÚä¯ÀÀÆ÷Öлá¼ûGrafana£º
ÔÚä¯ÀÀÆ÷ÖÐÊäÈë http://localhost:3000£¬µÇ¼GrafanaĬÈϵÄÓû§ÃûºÍÃÜÂë¾ùΪadmin¡£
µã»÷×ó²à²Ëµ¥µÄ “Configuration” -> “Data Sources”£¬È»ºóµã»÷ “Add data source”¡£
ÌîдÒÔÏÂÐÅÏ¢£º
Name: Prometheus
Type: Prometheus
URL: http://localhost:9090
µã»÷ “Save & Test”¡£
°ì·¨Èý£ºÉèÖÃAlertmanager
AlertmanagerÊÇÒ»¸öÓÃÓÚÖÎÀíºÍ·¢Ë;¯±¨µÄ×é¼þ£¬¿ÉÒÔÓëPrometheus¼¯³É¡£Çëƾ֤ÒÔÏ°취¾ÙÐвÙ×÷£º
ÏÂÔØAlertmanager¶þ½øÖÆÎļþ£º
wget https://github.com/prometheus/alertmanager/releases/download/v0.20.0/alertmanager-0.20.0.linux-amd64.tar.gz
µÇ¼ºó¸´ÖÆ
½âѹËõÎļþ£º
tar -zxvf alertmanager-0.20.0.linux-amd64.tar.gz
µÇ¼ºó¸´ÖÆ
½øÈë½âѹºóµÄĿ¼£º
cd alertmanager-0.20.0.linux-amd64/
µÇ¼ºó¸´ÖÆ
ÉèÖÃAlertmanager£º
ÔÚ alertmanager.yml ÎļþÖÐÌí¼ÓÒÔÏÂÄÚÈÝ£º
global: slack_api_url: 'your-slack-api-url' route: receiver: 'slack'
µÇ¼ºó¸´ÖÆ
name: ‘slack’
slack_configs:
channel: ‘#your-slack-channel’
ÆäÖУ¬ your-slack-api-url ÊÇÄúµÄSlack API URL£¬ your-slack-channel ÊÇÄúÒª·¢Ë;¯±¨µÄSlackƵµÀ¡£
Æô¶¯Alertmanager£º
./alertmanager
µÇ¼ºó¸´ÖÆ
ÖÁ´Ë£¬AlertmanagerÒѾװÖò¢ÔËÐÐÔÚLinuxÉÏ¡£
½áÂÛ£º
ͨ¹ýÒÔÉÏ°ì·¨£¬ÎÒÃÇÀÖ³É×°Öò¢ÉèÖÃÁ˸߿ÉÓõÄÈÝÆ÷±àÅŹ¤¾ß¼à¿Øϵͳ¡£PrometheusÈÏÕæÍøÂçºÍ´æ´¢¼à¿ØÖ¸±ê£¬GrafanaÌṩÁË¿ÉÊÓ»¯µÄÒDZíÅÌ£¬¶øAlertmanagerÓÃÓÚÖÎÀíºÍ·¢Ë;¯±¨¡£ÕâЩ¹¤¾ß½«×ÊÖúÄú¼à¿ØºÍÖÎÀíÈÝÆ÷±àÅŹ¤¾ß£¬Ìá¸ßϵͳµÄ¿ÉÓÃÐÔºÍÎȹÌÐÔ¡£Ò»Ö±Ñ§Ï°ºÍÊìÁ·Ê¹ÓÃÕâЩ¹¤¾ß£¬Äܹ»¸üºÃµØÖÎÀíÄúµÄÈÝÆ÷ÇéÐΡ£
´úÂëʾÀý£º
ÔÚÉÏÊö°ì·¨ÖУ¬ÎÒÃÇÒѾÌṩÁËÏìÓ¦µÄ´úÂëʾÀý£¬°üÀ¨PrometheusµÄÉèÖÃÎļþ prometheus.yml¡¢GrafanaµÄÉèÖúÍAlertmanagerµÄÉèÖÃÎļþ alertmanager.yml¡£Äú¿ÉÒÔƾ֤ÉÏÊöʾÀý¾ÙÐвÙ×÷£¬²¢Æ¾Ö¤×Ô¼ºµÄÏÖÕæÏàÐξÙÐÐÏìÓ¦µÄÐ޸ġ£
Çë×¢ÖØ£¬´úÂëʾÀý½öΪ²Î¿¼£¬ÏêϸÉèÖúͲÎÊý¿ÉÄÜÒòÏÖÕæÏàÐζøÓÐËù²î±ð£¬Çëƾ֤ÄúµÄÐèÇó¾ÙÐÐÏìÓ¦µÄµ÷½â¡£
²Î¿¼×ÊÁÏ£º
Prometheus¹Ù·½Îĵµ£ºhttps://prometheus.io/docs/
Grafana¹Ù·½Îĵµ£ºhttps://grafana.com/docs/
Alertmanager¹Ù·½Îĵµ£ºhttps://prometheus.io/docs/alerting/alertmanager/
ÒÔÉϾÍÊÇÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄÈÝÆ÷±àÅŹ¤¾ß¼à¿ØµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡