0x0 前言

最近这几天研究了一下ElasticSearch相关的技术栈。前面一篇转发了别人些的非常详细的ElasticSearchKibana搭建的过程。发现Elastic家族还有Metricbeat这个神器,今天我们把前面搭建的和这个工具一起利用起来。

0x1 需求

需求是这样:我有很多个Golang写的应用程序,每程序连接一个Redis数据库,每个程序开在一台物理机上。我需要把每个golang应用每个Redis数据库和每个所在的物理机监控起来。

0x2 启动Metricbeat

  1. 下载Metricbeat https://www.elastic.co/downloads/beats/metricbeat,注意和前面ElasticSearch和Kibana版本匹配,我用的全是6.8.0的版本。

  2. 修改配置

    1)修改根目录下metricbeat.yml配置。主要是general里的name和Elasticsearch output里的hosts,以及Kibana里的host。general的name自己取一个特征名字就行,这个步骤很关键,为后面能区分不同的服务器的数据用。

#================================ General =====================================

# The name of the shipper that publishes the network data. It can be used to group
# all the transactions sent by a single shipper in the web interface.
name: "server-1" #-------------------------- Elasticsearch output ------------------------------
output.elasticsearch:
# Array of hosts to connect to.
hosts: ["localhost:9200"] #============================== Kibana ===================================== # Starting with Beats version 6.0.0, the dashboards are loaded via the Kibana API.
# This requires a Kibana endpoint configuration.
setup.kibana: # Kibana Host
# Scheme and port can be left out and will be set to the default (http and 5601)
# In case you specify and additional path, the scheme is required: http://localhost:5601/path
# IPv6 addresses should always be defined as: https://[2001:db8::1]:5601
host: "localhost:5601"

  

    2)修改modules.d下module配置

      i. 复制一份golang.yml.disable改名成golang.yml。修改配置如下 

# Module: golang
# Docs: https://www.elastic.co/guide/en/beats/metricbeat/6.8/metricbeat-module-golang.html - module: golang
metricsets:
- expvar
- heap
period: 10s
hosts: ["localhost:10000"]
heap.path: "/debug/vars"
expvar:
namespace: "example"
path: "/debug/vars"

      ii. 复制一份redis.yml.disabled改名成redis.yml。修改配置如下

# Module: redis
# Docs: https://www.elastic.co/guide/en/beats/metricbeat/6.8/metricbeat-module-redis.html - module: redis
metricsets:
- info
- keyspace
period: 10s # Redis hosts
hosts: ["127.0.0.1:6379"] # Network type to be used for redis connection. Default: tcp
#network: tcp # Max number of concurrent connections. Default: 10
#maxconn: 10 # Redis AUTH password. Empty by default.
# password: foobared

  

  3. 给ElasticSearch和Kibana导入index的mapping和dashboard。

  ./metricbeat setup

  如果前面的ElasticSearch和Kibana的配置不对这步会报错

  4. 启动Metricbeat   ./metricbeat -e -v -c ./metricbeat.yml

      

0x3 配置Kibana

  导入我这个dashboard展示数据(UI是我调的,可以根据自己需求调整)。

  1. 把下面这个保存成一个文件名命export.json。

[
{
"_id": "198d2300-7c3d-11e9-98c8-6b014c613efb",
"_type": "dashboard",
"_source": {
"title": "Server Info",
"hits": ,
"description": "Overview of Go profiling information",
"panelsJSON": "[{\"gridData\":{\"x\":0,\"y\":0,\"w\":48,\"h\":15,\"i\":\"8\"},\"id\":\"58000780-f529-11e6-844d-b170e2f0a07e\",\"panelIndex\":\"8\",\"type\":\"visualization\",\"version\":\"6.8.0\"},{\"gridData\":{\"x\":0,\"y\":15,\"w\":16,\"h\":20,\"i\":\"9\"},\"id\":\"95388680-f52a-11e6-969c-518c48c913e4\",\"panelIndex\":\"9\",\"type\":\"visualization\",\"version\":\"6.8.0\"},{\"gridData\":{\"x\":32,\"y\":15,\"w\":16,\"h\":20,\"i\":\"10\"},\"id\":\"b59a5200-f52a-11e6-969c-518c48c913e4\",\"panelIndex\":\"10\",\"type\":\"visualization\",\"version\":\"6.8.0\"},{\"gridData\":{\"x\":16,\"y\":15,\"w\":16,\"h\":20,\"i\":\"11\"},\"id\":\"9a9a8bf0-f52a-11e6-969c-518c48c913e4\",\"panelIndex\":\"11\",\"type\":\"visualization\",\"version\":\"6.8.0\"},{\"gridData\":{\"x\":24,\"y\":35,\"w\":24,\"h\":20,\"i\":\"12\"},\"id\":\"b046cb80-f52a-11e6-969c-518c48c913e4\",\"panelIndex\":\"12\",\"type\":\"visualization\",\"version\":\"6.8.0\"},{\"gridData\":{\"x\":0,\"y\":35,\"w\":24,\"h\":20,\"i\":\"13\"},\"id\":\"ab226b50-f52a-11e6-969c-518c48c913e4\",\"panelIndex\":\"13\",\"type\":\"visualization\",\"version\":\"6.8.0\"},{\"gridData\":{\"x\":24,\"y\":71,\"w\":24,\"h\":9,\"i\":\"14\"},\"version\":\"6.8.0\",\"panelIndex\":\"14\",\"type\":\"visualization\",\"id\":\"bfa5e400-1b16-11e7-b09e-037021c4f8df\",\"embeddableConfig\":{}},{\"gridData\":{\"x\":0,\"y\":80,\"w\":24,\"h\":12,\"i\":\"15\"},\"version\":\"6.8.0\",\"panelIndex\":\"15\",\"type\":\"visualization\",\"id\":\"e0f001c0-1b18-11e7-b09e-037021c4f8df\",\"embeddableConfig\":{}},{\"gridData\":{\"x\":24,\"y\":80,\"w\":24,\"h\":12,\"i\":\"16\"},\"version\":\"6.8.0\",\"panelIndex\":\"16\",\"type\":\"visualization\",\"id\":\"2e224660-1b19-11e7-b09e-037021c4f8df\",\"embeddableConfig\":{}},{\"gridData\":{\"x\":0,\"y\":71,\"w\":24,\"h\":9,\"i\":\"17\"},\"version\":\"6.8.0\",\"panelIndex\":\"17\",\"type\":\"visualization\",\"id\":\"ab2d1e90-1b1a-11e7-b09e-037021c4f8df\",\"embeddableConfig\":{}},{\"gridData\":{\"x\":24,\"y\":92,\"w\":24,\"h\":9,\"i\":\"18\"},\"version\":\"6.8.0\",\"panelIndex\":\"18\",\"type\":\"visualization\",\"id\":\"089b85d0-1b16-11e7-b09e-037021c4f8df\",\"embeddableConfig\":{}},{\"gridData\":{\"x\":0,\"y\":55,\"w\":48,\"h\":8,\"i\":\"27\"},\"version\":\"6.8.0\",\"panelIndex\":\"27\",\"type\":\"visualization\",\"id\":\"Redis-hosts\",\"embeddableConfig\":{}},{\"gridData\":{\"x\":0,\"y\":92,\"w\":24,\"h\":9,\"i\":\"32\"},\"version\":\"6.8.0\",\"panelIndex\":\"32\",\"type\":\"visualization\",\"id\":\"6b7b9a40-faa1-11e6-86b1-cd7735ff7e23\",\"embeddableConfig\":{}},{\"gridData\":{\"x\":16,\"y\":101,\"w\":18,\"h\":10,\"i\":\"33\"},\"version\":\"6.8.0\",\"panelIndex\":\"33\",\"type\":\"visualization\",\"id\":\"4d546850-1b15-11e7-b09e-037021c4f8df\",\"embeddableConfig\":{}},{\"gridData\":{\"x\":0,\"y\":101,\"w\":16,\"h\":10,\"i\":\"39\"},\"version\":\"6.8.0\",\"panelIndex\":\"39\",\"type\":\"visualization\",\"id\":\"4e4bb1e0-1b1b-11e7-b09e-037021c4f8df\",\"embeddableConfig\":{}},{\"gridData\":{\"x\":22,\"y\":63,\"w\":5,\"h\":8,\"i\":\"41\"},\"version\":\"6.8.0\",\"panelIndex\":\"41\",\"type\":\"visualization\",\"id\":\"34f97ee0-1b96-11e7-8ada-3df93aab833e\",\"embeddableConfig\":{}},{\"gridData\":{\"x\":44,\"y\":63,\"w\":4,\"h\":8,\"i\":\"43\"},\"version\":\"6.8.0\",\"panelIndex\":\"43\",\"type\":\"visualization\",\"id\":\"96976150-4d5d-11e7-aa29-87a97a796de6\",\"embeddableConfig\":{}},{\"gridData\":{\"x\":34,\"y\":101,\"w\":7,\"h\":10,\"i\":\"44\"},\"version\":\"6.8.0\",\"panelIndex\":\"44\",\"type\":\"visualization\",\"id\":\"99381c80-4d60-11e7-9a4c-ed99bbcaa42b\",\"embeddableConfig\":{}},{\"gridData\":{\"x\":41,\"y\":101,\"w\":7,\"h\":10,\"i\":\"45\"},\"version\":\"6.8.0\",\"panelIndex\":\"45\",\"type\":\"visualization\",\"id\":\"c5e3cf90-4d60-11e7-9a4c-ed99bbcaa42b\",\"embeddableConfig\":{}},{\"gridData\":{\"x\":35,\"y\":63,\"w\":5,\"h\":8,\"i\":\"48\"},\"version\":\"6.8.0\",\"panelIndex\":\"48\",\"type\":\"visualization\",\"id\":\"522ee670-1b92-11e7-bec4-a5e9ec5cab8b\",\"embeddableConfig\":{}},{\"gridData\":{\"x\":40,\"y\":63,\"w\":4,\"h\":8,\"i\":\"49\"},\"version\":\"6.8.0\",\"panelIndex\":\"49\",\"type\":\"visualization\",\"id\":\"1aae9140-1b93-11e7-8ada-3df93aab833e\",\"embeddableConfig\":{}},{\"gridData\":{\"x\":5,\"y\":63,\"w\":5,\"h\":8,\"i\":\"51\"},\"version\":\"6.8.0\",\"panelIndex\":\"51\",\"type\":\"visualization\",\"id\":\"d3166e80-1b91-11e7-bec4-a5e9ec5cab8b\",\"embeddableConfig\":{}},{\"gridData\":{\"x\":0,\"y\":63,\"w\":5,\"h\":8,\"i\":\"52\"},\"version\":\"6.8.0\",\"panelIndex\":\"52\",\"type\":\"visualization\",\"id\":\"83e12df0-1b91-11e7-bec4-a5e9ec5cab8b\",\"embeddableConfig\":{}},{\"gridData\":{\"x\":27,\"y\":63,\"w\":4,\"h\":8,\"i\":\"54\"},\"version\":\"6.8.0\",\"panelIndex\":\"54\",\"type\":\"visualization\",\"id\":\"590a60f0-5d87-11e7-8884-1bb4c3b890e4\",\"embeddableConfig\":{}},{\"gridData\":{\"x\":10,\"y\":63,\"w\":4,\"h\":8,\"i\":\"55\"},\"version\":\"6.8.0\",\"panelIndex\":\"55\",\"type\":\"visualization\",\"id\":\"825fdb80-4d1d-11e7-b5f2-2b7c1895bf32\",\"embeddableConfig\":{}},{\"gridData\":{\"x\":31,\"y\":63,\"w\":4,\"h\":8,\"i\":\"56\"},\"version\":\"6.8.0\",\"panelIndex\":\"56\",\"type\":\"visualization\",\"id\":\"d2e80340-4d5c-11e7-aa29-87a97a796de6\",\"embeddableConfig\":{}},{\"gridData\":{\"x\":14,\"y\":63,\"w\":4,\"h\":8,\"i\":\"57\"},\"version\":\"6.8.0\",\"panelIndex\":\"57\",\"type\":\"visualization\",\"id\":\"26732e20-1b91-11e7-bec4-a5e9ec5cab8b\",\"embeddableConfig\":{}},{\"gridData\":{\"x\":18,\"y\":63,\"w\":4,\"h\":8,\"i\":\"58\"},\"version\":\"6.8.0\",\"panelIndex\":\"58\",\"type\":\"visualization\",\"id\":\"19e123b0-4d5a-11e7-aee5-fdc812cc3bec\",\"embeddableConfig\":{}}]",
"optionsJSON": "{\"darkTheme\":false,\"useMargins\":true}",
"version": ,
"timeRestore": false,
"kibanaSavedObjectMeta": {
"searchSourceJSON": "{\"filter\":[{\"$state\":{\"store\":\"appState\"},\"meta\":{\"alias\":null,\"disabled\":true,\"index\":\"metricbeat-*\",\"key\":\"beat.name\",\"negate\":false,\"params\":{\"query\":\"sanguo-HOSTIP\",\"type\":\"phrase\"},\"type\":\"phrase\",\"value\":\"sanguo-HOSTIP\"},\"query\":{\"match\":{\"beat.name\":{\"query\":\"sanguo-HOSTIP\",\"type\":\"phrase\"}}}},{\"$state\":{\"store\":\"appState\"},\"meta\":{\"alias\":null,\"disabled\":false,\"index\":\"metricbeat-*\",\"key\":\"beat.name\",\"negate\":false,\"params\":{\"query\":\"BPC2797\",\"type\":\"phrase\"},\"type\":\"phrase\",\"value\":\"BPC2797\"},\"query\":{\"match\":{\"beat.name\":{\"query\":\"BPC2797\",\"type\":\"phrase\"}}}}],\"query\":{\"language\":\"lucene\",\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"default_field\":\"*\",\"query\":\"*\"}}},\"version\":true,\"highlightAll\":true}"
}
}
}
]

  2. 导入Kibana。

0x4 给golang程序增加监控代码

  这个比较简单直接在main.go的import里加入 _ "expvar",然后开启http服务器就行了http.ListenAndServe。注意这个端口要和上面golang.yml里配的端口一致。

  然后把这个程序运行起来

0x5 效果图

  回到Kibana,进入Dashboard页,里面增加了一个Server Info的项,点进去看到如下效果就成了

0x6 区分多个golang应用程序

  在步骤2里就要填metricbeat.yml里的name那个字段:server-1,当你开了多个metricbeat时就可以用不通的名字过滤。然后把这个模板clone一份再保存

[Metricbeat] Metricbeat监控golang服务器的更多相关文章

  1. Nagios学习实践系列——配置研究[监控当前服务器]

    其实上篇Nagios学习实践系列——基本安装篇只是安装了Nagios基本组件,虽然能够打开主页,但是如果不配置相关配置文件文件,那么左边菜单很多页面都打不开,相当于只是一个空壳子.接下来,我们来学习研 ...

  2. 关于nagios监控远程服务器对服务器性能影响的测试

    1.    Nagios监视远程服务器时,是通过在控制端执行以下命令进行数据收集的: /usr/local/nagios/libexec/check_http -I 192.168.16.11 /us ...

  3. 详解 Spotlight on MySQL监控MySQL服务器

    前一章详解了Spotlight on Unix 监控Linux服务器 ,今天再来看看Spotlight on MySQL怎么监控MySQL服务器. 注:http://www.cnblogs.com/J ...

  4. 通过SSIS监控远程服务器Windows服务并发送邮件报警!

    利用SSIS不仅可以做BI项目的ETL,而且还可以做一些系统监控和维护工作,由于之前供应商写的Windows服务是读取ESB的消息进行处理,且通过OA流程与访客系统进行了集成,无论是ESB出现状况,还 ...

  5. 通过SSIS监控远程服务器磁盘空间并发送邮件报警!

    由于之前ESB是供应商部署的,且部署在C盘(C盘空间很小,还添加了很多ESB的windows服务日志在C盘,很容易把C盘空间占满,导致ESB服务运行宕机,几乎每隔几周发生一次事故,需要人工干预处理,不 ...

  6. 监控linux服务器网卡流量

    监控linux服务器网卡流量 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.       欢迎加入:高级运维工程师之路 598432640 前言:众所周知,我们安装zabbix服务器 ...

  7. 对golang服务器开发模式的一些思考

    多线程+同步阻塞模型 在我们的游戏项目中使用的golang服务器开发方式如下 1.多线程逻辑 2.同步阻塞. 也就是说, 每个人一个线程(goroutine), io线程=逻辑线程 这种方式的优点: ...

  8. Linux下利用nc命令来监控检测服务器的端口使用情况(转载)

    最近碰到一个项目,前端用apache htttpd进行发布(80端口),通过双机负载均衡转发到后端的两个tomcat进行处理(8081和8082端口),现在需要随时监控这三个端口的情况,一旦down掉 ...

  9. 通过线程监控socket服务器是否done机

    现实中的socket可能会因为各种原因done机,但这么重要的服务器怎么能允许这种事情发生?这次我们就来通过一个线程去监控socket服务器,如果done机重新将其启动. 下面是监控项目和socket ...

随机推荐

  1. 四川第十届省赛 A.Angel Beats bitset

    四川第十届省赛 A.Angel Beats bitset 题目链接 题解参考:http://www.cnblogs.com/Aragaki/p/9142250.html 考虑用bitset来维护对于所 ...

  2. 201671030102陈飞 实验十四 团队项目评审&课程学习总结

    项目 内容 这个作业属于哪个课程 2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 实验十四 团队项目评审&课程学习总结 课程学习目标 1.掌握软件项目评审会议流程 ...

  3. python应用-彩票随机码的输出

    """ 双色球-6个红色球(1-33)和一个蓝色球(1-16) """ from random import randint def sel ...

  4. CodeForces - 1051E :Vasya and Big Integers(Z算法 & DP )

    题意:给定字符串S,A,B.现在让你对S进行切割,使得每个切割出来的部分在[A,B]范围内,问方案数. 思路:有方程,dp[i]=Σ dp[j]   (S[j+1,i]在合法范围内).    假设M和 ...

  5. Nginx——跨域造成的504问题

    前言 前台域名和后台域名是两个不同不同的二级域名,访问的时候造成了跨域,出现了504错误 解决 修改Nginx配置,将超时的时间设置为1200秒 keepalive_timeout 1200; pro ...

  6. python 二、八、十六进制之间的快速转换

    一.进制转换 1.2 十进制转二进制 bin(18)--> '0b10010'     去掉0b就是10010    即为十进制18转二进制是10010 十进制转八进制oct(18) --> ...

  7. Vuejs发送Ajax请求

    一.概况 ①vuejs中没有内置任何ajax请求方法 ②在vue1.0版本,使用的插件 vue resource 来发送请求,支持promise ③在vue2.0版本,使用社区的一个第三方库 axio ...

  8. CF 852E Casinos and travel

    题目链接 \(Desccription\) 给定一棵树,John从任意一个点开始,每次走向一个未到达过的点.每个点都可以有或没有赌场,每经过一个赌场心情都会反转,旅行开始前心情很好. 问有多少种方案使 ...

  9. 洛谷p2370yyy2015c01的U盘题解

    没什么特殊的想法 就是看自己很久没有更新关于题解类的文章了而已 (其实这是我好久之前做的, 只是把它从洛谷博客搬到了这里而已) 题目 首先分析题目要二分 他长成这个亚子太二分了 所以就要二分 最好是先 ...

  10. 埃氏筛优化(速度堪比欧拉筛) + 洛谷 P3383 线性筛素数 题解

    我们一般写的埃氏筛消耗的时间都是欧拉筛的三倍,但是欧拉筛并不好想(对于我这种蒟蒻) 虽然 -- 我 -- 也可以背过模板,但是写个不会的欧拉筛不如写个简单易懂的埃氏筛 于是就有了优化 这个优化还是比较 ...