aboutsummaryrefslogtreecommitdiffstats
path: root/community/zabbix/0001-Revert-.G.-ZBXNEXT-6596-added-native-linux-proc.num-.patch
blob: bd7e25ba9c6537ebfcbdd08d95d1f5217ebbd3e3 (plain) (blame)
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
From 581ae83ceaa4274fb4389d09fcf28d62d81f13d8 Mon Sep 17 00:00:00 2001
From: Leonardo Arena <rnalrd@alpinelinux.org>
Date: Wed, 18 Aug 2021 11:06:57 +0200
Subject: [PATCH] Revert "...G...... [ZBXNEXT-6596] added native linux proc.num
 support plugin to Zabbix agent 2"

This reverts commit 9427f39e32c5ff5201265ab8c5f73caff9962478.

See https://support.zabbix.com/browse/ZBX-19614
---
 src/go/pkg/zbxlib/checks_linux.go      |   2 +
 src/go/plugins/proc/proc_linux.go      | 110 +------------------------
 src/go/plugins/proc/procfs_linux.go    |  24 ------
 src/go/plugins/zabbix/sync/sync_nix.go |   1 +
 4 files changed, 6 insertions(+), 131 deletions(-)

diff --git a/src/go/pkg/zbxlib/checks_linux.go b/src/go/pkg/zbxlib/checks_linux.go
index 206ad9542d..99cefa30cc 100644
--- a/src/go/pkg/zbxlib/checks_linux.go
+++ b/src/go/pkg/zbxlib/checks_linux.go
@@ -74,6 +74,8 @@ func resolveMetric(key string) (cfunc unsafe.Pointer) {
 		cfunc = unsafe.Pointer(C.NET_DNS)
 	case "net.dns.record":
 		cfunc = unsafe.Pointer(C.NET_DNS_RECORD)
+	case "proc.num":
+		cfunc = unsafe.Pointer(C.PROC_NUM)
 	case "system.boottime":
 		cfunc = unsafe.Pointer(C.SYSTEM_BOOTTIME)
 	case "net.tcp.listen":
diff --git a/src/go/plugins/proc/proc_linux.go b/src/go/plugins/proc/proc_linux.go
index 20af05f34f..5b58d12071 100644
--- a/src/go/plugins/proc/proc_linux.go
+++ b/src/go/plugins/proc/proc_linux.go
@@ -121,7 +121,6 @@ type procQuery struct {
 	name    string
 	user    string
 	cmdline string
-	state   string
 }
 
 const (
@@ -129,7 +128,6 @@ const (
 	procInfoName
 	procInfoUser
 	procInfoCmdline
-	procInfoState
 )
 
 type procInfo struct {
@@ -138,7 +136,6 @@ type procInfo struct {
 	userid  int64
 	cmdline string
 	arg0    string
-	state   string
 }
 
 type cpuUtil struct {
@@ -172,7 +169,6 @@ func newCpuUtilQuery(q *procQuery, pattern *regexp.Regexp) (query *cpuUtilQuery,
 			return
 		}
 	}
-
 	query.cmdlinePattern = pattern
 	return
 }
@@ -185,13 +181,13 @@ func (p *Plugin) prepareQueries() (queries []*cpuUtilQuery, flags int) {
 	p.mutex.Lock()
 	for q, stats := range p.queries {
 		if now.Sub(stats.accessed) > maxInactivityPeriod {
-			p.Debugf("removed unused CPU utilization query %+v", q)
+			p.Debugf("removed unused CPU utilisation query %+v", q)
 			delete(p.queries, q)
 			continue
 		}
 		var query *cpuUtilQuery
 		if query, stats.err = newCpuUtilQuery(&q, stats.cmdlinePattern); stats.err != nil {
-			p.Debugf("cannot create CPU utilization query %+v: %s", q, stats.err)
+			p.Debugf("cannot create CPU utilisation query %+v: %s", q, stats.err)
 			continue
 		}
 		queries = append(queries, query)
@@ -415,45 +411,9 @@ func (p *Plugin) Export(key string, params []string, ctx plugin.ContextProvider)
 	}
 	return
 }
-func (p *PluginExport) prepareQuery(q *procQuery) (query *cpuUtilQuery, flags int, err error) {
-	regxp, err := regexp.Compile(q.cmdline)
-	if err != nil {
-		return nil, 0, fmt.Errorf("cannot compile regex for %s: %s", q.cmdline, err.Error())
-	}
-
-	if query, err = newCpuUtilQuery(q, regxp); err != nil {
-		return nil, 0, fmt.Errorf("cannot create CPU utilization query %+v: %s", q, err.Error())
-	}
-
-	if q.name != "" {
-		flags |= procInfoName | procInfoCmdline
-	}
-	if q.user != "" {
-		flags |= procInfoUser
-	}
-	if q.cmdline != "" {
-		flags |= procInfoCmdline
-	}
-	if q.state != "" {
-		flags |= procInfoState
-	}
-
-	return
-}
 
 // Export -
 func (p *PluginExport) Export(key string, params []string, ctx plugin.ContextProvider) (result interface{}, err error) {
-	switch key {
-	case "proc.mem":
-		return p.exportProcMem(params)
-	case "proc.num":
-		return p.exportProcNum(params)
-	}
-
-	return nil, plugin.UnsupportedMetricError
-}
-
-func (p *PluginExport) exportProcMem(params []string) (result interface{}, err error) {
 	var name, mode, cmdline, memtype string
 	var usr *user.User
 
@@ -632,67 +592,6 @@ func (p *PluginExport) exportProcMem(params []string) (result interface{}, err e
 	return memSize, nil
 }
 
-func (p *PluginExport) exportProcNum(params []string) (interface{}, error) {
-	var name, userName, state, cmdline string
-	switch len(params) {
-	case 4:
-		cmdline = params[3]
-		fallthrough
-	case 3:
-		switch params[2] {
-		case "all", "":
-		case "disk":
-			state = "D"
-		case "run":
-			state = "R"
-		case "sleep":
-			state = "S"
-		case "trace":
-			state = "T"
-		case "zomb":
-			state = "Z"
-		default:
-			return nil, errors.New("Invalid third parameter.")
-		}
-		fallthrough
-	case 2:
-		userName = params[1]
-		fallthrough
-	case 1:
-		name = params[0]
-	case 0:
-	default:
-		return nil, errors.New("Too many parameters.")
-	}
-
-	var count int
-
-	query, flags, err := p.prepareQuery(&procQuery{name, userName, cmdline, state})
-	if err != nil {
-		p.Debugf("Failed to prepare query: %s", err.Error())
-		return count, nil
-	}
-
-	procs, err := getProcesses(flags)
-	if err != nil {
-		return nil, fmt.Errorf("Failed to get local processes: %s", err.Error())
-	}
-
-	for _, proc := range procs {
-		if !query.match(proc) {
-			continue
-		}
-
-		if state != proc.state && state != "" {
-			continue
-		}
-
-		count++
-	}
-
-	return count, nil
-}
-
 func getMax(a, b float64) float64 {
 	if a > b {
 		return a
@@ -776,8 +675,5 @@ func (p *PluginExport) validFile(proc *procInfo, name string, uid int64, cmdRgx
 
 func init() {
 	plugin.RegisterMetrics(&impl, "Proc", "proc.cpu.util", "Process CPU utilization percentage.")
-	plugin.RegisterMetrics(&implExport, "ProcExporter",
-		"proc.mem", "Process memory utilization values.",
-		"proc.num", "The number of processes.",
-	)
+	plugin.RegisterMetrics(&implExport, "ProcExporter", "proc.mem", "Process memory utilization values.")
 }
diff --git a/src/go/plugins/proc/procfs_linux.go b/src/go/plugins/proc/procfs_linux.go
index e6e1637933..cd9427647a 100644
--- a/src/go/plugins/proc/procfs_linux.go
+++ b/src/go/plugins/proc/procfs_linux.go
@@ -27,7 +27,6 @@ import (
 	"io"
 	"os"
 	"strconv"
-	"strings"
 	"syscall"
 
 	"zabbix.com/pkg/procfs"
@@ -62,22 +61,6 @@ func getProcessName(pid string) (name string, err error) {
 	return string(data[left+1 : right]), nil
 }
 
-func getProcessState(pid string) (name string, err error) {
-	var data []byte
-	if data, err = read2k("/proc/" + pid + "/status"); err != nil {
-		return
-	}
-
-	s := strings.Split(string(data), "\n")
-	for _, tmp := range s {
-		if strings.HasPrefix(tmp, "State:") && len(tmp) > 7 {
-			return string(tmp[7:8]), nil
-		}
-	}
-
-	return "", fmt.Errorf("cannot find process state /proc/%s/status", pid)
-}
-
 func getProcessUserID(pid string) (userid int64, err error) {
 	var fi os.FileInfo
 	if fi, err = os.Stat("/proc/" + pid); err != nil {
@@ -184,13 +167,6 @@ func getProcesses(flags int) (processes []*procInfo, err error) {
 				continue
 			}
 		}
-		if flags&procInfoState != 0 {
-			if info.state, tmperr = getProcessState(entries[0].Name()); tmperr != nil {
-				impl.Debugf("cannot get process %s state: %s", entries[0].Name(), tmperr)
-				continue
-			}
-		}
-
 		processes = append(processes, info)
 	}
 
diff --git a/src/go/plugins/zabbix/sync/sync_nix.go b/src/go/plugins/zabbix/sync/sync_nix.go
index f22ef75fa7..b743d2e050 100644
--- a/src/go/plugins/zabbix/sync/sync_nix.go
+++ b/src/go/plugins/zabbix/sync/sync_nix.go
@@ -25,6 +25,7 @@ func getMetrics() []string {
 	return []string{
 		"net.dns", "Checks if DNS service is up.",
 		"net.dns.record", "Performs DNS query.",
+		"proc.num", "The number of processes.",
 		"system.hw.chassis", "Chassis information.",
 		"system.hw.devices", "Listing of PCI or USB devices.",
 		"vfs.dir.count", "Directory entry count.",
-- 
2.32.0