zabbix手動環境搭建及API呼叫
設定上海時區
timedatectl set-timezone Asia/Shanghai
yum install ntp
systemctl enable ntpd.service
systemctl start ntpd.service
ntpdate 0.centos.pool.ntp.org
[[email protected] ~]# cat /etc/selinux/config
SELINUX=disabled
[[email protected] ~]# setenforce 0 && getenforce
systemctl status firewalld
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld
firewall-cmd --state
//配置zabbix的yum源
[[email protected] ~]# wget http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
[[email protected] ~]# rpm -ivh ./zabbix-release-3.4-2.el7.noarch.rpm
//安裝zabbix程式包,安裝mysql,zabbix-agent
[[email protected] ~]# yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-agent mariadb-server
//啟動mariadb(資料庫)並設定開機啟動,建立資料庫例項,授權
[[email protected] ~]# systemctl start mariadb && systemctl enable mariadb
#建立zabbix資料庫
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
#授權所有主機訪問資料庫例項zabbix,使用者名稱/密碼 zabbix/zabbix
MariaDB [(none)]> grant all privileges on zabbix.* to [email protected]'%' identified by 'zabbix';
#授權localhost.localdomain主機訪問資料庫例項zabbix,使用者名稱zabbix/zabbix
MariaDB [(none)]> grant all privileges on zabbix.* to [email protected] identified by 'zabbix';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit;
#匯入初始模式和資料
[[email protected] ~]# cd /usr/share/doc/zabbix-server-mysql-3.4.10/
#這裡資料庫沒有設定密碼的
[[email protected] zabbix-server-mysql-3.4.10]# zcat create.sql.gz |mysql -uroot zabbix
[[email protected] zabbix-server-mysql-3.4.10]#
啟動zabbix-server
配置zabbix-server 配置檔案zabbix-server.conf
[[email protected] zabbix-server-mysql-3.4.10]# hostname
kolla
[[email protected] zabbix-server-mysql-3.4.10]# vi /etc/zabbix/zabbix_server.conf
91 DBHost=localhost #資料主機名
101 DBName=zabbix #資料庫例項
117 DBUser=zabbix #使用者名稱
126 DBPassword=zabbix #密碼
啟動zabbix-server服務,並開機啟動zabbix-server服務
[[email protected] ~]# systemctl start zabbix-server && systemctl enable zabbix-server
編輯Apache的配置檔案,註釋設定正確的時區
[[email protected] ~]# vi /etc/httpd/conf.d/zabbix.conf
12 <IfModule mod_php5.c>
13 php_value max_execution_time 300
14 php_value memory_limit 128M
15 php_value post_max_size 16M
16 php_value upload_max_filesize 2M
17 php_value max_input_time 300
18 php_value always_populate_raw_post_data -1
19 php_value date.timezone Asia/Shanghai
啟動httpd服務,設定開機啟動httpd服務
[[email protected] ~]# systemctl start httpd
[[email protected] ~]# systemctl enable httpd
啟動zabbix-agent並設定開機自啟動
[[email protected] ~]# systemctl start zabbix-agent
[[email protected] ~]# systemctl enable zabbix-agent
zabbix web網頁安裝
一路往下,登陸
所用到的API
1 認證並取得加密欄位
[[email protected] ~]#
curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":
"2.0","method":"user.login","params":{"user":"Admin","password":"zabbix"},"auth":
null,"id":0}' http://192.168.229.130/zabbix/api_jsonrpc.php;
返回結果
HTTP/1.1 200 OK
Date: Thu, 14 Jun 2018 08:10:28 GMT
Server: Apache/2.4.6 (CentOS) PHP/5.4.16
X-Powered-By: PHP/5.4.16
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Max-Age: 1000
Content-Length: 68
Content-Type: application/json
{"jsonrpc":"2.0","result":"7c4ba89691470b9c7018fa24206e71fd","id":0}
引數說明: result:返回的不需要賬號密碼得到的token,key值
2獲取指定活所有監控主機的hostids
[[email protected] ~]# curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"host.get","params":{"output":["hostid"]},"auth":"7c4ba89691470b9c7018fa24206e71fd","id":1}' http://192.168.229.130/zabbix/api_jsonrpc.php
HTTP/1.1 200 OK
Date: Thu, 14 Jun 2018 08:15:07 GMT
Server: Apache/2.4.6 (CentOS) PHP/5.4.16
X-Powered-By: PHP/5.4.16
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Max-Age: 1000
Content-Length: 54
Content-Type: application/json
{"jsonrpc":"2.0","result":[{"hostid":"10084"}],"id":1}
引數說明: hostid:為請求返回的所有hostid結果
3 zabbix獲取cpu資訊
3.1獲取空閒cpu請求
[[email protected] ~]# curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"item.get","params":{"output":"itemids","hostids":"10084","search":{"key_":"system.cpu.util[,idle]"}},"auth":"7c4ba89691470b9c7018fa24206e71fd","id":1}' http://192.168.229.130/zabbix/api_jsonrpc.php
HTTP/1.1 200 OK
Date: Thu, 14 Jun 2018 08:24:04 GMT
Server: Apache/2.4.6 (CentOS) PHP/5.4.16
X-Powered-By: PHP/5.4.16
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Max-Age: 1000
Content-Length: 54
Content-Type: application/json
{"jsonrpc":"2.0","result":[{"itemid":"23299"}],"id":1}
根據itemid獲取cpu使用資料
[[email protected] ~]# curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"history.get","params":{"output":"extend","history":0,"itemids":"23299","sortfield":"clock","sortorder":"DESC","limit":10},"auth":"7c4ba89691470b9c7018fa24206e71fd","id":1}' http://192.168.229.130/zabbix/api_jsonrpc.php
HTTP/1.1 200 OK
Date: Thu, 14 Jun 2018 08:29:36 GMT
Server: Apache/2.4.6 (CentOS) PHP/5.4.16
X-Powered-By: PHP/5.4.16
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Max-Age: 1000
Content-Length: 784
Content-Type: application/json
{"jsonrpc":"2.0","result":[{"itemid":"23299","clock":"1528964959","value":"99.6607","ns":"17298798"},{"itemid":"23299","clock":"1528964899","value":"99.6775","ns":"962278395"},{"itemid":"23299","clock":"1528964839","value":"99.6997","ns":"899333542"},{"itemid":"23299","clock":"1528964779","value":"99.7108","ns":"837009427"},{"itemid":"23299","clock":"1528964719","value":"99.7497","ns":"782085894"},{"itemid":"23299","clock":"1528964659","value":"99.6997","ns":"727213245"},{"itemid":"23299","clock":"1528964599","value":"99.7330","ns":"670066709"},{"itemid":"23299","clock":"1528964539","value":"99.6941","ns":"591833776"},{"itemid":"23299","clock":"1528964479","value":"99.7275","ns":"535724086"},{"itemid":"23299","clock":"1528964419","value":"99.7331","ns":"466218270"}],"id":1}
[[email protected] ~]#
說明: value:為請求時所定義的itemid歷史資料, 對應的值為物理機cpu的空閒百分比
---------------------------------
使用者cpu使用情況
curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"item.get","params":{"output":"itemids","hostids":"10084","search":{"key_":"system.cpu.util[,user]"}},
> "auth":"7c4ba89691470b9c7018fa24206e71fd","id":0}' http://192.168.229.130/zabbix/api_jsonrpc.php
HTTP/1.1 200 OK
Date: Thu, 14 Jun 2018 09:03:24 GMT
Server: Apache/2.4.6 (CentOS) PHP/5.4.16
X-Powered-By: PHP/5.4.16
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Max-Age: 1000
Content-Length: 54
Content-Type: application/json
{"jsonrpc":"2.0","result":[{"itemid":"23306"}],"id":0}
[[email protected] ~]#
根據itemid獲取cpu的使用資料
curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0", "method": "history.get","params":{"output":"extend", "history":0, "itemids":"23306","sortfield":"clock","sortorder":"DESC","limit":10}, "auth":"7c4ba89691470b9c7018fa24206e71fd","id":1}' http://192.168.229.130/zabbix/api_jsonrpc.php
HTTP/1.1 200 OK
Date: Thu, 14 Jun 2018 09:11:56 GMT
Server: Apache/2.4.6 (CentOS) PHP/5.4.16
X-Powered-By: PHP/5.4.16
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Max-Age: 1000
Content-Length: 774
Content-Type: application/json
{"jsonrpc":"2.0","result":[{"itemid":"23306","clock":"1528967486","value":"0.0945","ns":"644778520"},{"itemid":"23306","clock":"1528967426","value":"0.1001","ns":"579728930"},{"itemid":"23306","clock":"1528967366","value":"0.0834","ns":"518730693"},{"itemid":"23306","clock":"1528967306","value":"0.0778","ns":"450757183"},{"itemid":"23306","clock":"1528967246","value":"0.0834","ns":"388084039"},{"itemid":"23306","clock":"1528967186","value":"0.1001","ns":"321712401"},{"itemid":"23306","clock":"1528967126","value":"0.0945","ns":"256476597"},{"itemid":"23306","clock":"1528967066","value":"0.1001","ns":"186605449"},{"itemid":"23306","clock":"1528967006","value":"0.1001","ns":"118345066"},{"itemid":"23306","clock":"1528966946","value":"0.1001","ns":"45290570"}],"id":1}[[email protected] ~]#
[[email protected] ~]#
zabbix下獲取記憶體資訊:根據(總記憶體-可用記憶體)/總記憶體,得到記憶體使用率
獲取總的記憶體
[[email protected] ~]# curl -i -X POST -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","method":"item.get","params":{"output":"itemids","hostids":"10084","search":{"key_":"vm.memory.size[total]"}},"auth":"7c4ba89691470b9c7018fa24206e71fd","id":0}' http://192.168.229.130/zabbix/api_jsonrpc.php
HTTP/1.1 200 OK
Date: Thu, 14 Jun 2018 09:57:49 GMT
Server: Apache/2.4.6 (CentOS) PHP/5.4.16
X-Powered-By: PHP/5.4.16
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: POST
Access-Control-Max-Age: 1000
Content-Length: 54
Content-Type: application/json
{"jsonrpc":"2.0","result":[{"itemid":"23317"}],"id":0}
根據返回的itemid獲取記憶體總數
相關推薦
zabbix手動環境搭建及API呼叫
設定上海時區 timedatectl set-timezone Asia/Shanghai yum install ntp systemctl enable ntpd.service systemctl start ntpd.service ntpdat
[經驗技巧] “php+mysql+apache”環境搭建及"手動SQL註入",20180527-0
版本 lin AC 旗艦 分號 正常 HERE sele primary [經驗技巧] “php+mysql+apache”環境搭建及"手動SQL註入" 1.“php+mysql+apache”環境搭建 環境載體:虛擬機Window7 Service Pack 1
NDK在windows下的開發環境搭建及開發過程
刷新 -1 ont static blog 簡單 包名 mfp targe 在Android應用的開發project中。無論是遊戲還是普通應用。都時常會用到.so即動態鏈接庫,關於.so是什麽玩意兒,有什麽優點。這個大家能夠在網上查一下,本人不做過多解釋。.
Zabbix監控環境搭建
監控 zabbix Zabbix簡介:zabbix是一個基於WEB界面的提供分布式系統監視以及網絡監視功能的企業級的開源解決方案。zabbix能監視各種網絡參數,保證服務器系統的安全運營;並提供靈活的通知機制以讓系統管理員快速定位/解決存在的各種問題。zabbix由2部分構成,zabbix serve
maven的環境搭建及使用
技術分享 信息 幫助 解壓 使用 project 打印 jdk版本 規範 maven的環境搭建及使用 一、maven介紹及作用 maven是一個項目構
Ubuntu下kafka集群環境搭建及測試
delet 指定 文件中 新增 img --delete replicat pro alt 1,解壓 root@Ubuntu-1:/usr/local# tar zxvf kafka_2.11-0.8.2.2.tgz 2,重命名 root@Ubuntu-1:/usr/
Cordova 開發環境搭建及創建第一個app
maven 環境變量配置 src 搜索 編譯 win 所有 log api 整理記錄使用cordova創建app應用程序並將其部署至Android系統移動設備上詳細過程,具體如下: 一、前期安裝環境 1. 安裝JDK(java開發工具包) 2. 安裝gradle 3. 安裝
Linux鞏固記錄(1) J2EE開發環境搭建及網絡配置
version 環境 com sco 由於 lin spa node 開發環境 由於要近期使用hadoop等進行相關任務執行,操作linux時候就多了 以前只在linux上配置J2EE項目執行環境,無非配置下jdk,部署tomcat,再通過docker或者jenkins自動
Android開發之旅1:環境搭建及HelloWorld
lan 及其 其它 ply 新項目 bsp 驗證 for 對話框 ——工欲善其事必先利其器 引言 本系列適合0基礎的人員,因為我就是從0開始的,此系列記錄我步入Android開發的一些經驗分享,望與君共勉!作為Android隊伍中的一個新人的
PHPUnit實踐001--環境搭建及簡單用法
基礎 入門 單元測試 phpunit windows環境下搭建PHPUnit可以直接下安裝包傻瓜安裝,博主項目使用的是php5.6 所以下載了3.7的phpunit用composer安裝phpunitcomposer require --dev phpunit/phpunit ^6.2phpu
vuejs開發環境搭建及熱更新
輸入 成功 可用 app 熱更新 bpa bsp 保存 vue.js 推薦使用官方提供的命令行工具,可用於快速搭建大型單頁應用。只需一分鐘即可啟動帶熱重載、保存時靜態檢查以及可用於生產環境的構建配置項目。 1、安裝node https://nodejs.org/en/do
雲計算之路-虛擬化環境搭建及虛擬機創建
home 應用虛擬化 鍵盤 參考 紅色 翻譯 靈活性 不能 ont 轉載自 靈躍雲 :原文鏈接 1. 前言 在計算機技術中,虛擬化(Virtualization)是一種資源管理技術,它將計算機相關的各種資源(CPU、內存、磁盤、網絡適配器等)進行抽象、轉換
ROS開發環境搭建及入門
using nbsp cor bash body 開發環境 terminal evel new In new terminal: $ source /devel/setup.bash roscore is the first thing you should run w
APPIUM環境搭建及APP配合RF自動化的操作步驟
adb ice -a 業務流程 jre 端口號 圖片 ins pan 在用APPIUM做APP自動化測試過程中,首先碰到的問題就是環境搭建. 過程相對於WEB端自動化來說,搭建過程稍微復雜些,但是appium與WEB端的selenium原理相差不多. 二者在robotfra
CentOS+Nginx+Tomcat+Mysql+PHP 環境搭建及系統部署
Linux Centos tomcat mysql nginx ==============安裝centos 7.0=======================選擇最小安裝,將相關的"調試工具"、“兼容性程序庫”、“開發工具”選中。此操作是為了減少後期安裝或編譯相關服
【Python3.6+Django2.0+Xadmin2.0系列教程一】環境搭建及項目創建
添加 tran div 先來 ans 好的項目 tty 文件 mac 由於工作需要,接觸了大半年時間的Django+xadmin框架,一直沒空對這塊對進行相關的梳理。最近在同事的慫恿下,就在這分享下筆者的學習及工作經驗吧。 好了,話不多說,下面開始進入正題: 環境
01 RF環境搭建及簡介
2.4 編譯器 header 入參 高級 window uil 沒有 ref 目錄 [TOC] 一、RF安裝 1.1 Ride安裝 安裝Python2.7,配置好環境變量 安裝wxPython 2.8.12.1 (目前只有這個版本是官方支持的),一鍵式安裝 安裝ride,
Maven環境搭建及常用命令、生命周期
ngs 打包 efault info inf com clean setting 常用 一、下載maven包,解壓 二、配置環境變量,MAVEN_PATH=解壓路徑 添加到path中 三、測試 mvn -v 查看maven版本 四、設置本地倉庫的路徑 在co
智能合約開發環境搭建及Hello World合約
區塊鏈 智能合約 如果你對於以太坊智能合約開發還沒有概念(本文會假設你已經知道這些概念),建議先閱讀入門篇。就先學習任何編程語言一樣,入門的第一個程序都是Hello World。今天我們來一步一步從搭建以太坊智能合約開發環境開始,講解智能合約的Hello World如何編寫。 開發環境搭建 Solid
Java環境搭建及命令行編譯
nvi 命令行編譯 一個 rtu 技術分享 運行 編碼 env mach JDK和JRE概念 JDK: Java Development Kit Java開發工具包。JDK是提供給Java開發人員使用的,其中包含了java的開發工具,也包括了JRE JRE: J