{"id":43607,"date":"2023-12-17T00:52:40","date_gmt":"2023-04-08T03:21:50","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8snmp%e5%af%bc%e5%87%ba%e5%99%a8%e7%9a%84%e7%94%9f%e6%88%90%e5%99%a8%e3%80%82\/"},"modified":"2024-05-04T13:56:06","modified_gmt":"2024-05-04T05:56:06","slug":"%e4%bd%bf%e7%94%a8snmp%e5%af%bc%e5%87%ba%e5%99%a8%e7%9a%84%e7%94%9f%e6%88%90%e5%99%a8%e3%80%82","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8snmp%e5%af%bc%e5%87%ba%e5%99%a8%e7%9a%84%e7%94%9f%e6%88%90%e5%99%a8%e3%80%82\/","title":{"rendered":"\u4f7f\u7528SNMP\u5bfc\u51fa\u5668\u7684\u751f\u6210\u5668"},"content":{"rendered":"<h1>2017\u5e74\u666e\u7f57\u7c73\u4fee\u65af\u964d\u4e34\u65e5\u5386\u7684\u7b2c\u4e8c\u5929\u3002<\/h1>\n<p>\u8fd9\u662f\u4e00\u7bc7\u5173\u4e8eSNMP Exporter\u7684\u6587\u7ae0\u3002<\/p>\n<h1>SNMP Exporter\u662f\u4ec0\u4e48\uff1f<\/h1>\n<p>\u8fd9\u662f\u4e00\u79cd\u4f7f\u7528Prometheus\u6765\u76d1\u63a7\u901a\u8fc7SNMP\u83b7\u5f97\u7684\u4fe1\u606f\u7684\u5bfc\u51fa\u5668\u3002<br \/>\n\u5f53\u5e0c\u671b\u5c06\u73b0\u6709\u7684SNMP\u7ba1\u7406\u5668\u8fc1\u79fb\u5230Prometheus\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5b83\u3002<br \/>\n\u5b83\u7684\u529f\u80fd\u5f88\u7b80\u5355\uff0c\u53ea\u662f\u5728\u6536\u5230\u8bf7\u6c42\u65f6\uff0c\u5229\u7528SNMP\u6536\u96c6\u4fe1\u606f\u5e76\u8fdb\u884c\u663e\u793a\u3002<\/p>\n<h1>SNMP Exporter\u7684\u914d\u7f6e\u8bbe\u7f6e<\/h1>\n<p>SNMP Exporter\u7684\u8bbe\u7f6e\u662f\u6307\u901a\u8fc7\u4f7f\u7528SNMP\u6536\u96c6\u4ec0\u4e48\u6570\u636e\uff08\u4ee5\u53ca\u5982\u4f55\u6536\u96c6\uff09\u7684\u4e00\u4e2a\u65b9\u9762\u3002<br \/>\n\u5728SNMP Exporter\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u6a21\u5757\u7684\u5355\u4f4d\u6765\u8bbe\u7f6e\u8981\u6536\u96c6\u7684\u6570\u636e\u3002<br \/>\n\u914d\u7f6e\u6587\u4ef6\u4e2d\u5e76\u884c\u5217\u51fa\u4e86\u8bb8\u591a\u6a21\u5757\u3002<\/p>\n<p>\u6211\u5c06\u4eceif_mib\u6a21\u5757\u4e2d\u63d0\u53d6\u51fa\u4e00\u4e9b\u4f8b\u5b50\u6765\u8fdb\u884c\u8bf4\u660e\u3002<\/p>\n<p>\u5728\u4f7f\u7528walk\u547d\u4ee4\u65f6\uff0c\u60a8\u9700\u8981\u6307\u5b9a\u8981\u8fdb\u884csnmpwalk\u7684OID\u3002<br \/>\n\u53e6\u5916\uff0c\u5728metrics\u90e8\u5206\uff0c\u60a8\u9700\u8981\u8bb0\u5f55\u6bcf\u4e2aOID\u7684\u540d\u79f0\u3001\u503c\u7684\u7c7b\u578b\uff0c\u4ee5\u53ca\u5982\u679c\u5b58\u5728\u7d22\u5f15\u5219\u5305\u62ec\u7d22\u5f15\u7684\u4fe1\u606f\u3002<br \/>\n\u6b64\u5916\uff0c\u8fd8\u6709\u5176\u4ed6\u7684\u4e00\u4e9b\u8bbe\u7f6e\u90e8\u5206\uff0c\u6bd4\u5982\u79f0\u4e3aauth\u7684\u90e8\u5206\uff0c\u7528\u4e8e\u8bbe\u7f6eSNMP v2c\u7684Community\u4fe1\u606f\u6216\u8005SNMP v3\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801\u7b49\u7b49\u3002<\/p>\n<pre class=\"post-pre\"><code>if_mib:\r\n  walk:\r\n  - 1.3.6.1.2.1.1.3\r\n  - 1.3.6.1.2.1.2\r\n  - 1.3.6.1.2.1.31.1.1\r\n  metrics:\r\n  - name: sysUpTime\r\n    oid: 1.3.6.1.2.1.1.3\r\n    type: gauge\r\n    help: The time (in hundredths of a second) since the network management portion\r\n      of the system was last re-initialized. - 1.3.6.1.2.1.1.3\r\n  - name: ifNumber\r\n    oid: 1.3.6.1.2.1.2.1\r\n    type: gauge\r\n    help: The number of network interfaces (regardless of their current state) present\r\n      on this system. - 1.3.6.1.2.1.2.1\r\n  - name: ifIndex\r\n    oid: 1.3.6.1.2.1.2.2.1.1\r\n    type: gauge\r\n    help: A unique value, greater than zero, for each interface - 1.3.6.1.2.1.2.2.1.1\r\n    indexes:\r\n    - labelname: ifIndex\r\n      type: gauge\r\n  - name: ifDescr\r\n    oid: 1.3.6.1.2.1.2.2.1.2\r\n    type: DisplayString\r\n    help: A textual string containing information about the interface - 1.3.6.1.2.1.2.2.1.2\r\n    indexes:\r\n    - labelname: ifIndex\r\n      type: gauge\r\n  - name: ifType\r\n    oid: 1.3.6.1.2.1.2.2.1.3\r\n    type: gauge\r\n    help: The type of interface - 1.3.6.1.2.1.2.2.1.3\r\n    indexes:\r\n    - labelname: ifIndex\r\n      type: gauge\r\n  - name: ifMtu\r\n    oid: 1.3.6.1.2.1.2.2.1.4\r\n    type: gauge\r\n    help: The size of the largest packet which can be sent\/received on the interface,\r\n      specified in octets - 1.3.6.1.2.1.2.2.1.4\r\n    indexes:\r\n    - labelname: ifIndex\r\n      type: gauge\r\n  - name: ifSpeed\r\n    oid: 1.3.6.1.2.1.2.2.1.5\r\n    type: gauge\r\n    help: An estimate of the interface's current bandwidth in bits per second - 1.3.6.1.2.1.2.2.1.5\r\n    indexes:\r\n    - labelname: ifIndex\r\n      type: gauge\r\n  - name: ifPhysAddress\r\n    oid: 1.3.6.1.2.1.2.2.1.6\r\n    type: PhysAddress48\r\n    help: The interface's address at its protocol sub-layer - 1.3.6.1.2.1.2.2.1.6\r\n    indexes:\r\n    - labelname: ifIndex\r\n      type: gauge\r\n  - name: ifAdminStatus\r\n    oid: 1.3.6.1.2.1.2.2.1.7\r\n    type: gauge\r\n    help: The desired state of the interface - 1.3.6.1.2.1.2.2.1.7\r\n    indexes:\r\n    - labelname: ifIndex\r\n      type: gauge\r\n  - name: ifOperStatus\r\n    oid: 1.3.6.1.2.1.2.2.1.8\r\n    type: gauge\r\n    help: The current operational state of the interface - 1.3.6.1.2.1.2.2.1.8\r\n    indexes:\r\n    - labelname: ifIndex\r\n      type: gauge\r\n# \u4ee5\u4e0b\u7565\r\n<\/code><\/pre>\n<p>\u9019\u662f\u5f9e\u5b98\u65b9\u6a23\u672c\u4e2d\u63d0\u53d6\u51fa\u7684\u4e00\u90e8\u5206\u3002<br \/>\n\u5b83\u662f\u70ba\u4e86\u7372\u53d6\u4ecb\u9762\u4fe1\u606f\u800c\u8a2d\u8a08\u7684\u3002<br \/>\n\u914d\u7f6e\u672c\u8eab\u662f\u7531SNMP Exporter\u9644\u5e36\u7684\u751f\u6210\u5668\u5275\u5efa\u7684\u3002<\/p>\n<p>\u7136\u800c\uff0c\u76ee\u524d\u7684\u4e8c\u8fdb\u5236\u53d1\u884c\u7248\u672c\u6ca1\u6709\u9644\u5e26\u751f\u6210\u5668\u3002\u4f60\u9700\u8981\u4ece\u6e90\u4ee3\u7801\u8fdb\u884c\u6784\u5efa\u3002<\/p>\n<p>\u751f\u6210\u5668\u4f9d\u8d56\u4e8eNet-SNMP\uff0c\u5e76\u4e14\u76ee\u524d\u91c7\u7528\u52a8\u6001\u94fe\u63a5\u65b9\u5f0f\u521b\u5efa\u4e8c\u8fdb\u5236\u6587\u4ef6\u7684\u65b9\u5f0f\uff0c\u56e0\u6b64\u5904\u4e8e\u8fd9\u79cd\u72b6\u6001\u3002<br \/>\n\u8fd9\u4e2a\u95ee\u9898\u5df2\u7ecf\u88ab\u63d0\u51fa\uff0c\u5e76\u53ef\u80fd\u4f1a\u5728\u5c06\u6765\u88ab\u5305\u542b\u8fdb\u6765\u3002<\/p>\n<h1>\u4f7f\u7528\u53d1\u7535\u673a<\/h1>\n<h2>\u53d1\u7535\u673a\u7684\u6784\u5efa<\/h2>\n<p>\u53ea\u9700\u8981\u4e00\u500b\u9078\u64c7\uff1a<\/p>\n<p>\u5982\u524d\u6240\u8ff0\uff0c\u70ba\u4e86\u4f7f\u7528generator\uff0c\u9700\u8981\u9032\u884c\u7de8\u8b6f\u3002<br \/>\n\u9996\u5148\u53d6\u5f97Net-SNMP\u7684\u5eab\u548c\u76f8\u95dc\u7684include\u6a94\u6848\uff0c<br \/>\n\u4f8b\u5982\u4f7f\u7528\u4ee5\u4e0b\u6307\u4ee4\u9032\u884c\u5b89\u88dd\uff1ayum install net-snmp-devel\uff0capt install libsnmp-base libsnmp-devel\u7b49\u7b49\u3002<br \/>\n\u63a5\u8457\u5b89\u88ddgolang\uff0c<br \/>\n\u4e26\u4f7f\u7528\u4ee5\u4e0b\u6307\u4ee4\u7372\u53d6snmp_exporter\u7684\u539f\u59cb\u78bc\uff1a<br \/>\ngo get github.com\/prometheus\/snmp_exporter<br \/>\n\u7136\u5f8c\u9032\u5165\u76ee\u9304\uff1acd $GOPATH\/src\/github.com\/prometheus\/snmp_exporter\/generator<br \/>\n\u9032\u884c\u7de8\u8b6f\uff1ago build<br \/>\n\u9019\u6a23\u5c31\u6703\u751f\u6210generator\u7684\u53ef\u57f7\u884c\u6587\u4ef6\u3002<\/p>\n<p>\u53ea\u9700\u8981\u53c2\u8003generator.yml\u7684\u5185\u5bb9\u8fdb\u884c\u7f16\u5199\u3002<\/p>\n<p>\u751f\u6210\u5668\u53ea\u662f\u4e0a\u8ff0\u63d0\u5230\u7684SNMP\u8bbe\u7f6e\u793a\u4f8b\u4e2d\u7684\u4e00\u79cd\u3002<\/p>\n<pre class=\"post-pre\"><code>modules:\r\n  if_mib:\r\n    walk: [sysUpTime, interfaces, ifXTable]\r\n<\/code><\/pre>\n<p>\u53ea\u6709\u4e09\u884c\u800c\u5df2\u3002<\/p>\n<p>\u7531\u4e8e\u6613\u4e8e\u7406\u89e3\u548c\u7ba1\u7406\uff0c\u6211\u5efa\u8bae\u57fa\u672c\u4e0a\u4f7f\u7528generator\u6765\u751f\u6210\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<p>\u5728\u751f\u6210\u5668\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u6ca1\u6709OID\u4fe1\u606f\uff0c\u4f46\u8fd9\u4e9b\u4fe1\u606f\u90fd\u662f\u4eceMIB\u6587\u4ef6\u4e2d\u83b7\u53d6\u7684\u3002<br \/>\n\u6240\u4ee5\uff0c\u60a8\u9700\u8981\u5355\u72ec\u83b7\u53d6\u8981\u914d\u7f6e\u7684\u8bbe\u5907\u7684SNMP-MIB\u6587\u4ef6\u3002<br \/>\n\u5728\u751f\u6210\u5668\u7684README\u6587\u4ef6\u7684\u5e95\u90e8\uff0c\u6709\u5173\u4e3b\u8981MIB\u6587\u4ef6\u7684\u83b7\u53d6\u548c\u5b89\u88c5\u65b9\u6cd5\u5df2\u7ecf\u5199\u660e\u4e86\uff0c\u60a8\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u3002<\/p>\n<h2>\u53d1\u7535\u673a\u7684\u8bbe\u7f6e\uff08\u5b98\u65b9\u9875\u9762\u6458\u5f55\u548c\u89e3\u91ca\uff09<\/h2>\n<p>\u6240\u6709\u7684\u751f\u6210\u5668\u8bbe\u5b9a\u90fd\u8bb0\u5f55\u5728generator.yml\u6587\u4ef6\u4e2d\u3002<br \/>\n\u8bbe\u5b9a\u662f\u4ee5\u6a21\u5757\u4e3a\u5355\u4f4d\u8fdb\u884c\u7684\u3002<\/p>\n<pre class=\"post-pre\"><code>module:\r\n  &lt;module1&gt;:\r\n    module1\u306e\u8a2d\u5b9a\r\n  &lt;module2&gt;:\r\n    module2\u306e\u8a2d\u5b9a\r\n  &lt;module3&gt;:\r\n    module3\u306e\u8a2d\u5b9a\r\n<\/code><\/pre>\n<p>\u4ee5\u4e0b\u304c\u63d0\u4f9b\u3055\u308c\u307e\u3059\u3002<br \/>\n\u6bcf\u4e2a\u6a21\u5757\u90fd\u662f\u4e3a\u60a8\u63d0\u4f9b\u7684\u3002<\/p>\n<pre class=\"post-pre\"><code>  &lt;modulename&gt;:\r\n    walk:\r\n      snmpwalk\u3059\u308b\u3082\u306e\r\n    version: 2  # snmp v1,2,3 \u3092\u8a2d\u5b9a\u3059\u308b\u3082\u306e\r\n    max_repetitions: 25  #SNMP BULK Request\u3059\u308b\u3068\u304d\u306e\u6700\u5927\u5024\r\n    retries: 3 # \u30ea\u30c8\u30e9\u30a4\u56de\u6570\r\n    timeout: 10s # \u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u6642\u9593\r\n    auth:\r\n      \u8a8d\u8a3c\u60c5\u5831\r\n    lookups:\r\n      Index\u3092\u4ed6\u306e\u3082\u306e\u306b\u7f6e\u304d\u63db\u3048\u308b\u305f\u3081\u306e\u60c5\u5831\r\n    overrides:\r\n      metric\u60c5\u5831\u3092\u66f8\u304d\u63db\u3048\u308b\u305f\u3081\u306e\u60c5\u5831\r\n<\/code><\/pre>\n<p>\u7531\uff08module\u540d\uff09\u7ec4\u6210\u3002<br \/>\n\u5728\uff08module\u540d\uff09\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u60a8\u559c\u6b22\u7684\u540d\u79f0\u3002\u8fd9\u662f\u5728Prometheus\u7684\u914d\u7f6e\u4e2d\u8bbe\u7f6e\u7684\u6a21\u5757\u540d\u79f0\u3002\u5b83\u8fd8\u4f1a\u5728\u6536\u96c6\u65f6\u8bb0\u5f55\u4e0b\u6765\u3002<br \/>\n\u5728SNMP Exporter\u7684\u914d\u7f6e\u4e2d\uff0c\u6ca1\u6709\u63d0\u5230\u6307\u6807\uff08metrics\uff09\u7684\u5185\u5bb9\uff0c\u4f46\u8fd9\u4e9b\u6307\u6807\u4f1a\u81ea\u52a8\u4ecewalk:\u4e2d\u751f\u6210\u3002<br \/>\n\uff08\u56e0\u6b64\uff0c\u5982\u679c\u5728walk:\u4e2d\u5199\u5165\u5927\u91cf\u5185\u5bb9\uff0c\u4f1a\u8bbe\u7f6e\u5f88\u591a\u6307\u6807\uff09<br \/>\n\u5982\u679c\u6570\u91cf\u592a\u591a\uff0c\u4e00\u4e9b\u8bbe\u5907\u53ef\u80fd\u4f1a\u56e0\u8d85\u65f6\u800c\u65e0\u6cd5\u8fd4\u56de\u7ed3\u679c\uff0c\u8bf7\u6ce8\u610f\u3002<br \/>\n\u5728\u5c06\u4e0a\u8ff0if_mib\u914d\u7f6e\u5e94\u7528\u4e8e\u67d0\u4e2a\u8bbe\u5907\u65f6\uff0c\u6709\u65f6\u53ef\u80fd\u9700\u8981\u7b49\u5f8560\u79d2\u624d\u80fd\u5f97\u5230\u8fd4\u56de\u3002<\/p>\n<h3>\u67e5\u627e<\/h3>\n<p>\u67e5\u627e\u662f\u7528\u6765\u5c06\u7d22\u5f15\u8f6c\u6362\u4e3a\u6613\u4e8e\u7406\u89e3\u7684\u65b9\u5f0f\u3002<\/p>\n<pre class=\"post-pre\"><code>    lookups:\r\n      - old_index: ifIndex\r\n        new_index: ifName\r\n      - old_index: someIndex\r\n        new_index: someDescr\r\n<\/code><\/pre>\n<p>\u6309\u7167\u4ee5\u4e0b\u65b9\u5f0f\uff0c\u5c06\u539f\u59cb\u7d22\u5f15\u548c\u65b0\u7d22\u5f15\u6392\u5217\u5728\u4e00\u8d77\u3002<\/p>\n<p>\u8bf7\u6ce8\u610f\uff0c\u66ff\u6362\u540e\u7684\u7d22\u5f15\u5fc5\u987b\u662f\u552f\u4e00\u7684\u3002\u793a\u4f8b\u4e2d\u5305\u542b\u4e86\u5c06ifIndex\u66ff\u6362\u4e3amib_ifDescr\u6216mib_ifName\u7684\u8bbe\u7f6e\uff0c\u4f46\u662fifDescr\u7b49\u5e76\u4e0d\u80fd\u4fdd\u8bc1\u662f\u552f\u4e00\u7684\uff0c\u4f7f\u7528\u8fd9\u4e9b\u53ef\u80fd\u5bfc\u81f4\u65e0\u6cd5\u83b7\u53d6\u5230\u4fe1\u606f\uff0c\u8bf7\u6ce8\u610f\u3002\u5982\u679c\u9700\u8981\u6b64\u7c7b\u4fe1\u606f\uff0c\u5efa\u8bae\u4f7f\u7528Prometheus\u7684\u5f3a\u5927\u67e5\u8be2\u529f\u80fd\u6765\u5408\u6210\u3002<\/p>\n<pre class=\"post-pre\"><code>ifInOctets * on(ifIndex) group_left(ifName) ifName\r\n<\/code><\/pre>\n<p>&#8220;\u3068\u304b&#8221; \u53ef\u4ee5\u7528\u4e00\u79cd\u4e2d\u6587\u65b9\u5f0f\u8f6c\u8ff0\uff1a\u300c\u4e4b\u7c7b\u7684\u300d<\/p>\n<pre class=\"post-pre\"><code>ifInOctets * on(ifIndex) group_left(ifName) ifName * on(ifIndex) group_left(ifDescr) ifDescr\r\n<\/code><\/pre>\n<p>\u5982\u6b64\u67e5\u8be2\uff0c\u53ef\u4ee5\u5c06ifName\u548cifDescr\u8fdb\u884c\u5173\u8054\u3002<br \/>\n\u4f46\u662f\uff0c\u5982\u679c\u505a\u5f97\u8fc7\u591a\uff0c\u67e5\u8be2\u56de\u5e94\u4f1a\u53d8\u6162\uff0c\u6240\u4ee5\u8981\u9002\u5ea6\u8fdb\u884c\u3002<\/p>\n<p>\u5728\u6211\u7684\u5468\u56f4\u73af\u5883\u4e2d<\/p>\n<pre class=\"post-pre\"><code>rate(ifHCInOctets[5m]) * 8\r\nrate(ifHCInOctets[5m]) * 8 * on(instance,ifIndex) group_left(ifName) ifName * on(instance,ifIndex) group_left(ifDescr) ifDescr\r\n<\/code><\/pre>\n<p>\u5728\u4e24\u6b21\u6d4b\u8bd5\u4e2d\uff0c\u6211\u4eec\u53d1\u73b0\uff0c\u4e4b\u524d\u8fd4\u56de\u65f6\u95f4\u7ea6\u4e3a1500\u6beb\u79d2\u7684\u7ed3\u679c\uff0c\u52a0\u4e0aifName\u548cifDescr\u540e\uff0c\u65f6\u95f4\u53d8\u957f\uff0c\u5927\u7ea6\u57282900\u6beb\u79d2\u5de6\u53f3\u3002<\/p>\n<p>\u8ba9\u6211\u4eec\u572816\u65e5\u7684\u67e5\u8be2\u8bad\u7ec3\u573a\u5b66\u4e60\u8bb0\u4f4f\u6709\u5173\u67e5\u8be2\u7684\u5185\u5bb9\u3002<\/p>\n<p>\u6211\u8ba4\u4e3a\uff0c\u4e00\u65e6\u53d8\u6210\u8fd9\u6837\uff0c\u6700\u597d\u8fd8\u662f\u5229\u7528\u666e\u7f57\u7c73\u4fee\u65af\u7684\u89c4\u5219\u5728\u6536\u96c6\u65f6\u8fdb\u884c\u6dfb\u52a0\u3002<\/p>\n<h3>\u8d85\u8d8a<\/h3>\n<p>overrides\u662f\u7528\u6765\u4fee\u6539\u548c\u4fdd\u5b58\u901a\u8fc7SNMP\u83b7\u53d6\u7684\u4fe1\u606f\u7684\u5de5\u5177\u3002<br \/>\n\u4f8b\u5982\uff0c\u5f53\u4f7f\u7528SNMP\u83b7\u53d6\u503c\u65f6\uff0c\u53ef\u80fd\u4f1a\u8fd4\u56de\u5b57\u7b26\u4e32\u5982\u201cOK\u201d\u3001\u201cNG\u201d\u3001\u201cUNKNOWN\u201d\uff0c\u8fd9\u4e9b\u65e0\u6cd5\u4f5c\u4e3a\u6307\u6807\u6765\u5904\u7406\u3002\u4e3a\u4e86\u5c06\u5b83\u4eec\u4f5c\u4e3a\u6307\u6807\u5904\u7406\uff0c\u53ef\u4ee5\u5c06\u5176\u66ff\u6362\u4e3a\u6570\u5b57\uff0c\u4f8b\u5982\u5c06OK\u66ff\u6362\u4e3a1\u3001NG\u66ff\u6362\u4e3a2\u3001UNKNOWN\u66ff\u6362\u4e3a3\u7b49\u7b49\u3002<br \/>\n\u5728\u4f7f\u7528\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u3002<\/p>\n<pre class=\"post-pre\"><code>    overrides:\r\n      &lt;MetricName&gt;:\r\n        regex_extracts:\r\n          &lt;SubName&gt;:\r\n            - regex: 'OK'\r\n              value: '1'\r\n            - regex: 'NG'\r\n              value: '2'\r\n            - regex: 'UNKNOWN'\r\n              value: '3'\r\n            - regex: '(.*)'\r\n              value: '0'\r\n<\/code><\/pre>\n<p>\u5c31\u50cf\u8fd9\u6837\uff0c\u5b83\u4eec\u53ef\u4ee5\u5404\u81ea\u88ab\u5206\u914d\u3002\u8fd9\u6837\u4e00\u6765\uff0c\u5c31\u53ef\u4ee5\u8fdb\u884c\u76d1\u63a7\u4e86\u3002<br \/>\n\u5373\u539f\u59cb\u540d\u79f0\uff0c\u5373\u65b0\u540d\u79f0\u3002<br \/>\n\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6570\u636e\u5c06\u88ab\u547d\u540d\u4e3a\uff08\u5373\u539f\u59cb\u540d\u79f0\u4e0e\u81ea\u5df1\u53d6\u7684\u540d\u79f0\u7684\u8fde\u63a5\uff09\u3002<br \/>\n\u540c\u65f6\uff0c\u539f\u6765\u7684\u6570\u636e\u5c06\u4e0d\u518d\u51fa\u73b0\u5728SNMP Exporter\u4e0a\u3002<\/p>\n<h3>\u521b\u5efasnmp.yml\u6587\u4ef6<\/h3>\n<p>\u5f53 generator.yml \u6587\u4ef6\u5b8c\u6210\u540e\uff0c\u53ea\u9700\u5728 generator.yml \u6240\u5728\u7684\u76ee\u5f55\u4e2d\u6267\u884c \/path\/to\/generator generate\uff0c\u5c06\u4f1a\u521b\u5efa snmp.yml \u6587\u4ef6\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u4ece snmp_exporter \u6307\u5b9a\u8be5\u6587\u4ef6\u5e76\u8fdb\u884c\u64cd\u4f5c\u6d4b\u8bd5\u3002<\/p>\n<h1>\u6211\u5df2\u7ecf\u5b9e\u9645\u521b\u5efa\u5e76\u5c1d\u8bd5\u4f7f\u7528\u4e86generator.yml\u3002<\/h1>\n<p>\u8fd9\u662f\u4ece\u8fdb\u884c\u9a8c\u8bc1\u7b49\u5de5\u4f5c\u4e2d\u521b\u5efa\u7684generator.yml\u6587\u4ef6\u4e2d\u63d0\u53d6\u7684\u6458\u5f55\u3002<\/p>\n<pre class=\"post-pre\"><code>  yamaha:\r\n    auth:\r\n      community: public\r\n    walk:\r\n      - sysName\r\n      - yrhCpuUtil1min\r\n      - yrhInboxTemperature\r\n      - yrhMemoryUtil\r\n      - yrhFanModuleStatus\r\n      - yrhFanModuleIndex\r\n  if_name:\r\n    auth:\r\n      community: public\r\n    walk:\r\n      - sysUpTime\r\n      - ifAdminStatus\r\n      - ifOperStatus\r\n      - ifInErrors\r\n      - ifOutErrors\r\n      - ifInDiscards\r\n      - ifOutDiscards\r\n      - ifOutQLen\r\n      - ifDescr\r\n      - ifName\r\n      - ifAlias\r\n      - ifHCInOctets\r\n      - ifHCOutOctets\r\n      - ifHCInUcastPkts\r\n      - ifHCInBroadcastPkts\r\n      - ifHCInMulticastPkts\r\n      - ifHCOutUcastPkts\r\n      - ifHCOutBroadcastPkts\r\n      - ifHCOutMulticastPkts\r\n    lookups:\r\n      - old_index: ifIndex\r\n        new_index: ifName\r\n  paloalto:\r\n    auth:\r\n      community: public\r\n    walk:\r\n      - entPhysicalDescr\r\n      - entPhySensorValue\r\n      - entPhySensorOperStatus\r\n      - hrProcessorLoad\r\n      - hrDeviceDescr\r\n      - hrStorageDescr\r\n      - hrStorageUsed\r\n      - hrStorageSize\r\n      - panSessionActive\r\n      - panSessionActiveICMP\r\n      - panSessionActiveTcp\r\n      - panSessionActiveUdp\r\n      - panSessionUtilization\r\n      - panSysHAPeerState\r\n      - panSysHAState\r\n      - sysName\r\n    overrides:\r\n      panSysHAPeerState:\r\n        regex_extracts:\r\n          Status:\r\n            - regex: '.*active.*'\r\n              value: '1'\r\n            - regex: '.*passive.*'\r\n              value: '2'\r\n            - regex: '.*'\r\n              value: '0'\r\n      panSysHAState:\r\n        regex_extracts:\r\n          Status:\r\n            - regex: '.*active.*'\r\n              value: '1'\r\n            - regex: '.*passive.*'\r\n              value: '2'\r\n            - regex: '.*'\r\n              value: '0'\r\n<\/code><\/pre>\n<h1>\u7ed3\u675f\u4e86<\/h1>\n<p>SNMP Exporter\u7684\u4f7f\u7528\u8bf4\u660e\u53ea\u662f\u57fa\u672c\u7684\u4ecb\u7ecd\u3002<\/p>\n<p>\u5982\u679c\u6709\u4eba\u60f3\u4ece\u4f7f\u7528\u5176\u4ed6\u57fa\u4e8eSNMP\u7684\u6307\u6807\u6536\u96c6\u5de5\u5177\u8fc1\u79fb\u5230Prometheus\uff0c\u5e0c\u671b\u8fd9\u4e2a\u53c2\u8003\u80fd\u591f\u5e2e\u5230\u4ed6\u4eec\uff01<\/p>\n<p>\u9644\u8a00\uff1a\u975e\u5e38\u6b22\u8fce\u6307\u51fa\u6709\u4efb\u4f55\u9519\u8bef\u7684\u5730\u65b9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2017\u5e74\u666e\u7f57\u7c73\u4fee\u65af\u964d\u4e34\u65e5\u5386\u7684\u7b2c\u4e8c\u5929\u3002 \u8fd9\u662f\u4e00\u7bc7\u5173\u4e8eSNMP Exporter\u7684\u6587\u7ae0\u3002 SNMP Export [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-43607","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4f7f\u7528SNMP\u5bfc\u51fa\u5668\u7684\u751f\u6210\u5668 - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528snmp\u5bfc\u51fa\u5668\u7684\u751f\u6210\u5668\u3002\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4f7f\u7528SNMP\u5bfc\u51fa\u5668\u7684\u751f\u6210\u5668\" \/>\n<meta property=\"og:description\" content=\"2017\u5e74\u666e\u7f57\u7c73\u4fee\u65af\u964d\u4e34\u65e5\u5386\u7684\u7b2c\u4e8c\u5929\u3002 \u8fd9\u662f\u4e00\u7bc7\u5173\u4e8eSNMP Exporter\u7684\u6587\u7ae0\u3002 SNMP Export [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528snmp\u5bfc\u51fa\u5668\u7684\u751f\u6210\u5668\u3002\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-04-08T03:21:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-04T05:56:06+00:00\" \/>\n<meta name=\"author\" content=\"\u6587, \u7fd4\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u6587, \u7fd4\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8snmp%e5%af%bc%e5%87%ba%e5%99%a8%e7%9a%84%e7%94%9f%e6%88%90%e5%99%a8%e3%80%82\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8snmp%e5%af%bc%e5%87%ba%e5%99%a8%e7%9a%84%e7%94%9f%e6%88%90%e5%99%a8%e3%80%82\/\",\"name\":\"\u4f7f\u7528SNMP\u5bfc\u51fa\u5668\u7684\u751f\u6210\u5668 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-04-08T03:21:50+00:00\",\"dateModified\":\"2024-05-04T05:56:06+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/64d5cc7727fffbff2f9a2a8da1de3e5c\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8snmp%e5%af%bc%e5%87%ba%e5%99%a8%e7%9a%84%e7%94%9f%e6%88%90%e5%99%a8%e3%80%82\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8snmp%e5%af%bc%e5%87%ba%e5%99%a8%e7%9a%84%e7%94%9f%e6%88%90%e5%99%a8%e3%80%82\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8snmp%e5%af%bc%e5%87%ba%e5%99%a8%e7%9a%84%e7%94%9f%e6%88%90%e5%99%a8%e3%80%82\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4f7f\u7528SNMP\u5bfc\u51fa\u5668\u7684\u751f\u6210\u5668\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/64d5cc7727fffbff2f9a2a8da1de3e5c\",\"name\":\"\u6587, \u7fd4\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/920c3d673e0bccacc98e5e6b7149bb3c22edd8d39cb753e5d7d7e471498118a1?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/920c3d673e0bccacc98e5e6b7149bb3c22edd8d39cb753e5d7d7e471498118a1?s=96&d=mm&r=g\",\"caption\":\"\u6587, \u7fd4\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/wenxiang\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8snmp%e5%af%bc%e5%87%ba%e5%99%a8%e7%9a%84%e7%94%9f%e6%88%90%e5%99%a8%e3%80%82\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u4f7f\u7528SNMP\u5bfc\u51fa\u5668\u7684\u751f\u6210\u5668 - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528snmp\u5bfc\u51fa\u5668\u7684\u751f\u6210\u5668\u3002\/","og_locale":"zh_CN","og_type":"article","og_title":"\u4f7f\u7528SNMP\u5bfc\u51fa\u5668\u7684\u751f\u6210\u5668","og_description":"2017\u5e74\u666e\u7f57\u7c73\u4fee\u65af\u964d\u4e34\u65e5\u5386\u7684\u7b2c\u4e8c\u5929\u3002 \u8fd9\u662f\u4e00\u7bc7\u5173\u4e8eSNMP Exporter\u7684\u6587\u7ae0\u3002 SNMP Export [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528snmp\u5bfc\u51fa\u5668\u7684\u751f\u6210\u5668\u3002\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-04-08T03:21:50+00:00","article_modified_time":"2024-05-04T05:56:06+00:00","author":"\u6587, \u7fd4","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u6587, \u7fd4","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8snmp%e5%af%bc%e5%87%ba%e5%99%a8%e7%9a%84%e7%94%9f%e6%88%90%e5%99%a8%e3%80%82\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8snmp%e5%af%bc%e5%87%ba%e5%99%a8%e7%9a%84%e7%94%9f%e6%88%90%e5%99%a8%e3%80%82\/","name":"\u4f7f\u7528SNMP\u5bfc\u51fa\u5668\u7684\u751f\u6210\u5668 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-04-08T03:21:50+00:00","dateModified":"2024-05-04T05:56:06+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/64d5cc7727fffbff2f9a2a8da1de3e5c"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8snmp%e5%af%bc%e5%87%ba%e5%99%a8%e7%9a%84%e7%94%9f%e6%88%90%e5%99%a8%e3%80%82\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8snmp%e5%af%bc%e5%87%ba%e5%99%a8%e7%9a%84%e7%94%9f%e6%88%90%e5%99%a8%e3%80%82\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8snmp%e5%af%bc%e5%87%ba%e5%99%a8%e7%9a%84%e7%94%9f%e6%88%90%e5%99%a8%e3%80%82\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u4f7f\u7528SNMP\u5bfc\u51fa\u5668\u7684\u751f\u6210\u5668"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/64d5cc7727fffbff2f9a2a8da1de3e5c","name":"\u6587, \u7fd4","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/920c3d673e0bccacc98e5e6b7149bb3c22edd8d39cb753e5d7d7e471498118a1?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/920c3d673e0bccacc98e5e6b7149bb3c22edd8d39cb753e5d7d7e471498118a1?s=96&d=mm&r=g","caption":"\u6587, \u7fd4"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/wenxiang\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8snmp%e5%af%bc%e5%87%ba%e5%99%a8%e7%9a%84%e7%94%9f%e6%88%90%e5%99%a8%e3%80%82\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/43607","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=43607"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/43607\/revisions"}],"predecessor-version":[{"id":98724,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/43607\/revisions\/98724"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=43607"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=43607"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=43607"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}