Skip to content

Commit b88f978

Browse files
committed
feat: added monitoring for user-facing or demanding processes
1 parent 040f915 commit b88f978

4 files changed

Lines changed: 95 additions & 0 deletions

File tree

‎packages/ns-plug/files/ns-controller-push-info‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ try:
6464
telegraf_config = f"""# Controller prometheus exporter
6565
[[outputs.prometheus_client]]
6666
listen = \"{ifconfig_local}:9273\"
67+
namedrop = [\"procstat*\"]
6768
"""
6869
with open('/etc/telegraf.conf.d/controller-prometheus.conf', 'w') as f:
6970
f.write(telegraf_config)

‎packages/telegraf/Makefile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ GO_PKG_TAGS:= \
4444
inputs.nstat \
4545
inputs.ping \
4646
inputs.processes \
47+
inputs.procstat \
4748
inputs.sensors \
4849
inputs.smart \
4950
inputs.system \
@@ -92,6 +93,7 @@ define Package/telegraf/install
9293
$(INSTALL_DATA) ./files/telegraf.conf.d/services.conf $(1)/etc/telegraf.conf.d/services.conf
9394
$(INSTALL_DATA) ./files/telegraf.conf.d/mwan.conf $(1)/etc/telegraf.conf.d/mwan.conf
9495
$(INSTALL_DATA) ./files/telegraf.conf.d/ha.conf $(1)/etc/telegraf.conf.d/ha.conf
96+
$(INSTALL_DATA) ./files/telegraf.conf.d/procstat.conf $(1)/etc/telegraf.conf.d/procstat.conf
9597
$(INSTALL_DIR) $(1)/etc/rsyslog.d/victoria-logs.d
9698
$(INSTALL_DATA) ./files/rsyslog-victoria-logs.conf $(1)/etc/rsyslog.d/victoria-logs.d/telegraf.conf
9799
$(INSTALL_DIR) $(1)/etc/uci-defaults

‎packages/telegraf/README.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,26 @@ curl -s 'http://127.0.0.1:8428/api/v1/query?query=mwan_interface_online'
123123
storage_status_error = 1 (error) or 0 (ok / not configured)
124124
```
125125

126+
### Process Resource Monitoring (procstat.conf)
127+
128+
**How it works**: Every 30 seconds, Telegraf `procstat` collects CPU and memory usage of the most resource-intensive daemons and of the user-facing services. Each process group is a filter named after its procd service, so it can be matched with `procd_service`. Services that run more than one process with the same name (`openvpn`, `ns-plug`, `dropbear`, `nginx`, `dnsmasq`) also get a `pid` tag.
129+
130+
These metrics are kept in the local Victoria Metrics only, the controller exporter drops them.
131+
132+
**Metric format**:
133+
```
134+
procstat_cpu_usage{filter="snort", process_name="snort3"} = percent
135+
procstat_memory_rss{filter="nginx", process_name="nginx", pid="9086"} = bytes
136+
procstat_lookup_running{filter="openvpn"} = number of matching processes
137+
```
138+
139+
#### Querying Process Usage
140+
141+
```bash
142+
# Memory of every monitored service, summing multi-process ones
143+
curl -s 'http://127.0.0.1:8428/api/v1/query?query=sum(procstat_memory_rss)by(filter)'
144+
```
145+
126146
## Advanced Configuration
127147

128148
To add custom metrics or modify collection intervals, edit the `/etc/telegraf.conf.d/` files following [Telegraf documentation](https://docs.influxdata.com/telegraf/). Common customizations:
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Per-process CPU and memory usage
2+
# Filter names match the procd service names used by procd_service.
3+
4+
[[inputs.procstat]]
5+
interval = "30s"
6+
properties = ["cpu", "memory"]
7+
8+
[[inputs.procstat.filter]]
9+
name = "snort"
10+
executables = ["/usr/bin/snort"]
11+
[[inputs.procstat.filter]]
12+
name = "netifyd"
13+
executables = ["/usr/sbin/netifyd"]
14+
[[inputs.procstat.filter]]
15+
name = "victoria-metrics"
16+
executables = ["/usr/bin/victoria-metrics"]
17+
[[inputs.procstat.filter]]
18+
name = "victoria-logs"
19+
executables = ["/usr/bin/victoria-logs"]
20+
[[inputs.procstat.filter]]
21+
name = "vmalert"
22+
executables = ["/usr/bin/vmalert"]
23+
[[inputs.procstat.filter]]
24+
name = "telegraf"
25+
executables = ["/usr/bin/telegraf"]
26+
[[inputs.procstat.filter]]
27+
name = "ns-flows"
28+
executables = ["/usr/sbin/ns-flows"]
29+
[[inputs.procstat.filter]]
30+
name = "ns-stats"
31+
executables = ["/usr/sbin/ns-stats"]
32+
[[inputs.procstat.filter]]
33+
name = "ns-api-server"
34+
executables = ["/usr/bin/nethsecurity-api"]
35+
# fail2ban-server runs under python3
36+
[[inputs.procstat.filter]]
37+
name = "fail2ban"
38+
patterns = ["fail2ban-server"]
39+
[[inputs.procstat.filter]]
40+
name = "swanctl"
41+
executables = ["/usr/lib/ipsec/charon"]
42+
[[inputs.procstat.filter]]
43+
name = "odhcpd"
44+
executables = ["/usr/sbin/odhcpd"]
45+
46+
[inputs.procstat.tags]
47+
influxdb_db = "os-metrics"
48+
49+
# Services running more than one process with the same name
50+
[[inputs.procstat]]
51+
interval = "30s"
52+
properties = ["cpu", "memory"]
53+
tag_with = ["pid"]
54+
55+
[[inputs.procstat.filter]]
56+
name = "openvpn"
57+
patterns = ["^/usr/sbin/openvpn "]
58+
[[inputs.procstat.filter]]
59+
name = "ns-plug"
60+
patterns = ["^openvpn /usr/share/ns-plug/client.conf"]
61+
[[inputs.procstat.filter]]
62+
name = "dropbear"
63+
executables = ["/usr/sbin/dropbear"]
64+
[[inputs.procstat.filter]]
65+
name = "nginx"
66+
executables = ["/usr/sbin/nginx"]
67+
[[inputs.procstat.filter]]
68+
name = "dnsmasq"
69+
executables = ["/usr/sbin/dnsmasq"]
70+
71+
[inputs.procstat.tags]
72+
influxdb_db = "os-metrics"

0 commit comments

Comments
 (0)