Skip to content

Commit

Permalink
remove folder
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Jan 7, 2025
1 parent 2c9f024 commit d12f9fd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ providers:
},
"includeAll": false,
"name": "datasource",
"label": "Datasource",
"options": [],
"query": "prometheus",
"refresh": 1,
Expand All @@ -843,17 +844,17 @@ providers:
"type": "prometheus",
"uid": "uid4prometheus"
},
"type": "custom",
"type": "query",
"name": "${cluster_label}",
"label": "Cluster",
"options": [],
"query": "${cluster_name}",
"query": "label_values(${cluster_label})",
"refresh": 2,
"multi": false,
"includeAll": false,
"current": {
"text": "${cluster_name}",
"value": "${cluster_name}"
"text": "${default_cluster_name}",
"value": "${default_cluster_name}"
}
},
{
Expand All @@ -863,6 +864,7 @@ providers:
},
"includeAll": false,
"name": "resolution",
"label": "Resolution",
"options": [
{
"selected": false,
Expand Down Expand Up @@ -901,8 +903,8 @@ providers:
},
"timepicker": {},
"timezone": "",
"title": "${cluster_name}",
"uid": "dbuid_${cluster_name}",
"title": "${dashboard_name}",
"uid": "dbuid_${dashboard_name}",
"version": 4,
"weekStart": ""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class GrafanaParams extends InfraParams {
private String prometheusServer;
private String prometheusPort;

List<Map<String, Object>> dashboards;
private List<Map<String, Object>> dashboards;

public GrafanaParams(CommandPayload commandPayload) {
super(commandPayload);
Expand Down Expand Up @@ -83,8 +83,8 @@ public String dashboardsDir() {
return MessageFormat.format("{0}/dashboards", provisioningDir());
}

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

@GlobalParams
Expand Down Expand Up @@ -135,25 +135,27 @@ public String getServiceName() {
}

public List<String> getClusters() {
if (getClusterHosts() == null) {
return new ArrayList<>();
}
return new ArrayList<>(getClusterHosts().keySet());
}

// TODO: add host dashboard
public void setDashboards() {
dashboards = new ArrayList<>();
if (getClusterHosts() == null) {
return;
}
for (String cluster : getClusters()) {
Map<String, Object> dashboard = new HashMap<>();
// Used for dashboard yaml configuration
dashboard.put("name", cluster);
dashboard.put("folder", cluster);
dashboard.put("path", dashboardConfigDir(cluster));

// Used for dashboard json configuration
dashboard.put("cluster_label", PrometheusParams.AGENT_TARGET_LABEL);
dashboard.put("cluster_name", cluster);
dashboards.add(dashboard);
}

Map<String, Object> clusterDashboard = new HashMap<>();
// Used for dashboard yaml configuration
clusterDashboard.put("name", "Cluster");
clusterDashboard.put("folder", "Cluster");
clusterDashboard.put("path", dashboardConfigDir("Cluster"));

// Used for dashboard json configuration
clusterDashboard.put("cluster_label", PrometheusParams.AGENT_TARGET_LABEL);
clusterDashboard.put("default_cluster_name", getClusters().get(0));
clusterDashboard.put("dashboard_name", "Cluster");

dashboards.add(clusterDashboard);
}
}

0 comments on commit d12f9fd

Please sign in to comment.