Skip to content

Commit 34e1f42

Browse files
committed
More efficient Zabbix polling
Modified Zabbix template to collect metrics for all switch ports in a single poll, then break out the individual metrics per port as dependent items in Zabbix.
1 parent 1febb43 commit 34e1f42

2 files changed

Lines changed: 92 additions & 45 deletions

File tree

Template_essstat.json

Lines changed: 88 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,91 @@
66
"uuid": "550e8400e29b41d4a716446655440000",
77
"template": "TP-Link Easy Smart Switch",
88
"name": "TP-Link Easy Smart Switch",
9-
"groups": [
10-
{ "name": "Templates" }
11-
],
9+
"groups": [{ "name": "Templates" }],
1210
"macros": [
1311
{ "macro": "{$SWITCH_USER}", "value": "admin" },
1412
{ "macro": "{$SWITCH_PWD}", "value": "changeme" },
1513
{ "macro": "{$SWITCH_IP}", "value": "{HOST.HOST}" }
1614
],
15+
"items": [
16+
{
17+
"uuid": "550e8400e29b41d4a716446655442000",
18+
"name": "ESS CSV single line",
19+
"key": "essstat.1line[{$SWITCH_IP},{$SWITCH_USER},{$SWITCH_PWD}]",
20+
"type": "ZABBIX_PASSIVE",
21+
"value_type": "TEXT",
22+
"delay": "1m",
23+
"history": "1d",
24+
"description": "One CSV line: ts,port_count,(port,state,link_status,TxGoodPkt,TxBadPkt,RxGoodPkt,RxBadPkt)*"
25+
}
26+
],
1727
"discovery_rules": [
1828
{
1929
"uuid": "550e8400e29b41d4a716446655441001",
2030
"name": "ESS Port Discovery",
2131
"key": "essstat.discovery[{$SWITCH_IP},{$SWITCH_USER},{$SWITCH_PWD}]",
2232
"type": "ZABBIX_PASSIVE",
23-
"delay": "1m",
33+
"delay": "5m",
2434
"lifetime": "7d",
2535
"item_prototypes": [
2636
{
27-
"uuid": "550e8400e29b41d4a716446655441006",
37+
"uuid": "550e8400e29b41d4a716446655441206",
2838
"name": "Port {#PORT} State",
29-
"key": "essstat.port[{$SWITCH_IP},{$SWITCH_USER},{$SWITCH_PWD},{#PORT},state]",
30-
"type": "ZABBIX_PASSIVE",
39+
"key": "essstat.value[{#PORT},state]",
40+
"type": "DEPENDENT",
41+
"master_item": { "key": "essstat.1line[{$SWITCH_IP},{$SWITCH_USER},{$SWITCH_PWD}]" },
3142
"value_type": "UNSIGNED",
32-
"delay": "1m",
43+
"delay": "0",
44+
"preprocessing": [
45+
{
46+
"type": "JAVASCRIPT",
47+
"parameters": [
48+
"var p='{#PORT}';\nvar a=value.trim().split(',');\nif(a.length<3) return null;\nfor(var i=2;i+6<a.length;i+=7){ if(a[i]===String(p)) return a[i+1]; }\nreturn null;"
49+
]
50+
}
51+
],
3352
"tags": [
3453
{ "tag": "metric", "value": "State" },
3554
{ "tag": "port", "value": "{#PORT}" }
3655
]
3756
},
3857
{
39-
"uuid": "550e8400e29b41d4a716446655441007",
58+
"uuid": "550e8400e29b41d4a716446655441207",
4059
"name": "Port {#PORT} Link Status",
41-
"key": "essstat.port[{$SWITCH_IP},{$SWITCH_USER},{$SWITCH_PWD},{#PORT},link_status]",
42-
"type": "ZABBIX_PASSIVE",
60+
"key": "essstat.value[{#PORT},link_status]",
61+
"type": "DEPENDENT",
62+
"master_item": { "key": "essstat.1line[{$SWITCH_IP},{$SWITCH_USER},{$SWITCH_PWD}]" },
4363
"value_type": "UNSIGNED",
44-
"delay": "1m",
64+
"delay": "0",
65+
"preprocessing": [
66+
{
67+
"type": "JAVASCRIPT",
68+
"parameters": [
69+
"var p='{#PORT}';\nvar a=value.trim().split(',');\nif(a.length<3) return null;\nfor(var i=2;i+6<a.length;i+=7){ if(a[i]===String(p)) return a[i+2]; }\nreturn null;"
70+
]
71+
}
72+
],
4573
"tags": [
4674
{ "tag": "metric", "value": "LinkStatus" },
4775
{ "tag": "port", "value": "{#PORT}" }
4876
]
4977
},
5078
{
51-
"uuid": "550e8400e29b41d4a716446655441002",
79+
"uuid": "550e8400e29b41d4a716446655441202",
5280
"name": "Port {#PORT} TxGoodPkt",
53-
"key": "essstat.port[{$SWITCH_IP},{$SWITCH_USER},{$SWITCH_PWD},{#PORT},TxGoodPkt]",
54-
"type": "ZABBIX_PASSIVE",
81+
"key": "essstat.value[{#PORT},TxGoodPkt]",
82+
"type": "DEPENDENT",
83+
"master_item": { "key": "essstat.1line[{$SWITCH_IP},{$SWITCH_USER},{$SWITCH_PWD}]" },
5584
"value_type": "FLOAT",
56-
"delay": "1m",
85+
"delay": "0",
5786
"units": "pps",
5887
"preprocessing": [
88+
{
89+
"type": "JAVASCRIPT",
90+
"parameters": [
91+
"var p='{#PORT}';\nvar a=value.trim().split(',');\nif(a.length<3) return null;\nfor(var i=2;i+6<a.length;i+=7){ if(a[i]===String(p)) return a[i+3]; }\nreturn null;"
92+
]
93+
},
5994
{ "type": "CHANGE_PER_SECOND", "parameters": [""] }
6095
],
6196
"tags": [
@@ -64,14 +99,21 @@
6499
]
65100
},
66101
{
67-
"uuid": "550e8400e29b41d4a716446655441003",
102+
"uuid": "550e8400e29b41d4a716446655441203",
68103
"name": "Port {#PORT} TxBadPkt",
69-
"key": "essstat.port[{$SWITCH_IP},{$SWITCH_USER},{$SWITCH_PWD},{#PORT},TxBadPkt]",
70-
"type": "ZABBIX_PASSIVE",
104+
"key": "essstat.value[{#PORT},TxBadPkt]",
105+
"type": "DEPENDENT",
106+
"master_item": { "key": "essstat.1line[{$SWITCH_IP},{$SWITCH_USER},{$SWITCH_PWD}]" },
71107
"value_type": "FLOAT",
72-
"delay": "1m",
108+
"delay": "0",
73109
"units": "pps",
74110
"preprocessing": [
111+
{
112+
"type": "JAVASCRIPT",
113+
"parameters": [
114+
"var p='{#PORT}';\nvar a=value.trim().split(',');\nif(a.length<3) return null;\nfor(var i=2;i+6<a.length;i+=7){ if(a[i]===String(p)) return a[i+4]; }\nreturn null;"
115+
]
116+
},
75117
{ "type": "CHANGE_PER_SECOND", "parameters": [""] }
76118
],
77119
"tags": [
@@ -80,14 +122,21 @@
80122
]
81123
},
82124
{
83-
"uuid": "550e8400e29b41d4a716446655441004",
125+
"uuid": "550e8400e29b41d4a716446655441204",
84126
"name": "Port {#PORT} RxGoodPkt",
85-
"key": "essstat.port[{$SWITCH_IP},{$SWITCH_USER},{$SWITCH_PWD},{#PORT},RxGoodPkt]",
86-
"type": "ZABBIX_PASSIVE",
127+
"key": "essstat.value[{#PORT},RxGoodPkt]",
128+
"type": "DEPENDENT",
129+
"master_item": { "key": "essstat.1line[{$SWITCH_IP},{$SWITCH_USER},{$SWITCH_PWD}]" },
87130
"value_type": "FLOAT",
88-
"delay": "1m",
131+
"delay": "0",
89132
"units": "pps",
90133
"preprocessing": [
134+
{
135+
"type": "JAVASCRIPT",
136+
"parameters": [
137+
"var p='{#PORT}';\nvar a=value.trim().split(',');\nif(a.length<3) return null;\nfor(var i=2;i+6<a.length;i+=7){ if(a[i]===String(p)) return a[i+5]; }\nreturn null;"
138+
]
139+
},
91140
{ "type": "CHANGE_PER_SECOND", "parameters": [""] }
92141
],
93142
"tags": [
@@ -96,14 +145,21 @@
96145
]
97146
},
98147
{
99-
"uuid": "550e8400e29b41d4a716446655441005",
148+
"uuid": "550e8400e29b41d4a716446655441205",
100149
"name": "Port {#PORT} RxBadPkt",
101-
"key": "essstat.port[{$SWITCH_IP},{$SWITCH_USER},{$SWITCH_PWD},{#PORT},RxBadPkt]",
102-
"type": "ZABBIX_PASSIVE",
150+
"key": "essstat.value[{#PORT},RxBadPkt]",
151+
"type": "DEPENDENT",
152+
"master_item": { "key": "essstat.1line[{$SWITCH_IP},{$SWITCH_USER},{$SWITCH_PWD}]" },
103153
"value_type": "FLOAT",
104-
"delay": "1m",
154+
"delay": "0",
105155
"units": "pps",
106156
"preprocessing": [
157+
{
158+
"type": "JAVASCRIPT",
159+
"parameters": [
160+
"var p='{#PORT}';\nvar a=value.trim().split(',');\nif(a.length<3) return null;\nfor(var i=2;i+6<a.length;i+=7){ if(a[i]===String(p)) return a[i+6]; }\nreturn null;"
161+
]
162+
},
107163
{ "type": "CHANGE_PER_SECOND", "parameters": [""] }
108164
],
109165
"tags": [
@@ -120,34 +176,22 @@
120176
{
121177
"color": "00AA00",
122178
"calc_fnc": "ALL",
123-
"item": {
124-
"host": "TP-Link Easy Smart Switch",
125-
"key": "essstat.port[{$SWITCH_IP},{$SWITCH_USER},{$SWITCH_PWD},{#PORT},TxGoodPkt]"
126-
}
179+
"item": { "host": "TP-Link Easy Smart Switch", "key": "essstat.value[{#PORT},TxGoodPkt]" }
127180
},
128181
{
129182
"color": "0000AA",
130183
"calc_fnc": "ALL",
131-
"item": {
132-
"host": "TP-Link Easy Smart Switch",
133-
"key": "essstat.port[{$SWITCH_IP},{$SWITCH_USER},{$SWITCH_PWD},{#PORT},RxGoodPkt]"
134-
}
184+
"item": { "host": "TP-Link Easy Smart Switch", "key": "essstat.value[{#PORT},RxGoodPkt]" }
135185
},
136186
{
137187
"color": "AA0000",
138188
"calc_fnc": "ALL",
139-
"item": {
140-
"host": "TP-Link Easy Smart Switch",
141-
"key": "essstat.port[{$SWITCH_IP},{$SWITCH_USER},{$SWITCH_PWD},{#PORT},TxBadPkt]"
142-
}
189+
"item": { "host": "TP-Link Easy Smart Switch", "key": "essstat.value[{#PORT},TxBadPkt]" }
143190
},
144191
{
145192
"color": "AA00AA",
146193
"calc_fnc": "ALL",
147-
"item": {
148-
"host": "TP-Link Easy Smart Switch",
149-
"key": "essstat.port[{$SWITCH_IP},{$SWITCH_USER},{$SWITCH_PWD},{#PORT},RxBadPkt]"
150-
}
194+
"item": { "host": "TP-Link Easy Smart Switch", "key": "essstat.value[{#PORT},RxBadPkt]" }
151195
}
152196
]
153197
}

essstat.conf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# LLD discovery of switch ports
22
UserParameter=essstat.discovery[*],/usr/local/bin/essstat.py --lld "$1" --username="$2" --password="$3"
33

4+
# Switch-wide metric collection
5+
UserParameter=essstat.1line[*],/usr/local/bin/essstat.py --1line "$1" --username "$2" --password "$3"
6+
47
# Per-port metrics
5-
UserParameter=essstat.port[*],/usr/local/bin/essstat.py "$1" --username="$2" --password="$3" --port="$4" --metric="$5"
8+
UserParameter=essstat.port[*],/usr/local/bin/essstat.py "$1" --username="$2" --password="$3" --port="$4" --metric="$5"

0 commit comments

Comments
 (0)