diff --git a/tcp-proxy/Makefile b/tcp-proxy/Makefile index 62f2cb2c9..f98a927b0 100644 --- a/tcp-proxy/Makefile +++ b/tcp-proxy/Makefile @@ -1,9 +1,10 @@ CXX=$(shell which clang++ g++ c++ 2>/dev/null | head -n 1) -INCLUDES?=-isystem ../ext/prometheus-cpp-lite-1.0/core/include -isystem ../ext/prometheus-cpp-lite-1.0/simpleapi/include +INCLUDES?=-isystem ../ext/prometheus-cpp-lite-1.0/core/include -isystem ../ext/prometheus-cpp-lite-1.0/simpleapi/include -isystem ../ext/ OBJS=Metrics.o \ - ../node/Metrics.o + ../node/Metrics.o \ + ../osdep/OSUtils.o CXXFLAGS=-O3 -fno-rtti $(INCLUDES) -std=c++17 -pthread -frtti diff --git a/tcp-proxy/tcp-proxy.cpp b/tcp-proxy/tcp-proxy.cpp index 31fda7507..770ee02b2 100644 --- a/tcp-proxy/tcp-proxy.cpp +++ b/tcp-proxy/tcp-proxy.cpp @@ -42,12 +42,15 @@ #include #include "../osdep/Phy.hpp" +#include "../osdep/OSUtils.hpp" #include "Metrics.hpp" #define ZT_TCP_PROXY_CONNECTION_TIMEOUT_SECONDS 300 #define ZT_TCP_PROXY_TCP_PORT 443 +#define HOMEDIR "/var/lib/zt-tcp-proxy" + using namespace ZeroTier; /* @@ -300,6 +303,17 @@ int main(int argc,char **argv) signal(SIGHUP,SIG_IGN); srand(time((time_t *)0)); + if (!OSUtils::fileExists(HOMEDIR)) { + if (!OSUtils::mkdir(HOMEDIR)) { + fprintf(stderr,"%s: fatal error: unable to create %s\n",argv[0],HOMEDIR); + return 1; + } + } + + prometheus::simpleapi::saver.set_registry(prometheus::simpleapi::registry_ptr); + prometheus::simpleapi::saver.set_delay(std::chrono::seconds(5)); + prometheus::simpleapi::saver.set_out_file(HOMEDIR "/metrics.json"); + TcpProxyService svc; Phy phy(&svc,false,true); svc.phy = &phy;