function system_values() { $unix = new unix(); $CPU_NUMBER = $unix->CPU_NUMBER(); @file_put_contents("/usr/share/artica-postfix/ressources/interface-cache/CPU_NUMBER", $CPU_NUMBER); events("CPU_NUMBER: {$CPU_NUMBER}"); @chmod("/usr/share/artica-postfix/ressources/interface-cache/CPU_NUMBER", 0755); $influxdb_version = influxdb_version(); events("InfluxDB version: {$influxdb_version}"); @file_put_contents("{$GLOBALS["BASEDIR"]}/influxdb_version", $influxdb_version); @chmod("{$GLOBALS["BASEDIR"]}/influxdb_version", 0777); }
function start($aspid = false) { $unix = new unix(); $sock = new sockets(); $Masterbin = "/opt/influxdb/influxd"; if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } if (!is_file($Masterbin)) { Install(); if (!is_file($Masterbin)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, influxdb not installed\n"; } return; } } $pid = PID_NUM(); $SquidPerformance = intval($sock->GET_INFO("SquidPerformance")); @mkdir("/home/artica/squid/InfluxDB", 0755, true); if ($unix->process_exists($pid)) { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($SquidPerformance > 2) { stop(true); } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n"; } return; } if ($SquidPerformance > 2) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Perfomance is set to no statistics\n"; } return; } $php5 = $unix->LOCATE_PHP5_BIN(); $sysctl = $unix->find_program("sysctl"); $echo = $unix->find_program("echo"); $nohup = $unix->find_program("nohup"); if (!is_dir("/var/log/influxdb")) { @mkdir("/var/log/influxdb", 0755, true); } $influxdb_version = influxdb_version(); Config($influxdb_version); if (preg_match("#^0\\.9#", $influxdb_version)) { $f[] = "{$Masterbin} run -config=/etc/opt/influxdb/influxdb.conf"; $f[] = "-pidfile=/var/run/influxdb.pid"; } if (preg_match("#^0\\.8#", $influxdb_version)) { $f[] = "{$Masterbin} -config=/etc/opt/influxdb/influxdb.conf"; $f[] = "-pidfile=/var/run/influxdb.pid"; } $cmd = @implode(" ", $f) . " >/dev/null 2>&1 &"; if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} v{$influxdb_version} service\n"; } shell_exec($cmd); for ($i = 1; $i < 5; $i++) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n"; } sleep(1); $pid = PID_NUM(); if ($unix->process_exists($pid)) { break; } } $pid = PID_NUM(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success v{$influxdb_version} PID {$pid}\n"; } } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n"; } } }
function Config($influxdb_version = null) { $unix = new unix(); $php = $unix->LOCATE_PHP5_BIN(); $sock = new sockets(); @mkdir("/etc/opt/influxdb", 0755, true); @mkdir("/home/artica/squid/InfluxDB/logs", 0755, true); @mkdir("/home/artica/squid/InfluxDB/raft", 0755, true); @mkdir("/home/artica/squid/InfluxDB/db", 0755, true); $InfluxListenIP = null; $InFluxBackupDatabaseDir = $sock->GET_INFO("InFluxBackupDatabaseDir"); if ($InFluxBackupDatabaseDir == null) { $InFluxBackupDatabaseDir = "/home/artica/influx/backup"; } $InFluxBackupDatabaseMaxContainers = intval("InFluxBackupDatabaseMaxContainers"); if ($InFluxBackupDatabaseMaxContainers == 0) { $InFluxBackupDatabaseMaxContainers = 5; } $InFluxBackupDatabaseInterval = intval("InFluxBackupDatabaseInterval"); if ($InFluxBackupDatabaseInterval == 0) { $InFluxBackupDatabaseInterval = 10080; } if ($InFluxBackupDatabaseInterval < 1440) { $InFluxBackupDatabaseInterval = 1440; } $InfluxListenInterface = $sock->GET_INFO("InfluxListenInterface"); $STATS_APPLIANCE = false; $Intervals[60] = "45 * * * * *"; $Intervals[120] = "45 0,2,4,6,8,10,12,14,16,18,20,22 * * *"; $Intervals[240] = "45 0,4,6,10,14,18,22 * * *"; $Intervals[1440] = "10 1 * * *"; $CRON[] = "MAILTO=\"\""; $CRON[] = "{$Intervals[$InFluxBackupDatabaseInterval]} root {$php} " . __FILE__ . " --backup >/dev/null 2>&1"; $CRON[] = ""; file_put_contents("/etc/cron.d/InfluxBackup", @implode("\n", $CRON)); $CRON = array(); chmod("/etc/cron.d/InfluxBackup", 0640); chown("/etc/cron.d/InfluxBackup", "root"); system("/etc/init.d/cron reload"); if (is_file("/etc/artica-postfix/STATS_APPLIANCE")) { $STATS_APPLIANCE = true; } if ($STATS_APPLIANCE) { if ($InfluxListenInterface == null) { $InfluxListenInterface = "ALL"; } } if ($InfluxListenInterface == null) { $InfluxListenInterface = "lo"; } $influxdb_version = influxdb_version(); if (preg_match("#^([0-9]+)\\.([0-9]+)\\.([0-9]+)#", $influxdb_version, $re)) { $MAJOR = $re[1]; $MINOR = $re[2]; $REV = $re[3]; } $AS_092 = false; $AS_093 = false; if ($MAJOR == 0) { if ($MINOR == 9) { if ($REV == 1) { $AS_092 = true; } if ($REV == 2) { $AS_092 = true; } if ($REV >= 3) { $AS_092 = false; $AS_093 = true; } } } $InfluxListenIP = GetInfluxListenIP(); $InfluxApiIP = $InfluxListenIP; if ($InfluxListenIP == "0.0.0.0") { $InfluxApiIP = "127.0.0.1"; } if ($InfluxListenIP == "127.0.0.1") { $InfluxApiIP = "127.0.0.1"; } $sock->SET_INFO("InfluxApiIP", $InfluxApiIP); $InfluxAdminDisabled = intval($sock->GET_INFO("InfluxAdminDisabled")); $InfluxAdminPort = intval($sock->GET_INFO("InfluxAdminPort")); if ($InfluxAdminPort == 0) { $InfluxAdminPort = 8083; } $unix = new unix(); @mkdir("/home/artica/squid/InfluxDB", 0755, true); @mkdir("/home/artica/squid/InfluxDB/db", 0755, true); @mkdir("/home/artica/squid/InfluxDB/raft", 0755, true); @mkdir("/home/artica/squid/InfluxDB/meta", 0755, true); @mkdir("/home/artica/squid/InfluxDB/hh", 0755, true); $InfluxListenHosname = $InfluxListenIP; if ($InfluxListenHosname == "0.0.0.0") { $InfluxListenHosname = $unix->hostname_g(); } $f[] = "# Created on " . date("Y-m-d H:i:s"); $f[] = "# Welcome to the InfluxDB configuration file."; $f[] = "# Listen interface {$InfluxListenInterface}/{$InfluxListenIP}/{$InfluxApiIP}."; $f[] = ""; $f[] = "# If hostname (on the OS) doesn't return a name that can be resolved by the other"; $f[] = "# systems in the cluster, you'll have to set the hostname to an IP or something"; $f[] = "# that can be resolved here."; $f[] = "hostname = \"{$InfluxListenHosname}\""; $f[] = "bind-address = \"{$InfluxListenIP}\""; $f[] = ""; $f[] = "# The default cluster and API port"; $f[] = "port = 8086"; $f[] = ""; $f[] = "# Once every 24 hours InfluxDB will report anonymous data to m.influxdb.com"; $f[] = "# The data includes raft id (random 8 bytes), os, arch and version"; $f[] = "# We don't track ip addresses of servers reporting. This is only used"; $f[] = "# to track the number of instances running and the versions, which"; $f[] = "# is very helpful for us."; $f[] = "# Change this option to true to disable reporting."; $f[] = "reporting-disabled = true"; $f[] = ""; $f[] = "# Controls settings for initial start-up. Once a node is successfully started,"; $f[] = "# these settings are ignored. If a node is started with the -join flag,"; $f[] = "[initialization]"; $f[] = "join-urls = \"\" # Comma-delimited URLs, in the form http://host:port, for joining another cluster."; $f[] = ""; $f[] = "# Control authentication"; $f[] = "# If not set authetication is DISABLED. Be sure to explicitly set this flag to"; $f[] = "# true if you want authentication."; $f[] = "[authentication]"; $f[] = "enabled = false"; $f[] = ""; $f[] = ""; $f[] = "[meta]"; $f[] = " dir = \"/home/artica/squid/InfluxDB/meta\""; $f[] = " hostname = \"{$InfluxListenHosname}\""; $f[] = " bind-address = \":8089\""; $f[] = " retention-autocreate = true"; $f[] = " election-timeout = \"1s\""; $f[] = " heartbeat-timeout = \"1s\""; $f[] = " leader-lease-timeout = \"500ms\""; $f[] = " commit-timeout = \"50ms\""; $f[] = ""; $f[] = ""; $f[] = "[hinted-handoff]"; $f[] = " enabled = true"; $f[] = " dir = \"/home/artica/squid/InfluxDB/hh\""; $f[] = " max-size = 1073741824"; $f[] = " max-age = \"168h0m0s\""; $f[] = " retry-rate-limit = 0"; $f[] = " retry-interval = \"1s\""; $f[] = ""; $f[] = "# Configure the admin server"; $f[] = "[admin]"; //$f[]="auth-enabled=true"; if ($InfluxAdminDisabled == 0) { $f[] = "enabled = true"; $f[] = "port = {$InfluxAdminPort}"; } else { $f[] = "enabled = false"; $f[] = "#port = {$InfluxAdminPort}"; } $f[] = ""; $f[] = "# Configure the HTTP API endpoint. All time-series data and queries uses this endpoint."; $f[] = "[api]"; $f[] = "# ssl-port = 8087 # SSL support is enabled if you set a port and cert"; $f[] = "# ssl-cert = \"/path/to/cert.pem\""; $f[] = ""; $f[] = "# Configure the Graphite plugins."; $f[] = "[[graphite]] # 1 or more of these sections may be present."; $f[] = "enabled = false"; $f[] = "# protocol = \"\" # Set to \"tcp\" or \"udp\""; $f[] = "# address = \"0.0.0.0\" # If not set, is actually set to bind-address."; $f[] = "# port = 2003"; $f[] = "# name-position = \"last\""; $f[] = "# name-separator = \"-\""; $f[] = "# database = \"\" # store graphite data in this database"; $f[] = ""; $f[] = "# Configure the collectd input."; $f[] = "[collectd]"; $f[] = "enabled = false"; $f[] = "#address = \"0.0.0.0\" # If not set, is actually set to bind-address."; $f[] = "#port = 25827"; $f[] = "#database = \"collectd_database\""; $f[] = "#typesdb = \"types.db\""; $f[] = ""; $f[] = "# Configure the OpenTSDB input."; $f[] = "[opentsdb]"; $f[] = "enabled = false"; $f[] = "#address = \"0.0.0.0\" # If not set, is actually set to bind-address."; $f[] = "#port = 4242"; $f[] = "#database = \"opentsdb_database\""; $f[] = ""; $f[] = "# Configure UDP listener for series data."; if ($AS_093) { $f[] = "[[udp]]"; } else { $f[] = "[udp]"; } $f[] = "enabled = false"; $f[] = "#bind-address = \"0.0.0.0\""; $f[] = "#port = 4444"; $f[] = ""; $f[] = "# Broker configuration. Brokers are nodes which participate in distributed"; $f[] = "# consensus."; $f[] = "[broker]"; $f[] = "enabled = true"; $f[] = "# Where the Raft logs are stored. The user running InfluxDB will need read/write access."; $f[] = "dir = \"/home/artica/squid/InfluxDB/raft\""; $f[] = "truncation-interval = \"10m\""; $f[] = "max-topic-size = 52428800"; $f[] = "max-segment-size = 10485760"; $f[] = ""; $f[] = "# Raft configuration. Controls the distributed consensus system."; $f[] = "[raft]"; $f[] = "apply-interval = \"10ms\""; $f[] = "election-timeout = \"5s\""; $f[] = "heartbeat-interval = \"100ms\""; $f[] = "reconnect-timeout = \"10ms\""; $f[] = ""; $f[] = "# Data node configuration. Data nodes are where the time-series data, in the form of"; $f[] = "# shards, is stored."; $f[] = "[data]"; $f[] = "enabled = true"; $f[] = "dir = \"/home/artica/squid/InfluxDB/db\""; if ($AS_093) { $f[] = "# The following WAL settings are for the b1 storage engine used in 0.9.2. They won't"; $f[] = "# apply to any new shards created after upgrading to a version > 0.9.3."; $f[] = "max-wal-size = 104857600 # Maximum size the WAL can reach before a flush. Defaults to 100MB."; $f[] = "wal-flush-interval = \"10m\" # Maximum time data can sit in WAL before a flush."; $f[] = "wal-partition-flush-delay = \"2s\" # The delay time between each WAL partition being flushed."; $f[] = ""; if (!is_dir("/home/artica/squid/InfluxDB/wal")) { @mkdir("/home/artica/squid/InfluxDB/wal", 0755, true); } $f[] = "# These are the WAL settings for the storage engine >= 0.9.3"; $f[] = "wal-dir = \"/home/artica/squid/InfluxDB/wal\""; $f[] = "wal-enable-logging = true"; $f[] = ""; $f[] = "# When a series in the WAL in-memory cache reaches this size in bytes it is marked as ready to"; $f[] = "# flush to the index"; $f[] = "wal-ready-series-size = 4096"; $f[] = ""; $f[] = "# Flush and compact a partition once this ratio of series are over the ready size"; $f[] = "# wal-compaction-threshold = 0.6"; $f[] = ""; $f[] = "# Force a flush and compaction if any series in a partition gets above this size in bytes"; $f[] = "# wal-max-series-size = 2097152"; $f[] = ""; $f[] = "# Force a flush of all series and full compaction if there have been no writes in this"; $f[] = "# amount of time. This is useful for ensuring that shards that are cold for writes don't"; $f[] = "# keep a bunch of data cached in memory and in the WAL."; $f[] = "# wal-flush-cold-interval = \"10m\""; $f[] = ""; $f[] = "# Force a partition to flush its largest series if it reaches this approximate size in"; $f[] = "# bytes. Remember there are 5 partitions so you'll need at least 5x this amount of memory."; $f[] = "# The more memory you have, the bigger this can be."; $f[] = "wal-partition-size-threshold = 10485760"; } $f[] = ""; $f[] = "# Auto-create a retention policy when a database is created. Defaults to true."; $f[] = "retention-auto-create = true"; $f[] = ""; $f[] = "# Control whether retention policies are enforced and how long the system waits between"; $f[] = "# enforcing those policies."; $f[] = "retention-check-enabled = true"; $f[] = "retention-check-period = \"10m\""; $f[] = ""; $f[] = "# Configuration for snapshot endpoint."; $f[] = "[snapshot]"; $f[] = "enabled = true # Enabled by default if not set."; $f[] = ""; $f[] = "[logging]"; $f[] = "write-tracing = false # If true, enables detailed logging of the write system."; $f[] = "raft-tracing = false # If true, enables detailed logging of Raft consensus."; $f[] = "http-access = false # If true, logs each HTTP access to the system."; $f[] = ""; $f[] = "# InfluxDB can store statistical and diagnostic information about itself. This is useful for"; $f[] = "# monitoring purposes. This feature is disabled by default, but if enabled, these data can be"; $f[] = "# queried like any other data."; $f[] = "[monitoring]"; $f[] = "enabled = false"; $f[] = "write-interval = \"1m\" # Period between writing the data.\n"; if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Saving settings in 0.9x mode\n"; } build_progress_rs("{starting_service} {configuration_done}", 40); @file_put_contents("/etc/opt/influxdb/influxdb.conf", @implode("\n", $f)); }