Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user mode updates for victoria metrics mode #135

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions omnistat/omni_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ def __init__(self):
self.scrape_interval = 30 # default scrape interval in seconds
self.timeout = 5 # default scrape timeout in seconds
self.__hosts = None
self.__RMS_Detected = False

def setup(self, configFileArgument):
self.configFile = utils.findConfigFile(configFileArgument)
self.runtimeConfig = utils.readConfig(self.configFile)
self.rmsDetection()
self.getRMSHosts()

# Path to Omnistat's executable scripts. For source deployments, this
# is the top directory of a working copy of Omnistat. For package
Expand All @@ -73,13 +72,21 @@ def setMonitoringInterval(self, interval):

def rmsDetection(self):
"""Query environment to infer resource manager"""

if self.__RMS_Detected:
return

if "SLURM_JOB_NODELIST" in os.environ:
self.__rms = "slurm"
elif "FLUX_URI" in os.environ:
self.__rms = "flux"
else:
utils.error("Unknown/unsupported resource manager")
logging.info("RMS detected = %s" % self.__rms)

self.getRMSHosts()
self.__RMS_Detected = True

return

def getRMSHosts(self):
Expand Down Expand Up @@ -126,7 +133,13 @@ def startVictoriaServer(self):
vm_logfile = self.runtimeConfig[section].get("victoria_logfile", "victoria_server.log")
vm_corebinding = self.runtimeConfig[section].getint("victoria_corebinding", None)

command = [vm_binary, "--storageDataPath=%s" % vm_datadir, "-memory.allowedPercent=10"]
command = [
vm_binary,
"--storageDataPath=%s" % vm_datadir,
"-memory.allowedPercent=10",
"-retentionPeriod=10y",
"-httpListenAddr=:9090",
]
envAddition = {}
# restrict thread usage
envAddition["GOMAXPROCS"] = "4"
Expand All @@ -146,6 +159,8 @@ def startPromServer(self, victoriaMode=False):
self.startVictoriaServer()
return

self.rmsDetection()

logging.info("Starting prometheus server on localhost")
if self.scrape_interval >= 1:
scrape_interval = "%ss" % int(self.scrape_interval)
Expand Down Expand Up @@ -187,14 +202,6 @@ def startPromServer(self, victoriaMode=False):
"static_configs": [computes],
}
)
# if remoteWrite:
# auth = {
# "username": remoteWriteConfig["auth_user"],
# "password": remoteWriteConfig["auth_cred"],
# }

# prom_config["remote_write"] = []
# prom_config["remote_write"].append({"url": remoteWriteConfig["url"], "basic_auth": auth})

with open("prometheus.yml", "w") as yaml_file:
yaml.dump(prom_config, yaml_file, sort_keys=False)
Expand Down Expand Up @@ -238,6 +245,8 @@ def startExporters(self, victoriaMode=False):
ssh_key = self.runtimeConfig["omnistat.usermode"].get("ssh_key", "~/.ssh/id_rsa")
corebinding = self.runtimeConfig["omnistat.usermode"].getint("exporter_corebinding", None)

self.rmsDetection()

if victoriaMode:
if os.path.exists("./exporter.log"):
os.remove("./exporter.log")
Expand Down Expand Up @@ -349,7 +358,7 @@ def startExporters(self, victoriaMode=False):
return

def stopExporters(self, victoriaMode=False):

self.rmsDetection()
port = self.runtimeConfig["omnistat.collectors"].get("port", "8001")
for host in self.__hosts:
logging.info("Stopping exporter for host -> %s" % host)
Expand Down
3 changes: 1 addition & 2 deletions omnistat/standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ def polling(self, monitor, interval_secs):
logging.info("Previous metric push is still running - blocking till complete.")
push_thread.join()
logging.info("Resuming after previous metric push complete.")

try:
push_start_time = time.perf_counter()
dataToPush = self.__dataVM
Expand Down Expand Up @@ -256,7 +255,7 @@ def parse_args():
parser.add_argument("--interval", type=float, help="sampling frequency (in secs)", default=0.5)
parser.add_argument("--logfile", type=str, help="redirect stdout to logfile", default=None)
parser.add_argument("--endpoint", type=str, help="hostname of VictoriaMetrics server", default="localhost")
parser.add_argument("--port", type=int, help="port to access VictoriaMetrics server", default=8428)
parser.add_argument("--port", type=int, help="port to access VictoriaMetrics server", default=9090)

return parser.parse_args()

Expand Down