Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Dec 24, 2024
1 parent 9c186c2 commit ca61706
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public class PrometheusParams extends InfraParams {
private List<Map<String, Object>> scrapeJobs;
private String prometheusPort;
private String prometheusContent;
private String prometheusScrapeInterval;
private String prometheusRulesFilename;
private String prometheusRulesFileContent;

Expand All @@ -60,18 +59,13 @@ public PrometheusParams(CommandPayload commandPayload) {
scrapeJobs.add(prometheusScrapeJob);
scrapeJobs.add(agentScrapeJob);
globalParamsMap.put("scrape_jobs", scrapeJobs);
globalParamsMap.put("scrape_interval", prometheusScrapeInterval);
globalParamsMap.put("rules_file_name", prometheusRulesFilename);
}

public String dataDir() {
return MessageFormat.format("{0}/data", serviceHome());
}

public String confDir() {
return MessageFormat.format("{0}", serviceHome());
}

public String targetsConfigFile(String jobName) {
return MessageFormat.format("{0}/{1}_targets.json", confDir(), jobName);
}
Expand All @@ -92,7 +86,7 @@ protected List<String> getAllHost() {

@GlobalParams
public Map<String, Object> prometheusJob() {
Map<String, Object> configuration = LocalSettings.configurations(getServiceName(), "prometheus-conf");
Map<String, Object> configuration = LocalSettings.configurations(getServiceName(), "prometheus");
prometheusPort = (String) configuration.get("port");
Map<String, Object> job = new HashMap<>();
job.put("name", PROMETHEUS_SELF_JOB_NAME);
Expand All @@ -109,15 +103,14 @@ public Map<String, Object> agentJob() {
job.put("targets_file", targetsConfigFile(BM_AGENT_JOB_NAME));
job.put("targets_list", getAllHost());
agentScrapeJob = job;
return LocalSettings.configurations(getServiceName(), "prometheus-conf");
return LocalSettings.configurations(getServiceName(), "prometheus");
}

@GlobalParams
public Map<String, Object> configs() {
Map<String, Object> configuration = LocalSettings.configurations(getServiceName(), "prometheus-conf");
Map<String, Object> configuration = LocalSettings.configurations(getServiceName(), "prometheus");

prometheusContent = (String) configuration.get("content");
prometheusScrapeInterval = (String) configuration.get("scrape_interval");
return configuration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public ShellResult start(Params params) {
configure(params);
PrometheusParams prometheusParams = (PrometheusParams) params;
String cmd = MessageFormat.format(
"nohup {0}/prometheus --config.file={0}/prometheus.yml --web.listen-address={1} --storage.tsdb.path={0}/data > {0}/nohup.out 2>&1 &",
prometheusParams.serviceHome(), prometheusParams.listenAddress());
"nohup {0}/prometheus --config.file={1}/prometheus.yml --web.listen-address={2} --storage.tsdb.path={0}/data > {0}/nohup.out 2>&1 &",
prometheusParams.serviceHome(), prometheusParams.confDir(), prometheusParams.listenAddress());
try {
ShellResult shellResult = LinuxOSUtils.sudoExecCmd(cmd, prometheusParams.user());
if (shellResult.getExitCode() != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static ShellResult config(Params params) {
String group = prometheusParams.group();

LinuxFileUtils.createDirectories(prometheusParams.dataDir(), user, group, Constants.PERMISSION_755, true);
LinuxFileUtils.createDirectories(prometheusParams.confDir(), user, group, Constants.PERMISSION_755, true);

LinuxFileUtils.toFileByTemplate(
prometheusParams.getPrometheusContent(),
Expand Down

0 comments on commit ca61706

Please sign in to comment.