<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Grafana &#8211; 良的世界</title>
	<atom:link href="https://www.lemonary.cn/tag/grafana/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.lemonary.cn</link>
	<description></description>
	<lastBuildDate>Mon, 26 May 2025 06:48:55 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://www.lemonary.cn/wp-content/uploads/2024/12/logo-150x150.jpg</url>
	<title>Grafana &#8211; 良的世界</title>
	<link>https://www.lemonary.cn</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>搭建Prometheus+Grafana监控达梦数据库</title>
		<link>https://www.lemonary.cn/%e6%90%ad%e5%bb%baprometheusgrafana%e7%9b%91%e6%8e%a7%e8%be%be%e6%a2%a6%e6%95%b0%e6%8d%ae%e5%ba%93/</link>
					<comments>https://www.lemonary.cn/%e6%90%ad%e5%bb%baprometheusgrafana%e7%9b%91%e6%8e%a7%e8%be%be%e6%a2%a6%e6%95%b0%e6%8d%ae%e5%ba%93/#respond</comments>
		
		<dc:creator><![CDATA[shine]]></dc:creator>
		<pubDate>Mon, 26 May 2025 06:48:53 +0000</pubDate>
				<category><![CDATA[DM]]></category>
		<category><![CDATA[Grafana]]></category>
		<category><![CDATA[Prometheus]]></category>
		<category><![CDATA[Zabbix]]></category>
		<guid isPermaLink="false">https://www.lemonary.cn/?p=1859</guid>

					<description><![CDATA[原文地址：https://eco.dameng.com/community/post/202212111637 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>原文地址：<br><a href="https://eco.dameng.com/community/post/202212111637462EPK4EAM53PH9M9Q6W">https://eco.dameng.com/community/post/202212111637462EPK4EAM53PH9M9Q6W</a><br><a href="https://eco.dameng.com/community/post/202212160930507DKZJFLJ854UQE41TM">https://eco.dameng.com/community/post/202212160930507DKZJFLJ854UQE41TM</a></p>



<h2 class="wp-block-heading">一、前言</h2>



<p>使用监控软件实时监控达梦数据库的健康状况是保证高效运维工作的前提，接下来本文会从各个组件的搭建、如何自定义采集项exporter组件（源码）、手动/自动推送数据、邮件告警、短信告警、自动化部署脚本、注意事项等深入讲解热门监控软件Prometheu+Grafana监控达梦数据库的部署方法。</p>



<h2 class="wp-block-heading">二、组件介绍</h2>



<h3 class="wp-block-heading">2.1 Prometheus介绍</h3>



<p>Prometheus(由go语言(golang)开发)是一套开源的监控&amp;报警&amp;时间序列数据库（TSDB）的组合。它受启发于 Google 的 内部的监控系统，由工作在 SoundCloud 的前 google 员工在 2012 年创建，作为社区开源项目进行开发，并于 2015 年正式发布。<br>2016 年，doker容器化部署兴起，Prometheus 正式加入 Cloud Native Computing Foundation（CNCF）基金会的项目，成为受欢迎度仅次于 Kubernetes 的项目。2017 年底发布了基于全新存储层的 2.0 版本，能更好地与容器平台、云平台配合。因为kubernetes(俗称k8s)的流行带动了prometheus的发展。</p>



<p>官网：<a href="https://prometheus.io/docs/introduction/overview/">https://prometheus.io/docs/introduction/overview/</a></p>



<p>Prometheus的基本原理是通过HTTP周期性抓取被监控组件的状态（接口），任意组件只要提供对应的HTTP接口并且符合Prometheus定义的数据格式，就可以接入Prometheus监控。</p>



<p>Prometheus Server负责定时在目标（被监控组件）上抓取Metrics（指标）数据并保存到本地存储里面。Prometheus主要采用了Pull（拉）的方式获取数据，不仅降低客户端的复杂度，客户端只需要采集数据，无需了解服务端情况，而且服务端可以更加方便的水平扩展。</p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="442" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-2-1024x442.png" alt="" class="wp-image-1860" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-2-1024x442.png 1024w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-2-300x130.png 300w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-2-768x332.png 768w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-2.png 1125w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h3 class="wp-block-heading">2.2 Prometheus与Zabbix的对比</h3>



<p>Prometheus：Prometheus是由SoundCloud开发的开源监控报警系统和时序列数据库,并且系统每隔一两周就会有一个小版本的更新，而Prometheus与它的“师兄”Kubernetes都自带云原生的光环，天然能够友好协作。</p>



<p>Zabbix：Zabbix是由Alexei Vladishev开源的分布式监控系统，是一个企业级的分布式开源监控方案。能够监控各种网络参数以及服务器健康性和完整性的软件。</p>



<div class="wpdt-c row wpDataTableContainerSimpleTable wpDataTables wpDataTablesWrapper
"
    >
        <table id="wpdtSimpleTable-31"
           style="border-collapse:collapse;
                   border-spacing:0px;"
           class="wpdtSimpleTable wpDataTable"
           data-column="2"
           data-rows="8"
           data-wpID="31"
           data-responsive="0"
           data-has-header="0">

                    <tbody>        <tr class="wpdt-cell-row " >
                                <td class="wpdt-cell wpdt-fs-000016 wpdt-bold"
                                            data-cell-id="A1"
                    data-col-index="0"
                    data-row-index="0"
                    style=" width:49.098712446352%;                    padding:10px;
                    "
                    >
                                        Zabbix                    </td>
                                                <td class="wpdt-cell wpdt-fs-000016 wpdt-bold"
                                            data-cell-id="B1"
                    data-col-index="1"
                    data-row-index="0"
                    style=" width:50.901287553648%;                    padding:10px;
                    "
                    >
                                        Prometheus                    </td>
                                        </tr>
                            <tr class="wpdt-cell-row " >
                                <td class="wpdt-cell wpdt-fs-000016"
                                            data-cell-id="A2"
                    data-col-index="0"
                    data-row-index="1"
                    style="                    padding:10px;
                    "
                    >
                                        后端用C语言开发，界面用PHP开发，定制化难度很高。                    </td>
                                                <td class="wpdt-cell wpdt-fs-000016"
                                            data-cell-id="B2"
                    data-col-index="1"
                    data-row-index="1"
                    style="                    padding:10px;
                    "
                    >
                                        后端用golang开发，前端是Grafana，JSON编辑节即可解决。定制化难度较低。                    </td>
                                        </tr>
                            <tr class="wpdt-cell-row " >
                                <td class="wpdt-cell wpdt-fs-000016"
                                            data-cell-id="A3"
                    data-col-index="0"
                    data-row-index="2"
                    style="                    padding:10px;
                    "
                    >
                                        集群规模上限为10000个节点。                    </td>
                                                <td class="wpdt-cell wpdt-fs-000016"
                                            data-cell-id="B3"
                    data-col-index="1"
                    data-row-index="2"
                    style="                    padding:10px;
                    "
                    >
                                        支持更大的集群规模，速度也更快。                    </td>
                                        </tr>
                            <tr class="wpdt-cell-row " >
                                <td class="wpdt-cell wpdt-fs-000016"
                                            data-cell-id="A4"
                    data-col-index="0"
                    data-row-index="3"
                    style="                    padding:10px;
                    "
                    >
                                        更适合监控物理机环境。                    </td>
                                                <td class="wpdt-cell wpdt-fs-000016"
                                            data-cell-id="B4"
                    data-col-index="1"
                    data-row-index="3"
                    style="                    padding:10px;
                    "
                    >
                                        更适合云环境的监控，对OpenStack，Kubernetes有更好的集成。                    </td>
                                        </tr>
                            <tr class="wpdt-cell-row " >
                                <td class="wpdt-cell wpdt-fs-000016"
                                            data-cell-id="A5"
                    data-col-index="0"
                    data-row-index="4"
                    style="                    padding:10px;
                    "
                    >
                                        监控数据库存储在关系型数据库内，如MySQL，很难从现有数据中扩展维度。                    </td>
                                                <td class="wpdt-cell wpdt-fs-000016"
                                            data-cell-id="B5"
                    data-col-index="1"
                    data-row-index="4"
                    style="                    padding:10px;
                    "
                    >
                                        监控数据存储在基于时间序列的数据库内，便于对已有数据进行新的聚合。                    </td>
                                        </tr>
                            <tr class="wpdt-cell-row " >
                                <td class="wpdt-cell wpdt-fs-000016"
                                            data-cell-id="A6"
                    data-col-index="0"
                    data-row-index="5"
                    style="                    padding:10px;
                    "
                    >
                                        安装简单，zabbix-server一个软件包中包括了所有的服务端功能。                    </td>
                                                <td class="wpdt-cell wpdt-fs-000016"
                                            data-cell-id="B6"
                    data-col-index="1"
                    data-row-index="5"
                    style="                    padding:10px;
                    "
                    >
                                        安装相对复杂，监控、告警和界面都分属不同的组件。                    </td>
                                        </tr>
                            <tr class="wpdt-cell-row " >
                                <td class="wpdt-cell wpdt-fs-000016"
                                            data-cell-id="A7"
                    data-col-index="0"
                    data-row-index="6"
                    style="                    padding:10px;
                    "
                    >
                                        图形化界面比较成熟，界面上基本能完成全部的配置操作。                    </td>
                                                <td class="wpdt-cell wpdt-fs-000016"
                                            data-cell-id="B7"
                    data-col-index="1"
                    data-row-index="6"
                    style="                    padding:10px;
                    "
                    >
                                        界面相对较弱，很多配置需要修改配置文件。                    </td>
                                        </tr>
                            <tr class="wpdt-cell-row " >
                                <td class="wpdt-cell wpdt-fs-000016"
                                            data-cell-id="A8"
                    data-col-index="0"
                    data-row-index="7"
                    style="                    padding:10px;
                    "
                    >
                                        发展的时间更长，对于很多监控场景，都有现成的解决方案。                    </td>
                                                <td class="wpdt-cell wpdt-fs-000016"
                                            data-cell-id="B8"
                    data-col-index="1"
                    data-row-index="7"
                    style="                    padding:10px;
                    "
                    >
                                        2015年后开始快速发展，但发展时间较短，成熟度不及Zabbix。                    </td>
                                        </tr>
                    </table>
</div><style id='wpdt-custom-style-31'>
.wpdt-fs-000016 { font-size: 16px !important;}
</style>




<h3 class="wp-block-heading">2.3 Prometheus丨TSDB时序数据库</h3>



<p>时序数据库就是存放时序数据的数据库，并且需要支持时序数据的快速写入、持久化、多纬度的聚合查询等基本功能。</p>



<p>时间序列数据(TimeSeries Data) : 按照时间顺序记录系统、设备状态变化的数据被称为时序数据。应用的场景很多, 如：</p>



<ul class="wp-block-list">
<li>无人驾驶车辆运行中要记录的经度，纬度，速度，方向，旁边物体的距离等等。每时每刻都要将数据记录下来做分析</li>



<li>某一个地区的各车辆的行驶轨迹数据</li>



<li>传统证券行业实时交易数据</li>



<li>实时运维监控数据等</li>
</ul>



<h3 class="wp-block-heading">2.4 Grafana介绍</h3>



<p>Grafana是一款采用 Go 语言编写的开源应用，主要用于大规模指标数据的可视化展现，是网络架构和应用分析中最流行的时序数据展示工具，目前已经支持绝大部分常用的时序数据库。</p>



<p>下载地址：<a href="https://grafana.com/grafana/download/">https://grafana.com/grafana/download/</a></p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="554" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-3-1024x554.png" alt="" class="wp-image-1862" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-3-1024x554.png 1024w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-3-300x162.png 300w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-3-768x416.png 768w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-3.png 1125w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">三、配置Prometheus</h2>



<h3 class="wp-block-heading">3.1 下载Prometheus</h3>



<p>下载地址：<a href="https://prometheus.io/download/">https://prometheus.io/download/</a></p>



<p>根据环境下载对应的版本，x86环境的话用这个。</p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="517" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-4-1024x517.png" alt="" class="wp-image-1863" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-4-1024x517.png 1024w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-4-300x151.png 300w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-4-768x388.png 768w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-4-1536x775.png 1536w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-4.png 1761w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h3 class="wp-block-heading">3.2 安装Prometheus</h3>



<p>更新同步操作系统时间，避免时间误差</p>



<pre class="wp-block-code"><code>ntpdate edu.ntp.org.cn  &amp;&amp; hwclock -w</code></pre>



<p>创建目录</p>



<pre class="wp-block-code"><code>mkdir -p /opt/jiankong/jiankongSoft
cd /opt/jiankong/jiankongSoft</code></pre>



<p>上传压缩包到jiankongSoft下，并解压</p>



<pre class="wp-block-code"><code>tar -zxvf prometheus-3.4.0.linux-amd64.tar.gz -C /opt/jiankong/</code></pre>



<p>重命名prometheus文件名</p>



<pre class="wp-block-code"><code>cd /opt/jiankong/
mv prometheus-3.4.0.linux-amd64/ prometheus-3.4.0</code></pre>



<h3 class="wp-block-heading">3.3 启动Prometheus</h3>



<p>前台启动服务进行测试</p>



<pre class="wp-block-code"><code>cd prometheus-3.4.0/
./prometheus --config.file="prometheus.yml</code></pre>



<p>前台启动-指定监听端口（添加web.listen-address参数）</p>



<pre class="wp-block-code"><code>./prometheus --config.file="prometheus.yml" --web.listen-address="0.0.0.0:9091"</code></pre>



<p>验证是否启动正常</p>



<pre class="wp-block-code"><code>lsof -i:9091</code></pre>



<p>或者浏览器访问：<a href="http://192.168.241.131:9091/">http://192.168.241.131:9091/</a></p>



<p>验证无误后，改成后台方式启动</p>



<pre class="wp-block-code"><code>nohup ./prometheus --config.file="prometheus.yml" --web.listen-address="0.0.0.0:9091" > ./prometheus.log 2>&amp;1 &amp;</code></pre>



<p>查询进程是否存在</p>



<pre class="wp-block-code"><code>ps -ef|grep prometheus</code></pre>



<h3 class="wp-block-heading">3.4 使用Prometheus</h3>



<p>通过浏览器访问http://服务器IP:9091就可以访问到prometheus的主界面(默认时9090，我的是9091端口)</p>



<p><a href="http://192.168.241.131:9091/">http://192.168.241.131:9091/</a></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="364" height="619" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-5.png" alt="" class="wp-image-1864" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-5.png 364w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-5-176x300.png 176w" sizes="auto, (max-width: 364px) 100vw, 364px" /></figure>



<p>就可以查看监控的机器，如下</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="418" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-6-1024x418.png" alt="" class="wp-image-1865" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-6-1024x418.png 1024w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-6-300x122.png 300w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-6-768x313.png 768w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-6-1536x626.png 1536w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-6-2048x835.png 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>因为我已经全部配置好了，所以这里有三个节点。默认的情况下只监控本机（最下面一个）。</p>



<p>采集的信息可以通过http://服务器IP:9091/metrics可以查看到监控的数据 (prometheus本身也会采集本机的信息)<br><a href="http://192.168.145.161:9091/metrics">http://192.168.241.131:9091/metrics</a></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="549" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-7-1024x549.png" alt="" class="wp-image-1866" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-7-1024x549.png 1024w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-7-300x161.png 300w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-7-768x412.png 768w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-7-1536x823.png 1536w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-7-2048x1098.png 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>在web主界面可以通过关键字查询监控项</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="549" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-8-1024x549.png" alt="" class="wp-image-1867" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-8-1024x549.png 1024w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-8-300x161.png 300w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-8-768x412.png 768w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-8-1536x823.png 1536w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-8-2048x1098.png 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h3 class="wp-block-heading">3.5 注册服务</h3>



<p>编辑服务配置文件如下</p>



<pre class="wp-block-code"><code>&#091;root@dwp prometheus-3.4.0]# cat /lib/systemd/system/prometheus.service
&#091;Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target
&#091;Service]
Type=simple
Restart=on-failure
User=root
Group=root
WorkingDirectory=/opt/jiankong/prometheus-3.4.0/
ExecStart=/opt/jiankong/prometheus-3.4.0/prometheus --web.listen-address="0.0.0.0:9091" --web.read-timeout=5m --web.max-connections=256 --storage.tsdb.retention=15d --storage.tsdb.path=data/ --query.max-concurrency=20 --query.timeout=2m
ExecReload=/bin/kill -HUP $MAINPID
LimitNOFILE=65535
&#091;Install]
WantedBy=multi-user.target

## 我们需要将定制的prometheus的配置文件和数据目录作为启动参数配置好
## 其它的参数，可以基于prometheus --help配置。</code></pre>



<p>更新 systemd 服务信息</p>



<pre class="wp-block-code"><code>systemctl daemon-reload</code></pre>



<p>开机自启</p>



<pre class="wp-block-code"><code>systemctl enable --now prometheus.service</code></pre>



<p>启动服务</p>



<pre class="wp-block-code"><code>systemctl start prometheus</code></pre>



<p>其他命令</p>



<pre class="wp-block-code"><code>systemctl enable prometheus.service
systemctl stop prometheus.service
systemctl restart prometheus.service
systemctl status prometheus.service
## 查看日志
journalctl -u prometheus -f -n 500</code></pre>



<h2 class="wp-block-heading">四、配置Grafana</h2>



<h3 class="wp-block-heading">4.1 下载Grafana</h3>



<p>下载地址：<a href="https://grafana.com/grafana/download">https://grafana.com/grafana/download</a><br>根据环境下载对应的版本，x86环境的话用这个<strong>Standalone Linux Binaries(64 Bit)</strong></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="678" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-9-1024x678.png" alt="" class="wp-image-1869" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-9-1024x678.png 1024w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-9-300x199.png 300w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-9-768x508.png 768w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-9-1536x1017.png 1536w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-9.png 1813w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h3 class="wp-block-heading">4.2 安装Grafana</h3>



<p>上传压缩包到jiankongSoft下，并解压</p>



<pre class="wp-block-code"><code>tar -zxvf grafana-enterprise-12.0.1.linux-amd64.tar.gz -C /opt/jiankong/</code></pre>



<h3 class="wp-block-heading">4.3 启动Grafana</h3>



<p>启动步骤</p>



<pre class="wp-block-code"><code>cd /opt/jiankong/grafana-v12.0.1/

## 后台方式启动
nohup ./bin/grafana-server > ./grafana.log 2>&amp;1 &amp;</code></pre>



<p>查看端口默认是3000（稍等几秒）</p>



<pre class="wp-block-code"><code>lsof -i:3000</code></pre>



<p>通过浏览器访问http://IP:3000 ，<a href="http://192.168.241.131:3000">http://192.168.241.131:3000</a>。默认用户名和密码：<code>admin</code></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="549" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-10-1024x549.png" alt="" class="wp-image-1870" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-10-1024x549.png 1024w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-10-300x161.png 300w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-10-768x412.png 768w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-10-1536x823.png 1536w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-10-2048x1098.png 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h3 class="wp-block-heading">4.4 注册服务</h3>



<p>编辑服务配置文件如下</p>



<pre class="wp-block-code"><code>&#091;root@dwp grafana-v12.0.1]# cat /lib/systemd/system/grafana_server.service
&#091;Unit]
Description=Grafana
After=network.target
&#091;Service]
Restart=simple
##注意用户
User=root
Group=root
WorkingDirectory=/opt/jiankong/grafana-v12.0.1
ExecStart=/opt/jiankong/grafana-v12.0.1/bin/grafana-server 
ExecReload=/bin/kill -HUP $MAINPID
LimitNOFILE=65535
&#091;Install]
WantedBy=multi-user.target</code></pre>



<p>更新 systemd 服务信息</p>



<pre class="wp-block-code"><code>systemctl daemon-reload</code></pre>



<p>开机自启</p>



<pre class="wp-block-code"><code>systemctl enable --now grafana_server.service</code></pre>



<p>启动服务</p>



<pre class="wp-block-code"><code>systemctl start grafana_server</code></pre>



<p>其他命令</p>



<pre class="wp-block-code"><code>systemctl enable grafana_server.service
systemctl stop grafana_server.service
systemctl restart grafana_server.service
systemctl status grafana_server.service
## 查看日志
journalctl -u grafana_server -f -n 500</code></pre>



<h3 class="wp-block-heading">4.5 添加Prometheus数据源相关联</h3>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="444" height="1024" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-11-444x1024.png" alt="" class="wp-image-1871" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-11-444x1024.png 444w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-11-130x300.png 130w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-11.png 454w" sizes="auto, (max-width: 444px) 100vw, 444px" /></figure>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="138" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-12-1024x138.png" alt="" class="wp-image-1872" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-12-1024x138.png 1024w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-12-300x40.png 300w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-12-768x103.png 768w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-12-1536x206.png 1536w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-12-2048x275.png 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="792" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-13-1024x792.png" alt="" class="wp-image-1873" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-13-1024x792.png 1024w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-13-300x232.png 300w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-13-768x594.png 768w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-13-1536x1188.png 1536w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-13.png 1552w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="802" height="1024" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-14-802x1024.png" alt="" class="wp-image-1874" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-14-802x1024.png 802w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-14-235x300.png 235w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-14-768x980.png 768w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-14.png 940w" sizes="auto, (max-width: 802px) 100vw, 802px" /></figure>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="387" height="325" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-15.png" alt="" class="wp-image-1875" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-15.png 387w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-15-300x252.png 300w" sizes="auto, (max-width: 387px) 100vw, 387px" /></figure>



<p>保存成功后看到提示</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="162" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-16-1024x162.png" alt="" class="wp-image-1876" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-16-1024x162.png 1024w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-16-300x48.png 300w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-16-768x122.png 768w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-16-1536x243.png 1536w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-16-2048x325.png 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>返回数据源列表便可以看到刚刚添加的Prometheus</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="198" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-17-1024x198.png" alt="" class="wp-image-1877" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-17-1024x198.png 1024w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-17-300x58.png 300w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-17-768x148.png 768w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-17-1536x296.png 1536w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-17-2048x395.png 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>接下来进行自定义采集的部署工作，自定义的采集项的流程大致如图所示，数据库所在机器需要部署两个进程，一个是监控服务器的exporter，一个是监控主机的exporter</p>
</blockquote>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="333" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-19-1024x333.png" alt="" class="wp-image-1879" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-19-1024x333.png 1024w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-19-300x98.png 300w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-19-768x250.png 768w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-19-1536x499.png 1536w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-19-2048x666.png 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">五、监控主机</h2>



<h3 class="wp-block-heading">5.1 下载node_exporter</h3>



<p>下载地址：<a href="https://prometheus.io/download/">https://prometheus.io/download/</a> ，下载相应版本，安装到服务器上官网提供的是二进制版，解压就能用，不需要编译。</p>



<p>根据环境下载对应的版本，x86环境的话用这个<strong>node_exporter-1.9.1.linux-amd64.tar.gz</strong></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="269" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-18-1024x269.png" alt="" class="wp-image-1878" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-18-1024x269.png 1024w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-18-300x79.png 300w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-18-768x201.png 768w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-18-1536x403.png 1536w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-18.png 1773w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h3 class="wp-block-heading">5.2 安装node_exporter</h3>



<p><strong>部署在数据库所在服务器</strong></p>



<p>更新同步操作系统时间，避免时间误差</p>



<pre class="wp-block-code"><code>ntpdate edu.ntp.org.cn  &amp;&amp; hwclock -w</code></pre>



<p>新建目录</p>



<pre class="wp-block-code"><code>mkdir -p /opt/jiankong/jiankongSoft
cd /opt/jiankong/jiankongSoft</code></pre>



<p>上传压缩包，并解压</p>



<pre class="wp-block-code"><code>tar -zxvf node_exporter-1.9.1.linux-amd64.tar.gz -C /opt/jiankong/</code></pre>



<p>重命名node_exporter文件名</p>



<pre class="wp-block-code"><code>cd /opt/jiankong/
mv node_exporter-1.9.1.linux-amd64/ node_exporter-1.9.1</code></pre>



<h3 class="wp-block-heading">5.3 启动node_exporter</h3>



<p>后台方式启动</p>



<pre class="wp-block-code"><code>cd node_exporter-1.9.1/
nohup  ./node_exporter > ./node_exporter.log 2>&amp;1 &amp;</code></pre>



<p>查看端口，默认是9100</p>



<pre class="wp-block-code"><code>lsof -i:9100</code></pre>



<p>通过浏览器访问 http://被监控端IP:9100/metrics，就可以查看到node_exporter在被监控端收集的监控信息<br><a href="http://192.168.241.131:9100/metrics">http://192.168.241.131:9100/metrics</a></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="565" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-21-1024x565.png" alt="" class="wp-image-1882" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-21-1024x565.png 1024w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-21-300x165.png 300w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-21-768x424.png 768w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-21-1536x847.png 1536w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-21-2048x1129.png 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>修改端口的话，用下面的命令</p>



<pre class="wp-block-code"><code>nohup  ./node_exporter --web.listen-address=":9101" > ./node_exporter.log 2>&amp;1 &amp;</code></pre>



<h3 class="wp-block-heading">5.4 注册服务</h3>



<p>编辑服务配置文件如下</p>



<pre class="wp-block-code"><code>&#091;root@dwp node_exporter-1.9.1]# cat /lib/systemd/system/node_exporter.service
&#091;Unit]
Description=Node Exporter
After=network.target
&#091;Service]
Type=simple
User=root
Group=root
ExecStart=/opt/jiankong/node_exporter-1.9.1/node_exporter  --web.listen-address=":9100"
Restart=on-failure
&#091;Install]
WantedBy=multi-user.target</code></pre>



<p>更新 systemd 服务信息</p>



<pre class="wp-block-code"><code>systemctl daemon-reload</code></pre>



<p>开机自启</p>



<pre class="wp-block-code"><code>systemctl enable --now node_exporter.service</code></pre>



<p>启动服务</p>



<pre class="wp-block-code"><code>systemctl start node_exporter</code></pre>



<p>其他命令</p>



<pre class="wp-block-code"><code>systemctl enable node_exporter.service
systemctl stop node_exporter.service
systemctl restart node_exporter.service
systemctl status node_exporter.service
## 查看日志
journalctl -u node_exporter -f -n 500</code></pre>



<h2 class="wp-block-heading">六、监控数据库</h2>



<h3 class="wp-block-heading">6.1 部署自定义exporter</h3>



<p><strong>部署在数据库所在服务器</strong></p>



<ol class="wp-block-list">
<li><strong>这里数据采集的jar包，是自定义编写的。源码在后面的文章也会有提供。可以按需开发修改</strong></li>



<li><strong>jar包中sql语句只会执行select语句不会生成中间表等操作并且只有readonly权限</strong></li>



<li><strong>jar包运行需要jdk1.8的运行环境，如本地没有环境可直接使用DM8目录下的jdk环境</strong></li>
</ol>



<p>新建目录</p>



<pre class="wp-block-code"><code>mkdir -p /opt/jiankong/dm_prometheus</code></pre>



<p>上传压缩包dm_prometheus-1.0.jar，并解压</p>



<pre class="wp-block-code"><code>unzip dm_prometheus-1.0.jar -d /opt/jiankong/dm_prometheus</code></pre>



<p>修改jar包连接数据的账号与密码（BOOT-INF/classes/下编辑db.setting）</p>



<h3 class="wp-block-heading">6.2 启动自定义exporter</h3>



<p>启动服务（启动jar包前修改环境变量<code>MALLOC_ARENA_MAX</code>，避免jvm占用内存过多）</p>



<pre class="wp-block-code"><code>export MALLOC_ARENA_MAX=2
## 如果机器内存比较大可调整为 -Xms128m  -Xmx1024m
后台方式启动
nohup java -jar -Xms256m  -Xmx512m dm_prometheus-1.0.jar  > ./dm_prometheus.log 2>&amp;1 &amp;</code></pre>



<p>查看端口，默认为9200，需要等几秒</p>



<pre class="wp-block-code"><code>lsof -i:9200</code></pre>



<p>通过浏览器访问 http://被监控端IP:9200/prometheus，就可以查看到dm_prometheus在被监控端收集的监控信息<br><a href="http://192.168.241.131:9200/prometheus">http://192.168.241.131:9200/prometheus</a></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="793" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-20-1024x793.png" alt="" class="wp-image-1881" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-20-1024x793.png 1024w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-20-300x232.png 300w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-20-768x595.png 768w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-20-1536x1190.png 1536w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-20.png 1549w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">七、修改Prometheus配置文件关联数据</h2>



<p>进入到prometheus目录</p>



<pre class="wp-block-code"><code>cd /opt/jiankong/prometheus-3.4.0/</code></pre>



<p>编辑prometheus.yml配置文件</p>



<pre class="wp-block-code"><code># my global config
global:
  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 configuration
alerting:
  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=&lt;job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"
    static_configs:
      - targets: &#091;"localhost:9091"]
       # The label name is added as a label `label_name=&lt;label_value>` to any timeseries scraped from this config.
        labels:
          app: "prometheus"

  # 添加的是主机监控的接口9100接口
  - job_name: "dm_node_single"
    static_configs:
      - targets: &#091;"192.168.241.131:9100"]
        labels:
          origin_prometheus: '单机测试'

  # 添加的是数据库监控的接口9200接口，如果是一套集群，则在targets标签后进行逗号拼接，如下图所示
  - job_name: "dm_db_single"
    metrics_path: "/prometheus"
    static_configs:
      - targets: &#091;"192.168.241.131:9200"]
        labels:
          cluster_name: '单机测试'  

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.</code></pre>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>注意：9200的地方：单机的话填一个IP，如果是集群的话，则在 targets 标签中添加，用逗号分隔</p>
</blockquote>



<p>修改完成以后进行配置文件校验，避免因为空格等问题导致出错</p>



<pre class="wp-block-code"><code>&#091;root@dwp prometheus-3.4.0]# ./promtool check config prometheus.yml
Checking prometheus.yml
 SUCCESS: prometheus.yml is valid prometheus config file syntax</code></pre>



<h2 class="wp-block-heading">八、重启Prometheus并进行连接校验</h2>



<p>查看进程号</p>



<pre class="wp-block-code"><code>&#091;root@dwp prometheus-3.4.0]# ps -ef|grep prometheus
root       68252       1  0 14:03 ?        00:00:25 ./prometheus --config.file=prometheus.yml --web.listen-address=0.0.0.0:9091</code></pre>



<p>杀掉进程</p>



<pre class="wp-block-code"><code>kill -9 68252</code></pre>



<p>重新启动</p>



<pre class="wp-block-code"><code>nohup ./prometheus --config.file="prometheus.yml" --web.listen-address="0.0.0.0:9091" > ./prometheus.log 2>&amp;1 &amp;</code></pre>



<p>web界面查看验证：<a href="http://192.168.241.131:9091/targets">http://192.168.241.131:9091/targets</a></p>



<h2 class="wp-block-heading">九、Grafana配置监控主机的图表</h2>



<h3 class="wp-block-heading">9.1 下载NodeExporter</h3>



<p>进入 <a href="https://grafana.com/dashboards" target="_blank" rel="noreferrer noopener">https://grafana.com/dashboards</a> 页面，<br>➢ 搜索 Node Exporter，选择下载量最高的中文版本：<br><a href="https://grafana.com/grafana/dashboards/16098-1-node-exporter-for-prometheus-dashboard-cn-0417-job/" target="_blank" rel="noreferrer noopener">https://grafana.com/grafana/dashboards/</a><br>➢ 下载模板 json 文件</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="596" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-22-1024x596.png" alt="" class="wp-image-1883" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-22-1024x596.png 1024w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-22-300x175.png 300w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-22-768x447.png 768w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-22.png 1125w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h3 class="wp-block-heading">9.2 导入Node Exporter模板：监控主机</h3>



<p>Dashboards ===> import ===> 选择json文件 ===> 改名===> 选择 Prometheus</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="159" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-23-1024x159.png" alt="" class="wp-image-1884" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-23-1024x159.png 1024w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-23-300x47.png 300w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-23-768x119.png 768w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-23-1536x239.png 1536w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-23-2048x318.png 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>效果图</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="549" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-24-1024x549.png" alt="" class="wp-image-1885" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-24-1024x549.png 1024w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-24-300x161.png 300w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-24-768x412.png 768w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-24-1536x823.png 1536w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-24-2048x1098.png 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">十、Grafana配置数据库的图表</h2>



<p>导入 Node Exporter 模板：监控达梦<br>Dashboards ===&gt; import ===&gt; 选择json文件 ===&gt; 改名===&gt; 选择 Prometheus</p>



<p>效果图</p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="549" src="https://www.lemonary.cn/wp-content/uploads/2025/05/image-25-1024x549.png" alt="" class="wp-image-1886" srcset="https://www.lemonary.cn/wp-content/uploads/2025/05/image-25-1024x549.png 1024w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-25-300x161.png 300w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-25-768x412.png 768w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-25-1536x823.png 1536w, https://www.lemonary.cn/wp-content/uploads/2025/05/image-25-2048x1098.png 2048w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">资料</h2>



<p>链接：<a href="https://pan.baidu.com/s/1lo6AynZBR5JdRZwY_1arbA?pwd=o178" target="_blank" rel="noreferrer noopener">https://pan.baidu.com/s/1lo6AynZBR5JdRZwY_1arbA?pwd=o178</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lemonary.cn/%e6%90%ad%e5%bb%baprometheusgrafana%e7%9b%91%e6%8e%a7%e8%be%be%e6%a2%a6%e6%95%b0%e6%8d%ae%e5%ba%93/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
