40-zabbix.html 39.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763


<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>4. zabbix监测系统 &mdash; watchmen 1.0 documentation</title>
  

  
  
  
  

  

  
  
    

  

  <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="5. watchmen在繁星的应用与开发" href="80-starnet-dev.html" />
    <link rel="prev" title="3. elk日志系统" href="30-elk.html" /> 

  
  <script src="_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="index.html" class="icon icon-home"> watchmen
          

          
          </a>

          
            
            
              <div class="version">
                1.0
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="10-summary.html">1. 概述</a></li>
<li class="toctree-l1"><a class="reference internal" href="20-ansible.html">2. ansible集群管理工具</a></li>
<li class="toctree-l1"><a class="reference internal" href="30-elk.html">3. elk日志系统</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">4. zabbix监测系统</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#id1">4.1. 服务端安装</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#docker">4.1.1. 使用docker安装/运行方式(建议使用此方式)</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#id2">4.1.1.1. 镜像加载</a></li>
<li class="toctree-l4"><a class="reference internal" href="#postgres">4.1.1.2. postgres数据库客户端安装</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id3">4.1.1.3. 运行docker,创建数据库</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#id4">4.1.2. 本地安装/运行方式(坑多)</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#id7">4.2. 节点端安装</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#id8">4.2.1. 主节点安装</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id9">4.2.2. 子节点安装</a></li>
<li class="toctree-l3"><a class="reference internal" href="#web">4.2.3. 进入web配置</a></li>
<li class="toctree-l3"><a class="reference internal" href="#host">4.2.4. 使用脚本添加host</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#id10">4.3. 手动配置(前面安装章节已包含自动化配置,没有特殊需求可略过本章节)</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#zabbix-agent">4.3.1. zabbix_agent配置</a></li>
<li class="toctree-l3"><a class="reference internal" href="#zabbix-proxy">4.3.2. zabbix_proxy配置</a></li>
<li class="toctree-l3"><a class="reference internal" href="#zabbix-server">4.3.3. zabbix_server配置</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#id11">4.4. 使用</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#quick-start">4.4.1. quick start</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id12">4.4.2. 模板</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#id13">4.5. 自定义监测项</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#id14">4.5.1. 繁星增加自定义监测项典型流程</a></li>
<li class="toctree-l3"><a class="reference internal" href="#vproc">4.5.2. vproc</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#id15">4.6. 自定义监测项列表</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#vaserver">4.6.1. VAServer</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#item">4.7. 动态item</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#id16">4.7.1. 概述</a></li>
<li class="toctree-l3"><a class="reference internal" href="#id19">4.7.2. 操作教程</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#id20">4.7.2.1. web上的配置</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id21">4.7.2.2. 设备上配置文件</a></li>
<li class="toctree-l4"><a class="reference internal" href="#id22">4.7.2.3. 运作流程简述</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#id23">4.8. 监控docker</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="80-starnet-dev.html">5. watchmen在繁星的应用与开发</a></li>
<li class="toctree-l1"><a class="reference internal" href="99-history.html">6. 修订历史</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="index.html">watchmen</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="index.html">Docs</a> &raquo;</li>
        
      <li>4. zabbix监测系统</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="_sources/40-zabbix.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="zabbix">
<h1>4. zabbix监测系统<a class="headerlink" href="#zabbix" title="Permalink to this headline"></a></h1>
<div class="section" id="id1">
<h2>4.1. 服务端安装<a class="headerlink" href="#id1" title="Permalink to this headline"></a></h2>
<div class="section" id="docker">
<h3>4.1.1. 使用docker安装/运行方式(建议使用此方式)<a class="headerlink" href="#docker" title="Permalink to this headline"></a></h3>
<p>离线安装包:  <a class="reference external" href="smb://192.168.9.1">smb://192.168.9.1</a>/公共模块/繁星/繁星二代/自检系统/zabbix_docker .</p>
<div class="section" id="id2">
<h4>4.1.1.1. 镜像加载<a class="headerlink" href="#id2" title="Permalink to this headline"></a></h4>
<p>有docker离线包zabbix_docker,拷贝到有docker的主机上,加载镜像:</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>docker load &lt; postgres9.6.docker.images
<span class="c1"># 屏幕会返回镜像的id,假设是:id-1</span>
<span class="c1"># 给镜像命名</span>
docker tag id-1 postgres:9.6

<span class="c1"># 下面两个镜像不需要命名,如果load后运行docker images 发现名字和版本都是none,则手动命名</span>
docker load &lt; zabbix-server-pgsql.docker.images
<span class="c1"># docker tag id-2 zabbix/zabbix-server-pgsql:ubuntu-3.4.13</span>

docker load &lt; zabbix-web-nginx-pgsql.docker.images
<span class="c1"># docker tag id-3 zabbix/zabbix-web-nginx-pgsql:ubuntu-3.4.13</span>

<span class="c1"># 加载完毕,docker images应该能显示</span>
root@user-ubuntu:~/zabbix_docker# docker images
REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
zabbix/zabbix-web-nginx-pgsql   ubuntu-3.4.13       bf422197fafe        <span class="m">4</span> weeks ago         <span class="m">254</span> MB
zabbix/zabbix-server-pgsql      ubuntu-3.4.13       af4434f6332b        <span class="m">4</span> weeks ago         <span class="m">224</span> MB
postgres                        <span class="m">9</span>.6                 4023a747a01a        <span class="m">20</span> months ago       <span class="m">265</span> MB
</pre></div>
</div>
</div>
<div class="section" id="postgres">
<h4>4.1.1.2. postgres数据库客户端安装<a class="headerlink" href="#postgres" title="Permalink to this headline"></a></h4>
<p>离线包里有libpq5_9.5.23-0ubuntu0.16.04.1_amd64.deb postgresql-client-9.5_9.5.23-0ubuntu0.16.04.1_amd64.deb</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>dpkg -i ./*.deb
</pre></div>
</div>
</div>
<div class="section" id="id3">
<h4>4.1.1.3. 运行docker,创建数据库<a class="headerlink" href="#id3" title="Permalink to this headline"></a></h4>
</div>
</div>
<div class="section" id="id4">
<h3>4.1.2. 本地安装/运行方式(坑多)<a class="headerlink" href="#id4" title="Permalink to this headline"></a></h3>
<p><a href="#id5"><span class="problematic" id="id6">**</span></a>此方法不同的机器上可能遇到不同的问题,下面的说明只能作为参考。 **</p>
<p>我用网上说的apt-get方式装,无法成功。web界面使用不正常,所以采用源码方式装。zabbix-3.4.13.tar.gz</p>
<p>环境依赖安装按照以下步骤:
<a class="reference external" href="https://blog.csdn.net/yannanxiu/article/details/54924198">https://blog.csdn.net/yannanxiu/article/details/54924198</a></p>
<p>zabbix-proxy zabbix-server zabbix-front-php 用源码安装,参考:
<a class="reference external" href="https://www.zabbix.com/documentation/3.4/zh/manual/installation/install">https://www.zabbix.com/documentation/3.4/zh/manual/installation/install</a></p>
<p>数据库安装,建立zabbix用户,建立zabbix数据库,运行zabbix-3.4.13/database/postgresql/中的3个脚本。命令行:</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>su postgres
createdb zabbix
createuser -SDRP zabbix
su root
cat ./zabbix-3.4.13/zabbix-3.4.13/database/postgresql/<span class="o">{</span>schema,images,data<span class="o">}</span>.sql.gz    <span class="p">|</span> psql -h <span class="m">127</span>.0.0.1 zabbix postgres
</pre></div>
</div>
<p>或者带界面的postgres客户端做也行。自行选择</p>
<p>zabbix-fornt(web界面)</p>
<p># 从源码拷贝到apache2
sudo cp -r zabbix-3.4.13/frontends/php/ /var/www/html/zabbix</p>
<ul class="simple">
<li>zabbix_sender报错</li>
</ul>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>root@tegra-ubuntu:/home/ubuntu# zabbix_sender -s <span class="s2">&quot;192.168.5.198&quot;</span> -z <span class="s2">&quot;192.168.5.133&quot;</span> -k <span class="s2">&quot;keytrtest&quot;</span> -o <span class="s2">&quot;1133&quot;</span>
info from server: <span class="s2">&quot;processed: 0; failed: 1; total: 1; seconds spent: 0.000026&quot;</span>
这里failed: 1说明失败了。
</pre></div>
</div>
<p>注意看item的type必须是Zabbix trapper</p>
<p>server主动获取,在zabbix_agent.conf增加的item的type是Zabbix trapper</p>
</div>
</div>
<div class="section" id="id7">
<h2>4.2. 节点端安装<a class="headerlink" href="#id7" title="Permalink to this headline"></a></h2>
<p>离线安装包:  <a class="reference external" href="smb://192.168.9.1">smb://192.168.9.1</a>/公共模块/繁星/繁星二代/自检系统/tx1_离线包/watchmen_tx1.tar.gz</p>
<div class="section" id="id8">
<h3>4.2.1. 主节点安装<a class="headerlink" href="#id8" title="Permalink to this headline"></a></h3>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>tar zxvf watchmen_tx1.tar.gz
<span class="nb">cd</span> watchmen_tx1
./watchmen_install_tx1.sh master
<span class="c1"># --server_ip平台ip。    --zabbix_proxy_name代理名称,必须和web上创建的一致</span>
./watchmen_config_tx1.sh --server_ip<span class="o">=</span><span class="m">192</span>.168.9.62 --zabbix_proxy_name<span class="o">=</span>190master
</pre></div>
</div>
</div>
<div class="section" id="id9">
<h3>4.2.2. 子节点安装<a class="headerlink" href="#id9" title="Permalink to this headline"></a></h3>
<p>确保主节点已安装了ansible</p>
<p>假如当前主节点管理的子节点组命名tx2</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>ansible -b tx2 -m copy -a <span class="s2">&quot;src=watchmen_tx1.tar.gz dest=/root/UserApp/&quot;</span>
ansible -b tx2 -m raw -a <span class="s2">&quot;cd /root/UserApp/; tar zxvf watchmen_tx1.tar.gz; cd watchmen_tx1; ./watchmen_install_tx1.sh slave&quot;</span>
</pre></div>
</div>
</div>
<div class="section" id="web">
<h3>4.2.3. 进入web配置<a class="headerlink" href="#web" title="Permalink to this headline"></a></h3>
<ol class="arabic simple">
<li>导入模版(参考使用章节)</li>
<li>添加代理(参考使用章节)</li>
</ol>
<p>每个主节点都需要添加代理</p>
</div>
<div class="section" id="host">
<h3>4.2.4. 使用脚本添加host<a class="headerlink" href="#host" title="Permalink to this headline"></a></h3>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span><span class="c1"># --baseurl zabbix web地址</span>
<span class="c1"># --ipstart 批量ip开始</span>
<span class="c1"># --ipsend 批量ip结束</span>
<span class="c1"># --hostgroup 在zabbix创建的group名。如果没有特殊要求填写starnet_tx1_slave_group</span>
<span class="c1"># --proxyname 代理名称,必须和web添加的代理名一致</span>
<span class="c1"># --template1模版名,监控项都在模版里</span>
<span class="c1"># 下面的命令会添加192.168.8.2/3/4/5/6 五个子节点</span>
python2 zabbix_addhost.py --baseurl<span class="o">=</span>http://192.168.9.62:9210 --ipstart<span class="o">=</span><span class="m">192</span>.168.8.2 --ipend<span class="o">=</span><span class="m">192</span>.168.8.6 --hostgroup<span class="o">=</span>starnet_tx1_slave_group --proxyname<span class="o">=</span>190master --template1<span class="o">=</span>starnet_tx1_slave_tp
</pre></div>
</div>
</div>
</div>
<div class="section" id="id10">
<h2>4.3. 手动配置(前面安装章节已包含自动化配置,没有特殊需求可略过本章节)<a class="headerlink" href="#id10" title="Permalink to this headline"></a></h2>
<div class="section" id="zabbix-agent">
<h3>4.3.1. zabbix_agent配置<a class="headerlink" href="#zabbix-agent" title="Permalink to this headline"></a></h3>
<p><strong>需要在系统配置开机启动</strong></p>
<p>zabbix_agentd安装包是在tx1上编译的。zabbix_agent_proxy_tx1的install.sh会将配置文件拷贝到
/usr/local/etc/zabbix_agent.conf</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span><span class="c1"># 填写主节点ip</span>
<span class="nv">Server</span><span class="o">=</span><span class="m">192</span>.168.5.177
<span class="nv">ServerActive</span><span class="o">=</span><span class="m">192</span>.168.5.177
<span class="c1"># 主节点运行的是proxy,在默认情况下这样填写</span>
<span class="nv">Hostname</span><span class="o">=</span>Zabbix proxy

<span class="nv">AllowRoot</span><span class="o">=</span><span class="m">1</span>
</pre></div>
</div>
<p>修改完重启进程</p>
</div>
<div class="section" id="zabbix-proxy">
<h3>4.3.2. zabbix_proxy配置<a class="headerlink" href="#zabbix-proxy" title="Permalink to this headline"></a></h3>
<p><strong>需要在系统配置开机启动</strong></p>
<p>zabbix_proxy安装包是在tx1上编译的。zabbix_agent_proxy_tx1的install.sh会将配置文件拷贝到
/usr/local/etc/zabbix_proxy.conf</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span><span class="c1"># zabbix_server主机ip</span>
<span class="nv">Server</span><span class="o">=</span><span class="m">192</span>.168.9.133
<span class="c1"># 需和zabbix_agent配置的Hostname对应</span>
<span class="nv">Hostname</span><span class="o">=</span>Zabbix proxy
<span class="c1"># zabbix_proxy数据库目录,如果是使用install.sh脚本安装的,会放在/root/UserApp下。</span>
<span class="nv">DBName</span><span class="o">=</span>/root/UserApp/zabbix_proxy.db
<span class="c1"># 多长间隔从zabbix_server拉取配置(秒)</span>
<span class="nv">ConfigFrequency</span><span class="o">=</span><span class="m">120</span>

<span class="nv">AllowRoot</span><span class="o">=</span><span class="m">1</span>
</pre></div>
</div>
</div>
<div class="section" id="zabbix-server">
<h3>4.3.3. zabbix_server配置<a class="headerlink" href="#zabbix-server" title="Permalink to this headline"></a></h3>
<p><strong>需要在系统配置开机启动</strong></p>
<p>zabbix_server在docker运行,在每次启动容器的时候会将必要参数传入,zabbix_docker/dockerrun_zabbix.sh已写好,运行即可</p>
</div>
</div>
<div class="section" id="id11">
<h2>4.4. 使用<a class="headerlink" href="#id11" title="Permalink to this headline"></a></h2>
<p>访问路径: <a class="reference external" href="http://ip:9210">http://ip:9210</a></p>
<p>第一次运行会有一些额外步骤,按照提示下一步即可</p>
<div class="section" id="quick-start">
<h3>4.4.1. quick start<a class="headerlink" href="#quick-start" title="Permalink to this headline"></a></h3>
<p>添加proxy,注意Proxy name必须和 zabbix_proxy配置中的Hostname相同。其他配置默认即可。点add添加成功</p>
<img alt="_images/zabbix-01.png" src="_images/zabbix-01.png" />
<p>添加host,Configuration-&gt;Hosts-&gt;Create host</p>
<img alt="_images/zabbix-02.png" src="_images/zabbix-02.png" />
<p>红框都是需要填写修改的。Groups可以自己建,给设备分组。Monitored by proxy必须选择正确的proxy代理</p>
<img alt="_images/zabbix-03.png" src="_images/zabbix-03.png" />
<p>点Template配置模板,模板决定了有哪些监测项。select选择一个模板,模板后续我们会自己创建,这里先选择Template OS Linux,包含了很多linux的监测项
点小add后再点大add</p>
<img alt="_images/zabbix-04.png" src="_images/zabbix-04.png" />
<p>添加成功</p>
<p>Dashboard可以浏览状态、报警等,Edit dashboard可以自定义。比如Problems中提示我的主机掉线了。</p>
<img alt="_images/zabbix-05.png" src="_images/zabbix-05.png" />
<p>如果想有目的的查询监测项状态,可以打开Monitoring-&gt;Lastest data。可以在过滤条件选择感兴趣的主机和检测项组
可以看到最后的值,可以点Graph看数值历史折线图。</p>
<img alt="_images/zabbix-06.png" src="_images/zabbix-06.png" />
<img alt="_images/zabbix-07.png" src="_images/zabbix-07.png" />
<p>这是最基本的使用,后续添加如何自定义监测项,利用api批量添加主机、动态管理监测项等功能。</p>
</div>
<div class="section" id="id12">
<h3>4.4.2. 模板<a class="headerlink" href="#id12" title="Permalink to this headline"></a></h3>
<p>繁星2代模板已放在sdv上 <a class="reference external" href="smb://192.168.9.1">smb://192.168.9.1</a>/公共模块/繁星/繁星二代/自检系统/zabbix_template</p>
</div>
</div>
<div class="section" id="id13">
<h2>4.5. 自定义监测项<a class="headerlink" href="#id13" title="Permalink to this headline"></a></h2>
<p>zabbix的监测项有两种:</p>
<ol class="arabic simple">
<li>上报型</li>
</ol>
<p>zabbix item type选择 traper。需配合zabbix_sender使用</p>
<ol class="arabic simple" start="2">
<li>查询型</li>
</ol>
<p>zabbix item type选择 agent</p>
<p>如果没有特殊需求,均采用查询型,走vproc流程。</p>
<p>应用程序使用vproc将状态写到文件,zabbix_agentd用vproc查询各状态的值,采用这种方式的原因:</p>
<ul class="simple">
<li>zabbix的交互压力可控,查询频率在web上配一下就好了。</li>
<li>应用程序写状态的操作与zabbix解耦。即使没有zabbix,我们在调试程序时也可以使用vproc,可以用命令行查询检测项的值。有助于调试</li>
</ul>
<p>vproc后面章节有详细介绍</p>
<div class="section" id="id14">
<h3>4.5.1. 繁星增加自定义监测项典型流程<a class="headerlink" href="#id14" title="Permalink to this headline"></a></h3>
<p>细节可以自行百度“zabbix增加自定义item”</p>
<p>界面上操作可参考:<a class="reference external" href="https://blog.csdn.net/u012062455/article/details/53257059">https://blog.csdn.net/u012062455/article/details/53257059</a></p>
<p>zabbix_agentd端操作可参考:<a class="reference external" href="https://www.cnblogs.com/mingerlcm/p/7754076.html">https://www.cnblogs.com/mingerlcm/p/7754076.html</a></p>
<p>以繁星2代为例。假设我们要在slave模板中增加vaserver的“进程号”、“是否授权”两个监测项。</p>
<ol class="arabic simple">
<li>在zabbix web端增加检测项</li>
</ol>
<p>监测项是添加到模板中的,添加后所有使用该模板的主机均生效,修改starnet_tx1_slave_tp模板</p>
<ul class="simple">
<li>点击Configuration-&gt;Template 。</li>
<li>点击starnet_tx1_slave_tp行的items。</li>
<li>点右上角的Create item</li>
<li>填写具体信息并保存</li>
</ul>
<ol class="arabic simple" start="2">
<li>在zabbix_agentd端配置</li>
</ol>
<ul class="simple">
<li>确保/usr/local/etc/zabbix_agentd.conf中有配置</li>
</ul>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span><span class="nv">UnsafeUserParameters</span><span class="o">=</span><span class="m">1</span>
<span class="nv">Include</span><span class="o">=</span>/usr/local/etc/zabbix_agentd.conf.d/*.conf
</pre></div>
</div>
<ul class="simple">
<li>在/usr/local/etc/zabbix_agentd.conf.d/vaserver.conf增加命令行,如果没有可新建文件</li>
</ul>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span><span class="c1"># UserParameter=后面是key值,必须跟web上配置的相同。逗号后面的是查询这个值所执行的指令。</span>
<span class="c1"># 进程号很简单,shell命令就能搞定</span>
<span class="nv">UserParameter</span><span class="o">=</span>vaserver.pid,pgrep VAServer
<span class="c1"># license状态是需要应用程序开发者写入到vproc系统中(/root/UserApp/vproc/vaserver/license文件内容)的。在这里用vproc工具进行查询。如果没查到,返回0</span>
<span class="nv">UserParameter</span><span class="o">=</span>vaserver.license,vproc <span class="nb">read</span> --key<span class="o">=</span>vaserver.license --value<span class="o">=</span><span class="m">0</span>
</pre></div>
</div>
<ol class="arabic simple" start="3">
<li>重启zabbix_agentd。过一会在web上就能看到了。</li>
</ol>
</div>
<div class="section" id="vproc">
<h3>4.5.2. vproc<a class="headerlink" href="#vproc" title="Permalink to this headline"></a></h3>
<p>vproc是python编写的工具</p>
<p>类似linux proc系统,应用程序调用vproc脚本将监测项状态值持续更新到指定文件中。外部可读取文件值,得知应用程序的运行情况。</p>
<p>vproc工具有5种用法。</p>
<ul class="simple">
<li>写:</li>
</ul>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span><span class="c1"># 此命令将创建文件 ROOT_VPROC/app/group1/group2/item,文件内容为value1</span>
./vproc write --key<span class="o">=</span>app.group1.gourp2.item --value<span class="o">=</span>value1
</pre></div>
</div>
<ul class="simple">
<li>读:</li>
</ul>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span><span class="c1"># 将ROOT_VPROC/app/group1/group2/item文件内容打印出来</span>
./vproc <span class="nb">read</span> --key<span class="o">=</span>app.group1.gourp2.item
</pre></div>
</div>
<ul class="simple">
<li>重置:</li>
</ul>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span><span class="c1"># 删除ROOT_VPROC/app/group1/目录。相当于重置状态值</span>
./vproc clean --path<span class="o">=</span>app.group1
</pre></div>
</div>
<ul class="simple">
<li>lld json功能:</li>
</ul>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span><span class="c1"># 将path目录下第一级目录/文件名当做macro的value,生成json</span>
<span class="c1"># 假设有 app.group1.group2.item和app.group1.item1</span>
./vproc lld --path<span class="o">=</span>app.group1 --macro<span class="o">=</span>DY
<span class="c1"># 输出</span>
<span class="o">{</span><span class="s2">&quot;data&quot;</span>: <span class="o">[{</span><span class="s2">&quot;{#DY}&quot;</span>: <span class="s2">&quot;group1&quot;</span><span class="o">}</span>, <span class="o">{</span><span class="s2">&quot;{#DY}&quot;</span>: <span class="s2">&quot;item1&quot;</span><span class="o">}]}</span>
</pre></div>
</div>
<p>这个功能是配合zabbix的lld功能使用。详情见watchmen文档动态item章节</p>
<ul class="simple">
<li>查看:</li>
</ul>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span><span class="c1"># 类似top,每隔1秒刷新输出一次状态值。参数path可以是任意级别,输出的监测项是path下的所有监测项。</span>
./vproc watch --path<span class="o">=</span>app.group1
</pre></div>
</div>
<p>所有key值均采用 app.[group1.gourp2…groupn].item方式组织。末端item为文件,记录监测项的值,前面是多级目录。比如key值vaserver.va0.cameraname,记录状态值的文件为VPORC_ROOT/vaserver/va0/cameraname。</p>
<p>单个监测项更新状态频率不宜过快。建议间隔时间1分钟以上</p>
<p><strong>注意</strong>: 建议在程序(以及能代表一组的流程)启动时、关闭时重置状态,<strong>避免旧的状态值干扰</strong></p>
<p>vproc 典型使用流程,拿vaserver举例:</p>
<p>有vaserver.event_count(发出了多少事件) ; vaserver.va0.taskname(分析通道0的任务名称); vaserver.va1.taskname</p>
<p>vaserver启动和退出时应调用</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span><span class="c1"># 清理旧状态</span>

./vproc clean --path<span class="o">=</span>vaserver
</pre></div>
</div>
<p>vaserver启动、关闭一个va时(假设是编号0)应调用</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span><span class="c1"># 清理旧状态</span>

./vproc clean --path<span class="o">=</span>vaserver.va0

<span class="c1"># 然后将任务信息状态更新</span>

./vproc write --key<span class="o">=</span>vaserver.va0.taskname --value<span class="o">=</span>taskname1

<span class="c1"># 其他状态值在恰当时更新</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="id15">
<h2>4.6. 自定义监测项列表<a class="headerlink" href="#id15" title="Permalink to this headline"></a></h2>
<div class="section" id="vaserver">
<h3>4.6.1. VAServer<a class="headerlink" href="#vaserver" title="Permalink to this headline"></a></h3>
<table border="1" class="docutils">
<colgroup>
<col width="41%" />
<col width="9%" />
<col width="51%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">key</th>
<th class="head">类型</th>
<th class="head">说明</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>vaserver.va0.taskname</td>
<td>Text</td>
<td>任务名称</td>
</tr>
<tr class="row-odd"><td>vaserver.va0.taskid</td>
<td>Text</td>
<td>任务id</td>
</tr>
<tr class="row-even"><td>vaserver.va0.cameraname</td>
<td>Text</td>
<td>相机名称</td>
</tr>
<tr class="row-odd"><td>vaserver.va0.cameraid</td>
<td>Text</td>
<td>相机id</td>
</tr>
<tr class="row-even"><td>vaserver.va0.playok</td>
<td>int</td>
<td>是否点播成功,实际接收到流后再更新状态</td>
</tr>
<tr class="row-odd"><td>vaserver.va0.sendresultcount</td>
<td>int</td>
<td>对外发送了多少条结果,1分钟更新一次</td>
</tr>
<tr class="row-even"><td>vaserver.va0.YUVfreq</td>
<td>int</td>
<td>YUV帧率</td>
</tr>
<tr class="row-odd"><td>vaserver.va0.playfreq</td>
<td>int</td>
<td>调试流帧率</td>
</tr>
<tr class="row-even"><td>vaserver.va0.MediaDatafreq</td>
<td>int</td>
<td>输入码流帧率</td>
</tr>
<tr class="row-odd"><td>vaserver.va0.personNumberAlarm</td>
<td>int</td>
<td>人流量结果数量</td>
</tr>
<tr class="row-even"><td>vaserver.va0.densityAlarm</td>
<td>int</td>
<td>密度结果数量</td>
</tr>
<tr class="row-odd"><td>vaserver.va[1…n].xxx</td>
<td>同va0</td>
<td>同va0</td>
</tr>
<tr class="row-even"><td>vaserver.license</td>
<td>int</td>
<td>授权状态,check license后更新</td>
</tr>
<tr class="row-odd"><td>vaserver.some</td>
<td>&#160;</td>
<td>&#160;</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="item">
<h2>4.7. 动态item<a class="headerlink" href="#item" title="Permalink to this headline"></a></h2>
<div class="section" id="id16">
<h3>4.7.1. 概述<a class="headerlink" href="#id16" title="Permalink to this headline"></a></h3>
<p>动态item的官方说法叫做  Low-level discovery(LLD)</p>
<p>之前我们使用zabbix时需要手动、明确的添加一个个item,对于某些特殊需求,这种方式无法优雅的实现。比如我们想监测所有正在点播的摄像机状态,我们无法预知有多少摄像机,无法预知摄像机id从而定义key值,这时LLD功能派上用场。</p>
<p>参考资料:</p>
<p><a class="reference external" href="https://www.zabbix.com/documentation/3.4/manual/discovery/low_level_discovery">官方文档</a></p>
<p><a class="reference external" href="http://www.zphj1987.com/2016/10/28/zabbix%E5%AE%9E%E7%8E%B0%E8%87%AA%E5%AE%9A%E4%B9%89%E8%87%AA%E5%8A%A8%E5%8F%91%E7%8E%B0%E7%9A%84%E6%B5%81%E7%A8%8B/">zabbix实现自定义自动发现的流程</a></p>
<p><a class="reference external" href="http://blog.51cto.com/cuidehua/1766027">zabbix 自定义自动发现的key! low level discovery</a></p>
</div>
<div class="section" id="id19">
<h3>4.7.2. 操作教程<a class="headerlink" href="#id19" title="Permalink to this headline"></a></h3>
<p>摄像机状态这个监控项有几个特点:</p>
<ol class="arabic simple">
<li>摄像机有多少不固定</li>
<li>摄像机是动态的,随时增减</li>
<li>每个设备点播的摄像机不同,能够监控的摄像机也就不同</li>
</ol>
<p>下面演示如何利用LLD功能满足摄像机状态的监控需求</p>
<div class="section" id="id20">
<h4>4.7.2.1. web上的配置<a class="headerlink" href="#id20" title="Permalink to this headline"></a></h4>
<p>打开zabbix web,点开模板配置,点击指定模板的Discovery,如图:</p>
<img alt="_images/zabbix-lld-01.png" src="_images/zabbix-lld-01.png" />
<p>此时进入了Discovery rules页面,点击右上角的Create discovery rule,填写相关内容:</p>
<ul class="simple">
<li>key 拉取macro集合的key值</li>
<li>Update interval是每隔多少秒拉取一次</li>
<li>Custom intervals是设备上删除了动态items后,zabbix web上多少秒后删除。 最低时间3600秒</li>
</ul>
<img alt="_images/zabbix-lld-02.png" src="_images/zabbix-lld-02.png" />
<p>创建成功后,在Discovery rules多出一行,点  Item prototypes</p>
<img alt="_images/zabbix-lld-03.png" src="_images/zabbix-lld-03.png" />
<p>此时进入了Item prototypes页面,点击右上角的Create item prototype,参考图中填写,注意:</p>
<ul class="simple">
<li>{#CAMERAID} 称之为宏macro,macro是动态items的关键,我们用macro处理 items key值中的变化项。macro可以是任何值,和设备上配置的对应上即可(后面会介绍)。</li>
<li>注意key的格式,中括号模式是带参数的key,中括号的值是参数,zabbix server向zabbix_agentd获取值时带参数。 设备上配置文件中会体现出作用。</li>
</ul>
<img alt="_images/zabbix-lld-04.png" src="_images/zabbix-lld-04.png" />
</div>
<div class="section" id="id21">
<h4>4.7.2.2. 设备上配置文件<a class="headerlink" href="#id21" title="Permalink to this headline"></a></h4>
<p>总结在zabbix web上的操作,我们创建了一个Discovery,在Discovery中创建了一个Item prototypes,涉及到两个key: cameras和cameras.fps[{#CAMERAID}]</p>
<p>在/usr/local/etc/zabbix_agentd.conf.d/test.conf中增加两行</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span><span class="nv">UserParameter</span><span class="o">=</span>cameras,vproc lld --path<span class="o">=</span>cameras --macro<span class="o">=</span>CAMERAID
<span class="nv">UserParameter</span><span class="o">=</span>cameras.fps<span class="o">[</span>*<span class="o">]</span>,vproc <span class="nb">read</span> --key<span class="o">=</span>cameras.<span class="nv">$1</span>.fps --value<span class="o">=</span>-1
</pre></div>
</div>
<p>第一行是发现items。vproc增加了lld功能,将–path下第一级的文件/目录名当做macro的赋值,返回zabbix定义的json串:</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span><span class="o">{</span><span class="s2">&quot;data&quot;</span>: <span class="o">[{</span><span class="s2">&quot;{#CAMERAID}&quot;</span>: <span class="s2">&quot;vax1&quot;</span><span class="o">}</span>, <span class="o">{</span><span class="s2">&quot;{#CAMERAID}&quot;</span>: <span class="s2">&quot;vax2&quot;</span><span class="o">}</span>, <span class="o">{</span><span class="s2">&quot;{#CAMERAID}&quot;</span>: <span class="s2">&quot;id2&quot;</span><span class="o">}</span>, <span class="o">{</span><span class="s2">&quot;{#CAMERAID}&quot;</span>: <span class="s2">&quot;id1&quot;</span><span class="o">}]}</span>
</pre></div>
</div>
<p>在设备上写测试数据,几个摄像机状态</p>
<div class="highlight-language notranslate"><div class="highlight"><pre><span></span>vproc write --key=cameras.vax1.fps --value=25
vproc write --key=cameras.vax1.playok --value=0
vproc write --key=cameras.vax2.fps --value=25
vproc write --key=cameras.vax2.playok --value=0
vproc write --key=cameras.id2.fps --value=25
vproc write --key=cameras.id2.playok --value=1
vproc write --key=cameras.id1.fps --value=25
vproc write --key=cameras.id1.playok --value=1

# 此时[vproc_root]/cameras目录下有vax1,vax2,id1,id2目录。 所以vproc lld命令读取到4个相机id,组成json返回zabbix
</pre></div>
</div>
<p>第二行是获取指定相机的fps,相机id用参数传进来。 $1代表参数。也就是web设置key值cameras.fps[{#CAMERAID}]时中括号里的值。我们这里中括号是macro</p>
<p>重启zabbix_agentd后,过一会就能看到效果了</p>
<img alt="_images/zabbix-lld-05.png" src="_images/zabbix-lld-05.png" />
<p>192.168.88.3我只写了id1和id2。</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">vproc</span> <span class="n">write</span> <span class="o">--</span><span class="n">key</span><span class="o">=</span><span class="n">cameras</span><span class="o">.</span><span class="n">id2</span><span class="o">.</span><span class="n">fps</span> <span class="o">--</span><span class="n">value</span><span class="o">=</span><span class="mi">25</span>
<span class="n">vproc</span> <span class="n">write</span> <span class="o">--</span><span class="n">key</span><span class="o">=</span><span class="n">cameras</span><span class="o">.</span><span class="n">id2</span><span class="o">.</span><span class="n">playok</span> <span class="o">--</span><span class="n">value</span><span class="o">=</span><span class="mi">1</span>
<span class="n">vproc</span> <span class="n">write</span> <span class="o">--</span><span class="n">key</span><span class="o">=</span><span class="n">cameras</span><span class="o">.</span><span class="n">id1</span><span class="o">.</span><span class="n">fps</span> <span class="o">--</span><span class="n">value</span><span class="o">=</span><span class="mi">25</span>
<span class="n">vproc</span> <span class="n">write</span> <span class="o">--</span><span class="n">key</span><span class="o">=</span><span class="n">cameras</span><span class="o">.</span><span class="n">id1</span><span class="o">.</span><span class="n">playok</span> <span class="o">--</span><span class="n">value</span><span class="o">=</span><span class="mi">1</span>
</pre></div>
</div>
<p>所以比88.2少了 vax1、vax2的监测项。我们在设备上继续添加其他其他摄像机状态,在web上会自动创建监测项。 设备上删除摄像机后,1小时后,web上会删除对应的监测项。</p>
</div>
<div class="section" id="id22">
<h4>4.7.2.3. 运作流程简述<a class="headerlink" href="#id22" title="Permalink to this headline"></a></h4>
<ul class="simple">
<li>创建Discovery后,zabbix server会每隔n秒,向设备拉取macro的value集合。 拉取动作有自己的key,在zabbix_agentd上配置这个key对应的command,command收集macro的value集合,生成json返回给zabbix server。 zabbix server解析json,保存macro的value集合。</li>
<li>在Discovery中创建的Item prototypes可以使用macro,创建带参数的key值,根据macro的value集合自动创建的item集合。</li>
<li>Discovery会检查macro的value的增减,新增就创建item,减少了就等n时间后删除item。</li>
<li>可以创建多个Item prototypes</li>
<li>macro的value集合json利用vproc lld功能生成</li>
</ul>
</div>
</div>
</div>
<div class="section" id="id23">
<h2>4.8. 监控docker<a class="headerlink" href="#id23" title="Permalink to this headline"></a></h2>
<p>已有开源项目https://github.com/monitoringartist/Zabbix-Docker-Monitoring</p>
<p>平台端运行zabbix_agentd定制版docker,离线包中已添加zabbix_docker/dockbix-agent-xxl-limited_3.4-3.images</p>
<p>dockerrun_zabbix.sh中有运行命令</p>
<p>zabbix web增加Zabbix-Template-App-Docker.xml模板。创建主机,关联此模板</p>
</div>
</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="80-starnet-dev.html" class="btn btn-neutral float-right" title="5. watchmen在繁星的应用与开发" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="30-elk.html" class="btn btn-neutral" title="3. elk日志系统" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2018, liuhang.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'./',
            VERSION:'1.0',
            LANGUAGE:'None',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: '.txt'
        };
    </script>
      <script type="text/javascript" src="_static/jquery.js"></script>
      <script type="text/javascript" src="_static/underscore.js"></script>
      <script type="text/javascript" src="_static/doctools.js"></script>

  

  <script type="text/javascript" src="_static/js/theme.js"></script>

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>