当前位置:首页 > CN2资讯 > 正文内容

windows服务器 java 监控系统挂了没 服务器运行监控

14小时前CN2资讯


 

什么是Prometheus?

Prometheus 是由 SoundCloud 开发的开源监控报警系统和时序列数据库(TSDB)。

Prometheus 使用 Go 语言开发,是 Google BorgMon 监控系统的开源版本。

其架构如下:




Prometheus 的基本原理是:

通过HTTP协议周期性抓取被监控组件的状态,任意组件只要提供对应的 HTTP 接口就可以接入监控。不需要任何SDK或者其他的集成过程。

Prometheus服务过程大概是这样:

  • Prometheus Daemon负责定时去目标上抓取metrics(指标)数据,每个抓取目标需要暴露一个 http 服务的接口给它定时抓取。Prometheus 采用 pull 的方式进行监控,即服务器可以直接通过目标 pull 数据.
  • Prometheus 在本地存储抓取的所有数据,并通过一定规则进行清理和整理数据,并把得到的结果存储到新的时间序列中。
  • Prometheus 通过 PromQL和其他 API 可视化地展示收集的数据。Prometheus 支持很多方式的图表可视化,例如 Grafana、自带的Promdash以及自身提供的模版引擎等等。Prometheus 还提供 HTTP API 的查询方式,自定义所需要的输出。
  • PushGateway支持 client 主动推送 metrics 到 PushGateway,而 Prometheus 只是定时去 Gateway 上抓取数据。
  • Alertmanager是独立于Prometheus的一个组件,可以支持 Prometheus 的查询语句,提供十分灵活的报警方式。

而我们的使用场景如下:

  • 4 台需要被监控的服务器;
  • 监控项主要有 CPU、内存的使用情况,可以使用 node_exporter 插件实现;
  • 1 台服务器既被监控同时也作为 server 来接收其余 3 台服务器的运行状况;
  • 可视化部分用 Grafana 来完成。

Prometheus 以及 node_exporter 的安装

  • 先在 server 机(用了4号机作为 server)上下载最新的 release 并解压 : https://prometheus.io/download/
  • $ wget https://github.com/prometheus/prometheus/releases/download/v2.0.0/prometheus-2.0.0.linux-amd64.tar.gz $ tar xvfz prometheus-*.tar.gz # 为文件夹改名
    • 在 prometheus 目录下有一个名为 prometheus.yml 的主配置文件。查看其内容:
    $ cd prometheus $ vim prometheus.yml# my global config global: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. 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=<job_name>` to any timeseries scraped from this config. 'prometheus' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: 'localhost:9090']

    其中 scrape_configs 项目中的内容是我们主要关注的,该配置项决定了我们的 Prometheus 需要去抓取哪些数据,默认配置中只有一个 prometheus 的 job ,这个 job 是 Prometheus 自带的,它的功能是提供 Prometheus 进程本身的运行数据以供我们抓取。

    除了 prometheus 这个 job 以外,我们还没任何为 Prometheus 提供数据的 HTTP API 程序。于是我们先将 Prometheus 的配置任务放去后面,下一步是在四台服务器上安装 node_exporter

    • 在 4 台需要监控的服务器上下载解压 node_exporter :https://prometheus.io/download/#node_exporter
    $ wget https://github.com/prometheus/node_exporter/releases/download/v0.15.1/node_exporter-0.15.1.linux-amd64.tar.gz $ tar -zxvf node_exporter-0.15.1.linux-amd64.tar.gz $ mv node_exporter-0.15.1.linux-amd64 prometheus/node_exporter # 将文件夹重命名后移入prometheus 文件夹 $ ls prometheus console_libraries consoles data LICENSE node_exporter NOTICE prometheus prometheus.yml promtool

    由于 node_exporter 是编译好的程序,我们可以将其配为服务直接运行。

    • 在 4 台需要监控的服务器上配置 node_exporter 服务:

    $ sudo vim /etc/systemd/system/node_exporter.service

    内容如下:

    [Unit] Description=Node Exporter [Service] User=admin ExecStart=/home/admin/prometheus/node_exporter/node_exporter [Install] WantedBy=default.target

    运行服务装载命令:

    $ sudo systemctl daemon-reload $ sudo systemctl enable node_exporter.service $ sudo systemctl start node_exporter.service $ systemctl status node_exporter ● node_exporter.service - Node Exporter Loaded: loaded (/etc/systemd/system/node_exporter.service; enabled; vendor preset: disabled) Active: active (running) since 二 2017-12-05 17:39:32 CST; 1 day 2h ago Main PID: 4752 (node_exporter) CGroup: /system.slice/node_exporter.service └─4752 /home/admin/prometheus/node_exporter/node_exporter

    node_exporter 的 HTTP API 默认端口是 9100 ,为其开放防火墙:

    $ sudo firewall-cmd --zone=public --add-port=9100/tcp --permanent ; sudo firewall-cmd --reload # 测试 $ curl http://localhost:9100 <html> <head><title>Node Exporter</title></head> <body> <h1>Node Exporter</h1> <p><a href="/metrics">Metrics</a></p> </body> </html>
    • 重新编辑 server 机上的 prometheus.yml 配置文件:
    # my global config global: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. 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=<job_name>` to any timeseries scraped from this config. 'prometheus' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: 'localhost:9090'] # 添加的部分 "node1" static_configs: '111.x.xxx.20:9100'] "node2" static_configs: '111.x.xxx.20:9100'] "node3" static_configs: '111.x.xxx.20:9100'] "node4" static_configs: '111.x.xxx.21:9100']
    • 配置 Prometheus 服务并运行:
    $ sudo vim /etc/systemd/system/prometheus.service $ cat vim /etc/systemd/system/prometheus.service [Unit] Description=Node Exporter [Service] User=root ExecStart=/home/admin/prometheus/prometheus --config.file=/home/admin/prometheus/prometheus.yml [Install] WantedBy=default.target $ sudo systemctl daemon-reload $ sudo systemctl enable prometheus.service $ sudo systemctl start prometheus.service $ systemctl status prometheus ● prometheus.service - Node Exporter Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor preset: disabled) Active: active (running) since 三 2017-12-06 20:43:35 CST; 3s ago Main PID: 5918 (prometheus) CGroup: /system.slice/prometheus.service └─5918 /home/admin/prometheus/prometheus --config.file=/home/admin/prometheus/prometheus.yml # 为 Prometheus 开启防火墙 $ sudo firewall-cmd --zone=public --add-port=9090/tcp --permanent ; sudo firewall-cmd --reload
  • 测试,访问 http://yourserverip:9090/graph ,执行 node_load1 可绘制 CPU 瞬时运行图,也可以通过 http://yourserverip:9090/targets 来查看 job 的部署情况,通过 http://yourserverip:9090/metrics。
  • Grafana 的安装

    用 Prometheus 自带的控制面板略显简陋,一时要手动刷新数据,二是可视化功能不够强大、不支持自定义数据显示,三是执行命令太过繁琐。

    于是我们选择 Grafana 来作为可视化工具。

    其安装过程(可在任意主机安装)如下:

    $ sudo yum install https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.6.2-1.x86_64.rpm # 为 Grafana 开启防火墙 $ sudo firewall-cmd --zone=public --add-port=9090/tcp --permanent ; sudo firewall-cmd --reload

    启动服务:

    $ sudo service grafana-server start

    启动后可使用 http://yourip:3000 访问 Grafana 页面,配置好用户名和密码后,先设置好数据源(data source),也就是从哪里获取数据。

    参考:

    可视化的具体配置可参考官方文档,推荐使用 Node Exporter Server Metrics 模板,访问 https://grafana.com/dashboards/405 ,在 Dashboard 中导入该模板即可

      你可能想看:

      扫描二维码推送至手机访问。

      版权声明:本文由皇冠云发布,如需转载请注明出处。

      本文链接:https://www.idchg.com/info/30417.html

      分享给朋友:

      “windows服务器 java 监控系统挂了没 服务器运行监控” 的相关文章

      搬瓦工带防御:如何提升VPS安全性,抵御DDoS攻击

      搬瓦工VPS的基本介绍 搬瓦工(Bandwagon Host)作为一家知名的VPS提供商,以其稳定的网络连接和出色的性能赢得了众多用户的青睐。无论是个人网站搭建、企业应用部署,还是科学上网需求,搬瓦工VPS都能提供灵活且高效的解决方案。它的价格相对亲民,同时支持多种操作系统和自定义配置,满足了不同用...

      高防IP的重要性及其在网络安全中的应用

      理解高防IP对维护网络安全的重要性是当今每个企业都应该重视的事。高防IP,它的全名是高防御IP地址,主要是为抵御各种网络攻击而特别设计的。随着网络攻击手段的日趋复杂化,很多公司和个人的在线安全面临着巨大的威胁。在这种背景下,高防IP凭借其流量清洗和分流等技术手段,为企业提供了一道坚实的安全屏障。 高...

      HostHatch优惠活动揭秘:如何以最低价格获取优质主机服务

      当提到主机服务,HostHatch绝对是个值得信赖的品牌。作为一家成立超过十年的主机商,HostHatch专注于提供高性能的NVMe VPS和大硬盘存储型专用主机。为什么会选择HostHatch呢?除了卓越的服务和强大的基础设施外,吸引人的优惠活动也是一个重要因素。 最近,HostHatch推出了针...

      Wikihost:构建高效知识库的理想WordPress主题

      Wikihost是一个专为WordPress平台设计的知识库主题,目的在于帮助用户轻松创建和管理知识库文章与文档页面。这款主题适合各种类型的网站,从小型企业到大型社区,用户都能通过它建立富有信息性的页面。Wikihost给用户提供了一整套便捷的功能,帮助他们分享知识和信息。 我发现Wikihost的...

      服务器租赁指南:如何选择适合的云服务和价格

      对于很多企业和个人用户来说,服务器租赁是一个非常实用的选择。简单来说,服务器租赁就是用户向服务器提供商支付费用,然后获得在一定时间内使用服务器的权利。这样一来,用户就无需花费时间和金钱去购买和维护物理服务器,可以迅速开始在线业务。 当我第一次接触服务器租赁时,发现这一服务的便利性令我十分惊讶。传统的...

      续费同价服务器:云服务的透明定价策略与用户优势

      续费同价服务器是什么呢?说白了,就是云服务提供商在定价上采取的一种政策。无论是新用户第一次购买,还是老用户续费,价格都是一样的。这种做法让很多用户感到安心,不用担心下次续费时价格会大幅上涨。这一策略在云服务行业越来越受到重视,也给用户带来了不少好处。 首先,续费同价服务器让价格变得透明。我之前在选择...