generated from openplotter/openplotter-myapp
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinstallInfluxdb2.py
More file actions
71 lines (63 loc) · 2.51 KB
/
installInfluxdb2.py
File metadata and controls
71 lines (63 loc) · 2.51 KB
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
#!/usr/bin/env python3
# This file is part of Openplotter.
# Copyright (C) 2019 by Sailoog <https://github.com/openplotter/openplotter-dashboards>
#
# Openplotter is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# any later version.
# Openplotter is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Openplotter. If not, see <http://www.gnu.org/licenses/>.
import os, subprocess, sys
from openplotterSettings import conf
from openplotterSettings import language
def main():
conf2 = conf.Conf()
currentdir = os.path.dirname(os.path.abspath(__file__))
currentLanguage = conf2.get('GENERAL', 'lang')
language.Language(currentdir,'openplotter-dashboards',currentLanguage)
print(_('Checking sources...'))
dist = conf2.get('GENERAL', 'hostID')
try:
deb = 'deb https://repos.influxdata.com/'+dist+' stable main'
sources = subprocess.check_output('apt-cache policy', shell=True).decode(sys.stdin.encoding)
if not 'https://repos.influxdata.com/'+dist in sources:
fo = open('/etc/apt/sources.list.d/influxdb.list', "w")
fo.write(deb)
fo.close()
os.system('cat '+currentdir+'/data/sources/influxdb.gpg.key | gpg --dearmor > "/etc/apt/trusted.gpg.d/influxdb.gpg"')
print(_('DONE'))
except Exception as e: print(_('FAILED: ')+str(e))
print(_('Installing/Updating InfluxDB OSS 2.x...'))
try:
os.system('apt update')
subprocess.call(['apt', 'install', '-y', 'influxdb2', 'telegraf'])
subprocess.call(['systemctl', 'daemon-reload'])
subprocess.call(['systemctl', 'disable', 'telegraf'])
subprocess.call(['systemctl', 'stop', 'telegraf'])
telegrafConf = '''[agent]
interval = "10s"
round_interval = false
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = "2s"
collection_offset = "0s"
flush_interval = "10s"
flush_jitter = "2s"
precision = "1s"
omit_hostname = true'''
fo = open('/etc/telegraf/telegraf.conf', "w")
fo.write(telegrafConf)
fo.close()
subprocess.call(['systemctl', 'enable', 'influxdb'])
subprocess.call(['systemctl', 'restart', 'influxdb'])
print(_('DONE'))
except Exception as e:
print(_('FAILED: ')+str(e))
if __name__ == '__main__':
main()