扫码阅读
手机扫码阅读

云原生丨Prometheus+Grafana监控 OpenGauss 数据库

329 2023-09-22

Cloud Native

ESG服务BU云原生交付中心、云基地

在云原生上的尝试、调研与分享



本期内容

Prometheus+Grafana

监控高斯数据库

随着科技发展,企业业务多样化带来的架构庞大而复杂,致使监控越来越重要。通过监控,我们可以对所研发的服务运行状态进行收集、告警、查看趋势等。


相较于之前,对于硬件监控较多,会选择zabbix,但近几年随着云原生的快速发展,各种应用容器化、微服务流行起来,新一代的监控如Prometheus等应运而生。

俗话说,没有监控的系统就是在裸奔,好的监控就是运维人员的第三只手,第三只眼。本期我们将使用Prometheus及Grafana搭建一套监控系统来监控OpenGauss 数据库(高斯数据库)

Prometheus

介绍及安装

Prometheus 介绍

Prometheus是一个开源监控解决方案,用于收集和聚合指标作为时间序列数据

在Kubernetes容器管理系统中,通常会搭配Prometheus进行监控,同时也支持多种exporter采集数据,还支持pushgateway进行数据上报。Prometheus性能足够支撑上万台规模的集群。

Prometheus 安装

Step 1:下载、解压、创建软链接

wget https://github.com/prometheus/prometheus/releases/download/v2.13.0/prometheus-2.13.0.linux-amd64.tar.gztar -xf prometheus-2.13.0.linux-amd64.tar.gzmv prometheus-2.13.0.linux-amd64 /usr/local/ln -s /usr/local/prometheus-2.13.0.linux-amd64/ /usr/local/prometheus

Step 2:创建Prometheus的用户及数据存储目录

useradd  -s /sbin/nologin -M prometheusmkdir  /data/prometheus -p

Step 3:启动Prometheus

nohup ./usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/data/prometheus &

Step 4:开放端口

iptables -I INPUT -p tcp --dport 9090 -j ACCEPT

Prometheus 配置文件 promethes.yml 需要更改该配置文件:

# my global configglobal: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # scrape_timeout is set to the global default (10s). # Alertmanager configurationalerting: alertmanagers: - static_configs: - targets: # - alertmanager:9093 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.rule_files: # - "first_rules.yml" # - "second_rules.yml" # A scrape configuration containing exactly one endpoint to scrape:# Here it's Prometheus itself.scrape_configs: # The job name is added as a label `job=` to any timeseries scraped from this config. - job_name: 'prometheus'  # metrics_path defaults to '/metrics' # scheme defaults to 'http'.  static_configs: - targets: ['localhost:9090']   #示例:定时pull node探针的数据 - job_name: 'node' static_configs: - targets: ['localhost:9100']   - job_name: 'opengauss' static_configs: - targets: ['localhost:9187']

Grafana的介绍及安装

Grafana 介绍

Grafana 是一款开源的数据可视化工具,使用 Grafana 可以非常轻松的将数据转成图表(如下图)的展现形式来做到数据监控以及数据统计。

Grafana 安装

Step 1:下载、解压、创建软链接

wget https://dl.grafana.com/oss/release/grafana-6.4.2.linux-amd64.tar.gztar -zxvf grafana-6.4.2.linux-amd64.tar.gzmv grafana-6.4.2 /usr/local/ln -s /usr/local/grafana-6.4.2/ /usr/local/grafana

Step 2:创建grafana用户及数据存放目录

useradd -s /sbin/nologin -M grafanamkdir /data/grafanachown -R grafana:grafana /usr/local/grafana/chown -R grafana:grafana  /data/grafana/

Step 3:修改配置文件

修改配置文件 /usr/local/grafana/conf/defaults.ini 文件

将文件内容梗概为以下内容:

data = /data/grafana/datalogs = /data/grafana/logplugins = /data/grafana/pluginsprovisioning = /data/grafana/conf/provisioning

Step 4:启动Grafana

nohup ./usr/local/grafana/bin/grafana-server -homepath /usr/local/grafana &

安装探针

安装Node Exporter探针

Step 1:下载、解压

wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gztar -xf node_exporter-0.18.1.linux-amd64.tar.gz

Step 2:新建一个目录专门安装各种exporter

mkdir -p /usr/local/prometheus_exportermv node_exporter-0.18.1.linux-amd64 /usr/local/prometheus_exporter/cd /usr/local/prometheus_exporter/ln -s node_exporter-0.18.1.linux-amd64/ node_exporter

Step 3:启动探针Node Exporter服务

cd /usr/local/prometheus_exporter/node_exporter/nohup ./node_exporter >/dev/null 2>&1 &

Node 探针监控端口为 9100,需要更改promethes.yml文件后重启Prometheus才会生效

安装opengauss_exporter探针

Step 1:下载、解压

下载:

opengauss_exporter_0.0.9_linux_amd64.zip

官方地址为:

https://gitee.com/opengauss/openGauss-prometheus-exporter

Step 2:解压

unzip opengauss_exporter_0.0.9_linux_amd64.zipmv opengauss_exporter_0.0.9_linux_amd64 /usr/local/prometheus_exporter/cd /usr/local/prometheus_exporter/ln -s opengauss_exporter_0.0.9_linux_amd64/ opengauss_exportercd opengauss_exporter

Step 3:设置环境变量

export DATA_SOURCE_NAME="host=数据库Ip地址 user=用户名 password=用户密码 port=数据库端口 dbname=数据库名 sslmode=disable"

Step 4:启动opengauss_exporter探针服务

nohup ./opengauss_exporter &

opengauss_exporter 与 postgres_exporter 探针一样,监听的都是9187端口,需要更改promethes.yml文件重启后才会生效

访问Prometheus

与Grafana

访问Prometheus

访问Prometheus 服务,localhost:9090 ,可以看到三个监听的服务,其中9090为默认的

访问 Grafana

访问 Grafana ,localhost:3000;

Step 1:添加数据源

点击保存并测试后,选择 Dashboards Tab 页,导入 Prometheus 2.0。

Step 2:导入 Node Dashboard

选择数据源

成功监控主机状态

监测OpenGauss

数据库

完成以上内容,至此,一套完整的监控系统就搭建好了。一起来看看效果吧~ ⬇

总结

监控是在业务开发中必不可少的一部分。

有了监控,就相当于给开发人员装上了眼睛和耳朵,实时的可以对服务运行状况进行监测,以及在系统出现异常时第一时间通知到相关人员以快速处理。

本期我们重点围绕Prometheus与Grafana搭建了一套监控系统,实现监测OpenGauss 数据库。

当然,若在生产环境下实际应用,大家还需借助云平台现有的服务以便降低自己搭建的复杂度

云平台的监控系统搭建实战

如果感兴趣,快上手试试

如果你有更好的办法或疑问

欢迎加入社群一起讨论哦⬇


本期作者

王凯

原文链接: http://mp.weixin.qq.com/s?__biz=Mzg5MzUyOTgwMQ==&mid=2247519119&idx=1&sn=bfa377f70f75bdc0f5c0d97d982ae3c3&chksm=c02fb029f758393fd5e10db230c731927b01911d9deac22b396fdc1f4e83719b1f87fa980b80#rd