现在一台服务器上可能会部署多个服务(不到 10 个的样子,是不同的服务,服务名不一样),如何采集这些进程的 CPU 、内存占用等数据呢
目前想到的是写一个程序去读 top 命令的结果,但是假如我有 10 个服务的话,我得同时执行 10 条 top 命令,不知道 top 命令本身性能怎么样,会不会对服务器负载造成影响
大佬们有现成的方案吗?
1 yanxin1111 290 天前 prometheus? |
![]() | 2 imherer OP @yanxin1111 这是拿到数据后的事了,现在的问题是这个数据怎么拿到 |
![]() | 3 hafuhafu 290 天前 ![]() All in one 可视化、监控、告警中心 n9e: https://github.com/ccfos/nightingale 配套的开箱即用的采集器 categraf: https://github.com/flashcatcloud/categraf 采集进程信息: categraf 中的 procstat 采集插件已经实现了,https://flashcat.cloud/docs/content/flashcat-monitor/categraf/plugin/procstat/,改成需要的配置就行。 |
4 FarmerChillax 290 天前 @imherer 我理解 #1 说的 prometheus 是指完整的的 prometheus 监控体系/生态。这确实是目前监控告警的主流 |
![]() | 5 imherer OP @FarmerChillax 我知道,只要拿到数据,用 prometheus+grafana 等一系列监控起来就行了。 可能是我标题写的不对,其实我更多的是想问怎么拿到这个数据 |
7 yanxin1111 290 天前 @imherer prometheus+grafana 这个可以自己配置要监控哪个服务的 |
![]() | 10 imherer OP ![]() @yanxin1111 #7 我知道,我的意思是现在怎么拿到某个服务它对应的指标数据。你在 grafana 里配置要监控哪个服务的前提是得拿到这个服务对应的这些指标数据 |
![]() | 12 hiwind 290 天前 elastic 有个 metricbeat 配合 es 使用 还有楼上提到的 node exporter 配合 Prometheus grafana 使用 |
![]() | 13 yuandj 290 天前 |
![]() | 14 easing 290 天前 Prometheus 的 node exporter 没看过么 |
![]() | 19 imherer OP |
![]() | 20 shiyuu 290 天前 ![]() 用 prometheus 就行。 官方的这么多 exporter 组件可以使用,都去了解一下没坏处 需要采集的节点装 exporter 组件组件就行,用得最多的是 node_exporter ,已经内置采集了系统的很多信息。 你想自定义采集,那就要自己写脚本,比如采集执行某个指令的结果,参考 https://github.com/prometheus/node_exporter#textfile-collector 其实用 gpt 来帮你写就行 采集的结果都会入库 prometheus ,再用 grafana 展示出来就行 prometheus alertmanager blackbox_exporter consul_exporter graphite_exporter memcached_exporter mysqld_exporter node_exporter promlens pushgateway statsd_exporter |
![]() | 21 yuandj 290 天前 @imherer 1. 先安装部署 Prometheus 和 Grafana 2. 在需要监控的节点上安装 Node Exporter ,并启动服务 3. 在 prometheus.yml 配置中,添加对应的监控配置,例子如下: ``` ### 其他配置 ### xxx # ========== 机器性能监控(基于 Node Exporter ,监控模板 ID:16098 ) =========== - job_name: 'base' # JobName 在面板中可选择不同的 Job 分组查看监控 static_configs: - targets: ['xx.xx.xx.xx:9100'] labels: #instance: '此处填写面板中要展示 IP 的名称,如果不配,面板中会使用默认的 ip:port' nodename: '节点名称 1' - targets: ['xx.xx.xx.xx:9100'] labels: nodename: '节点名称 2' ``` 4. 在 Grafana 添加 Prometheus 源 5. 导入 Grafana 面板;这是我用的面板 > https://grafana.com/grafana/dashboards/16098-node-exporter-dashboard-20240520-job/ 如果遇到卡点,可以留下你的联系方式交流一下 |
23 ala2008 290 天前 我们微服务 java 用了 jar 包,应该也可以用探针的方式吧 |
![]() | 24 yuan1028 290 天前 docker 部署吗?可以看看 https://github.com/google/cadvisor |
![]() | 25 COW 290 天前 via Android 不想太嗦了,这样说你就明白了。节点监控用 node exporter ,进程监控用 process exporter ,容器监控基本都是去集成 k8s 了。 |
![]() | 28 realityone 290 天前 newrelic 免费版 |
29 cassidy0134 290 天前 atop ,默认每十分钟拿一次机器上进程占用情况。 |
30 cassidy0134 290 天前 或者,用 docker compose 部署这十个服务。然后 docker top 看 usage |
31 263 290 天前 process-exporter 正则匹配 ``` process_names: - name: "{{.Comm}}:{{.Matches.ServerId}}" comm: - gmserver cmdline: - -C/data/code/(?P<ServerId>[0-9]+)/server.cfg - name: "{{.Comm}}:{{.Matches.ServerId}}" comm: - terrace cmdline: - -D/data/terrace/terrace_(?P<ServerId>[0-9]+) - name: "charge:{{.Comm}}:{{.Matches.ServerId}}" comm: - u3d-server cmdline: - -c(?P<ServerId>[0-9]+) - name: "ctrl:{{.Comm}}:{{.Matches.ServerId}}" comm: - u3d-server cmdline: - -w(?P<ServerId>[0-9]+) ``` |
32 Zss77 290 天前 首先想到的是 nmon ,是不是有些原始了…… |
33 mayli 290 天前 传统的方法是 collectd |
![]() | 34 billzhuang 290 天前 看 OP 这个问题问的这么豪放和对一楼的狂妄, 我觉的 datadog 更适合 OP 。 |
35 lzZzeucJri6FcR0o 290 天前 @qoo2019 #11 node exporter 采集指定不了自己服务的信息,只是系统的 cpu 、men ,我刚做过,自己写采集器才行 |
![]() | 37 Immunize 290 天前 top 没啥开销,核心就是去 /proc 目录下遍历下 PID ,采集两次间隔进程 CPU 执行时间的差值,算下占物理时间的间隔。不用脚本糊的话,很多语言都有第三方库可以干这种事,用顺手的就行,或者用 all in one 的东西。 |
![]() | 38 ShunYea 290 天前 哪吒监控? |
41 dbak 290 天前 |
42 theniupa 290 天前 nmon |
![]() | 43 git00ll 290 天前 prometheus 是机器级别的吧, 进程级别的没看到过有 exporter |
44 hugowangnz 290 天前 push gateway 可以主动发送数据到 Prometheus |
![]() | 45 treexie 290 天前 |
46 iceheart 290 天前 via Android 定时解析 /proc/pid/stat 文件 |
![]() | 47 dier 289 天前 |
48 julyclyde 289 天前 首先,读 top 肯定是错误的 二手数据 应该读 proc 或者 cgroup |