iis服务器助手广告广告
返回顶部
首页 > 资讯 > 精选 >怎么在CentOS7系统中搭建Prometheus 监控
  • 379
分享到

怎么在CentOS7系统中搭建Prometheus 监控

2023-06-07 20:06:51 379人浏览 八月长安
摘要

今天就跟大家聊聊有关怎么在Centos7系统中搭建prometheus 监控,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。 简介prometheus可以拆分成多个节点进行指

今天就跟大家聊聊有关怎么在Centos7系统中搭建prometheus 监控,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

 简介

prometheus可以拆分成多个节点进行指标收集。

安装环境:CentOS7

安装prometheus

wget -c https://GitHub.com/prometheus/prometheus/releases/download/v2.23.0/prometheus-2.23.0.linux-amd64.tar.gz 

tar zxvf prometheus-2.23.0.linux-amd64.tar.gz  -C /opt/ 

cd /opt/ 

ln -s prometheus-2.23.0.linux-amd64 prometheus 

cat > /etc/systemd/system/prometheus.service <<EOF 

[Unit] 

Description=prometheus 

After=network.target 

 

[Service] 

Type=simple 

WorkingDirectory=/opt/prometheus 

ExecStart=/opt/prometheus/prometheus --config.file="/opt/prometheus/prometheus.yml" 

LimitNOFILE=65536 

PrivateTmp=true 

RestartSec=2 

StartLimitInterval=0 

Restart=always 

 

[Install] 

WantedBy=multi-user.target 

EOF 

systemctl daemon-reload  

systemctl enable prometheus 

systemctl start prometheus 

 配置Prometheus

这里配置的是监听/opt/prometheus/servers/目录下的JSON文件

cat > /opt/prometheus/prometheus.yml <<EOF 

# 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=<job_name>` to any timeseries scraped from this config. 

  - job_name: 'prometheus' 

 

    # metrics_path defaults to '/metrics' 

    # scheme defaults to 'Http'. 

 

    static_configs: 

    - targets: ['localhost:9090'] 

     

  - job_name: 'servers' 

    file_sd_configs: 

    - refresh_interval: 61s 

      files: 

        - /opt/prometheus/servers/*.json 

EOF 

systemctl restart prometheus 

json格式

怎么在CentOS7系统中搭建Prometheus 监控[     

    { 

        "targets": [ 

            "192.168.1.164:9100" 

        ], 

        "labels": { 

            "instance": "192.168.1.164", 

            "job": "node_exporter" 

        } 

    }, 

    { 

        "targets": [ 

            "192.168.1.167:9100" 

        ], 

        "labels": { 

            "instance": "192.168.1.167", 

            "job": "node_exporter" 

        } 

    } 

安装node_exporter

安装到/opt/node_exporter路径下,保持默认的端口

https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz 

tar zxvf node_exporter-1.0.1.linux-amd64.tar.gz -C /opt/ 

cd /opt/ 

ln -s  node_exporter-1.0.1.linux-amd64 node_exporter 

cat > /etc/systemd/system/node_exporter.service <<EOF 

[Unit] 

Description=node_exporter 

After=network.target 

 

[Service] 

Type=simple 

WorkingDirectory=/opt/node_exporter 

ExecStart=/opt/node_exporter/node_exporter 

LimitNOFILE=65536 

PrivateTmp=true 

RestartSec=2 

StartLimitInterval=0 

Restart=always 

 

[Install] 

WantedBy=multi-user.target 

EOF 

systemctl daemon-reload 

systemctl enable node_exporter 

systemctl start node_exporter 

图形展示

直接安装grafana进行展示

yum -y install   https://dl.grafana.com/oss/release/grafana-7.3.6-1.x86_64.rpm 

systemctl enable grafana-server 

systemctl start grafana-server 

启动之后,grafana默认监听的是3000端口,直接使用浏览器进行访问就可以了,默认用户名密码是admin/admin,第一次登陆之后会提示修改。

怎么在CentOS7系统中搭建Prometheus 监控

配置数据源:鼠标左边的菜单 Configuration -> Data Source -> Add data source -> 选择prometheus -> url那栏填入prometheus的地址就可以了 -> 最后 Save & test 就可以了。

grafana.com/grafana/dashboards 官网已经有人做好的模板,我们直接import进来就可以了。

导入面板:鼠标左边的菜单 Dashboards -> Import -> 填入id -> Load -> 选择数据源就可以了。

我经常用的是:1860 、8919 这两个来查看node_exporter监控

怎么在CentOS7系统中搭建Prometheus 监控

看完上述内容,你们对怎么在CentOS7系统中搭建Prometheus 监控有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注编程网精选频道,感谢大家的支持。

原文地址:https://www.toutiao.com/i6914917162675192324/

--结束END--

本文标题: 怎么在CentOS7系统中搭建Prometheus 监控

本文链接: https://www.lsjlt.com/news/250057.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • c++中函数返回值的类型是由什么决定的
    在 c++ 中,函数返回值类型由其函数原型的类型决定,包括:函数原型指定返回值类型:在函数名称后跟冒号,再跟返回值类型。默认返回值类型为 int:如果不指定返回值类型,默认类型为 int...
    99+
    2024-05-14
    c++
  • 在c++中,什么叫函数的返回值
    在 c++ 中,函数只能返回一个值。解决方法:引用传递、结构体或类、out 参数。没有返回值的函数可以使用 void 类型,表示不返回任何值。 什么是 C++ 中函数的返回值? 在 C...
    99+
    2024-05-14
    c++
  • c++中static的作用和用法
    c++ 中的 static 关键字用于声明静态变量、函数或类成员,使其在程序生命周期内存在或与类的每个实例关联。具体用法如下:静态变量:在函数外声明,仅创建一份副本,在程序启动时初始化且...
    99+
    2024-05-14
    c++
  • static在c和c++中的区别
    static关键字在c和c++中用于控制变量的生命周期和作用域。在c中,它延长局部变量和限制全局变量的作用域。在c++中,它还用于定义类成员变量和函数、命名空间中的变量和函数,以及函数内...
    99+
    2024-05-14
    c语言 c++ 作用域
  • c++中a++与++a的区别
    c++ 中 a++ 和 ++a 区别:后缀递增 a++ 先返回原始值,再递增;前缀递增 ++a 先递增,再返回递增后的值。 C++ 中 a++ 与 ++a 的区别 在 C++ 中,a+...
    99+
    2024-05-14
    c++
  • if else在c++中的用法
    在 c++ 中,if else 语句根据条件执行不同代码块的语法为:if (condition) { } else { }。它可用于:检查数字是否为正数根据条件执行嵌套 if els...
    99+
    2024-05-14
    c++
  • struct在c和c++中的区别
    c和c++中struct的区别包括:c中成员默认公开访问,c++中默认私有访问。c++可以在struct定义中初始化成员,c中不允许。c++支持成员函数,c不支持。c++不支持匿名str...
    99+
    2024-05-14
    c++
  • c++中的所有函数都是传值调用吗
    函数调用类型可分为传值调用和引用调用,默认采用传值调用,传值调用中形参接收实参副本,引用调用中形参接收实参引用,对形参进行的修改也会影响实参。 C++中的函数调用类型 C++中,函数调...
    99+
    2024-05-14
    c++
  • c++中ifdef的用法
    c++ 中的 #ifdef 预处理器指令用于根据预定义宏是否存在来编译或不编译代码块。它的语法是 #ifdef ,其作用包括:检查宏是否存在,如果宏已定义,则编译其后的代码块;实现条件编...
    99+
    2024-05-14
    c++
  • c++中的函数调用有哪几种方式?它们有什么区别
    c++ 中的函数调用方式有 4 种:值传递(复制实参值,不影响实参)、引用传递(传递实参地址,修改形参值会修改实参)、指针传递(传递实参指向的内存地址,修改指向的值会影响实参)、rval...
    99+
    2024-05-14
    c++
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作