This commit is contained in:
dami
2025-08-02 19:34:25 +08:00
parent 45e35c4396
commit 0478356ea5
2 changed files with 21 additions and 14 deletions
+7 -7
View File
@@ -84,7 +84,7 @@ def getPidFile():
return tmp.groups()[0].strip()
def status():
cmd = "ps aux|grep grafana |grep -v grep | grep -v python | grep -v mdserver-web | awk '{print $2}'"
cmd = "ps aux|grep prometheus |grep -v grep | grep -v python | grep -v mdserver-web | awk '{print $2}'"
data = mw.execShell(cmd)
if data[0] == '':
return 'stop'
@@ -105,7 +105,7 @@ def contentReplace(content):
def openPort():
try:
from utils.firewall import Firewall as MwFirewall
MwFirewall.instance().addAcceptPort('3000', 'grafana', 'port')
MwFirewall.instance().addAcceptPort('3000', 'prometheus', 'port')
return port
except Exception as e:
return "Release failed {}".format(e)
@@ -116,7 +116,7 @@ def initDreplace():
# 初始化OP配置
init_file = getServerDir() + '/init.pl'
if not os.path.exists(init_file):
openPort()
# openPort()
mw.writeFile(init_file, 'ok')
# systemd
@@ -160,7 +160,7 @@ def initdStatus():
if current_os == 'darwin':
return "Apple Computer does not support"
shell_cmd = 'systemctl status grafana|grep loaded|grep "enabled;"'
shell_cmd = 'systemctl status prometheus|grep loaded|grep "enabled;"'
data = mw.execShell(shell_cmd)
if data[0] == '':
return 'fail'
@@ -172,7 +172,7 @@ def initdInstall():
if current_os == 'darwin':
return "Apple Computer does not support"
data = mw.execShell('systemctl enable grafana')
data = mw.execShell('systemctl enable prometheus')
if data[1] != '':
return data[1]
return 'ok'
@@ -183,13 +183,13 @@ def initdUinstall():
if current_os == 'darwin':
return "Apple Computer does not support"
data = mw.execShell('systemctl disable grafana')
data = mw.execShell('systemctl disable prometheus')
if data[1] != '':
return data[1]
return 'ok'
def runLog():
return getServerDir() + "/data/log/grafana.log"
return getServerDir() + "/data/log/prometheus.log"
def grafanaUrl():
ip = mw.getLocalIp()
@@ -1,13 +1,20 @@
[Unit]
Description=Grafana instance
Documentation=http://docs.grafana.org
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=grafana
Group=grafana
Restart=on-failure
ExecStart={$SERVER_PATH}/bin/grafana server --config={$SERVER_PATH}/grafana/conf/defa.defaults --homepath={$SERVER_PATH}/grafana
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP $MAINPID
ExecStart={$SERVER_PATH}/prometheus/prometheus \
--config.file={$SERVER_PATH}/prometheus/prometheus.yml \
--storage.tsdb.path={$SERVER_PATH}/prometheus/data \
--web.console.templates={$SERVER_PATH}/prometheus/consoles \
--web.console.libraries={$SERVER_PATH}/prometheus/console_libraries \
--web.listen-address=0.0.0.0:9090
SyslogIdentifier=prometheus
Restart=always
[Install]
WantedBy=multi-user.target