Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions config/netdata.conf

This file was deleted.

5 changes: 2 additions & 3 deletions packages/ns-api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ define Package/ns-api/install
$(INSTALL_DATA) ./files/ns.mwan.json $(1)/usr/share/rpcd/acl.d/
$(INSTALL_BIN) ./files/ns.dpi $(1)/usr/libexec/rpcd/
$(INSTALL_DATA) ./files/ns.dpi.json $(1)/usr/share/rpcd/acl.d/
$(INSTALL_BIN) ./files/ns.netdata $(1)/usr/libexec/rpcd/
$(INSTALL_DATA) ./files/ns.netdata.json $(1)/usr/share/rpcd/acl.d/
$(INSTALL_BIN) ./files/ns.telegraf $(1)/usr/libexec/rpcd/
$(INSTALL_DATA) ./files/ns.telegraf.json $(1)/usr/share/rpcd/acl.d/
$(INSTALL_BIN) ./files/ns.storage $(1)/usr/libexec/rpcd/
$(INSTALL_DATA) ./files/ns.storage.json $(1)/usr/share/rpcd/acl.d/
$(INSTALL_BIN) ./files/ns.account $(1)/usr/libexec/rpcd/
Expand Down Expand Up @@ -186,7 +186,6 @@ define Package/ns-api/install
$(INSTALL_CONF) ./files/config/ns-api $(1)/etc/config/ns-api
$(INSTALL_CONF) ./files/config/ns-wizard $(1)/etc/config/ns-wizard
$(INSTALL_CONF) ./files/templates $(1)/etc/config/
$(INSTALL_BIN) ./files/post-commit/restart-netdata.py $(1)/usr/libexec/ns-api/post-commit/
$(INSTALL_BIN) ./files/pre-commit/fix-redirect-reflections.py $(1)/usr/libexec/ns-api/pre-commit
$(INSTALL_BIN) ./files/pre-commit/update-objects.py $(1)/usr/libexec/ns-api/pre-commit
$(INSTALL_BIN) ./files/post-commit/reload-ipsets.py $(1)/usr/libexec/ns-api/post-commit
Expand Down
162 changes: 125 additions & 37 deletions packages/ns-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,124 @@ Response:
}
```

## ns.telegraf

Read and update Telegraf ping monitoring targets, query historical metrics stored in VictoriaMetrics, and list the current alerts evaluated by vmalert.

### get-configuration

Get the current list of hosts monitored by the Telegraf ping input:
```
api-cli ns.telegraf get-configuration
```

Output example:
```json
{
"hosts": [
"1.1.1.1",
"google.com"
]
}
```

### set-hosts

Set the list of hosts monitored by the Telegraf ping input and restart Telegraf:
```
api-cli ns.telegraf set-hosts --data '{"hosts": ["1.1.1.1", "8.8.8.8"]}'
```

Parameters:
- `hosts`: array of hostnames or IP addresses to monitor

Output example:
```json
{
"success": true
}
```

### metrics-history

Return historical system and network metrics collected by Telegraf and stored in VictoriaMetrics:
```
api-cli ns.telegraf metrics-history --data '{"start": 1746607800, "end": 1746608400, "step": 60}'
```

Parameters:
- `start`: start of the time range as Unix timestamp
- `end`: end of the time range as Unix timestamp
- `step`: sampling interval in seconds

Output example:
```json
{
"connections": {
"labels": [1746608100],
"datasets": [{ "label": "Connections", "data": [123] }]
},
"traffic": {},
"cpu": {
"labels": [1746608100],
"datasets": [{ "label": "CPU (%)", "data": [14.2] }]
},
"load": {
"labels": [1746608100],
"datasets": [
{ "label": "1m", "data": [0.12] },
{ "label": "5m", "data": [0.08] },
{ "label": "15m", "data": [0.05] }
]
},
"diskio": { "labels": [], "datasets": [] },
"disk": { "labels": [], "datasets": [] },
"processes": { "labels": [], "datasets": [] },
"memory": { "labels": [], "datasets": [] },
"packets": { "labels": [], "datasets": [] },
"latency_quality": {}
}
```

### list-alerts

List the current pending and firing alerts evaluated by vmalert:
```
api-cli ns.telegraf list-alerts
```

Output example:
```json
{
"alerts": [
{
"state": "firing",
"name": "BackupEncryptionDisabled",
"value": "0",
"labels": {
"alertgroup": "backup",
"alertname": "BackupEncryptionDisabled",
"severity": "warning",
"service": "backup"
},
"annotations": {
"summary_en": "Backup encryption is disabled",
"summary_it": "La cifratura dei backup e disattivata",
"description_en": "The backup passphrase file /etc/backup.pass is missing or empty.",
"description_it": "Il file della passphrase dei backup /etc/backup.pass manca o e vuoto."
},
"activeAt": "2026-05-07T09:18:00Z",
"expression": "backup_encryption_encrypted == 0",
"source": "http://NethSec:8082/vmalert/alert?group_id=10212661952842894290&alert_id=4214684507782533109"
}
]
}
```

Possible errors:
- `cannot_retrieve_alerts`
- `invalid_alerts_response`

## ns.firewall

### list-forward-rules
Expand Down Expand Up @@ -2436,7 +2554,10 @@ Response example:

### traffic-interface

Return an array of point describing the network traffic in the last hour:
Return an array of points describing the network traffic in the last hour.
Data is sourced from Victoria Metrics using `net_bytes_recv` and `net_bytes_sent` Telegraf counters,
converted to kb/s (kilobits per second). Labels are Unix timestamps in descending order (newest first),
with one point every 20 seconds (~180 points total).
```
api-cli ns.dashboard interface-traffic --data '{"interface": "eth0"}'
```
Expand Down Expand Up @@ -4504,39 +4625,6 @@ Error response example:
{"error": "restart_failed"}
```

## ns.netdata

Configure netdata reporting daemon.

### get-configuration

Get current netdata configuration:
```
api-cli ns.netdata get-configuration
```

Response example:
```json
{
"hosts": [
"1.2.3.4",
"google.it"
]
}
```

### set-hosts

Configure hosts to be monitored by fping:
```
api-cli ns.netdata set-hosts --data '{"hosts": ["1.1.1.1", "google.com"]}'
```

Response example:
```json
{"result": "success"}
```

## ns.factoryreset

### reset
Expand Down Expand Up @@ -7932,7 +8020,7 @@ Output example:

### latency-and-quality-report

Report latency metrics (minimum, maximum and average) and connectivy quality data (packet delivery rate) for every host configured in Netdata fping configuration file, located at `/etc/netdata/fping.conf`.
Report latency metrics (minimum, maximum and average) and connectivity quality data (packet loss percentage) for every host configured in the Telegraf ping plugin configuration file, located at `/etc/telegraf.conf.d/ping.conf`.
Usage example:
```
api-cli ns.report latency-and-quality-report
Expand Down Expand Up @@ -7982,7 +8070,7 @@ Output example:
],
[
1731485262,
99.8152174
100
],
[
1731484894,
Expand Down Expand Up @@ -8032,7 +8120,7 @@ Output example:
],
[
1731485262,
99.8152174
100
],
[
1731484894,
Expand Down
29 changes: 19 additions & 10 deletions packages/ns-api/files/ns.dashboard
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import os
import sys
import json
import subprocess
import time
import urllib.parse
import urllib.request
from euci import EUci
from nethsec import utils, ovpn
Expand Down Expand Up @@ -274,17 +276,24 @@ def system_info():

def interface_traffic(interface):
ret = {"labels": [], "data": []}
# retrieve from netdata the traffic for the last hour
url = f'http://127.0.0.1:19999/api/v1/data?chart=net.{interface}&after=-3600&points=180&options=abs'
try:
with urllib.request.urlopen(url, timeout=10) as fu:
data = json.loads(fu.read())
except:
return ret
vm_url = "http://127.0.0.1:8428/api/v1/query_range"
now = int(time.time())
one_hour_ago = now - 3600

def vm_query(expr):
params = urllib.parse.urlencode({"query": expr, "start": one_hour_ago, "end": now, "step": 20})
with urllib.request.urlopen(f"{vm_url}?{params}", timeout=5) as resp:
data = json.loads(resp.read())
result = data.get("data", {}).get("result", [])
return result[0].get("values", []) if result else []

for record in data["data"]:
ret["labels"].append(record[0])
ret["data"].append([record[1], record[2]])
try:
recv = vm_query(f'rate(net_bytes_recv{{interface="{interface}"}}[20s]) * 8 / 1000')
sent = vm_query(f'rate(net_bytes_sent{{interface="{interface}"}}[20s]) * 8 / 1000')
ret["labels"] = [int(ts) for ts, _ in reversed(recv)]
ret["data"] = [[float(r), float(s)] for (_, r), (_, s) in zip(reversed(recv), reversed(sent))]
except Exception:
pass

return ret

Expand Down
66 changes: 0 additions & 66 deletions packages/ns-api/files/ns.netdata

This file was deleted.

13 changes: 0 additions & 13 deletions packages/ns-api/files/ns.netdata.json

This file was deleted.

Loading
Loading