Skip to content

Commit

Permalink
add clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Jan 3, 2025
1 parent 608e9a3 commit 88e1d21
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ apiVersion: 1
providers:
<#if prometheus_url??>
- name: 'Prometheus Dashboards'
<#list db as dashboards>
- name: '${db.name}'
orgId: 1
folder: ''
folder: '${db.folder}'
type: file
options:
path: '${prometheus_dashboard_path}'
path: '${db.path}'
</#if>
]]>
</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import lombok.extern.slf4j.Slf4j;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -49,6 +51,8 @@ public class GrafanaParams extends InfraParams {
private String prometheusServer;
private String prometheusPort;

List<Map<String, Object>> dashboards;

public GrafanaParams(CommandPayload commandPayload) {
super(commandPayload);
globalParamsMap.put("port", grafanaPort);
Expand All @@ -57,7 +61,8 @@ public GrafanaParams(CommandPayload commandPayload) {
if (prometheusServer != null) {
globalParamsMap.put(
"prometheus_url", MessageFormat.format("http://{0}:{1}", prometheusServer, prometheusPort));
globalParamsMap.put("prometheus_dashboard_path", prometheusDashboardPath);

globalParamsMap.put("dashboards", dashboards);
}
}

Expand All @@ -81,6 +86,15 @@ public String dashboardsDir() {
return MessageFormat.format("{0}/dashboards", provisioningDir());
}

public String dashboardConfigDir(String cluster) {
return MessageFormat.format("{0}/{1}", dashboardsDir(), cluster);
}

/// TODO
public List<String> getClusters() {
return List.of("ALL");
}

@GlobalParams
public Map<String, Object> configs() {
Map<String, Object> configuration = LocalSettings.configurations(getServiceName(), "grafana");
Expand Down Expand Up @@ -115,11 +129,20 @@ public Map<String, Object> prometheus() {
}

@GlobalParams
public Map<String, Object> dashboard() {
public Map<String, Object> dashboards() {
Map<String, Object> configuration = LocalSettings.configurations(getServiceName(), "grafana-dashboard");
grafanaDashboardContent = (String) configuration.get("content");
bmAgentDashboardConfig = (String) configuration.get("bm_agent_dashboard");
prometheusDashboardPath = MessageFormat.format("{0}/prometheus", dashboardsDir());

dashboards = new ArrayList<>();
for (String cluster : getClusters()) {
Map<String, Object> dashboard = new HashMap<>();
dashboard.put("name", cluster);
dashboard.put("folder", cluster);
dashboard.put("path", dashboardConfigDir(cluster));
dashboards.add(dashboard);
}
return configuration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.bigtop.manager.common.constants.Constants;
import org.apache.bigtop.manager.common.shell.ShellResult;
import org.apache.bigtop.manager.stack.core.exception.StackException;
import org.apache.bigtop.manager.stack.core.spi.param.Params;
import org.apache.bigtop.manager.stack.core.utils.linux.LinuxFileUtils;

Expand All @@ -28,6 +29,7 @@
import lombok.extern.slf4j.Slf4j;

import java.text.MessageFormat;
import java.util.Map;

@Slf4j
@NoArgsConstructor(access = AccessLevel.PRIVATE)
Expand Down Expand Up @@ -60,22 +62,28 @@ public static ShellResult config(Params params) {

LinuxFileUtils.toFileByTemplate(
grafanaParams.getGrafanaDashboardContent(),
MessageFormat.format("{0}/prometheus.yaml", grafanaParams.dashboardsDir()),
MessageFormat.format("{0}/bm-dashboards.yaml", grafanaParams.dashboardsDir()),
user,
group,
Constants.PERMISSION_644,
grafanaParams.getGlobalParamsMap());

LinuxFileUtils.createDirectories(
grafanaParams.getPrometheusDashboardPath(), user, group, Constants.PERMISSION_755, true);
for (Map<String, Object> dashboard : grafanaParams.getDashboards()) {
String confPath = (String) dashboard.get("path");
if (confPath == null) {
throw new StackException("Dashboard path is not set");
}

LinuxFileUtils.toFileByTemplate(
grafanaParams.getBmAgentDashboardConfig(),
MessageFormat.format("{0}/bm-agent.json", grafanaParams.getPrometheusDashboardPath()),
user,
group,
Constants.PERMISSION_644,
grafanaParams.getGlobalParamsMap());
LinuxFileUtils.createDirectories(confPath, user, group, Constants.PERMISSION_755, true);

LinuxFileUtils.toFileByTemplate(
grafanaParams.getBmAgentDashboardConfig(),
MessageFormat.format("{0}/{1}.json", confPath, dashboard.get("name")),
user,
group,
Constants.PERMISSION_644,
grafanaParams.getGlobalParamsMap());
}
}

return ShellResult.success("Grafana Configure success!");
Expand Down

0 comments on commit 88e1d21

Please sign in to comment.