zoukankan      html  css  js  c++  java
  • 系统架构一:snmp+mrtg服务器监控

    //@author:yuan<turing_zhy@163.com>

    码字不易,转载请注明出处

    #==================================

    开始,服务器准备   ubuntu1~16.04.4

    1、安装snmp

    sudo apt-get install snmpd snmp snmp-mibs-downloader        -----安装

    rocommunity public
    disk / 51474044                 /etc/snmp/snmpd.conf                    --------添加这两行配置就行了,不必太复杂

    service snmpd restart                                                               -----重启服务

    chkconfig --level 35 snmp on ------开机自启动
    netstat -tunpl |grep :161 -------查看端口是否正常开启
    snmpget -v1 -cpublic localhost .1.3.6.1.4.1.2021.9.1.8.1 -------简单测试获取端口值[硬盘空间]
    注:snmp是将linux各项参数作为一个点来记录
     
     
    2、安装mrtg
    apt-get install mrtg ---------安装
     
     
    #Minimal mrtg.cfg
    #--------------------
    WorkDir: /var/www/html/hello_world/public/mrtg
    HtmlDir: /var/www/html/hello_world/public/mrtg
    ImageDir: /var/www/html/hello_world/public/mrtg
    LogDir: /var/lib/mrtg
    ThreshDir: /var/lib/mrtg
    WriteExpires: Yes
    Language: gb2312
    Title[^]: Traffic Analysis for


    #=============================================
    #监视eth0网卡(链接公网的)
    #=============================================
    #public权限监控位置
    Target[eth0_lan]:/10.105.84.244:public@localhost:
    #右对齐
    Options[eth0_lan]:growright
    #图片存放位置
    Directory[eth0_lan]:eth0
    #网卡最大值100M
    MaxBytes[eth0_lan]:100000000
    #y轴单位
    Kmg[eth0_lan]:K,M,G
    #y轴标题
    YLegend[eth0_lan]:Bytes per Second
    #y轴单位
    ShortLegend[eth0_lan]:B/s
    #网页标题配置
    Legend1[eth0_lan]:每秒流入量(单位Bytes)
    Legend2[eth0_lan]:每秒流出量(单位Bytes)
    LegendI[eth0_lan]:流入:
    LegendO[eth0_lan]:流出:
    Title[eth0_lan]:eth0网络流量[流入+流出]
    PageTop[eth0_lan]:<H1>eth0网络流量[流入+流出]</H1>
    #=============================================
    #监视cpu负载[使用+限制]
    #=============================================
    Target[cpuload]:.1.3.6.1.4.1.2021.11.50.0&.1.3.6.1.4.1.2021.11.53.0:public@localhost:
    Options[cpuload]:nopercent,growright
    Directory[cpuload]:cpu
    MaxBytes[cpuload]:100
    Unscaled[cpuload]:dwym
    YLegend[cpuload]:CPU Utilization
    ShortLegend[cpuload]:%
    Legend1[cpuload]:CPU用户负载(%)
    Legend2[cpuload]:CPU闲置(%)
    LegendI[cpuload]:使用:
    LegendO[cpuload]:闲置:
    Title[cpuload]:CPU负载[使用+闲置]
    PageTop[cpuload]:<H1>CPU负载[使用+闲置]</H1>
    #=============================================
    #监视内存使用量[Mem+swap]
    #=============================================
    #Target[memory]:WaLK.1.3.6.1.2.1.25.2.3.1.6.2&WaLK.1.3.6.1.2.1.25.2.3.1.6.2:public@localhost:
    #Options[memory]:gauge,growright
    #Directory[memory]:mem
    #MaxBytes[memory]:1917272
    #MaxBytes2[memory]:1917272
    #Kmg[memory]:K,M,G
    #Kilo[memory]:1024
    #Unscaled[memory]:dwym
    #YLegend[memory]:Mem Bytes
    #ShortLegend[memory]:B
    #Legend1[memory]:已用Mem(Bytes)
    #Legend2[memory]:已用Swap(Bytes)
    #Legend2[memory]:
    #LegendI[memory]:已用Mem:
    #LegendO[memory]:已用Swap:
    #LegendO[memory]:
    #Title[memory]:内存使用量[Mem+Swap]
    #PageTop[memory]:<h1>内存使用量[Mem+Swap]</h1>
    #=============================================
    #监视硬盘空间[系统盘+数据盘]
    #=============================================
    Target[disk]:.1.3.6.1.4.1.2021.9.1.8.1&.1.3.6.1.4.1.2021.9.1.8.1:public@localhost:
    Options[disk]:gauge,growright
    Directory[disk]:disk
    MaxBytes[disk]:51474044
    #MaxBytes2[disk]:51474044
    Kmg[disk]:K,M,G
    Kilo[disk]:1024
    Unscaled[disk]:dwym
    YLegend[disk]:Disk Bytes
    ShortLegend[disk]:B
    Legend1[disk]:根分区已用空间
    #Legend2[disk]:boot分区已用空间
    Legend2[disk]:
    LegendI[disk]:根分区已用:
    #LegendO[disk]:boot分区已用:
    LegendO[disk]:
    Title[disk]:硬盘空间[系统盘+数据盘]
    PageTop[disk]:<H1>硬盘空间[系统盘+数据盘]</H1>
    #=============================================
    #监控打开的TCP连接数[TCP连接数]
    #=============================================
    Target[tcpopen]:.1.3.6.1.2.1.6.9.0&.1.3.6.1.2.1.6.9.0:public@localhost:
    Options[tcpopen]:gauge,nopercent,growright
    Directory[tcpopen]:tcpopen
    MaxBytes[tcpopen]:100
    YLegend[tcpopen]:Tcp Connections
    ShortLegend[tcpopen]:个
    Legend1[tcpopen]:打开的TCP连接数(个)
    Legend2[tcpopen]:
    LegendI[tcpopen]:TCP连接数
    LegendO[tcpopen]:
    Title[tcpopen]:TCP连接数[TCP连接数]
    PageTop[tcpopen]:<H1>TCP连接数[TCP连接数]</H1> --------这是我自用的mrtg配置[都是我跟着视频码的,需要修改,联系我或者查资料]

     

    env  LANG=C /usr/bin/mrtg   /var/www/html/hello_world/public/mrtg/mrtg.cfg    ----第一次生成图片及首页可能报错,运行三次左右不会产生报错,除非你配置文件有错【注:mrtg为c++编写  先安装gcc】

    3、在crontab 加上定时命令定时产生节点信息

    crontab -e                                                                              --------打开cron设置项

    */5 * * * * env  LANG=C /usr/bin/mrtg   /var/www/html/hello_world/public/mrtg/mrtg.cfg          --------每5分钟生成一次

    4、效果展示

     注:可能会遇到一些编码问题,花点时间可以搞定,这里不在赘述

     注:现在大多的云服务商都有服务器监控的功能[更美观][更细致],这里只做学习使用,知其所以然。

     注:码字不易,转载请注明出处<turing_zhy@163.com>

    #==================================

  • 相关阅读:
    Node.js 基础介绍
    你所不知道该如何回答的面试题(一)
    深浅拷贝
    CSRF攻击:陌生链接不要随便点
    跨站脚本攻击(XSS)
    同源策略:为什么XMLHttpRequest不能跨域请求资源?
    HTTP/2:如何提升网络速度
    HTTP/1:HTTP性能优化
    WebComponent:像搭积木一样构建Web应用
    winform 保存文件 打开文件 选择文件 字体样式颜色(流 using System.IO;)
  • 原文地址:https://www.cnblogs.com/yuanyuanyuan/p/9327889.html
Copyright © 2011-2022 走看看