istio+prometheus+grafana 流量监控

从零到一配置 OpenAP

概要

       Istio采集指标prometheus+grafana方案,搭建(promethues+prometheus-postgresql-adapter+pg_prometheus) promethues·监控存储平台,

通过Istio+grafana 进行istio流量注入grafana图表展示,实现对API流量的统计。

配置 Prometheus 并且把数据存储至  Postgres (Prometheus + Postgres[TimescaleDB(pg_prometheus)])

安装配置 Prometheus

  1. 安装prometheus
  2. 配置promethues.yaml. 配置参数如下:
global:
scrape_interval: 5s
evaluation_interval: 5s
external_labels:
monitor: ‘codelab-monitor‘
scrape_configs:
- job_name: prometheus
static_configs:
- targets:
- node-exporter-default:9100

- job_name: dx-servicemesh
static_configs:
- targets:
- istio-telemetry.istio-system:42422

remote_write:
- url: "http://prometheus-postgresql-adapter-default:9201/write"  # 远程写入pg,需要用适配器转接
remote_read:
- url: "http://prometheus-postgresql-adapter-default:9201/read"

配置 Prometheus 数据存储至 Postgres

要将TimescaleDB和PostgreSQL连接到Prometheus,有两个组件:a. 的 Prometheus_PostgreSQL_Adapter   b.具有pg_prometheustimescaledb扩展名的PostgreSQL数据库

1.安装pg_prometheus:

  • 在postgresql的postgresql.conf中添加:shared_preload_libraries = ‘pg_prometheus‘,重启psql
  • 使用psql创建扩展:CREATE EXTENSION pg_prometheus;
  • 创建role: CREATE ROLE admin WITH LOGIN PASSWORD ‘admin‘;
  • 授权role admin:GRANT ALL ON SCHEMA prometheus TO admin;
  • 创建table:SELECT create_prometheus_table(‘metrics‘);

2.安装prometheus-postgresql-adapter:

启动命令如下,需要注意的是,由于在容器内部运行,-pg.host必须指定postgresql主机的地址,而非loopback接口:

-pg-host\=pg-prometheus-default -pg-password\=123456 -pg-prometheus-log-samples  # 连接pg数据库

配置集群外部服务接入,并监控访问流量 (Istio + Prometheus + Grafana)

安装 Istio

Istio.yam:l

# Gateway描述了在网格边缘运行的负载均衡器,用于接收传入或传出的HTTP / TCP连接
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: gateway-external-svcentry
spec:
selector:
istio: ingressgateway # use Istio default gateway implementation
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- external.with.svcentry

---
# VirtualService定义了一组寻址主机时要应用的流量路由规则
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: vs-external-svcentry
spec:
hosts:
- external.with.svcentry
gateways:
- gateway-external-svcentry
http:
- match:
- uri:
prefix: /
route:
- destination:
port:
number: 80
host: google-external-svcentry.service-pro.svc.cluster.local

---

apiVersion: v1
kind: Service
metadata:
name: google-external-svcentry
spec:
ports:
- name: http-8205
port: 80
protocol: TCP
targetPort: 8205
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}

---

apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
generation: 1
name: se-external-svcentry
spec:
endpoints:
- address: 10.8.1.157  #接入外部服务IP
labels: {}
hosts:
- google-external-svcentry.service-pro.svc.cluster.local
ports:
- name: http-8205
number: 8205  #外部服务端口
protocol: HTTP
resolution: STATIC

安装 Grafana

Grafana接入promethues图表显示,

Grafana接入pgsql进行图表展示。

配置 Prometheus 抓取 Istio 访问请求

mixer组件中遥测相关的对外提供的Kubernetes的Service的服务名是istio-telemetry,mixer对外开放的exporter的数据查询接口是/metrics;

- job_name: dx-servicemesh
static_configs:
- targets:
- istio-telemetry.istio-system:42422

Istio 接入外部服务

开放服务的IP和端口,接入istio服务。(这边开放了一个Google的IP和端口:10.7.122.10:30025)

apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
generation: 1
name: se-external-svcentry
spec:
endpoints:
- address: 10.7.122.10  #接入外部服务IP
labels: {}
hosts:
- google-external-svcentry.service-pro.svc.cluster.local
ports:
- name: http-8205
number: 30025  #外部服务端口
protocol: HTTP
resolution: STATIC

自己搭建的一个小demo:

1.	pg查询Google翻译istio_requests_total:

	连接pg数据库:
	命令: psql -U postgres -h 10.7.122.10 -p 30018 -d postgres 

	password:123456

	查询语句:

	SELECT time, name, value, labels FROM metrics WHERE name = ‘istio_requests_total‘ AND time >= ‘2020-01-03T09:54:53Z‘ AND time <= ‘2020-02-03T10:59:53Z‘  AND labels @> ‘{"destination_service":"google-external-svcentry.service-pro.svc.cluster.local","monitor":"codelab-monitor"}‘ ORDER BY time \g 

2.  promethues:http://10.7.122.10:30008/graph

	PromQL:istio_requests_total{destination_service="google-external-svcentry.service-pro.svc.cluster.local"}

3. Grafana: http://10.7.122.10:31234/dashboard/new?tab=queries&panelId=2&edit&fullscreen&orgId=1

	user: admin
	password:admin
	Metrics:istio_requests_total{destination_service="google-external-svcentry.service-pro.svc.cluster.local"}

原文地址:https://www.cnblogs.com/hanvans/p/12161892.html

时间: 2024-08-30 11:22:49

istio+prometheus+grafana 流量监控的相关文章

k8s+Prometheus+Grafana的监控部署

一.安装部署k8s集群 可以参考https://www.cnblogs.com/liugp/p/12115945.html 二.Prometheus+Grafana的监控部署 2.1.master/node节点环境部署 在[master]可以进行安装部署安装git,并下载相关yaml文件 https://gitee.com/liugpwwwroot/k8s-prometheus-grafana.git 在[node]节点下载监控所需镜像(非必须) docker pull prom/node-ex

prometheus+grafana+docker 监控tomcat jvm

说明:基于环境mesos+marathon+docker+prometheus+grafana监控tomcat一.配置环境(1)dockerfile from tomcat COPY tomcat-users.xml /usr/local/tomcat/conf/ COPY server.xml /usr/local/tomcat/conf/ COPY context.xml /usr/local/tomcat/webapps/manager/META-INF/ COPY catalina.sh

Prometheus+Grafana部署监控docker服务

1.环境192.168.244.128 Prometheus 监控服务器192.168.244.129 docker 服务(被监控端)注:都是centos7.5系统 2.下载安装包https://prometheus.io/download/ (需要的安装包都可以下载)wget https://github.com/prometheus/prometheus/releases/download/v2.3.2/prometheus-2.3.2.linux-amd64.tar.gz 服务端(监控se

springboot2+exporter+prometheus+grafana搭建监控体系

项目中需要监控系统指标(JVM,CPU,IO,MySQL等),这时候可以使用Prometheus来做.如果是需要监控日志系统,可以使用ELK stack.监控=日志(ELK)+指标(Prometheus). step1 编写springboot2程序 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</art

基于prometheus+grafana 搭建监控mysql redis mongodb等

先把题目定好,具体待这几天整理我的笔记补充进来. 官方网站 https://prometheus.io/ 参考文档: http://www.cnblogs.com/sfnz/p/6566951.html http://www.jb51.net/article/107386.htm https://www.iamle.com/archives/2130.html

Prometheus + Grafana 监控系统搭

本文主要介绍基于Prometheus + Grafana 监控Linux服务器. 一.Prometheus 概述(略) 与其他监控系统对比 1 Prometheus vs. Zabbix Zabbix 使用的是 C 和 PHP, Prometheus 使用 Golang, 整体而言 Prometheus 运行速度更快一点. Zabbix 属于传统主机监控,主要用于物理主机.交换机.网络等监控,Prometheus 不仅适用主机监控,还适用于 Cloud.SaaS.Openstack.Contai

Prometheus+Grafana监控部署实践

参考文档: Prometheus github:https://github.com/prometheus grafana github:https://github.com/grafana/grafana Prometheus getting_started:https://prometheus.io/docs/prometheus/latest/getting_started/ Prometheus node_exporter:https://github.com/prometheus/no

prometheus+grafana+consul+supervisor搭建监控系统(一)之supervisor搭建

随着公司业务增大,zabbix+脚本监控已经不能满足需求,经过一段时间的研究发现prometheus+grafana+consul+supervisor非常不错,supervisor托管非daemod进程,动态注册到consul中,prometheus通过targets发现consul中的服务,Grafan中data Source配置:Prometheus(http://xxx.xxx.xxx.xxx:9090)获取源数据展示出来(非常漂亮,美观) 把搭建的过程分享给大家  PS:有些还在研究中

cAdvisor+Prometheus+Grafana监控docker

cAdvisor+Prometheus+Grafana监控docker 一.cAdvisor(需要监控的主机都要安装) 官方地址:https://github.com/google/cadvisor CAdvisor是谷歌开发的用于分析运行中容器的资源占用和性能指标的开源工具.CAdvisor是一个运行时的守护进程,负责收集.聚合.处理和输出运行中容器的信息.注意在查找相关资料后发现这是最新版cAdvisor的bug,换成版本为google/cadvisor:v0.24.1 就ok了,映射主机端