mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-10-29 20:15:13 +08:00
🎨 Sync 2026-04-11 03:46:42
This commit is contained in:
1 parent
927182b1b3
commit
b38b5d9d96
20 files changed
+555
-1236
No files matched your search
@@ -0,0 +1,30 @@
|
||||
#!/bin/sh
|
||||
[ ! -f "/usr/share/ucitrack/luci-app-netdata.json" ] && {
|
||||
cat > /usr/share/ucitrack/luci-app-netdata.json << EEOF
|
||||
{
|
||||
"config": "netdata",
|
||||
"init": "netdata"
|
||||
}
|
||||
EEOF
|
||||
}
|
||||
# [ -f /usr/share/netdata/webcn/netdata.conf ] && mv -f /usr/share/netdata/webcn/netdata.conf /etc/netdata/netdata.conf
|
||||
[ -f /usr/share/netdata/webcn/netdata.config ] && mv -f /usr/share/netdata/webcn/netdata.config /etc/config/netdata
|
||||
[ -f /usr/share/netdata/webcn/netdata.init ] && mv -f /usr/share/netdata/webcn/netdata.init /etc/init.d/netdata
|
||||
|
||||
chmod +x /etc/init.d/netdata
|
||||
|
||||
[ -f "/etc/config/ucitrack" ] && {
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@netdata[-1]
|
||||
add ucitrack netdata
|
||||
set ucitrack.@netdata[-1].init=netdata
|
||||
commit ucitrack
|
||||
EOF
|
||||
}
|
||||
|
||||
rm -f /tmp/luci-indexcache* 2>/dev/null
|
||||
rm -f /tmp/luci-modulecache/* 2>/dev/null # OpenWrt 21.02
|
||||
rm -f /tmp/luci-indexcache
|
||||
|
||||
rm -rf /tmp/luci-*
|
||||
exit 0
|
||||
@@ -12,26 +12,26 @@
|
||||
},
|
||||
"admin/status/netdata/netdata": {
|
||||
"title": "Netdata",
|
||||
"order": 1,
|
||||
"order": 10,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "netdata/main"
|
||||
"path": "netdata/netdata"
|
||||
}
|
||||
},
|
||||
"admin/status/netdata/basic": {
|
||||
"title": "Basic Setting",
|
||||
"order": 20,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "netdata/basic"
|
||||
}
|
||||
},
|
||||
"admin/status/netdata/config": {
|
||||
"title": "Config",
|
||||
"order": 2,
|
||||
"title": "Config Setting",
|
||||
"order": 30,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "netdata/config"
|
||||
}
|
||||
},
|
||||
"admin/status/netdata/advanced": {
|
||||
"title": "Advanced",
|
||||
"order": 3,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "netdata/advanced"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
# Full configuration can be retrieved from the running
|
||||
# server at http://localhost:19999/netdata.conf
|
||||
#
|
||||
# Example:
|
||||
# curl -o /etc/netdata/netdata.conf http://localhost:19999/netdata.conf
|
||||
#
|
||||
|
||||
[global]
|
||||
update every = 2
|
||||
memory deduplication (ksm) = no
|
||||
debug log = none
|
||||
error log = none
|
||||
access log = none
|
||||
run as user = root
|
||||
|
||||
[web]
|
||||
default port = 19999
|
||||
allow connections from = *
|
||||
allow dashboard from = *
|
||||
|
||||
[plugins]
|
||||
cgroups = no
|
||||
apps = no
|
||||
charts.d = no
|
||||
fping = no
|
||||
node.d = no
|
||||
python.d = no
|
||||
|
||||
[health]
|
||||
enabled = no
|
||||
|
||||
[plugin:proc:ipc]
|
||||
shared memory totals = no
|
||||
@@ -0,0 +1,3 @@
|
||||
config netdata 'netdata'
|
||||
option enabled '0'
|
||||
option port '19999'
|
||||
@@ -0,0 +1,105 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=99
|
||||
USE_PROCD=1
|
||||
|
||||
APPBINARY=/usr/sbin/netdata
|
||||
CONFIGFILE=/etc/netdata/netdata.conf
|
||||
|
||||
config_load 'netdata'
|
||||
|
||||
get_config() {
|
||||
config_get_bool enabled $1 enabled 0
|
||||
config_get port $1 port 19999
|
||||
config_get_bool ssl $1 enable_ssl 0
|
||||
config_get cert_file $1 cert_file '/etc/ssl/ezopwrt.crt'
|
||||
config_get key_file $1 key_file '/etc/ssl/ezopwrt.key'
|
||||
config_get_bool ennginx $1 nginx_support 0
|
||||
config_get_bool auth $1 auth 0
|
||||
config_get userpw $1 user_passwd 'admin:$apr1$t7qQjoqb$YBHtAb7VGSkjIdObMG.Oy0'
|
||||
[ "$ennginx" == "1" ] && ssl=0
|
||||
}
|
||||
|
||||
#read_option <option>
|
||||
read_option() {
|
||||
[ -n "$1" ] || return 1
|
||||
sed -En "/^\[web\]/,/^(\[|$)/{s|^\s*$1 = *(.*)$|\1|p}" "$CONFIGFILE"
|
||||
}
|
||||
|
||||
#white_option <option> [value]
|
||||
white_option() {
|
||||
[ -n "$1" ] || return 1
|
||||
if [ -n "$(sed -En "/^\[web\]/,/^(\[|$)/{s|^\s*($1) =.*$|\1|p}" "$CONFIGFILE")" ]; then
|
||||
sed -Ei "/^\[web\]/,/^(\[|$)/{s|^(\s*)$1 =.*|\1$1 = $2|}" "$CONFIGFILE"
|
||||
else
|
||||
sed -Ei "/^\[web\]/a\\\t$1 = $2" "$CONFIGFILE"
|
||||
fi
|
||||
}
|
||||
|
||||
white_conf() {
|
||||
if [ "x$ssl" == "x1" ] ;then
|
||||
rm -f $certskey $certscrt
|
||||
hostname=$(uci -q get system.@system[0].hostname | awk '{print tolower($0)}')
|
||||
uci -q set network.lan.hostname=${hostname}
|
||||
uci -q set dhcp.@dnsmasq[0].domain="${hostname}.lan"
|
||||
openssl req -new -newkey rsa:2048 -days 3650 -nodes -x509 -keyout $key_file -out $cert_file -subj "/C=CN/CN=$hostname.lan"
|
||||
uci commit dhcp
|
||||
uci commit network
|
||||
else
|
||||
local cert_file='' key_file=''
|
||||
fi
|
||||
[ "$port" == "$(read_option 'default port')" ] || white_option 'default port' "$port"
|
||||
[ "$cert_file" == "$(read_option 'ssl certificate')" ] || white_option 'ssl certificate' "$cert_file"
|
||||
[ "$key_file" == "$(read_option 'ssl key')" ] || white_option 'ssl key' "$key_file"
|
||||
}
|
||||
|
||||
write_nginx() {
|
||||
local location="/etc/nginx/conf.d/netdata.locations"
|
||||
local htpasswd="/etc/nginx/conf.d/netdata.htpasswd"
|
||||
|
||||
echo "$userpw" > "$htpasswd"
|
||||
[ "$(sed -En "s|^\s*proxy_pass\s+https?://[^:]+:(\d+).*|\1|p" "$location")" == "$port" ] || sed -Ei "/proxy_pass/{s|(\bproxy_pass\b)(\s+.+)?|\1 http://localhost:$port/;|}" "$location"
|
||||
if [ "$auth" == "1" ];then
|
||||
sed -Ei "s|#(\bauth_basic_user_file\b)|\1|" "$location"
|
||||
else
|
||||
sed -Ei "s|^(\s*)(\bauth_basic_user_file\b)|\1#\2|" "$location"
|
||||
fi
|
||||
/etc/init.d/nginx reload
|
||||
}
|
||||
|
||||
netdata_instance() {
|
||||
mkdir -m 0755 -p /var/cache/netdata
|
||||
chown nobody /var/cache/netdata
|
||||
mkdir -m 0755 -p /var/lib/netdata
|
||||
chown nobody /var/lib/netdata
|
||||
mkdir -m 0755 -p /var/lib/netdata/cloud.d
|
||||
chown nobody /var/lib/netdata/cloud.d
|
||||
mkdir -m 0755 -p /var/log/netdata
|
||||
chown nobody /var/log/netdata
|
||||
procd_open_instance
|
||||
procd_set_param command $APPBINARY -D -c $CONFIGFILE
|
||||
procd_set_param file $CONFIGFILE
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
start_service() {
|
||||
config_foreach get_config 'netdata'
|
||||
[ "${enabled:=0}" == "0" ] && stop_service && return 1
|
||||
white_conf
|
||||
[ "$ennginx" == "1" ] && write_nginx
|
||||
netdata_instance
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
pgrep -f $APPBINARY | xargs kill -9 >/dev/null 2>&1
|
||||
return 0
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger 'netdata'
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
restart
|
||||
}
|
||||
@@ -5,10 +5,15 @@
|
||||
"file": {
|
||||
"/etc/netdata/netdata.conf": [ "read" ],
|
||||
"/etc/init.d/netdata": [ "exec" ],
|
||||
"/usr/bin/openssl passwd -apr1 *": [ "exec" ]
|
||||
"/usr/bin/openssl passwd -apr1 *": [ "exec" ],
|
||||
"/bin/pidof": [ "exec" ],
|
||||
"/bin/ps": [ "exec" ],
|
||||
"/bin/ash": [ "exec" ]
|
||||
},
|
||||
"ubus": {
|
||||
"file": [ "read" ]
|
||||
"rc": [ "*" ],
|
||||
"file": [ "read" ],
|
||||
"luci.netdata": [ "*" ]
|
||||
},
|
||||
"uci": [ "netdata" ]
|
||||
},
|
||||
@@ -17,7 +22,8 @@
|
||||
"/etc/netdata/netdata.conf": [ "write" ]
|
||||
},
|
||||
"ubus": {
|
||||
"file": [ "write" ]
|
||||
"file": [ "write" ],
|
||||
"luci.netdata": [ "*" ]
|
||||
},
|
||||
"uci": [ "netdata" ]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/ucode
|
||||
/*
|
||||
* SPDX-License-Identifier: GPL-2.0-only
|
||||
*
|
||||
* Copyright (C) 2021-2025 sirpdboy <herboy2008@gmail.com> https://github.com/sirpdboy/luci-app-netdata
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { access, popen } from 'fs';
|
||||
|
||||
function get_netdata_version() {
|
||||
if (!access('/usr/sbin/netdata'))
|
||||
return null;
|
||||
|
||||
const fd = popen("a=`/usr/sbin/netdata -v`&&echo $a |awk -F v '{printf $2}'");
|
||||
if (fd) {
|
||||
let output = trim(fd.read('all'));
|
||||
fd.close();
|
||||
// 方法1: 简单替换(推荐)
|
||||
let version_with_v = replace(output, "netdata ", "");
|
||||
// 方法2: 去掉 v 前缀
|
||||
let version_clean = replace(version_with_v, "v", "");
|
||||
return version_with_v; // 返回 "v2.3.2"
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
const methods = {
|
||||
get_version: {
|
||||
call: function() {
|
||||
let version = get_netdata_version();
|
||||
if (!version)
|
||||
return { version: null, error: '无法获取 netdata 版本' };
|
||||
|
||||
return { version: version };
|
||||
}
|
||||
},
|
||||
|
||||
get_version_clean: {
|
||||
call: function() {
|
||||
let version = get_netdata_version();
|
||||
if (!version)
|
||||
return { version: null, error: '无法获取 netdata 版本' };
|
||||
|
||||
// 去掉 "v" 前缀,返回纯数字版本
|
||||
let clean_version = replace(version, /^v/, "");
|
||||
return { version: clean_version };
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return { 'luci.netdata': methods };
|
||||
Reference in new issue
Block a user