使用Promethues+Grafana对Greenplum数据库监控

0    117    1

Tags:

👉 本文共约8837个字,系统预计阅读时间或需34分钟。

Promethues与Grafana简介

1、Prometheus简介

Prometheus是由SoundCloud开发的开源监控报警系统和时序列数据库(TSDB),使用Go语言开发。Prometheus目前在开源社区相当活跃。Prometheus性能也足够支撑上万台规模的集群。其架构图如下:

使用Promethues+Grafana对Greenplum数据库监控

  • Prometheus Server, 负责从 Exporter 拉取和存储监控数据,并提供一套灵活的查询语言(PromQL)供用户使用。
  • Exporter, 负责收集目标对象(host, container…)的性能数据,并通过 HTTP 接口供 Prometheus Server 获取。
  • 可视化组件,监控数据的可视化展现对于监控方案至关重要。以前 Prometheus 自己开发了一套工具,不过后来废弃了,因为开源社区出现了更为优秀的产品 Grafana。Grafana 能够与 Prometheus 无缝集成,提供完美的数据展示能力。
  • Alertmanager,用户可以定义基于监控数据的告警规则,规则会触发告警。一旦 Alermanager 收到告警,会通过预定义的方式发出告警通知。支持的方式包括 Email、PagerDuty、Webhook 等.

2、Grafana简介

Grafana是一个跨平台的开源的度量分析和可视化工具,可以通过将采集的数据查询然后可视化的展示,并及时通知。它主要有以下六大特点:

  • 1、展示方式:快速灵活的客户端图表,面板插件有许多不同方式的可视化指标和日志,官方库中具有丰富的仪表盘插件,比如热图、折线图、图表等多种展示方式;
  • 2、数据源:Graphite,InfluxDB,OpenTSDB,Prometheus,Elasticsearch,CloudWatch和KairosDB等;
  • 3、通知提醒:以可视方式定义最重要指标的警报规则,Grafana将不断计算并发送通知,在数据达到阈值时通过Slack、PagerDuty等获得通知;
  • 4、混合展示:在同一图表中混合使用不同的数据源,可以基于每个查询指定数据源,甚至自定义数据源;
  • 5、注释:使用来自不同数据源的丰富事件注释图表,将鼠标悬停在事件上会显示完整的事件元数据和标记;
  • 6、过滤器:Ad-hoc过滤器允许动态创建新的键/值过滤器,这些过滤器会自动应用于使用该数据源的所有查询。

Greenplum监控的实现

Greenplum的监控可类似于PostgreSQL来实现,但又存在差异,不同点在于:

  • 要实现一个Greenplum的Exporter指标采集器;
  • 使用Grafana绘制一个可视化状态图;
  • 基于Prometheus配置报警规则;

1、Greenplum的Exporter指标采集器

这里类比PostgreSQL数据库的Exporter实现方法,实现了一个Greenplum的Exporter,项目地址为:

https://github.com/tangyibo/greenplum_exporter

在greenplum_expoter里主要扩展了实现了客户连接信息、账号连接信息、Segment存储信息、集群节点同步状态、数据库锁监控等相关指标,具体指标如下:

2、支持的监控指标

No.指标名称类型标签组度量单位指标描述数据源获取方法GP版本
1greenplum_cluster_stateGaugeversion; master(master主机名);standby(standby主机名)booleangp 可达状态 ?:1→ 可用;0→ 不可用SELECT count(*) from gp_dist_random('gp_id'); select version(); SELECT hostname from gp_segment_configuration where content=-1 and role='p';ALL
2greenplum_cluster_uptimeGauge-int启动持续的时间select extract(epoch from now() - pg_postmaster_start_time());ALL
3greenplum_cluster_syncGauge-intMaster同步Standby状态? 1→ 正常;0→ 异常SELECT count(*) from pg_stat_replication where state='streaming'ALL
4greenplum_cluster_max_connectionsGauge-int最大连接个数show max_connections; show superuser_reserved_connections;ALL
5greenplum_cluster_total_connectionsGauge-int当前连接个数select count() total, count() filter(where current_query='') idle, count() filter(where current_query<>'') active, count() filter(where current_query<>'' and not waiting) running, count(*) filter(where current_query<>'' and waiting) waiting from pg_stat_activity where procpid <> pg_backend_pid();ALL
6greenplum_cluster_idle_connectionsGauge-intidle连接数同上ALL
7greenplum_cluster_active_connectionsGauge-intactive query同上ALL
8greenplum_cluster_running_connectionsGauge-intquery executing同上ALL
9greenplum_cluster_waiting_connectionsGauge-intquery waiting execute同上ALL
10greenplum_node_segment_statusGaugehostname; address; dbid; content; preferred_role; port; replication_portintsegment的状态status: 1(U)→ up; 0(D)→ downselect * from gp_segment_configuration;ALL
11greenplum_node_segment_roleGaugehostname; address; dbid; content; preferred_role; port; replication_portintsegment的role角色: 1(P)→ primary; 2(M)→ mirror同上ALL
12greenplum_node_segment_modeGaugehostname; address; dbid; content; preferred_role; port; replication_portintsegment的mode:1(S)→ Synced; 2(R)→ Resyncing; 3(C)→ Change Tracking; 4(N)→ Not Syncing同上ALL
13greenplum_node_segment_disk_free_mb_sizeGaugehostnameMBsegment主机磁盘空间剩余大小(MB)SELECT dfhostname as segment_hostname,sum(dfspace)/count(dfspace)/(1024*1024) as segment_disk_free_gb from gp_toolkit.gp_disk_free GROUP BY dfhostnameALL
14greenplum_cluster_total_connections_per_clientGaugeclientint每个客户端的total连接数select usename, count() total, count() filter(where current_query='') idle, count(*) filter(where current_query<>'') active from pg_stat_activity group by 1;ALL
15greenplum_cluster_idle_connections_per_clientGaugeclientint每个客户端的idle连接数同上ALL
16greenplum_cluster_active_connections_per_clientGaugeclientint每个客户端的active连接数同上ALL
17greenplum_cluster_total_online_user_countGauge-int在线账号数同上ALL
18greenplum_cluster_total_client_countGauge-int当前所有连接的客户端个数同上ALL
19greenplum_cluster_total_connections_per_userGaugeusenameint每个账号的total连接数select client_addr, count() total, count() filter(where current_query='') idle, count(*) filter(where current_query<>'') active from pg_stat_activity group by 1;ALL
20greenplum_cluster_idle_connections_per_userGaugeusenameint每个账号的idle连接数同上ALL
21greenplum_cluster_active_connections_per_userGaugeusenameint每个账号的active连接数同上ALL
22greenplum_cluster_config_last_load_time_secondsGauge-int系统配置加载时间SELECT pg_conf_load_time()Only GPOSS6 and GPDB6
23greenplum_node_database_name_mb_sizeGaugedbnameMB每个数据库占用的存储空间大小SELECT dfhostname as segment_hostname,sum(dfspace)/count(dfspace)/(1024*1024) as segment_disk_free_gb from gp_toolkit.gp_disk_free GROUP BY dfhostnameALL
24greenplum_node_database_table_total_countGaugedbname-每个数据库内表的总数量SELECT count(*) as total from information_schema.tables where table_schema not in ('gp_toolkit','information_schema','pg_catalog');ALL
25greenplum_exporter_total_scrapedCounter-int--ALL
26greenplum_exporter_total_errorCounter-int--ALL
27greenplum_exporter_scrape_duration_secondGauge-int--ALL
28greenplum_server_users_name_listGauge-int用户总数SELECT usename from pg_catalog.pg_user;ALL
29greenplum_server_users_total_countGauge-int用户明细同上ALL
30greenplum_server_locks_table_detailGaugepid;datname;usename;locktype;mode;application_name;state;lock_satus;queryint锁信息SELECT * from pg_locksALL
31greenplum_server_database_hit_cache_percent_rateGauge-float缓存命中率select sum(blks_hit)/(sum(blks_read)+sum(blks_hit))*100 from pg_stat_database;ALL
32greenplum_server_database_transition_commit_percent_rateGauge-float事务提交率select sum(xact_commit)/(sum(xact_commit)+sum(xact_rollback))*100 from pg_stat_database;ALL

3、使用Grafana绘制一个可视化状态图

根据以上监测指标,即可使用Grafana配置图像了,具体内容请见:

https://github.com/tangyibo/greenplum_exporter/blob/master/grafana/greenplum_dashboard.json

Greenplum监控安装实现

该章节里讲述在CentOS7操作系统环境下的安装过程。

安装Promethues

下载地址:

https://prometheus.io/download/

https://github.com/prometheus/prometheus

--web.enable-lifecycle 加上此参数可以远程热加载配置文件,无需重启prometheus,调用指令是curl -X POST http://ip:9090/-/reload

-- storage.tsdb.retention.time 数据默认保存时间为15天,启动时加上此参数可以控制数据保存时间

创建Systemd服务

启动Prometheus

5、访问WEB界面

访问如下地址以检测验证成功安装:

http://192.168.8.8:29090

安装Greenplum-Expoter

说明:

1、该Exporter支持Greenplum V5.x及Greenplum V6.x等版本。

2、软件默认安装在: /usr/local/greenplum_exporter

本人提供Oracle(OCP、OCM)、MySQL(OCP)、PostgreSQL(PGCA、PGCE、PGCM)等数据库的培训和考证业务,私聊QQ646634621或微信db_bao,谢谢!
使用Promethues+Grafana对Greenplum数据库监控后续精彩内容已被小麦苗无情隐藏,请输入验证码解锁本站所有文章!
验证码:
请先关注本站微信公众号,然后回复“验证码”,获取验证码。在微信里搜索“DB宝”或者“www_xmmup_com”或者微信扫描右侧二维码都可以关注本站微信公众号。

标签:

Avatar photo

小麦苗

学习或考证,均可联系麦老师,请加微信db_bao或QQ646634621

您可能还喜欢...

发表回复

嘿,我是小麦,需要帮助随时找我哦。
  • 18509239930
  • 个人微信

  • DB宝
  • 个人邮箱
  • 点击加入QQ群
  • 个人微店

  • 回到顶部