Skip to content

Commit

Permalink
Renamed to prometheusPort to prometheusBotPort, and added prometheusP…
Browse files Browse the repository at this point in the history
…ort.

prometheusBotPort is the port where the bot runs on
prometheusPort is the port where prometheus runs on
  • Loading branch information
Tais993 committed Mar 11, 2022
1 parent 1aed9af commit 5368e29
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
14 changes: 6 additions & 8 deletions src/main/java/nl/tijsbeek/Application.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package nl.tijsbeek;

import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.utils.MemberCachePolicy;
import nl.tijsbeek.config.Config;
import nl.tijsbeek.discord.components.ComponentDatabase;
import nl.tijsbeek.discord.system.CommandHandler;
Expand Down Expand Up @@ -53,12 +51,12 @@ public static void main(@NotNull final String @NotNull [] args) throws LoginExce

MetricsHandler matricsHandler = new MetricsHandler(commandHandler, config);

JDABuilder.create(config.getDiscordToken(), eventHandler.getGatewayIntents())
.enableIntents(GatewayIntent.GUILD_MEMBERS)
.enableCache(eventHandler.getCacheFlags())
.setMemberCachePolicy(MemberCachePolicy.NONE)
.addEventListeners(commandHandler, eventHandler, matricsHandler)
.build();
// JDABuilder.create(config.getDiscordToken(), eventHandler.getGatewayIntents())
// .enableIntents(GatewayIntent.GUILD_MEMBERS)
// .enableCache(eventHandler.getCacheFlags())
// .setMemberCachePolicy(MemberCachePolicy.NONE)
// .addEventListeners(commandHandler, eventHandler, matricsHandler)
// .build();


try {
Expand Down
22 changes: 12 additions & 10 deletions src/main/java/nl/tijsbeek/grafana/GrafanaSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,28 @@ public final class GrafanaSetup {
public GrafanaSetup(@NotNull final CommandHandler commandHandler, @NotNull final Config config) throws IOException, InterruptedException {
this.config = config;

generateDatasource();
generateDashboard(commandHandler);




}

private HttpRequest.Builder generateRequest(String apiUrl) {
private HttpRequest.Builder generateRequest() {
return HttpRequest.newBuilder()
.uri(URI.create("http://localhost:" + config.getGrafanaPort() + apiUrl))
.uri(URI.create("http://localhost:" + config.getGrafanaPort() + "/api/datasources/name/Discord bot"))
.setHeader("Content-Type", "application/json")
.setHeader("Authorization", "Bearer " + config.getGrafanaKey());
}


private void generateDatasource() throws IOException, InterruptedException {
String dataSource = getResourceAsString("datasource.json");
String commandTypeRow = getResourceAsString("datasource.json");

dataSource = dataSource.replace("{{DATA-SOURCE-NAME}}", dataSourceUid);
dataSource = dataSource.replace("{{PROMETHEUS-PORT}}", config.getPrometheusPort());
commandTypeRow = commandTypeRow.replace("{{DATA-SOURCE-NAME}}", dataSourceUid);
commandTypeRow = commandTypeRow.replace("{{PROMETHEUS-PORT}}", config.getPrometheusPort());

HttpRequest request = generateRequest("/api/datasources")
.POST(HttpRequest.BodyPublishers.ofString(dataSource))
HttpRequest request = generateRequest()
.GET()
.build();

System.out.println(httpClient.send(request, HttpResponse.BodyHandlers.ofString())
Expand All @@ -72,7 +74,7 @@ private void generateDashboard(@NotNull final CommandHandler commandHandler) thr

String fullJson = formatFullJson(rowsSlash + rowsUser + rowsMessage, templateSlash + templateUser + templateMessage);

HttpRequest request = generateRequest("/api/dashboards/db")
HttpRequest request = generateRequest()
.POST(HttpRequest.BodyPublishers.ofString(fullJson))
.build();

Expand Down
25 changes: 17 additions & 8 deletions src/main/resources/grafana/datasource.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
{
"uid": "{{DATA-SOURCE-NAME}}",
"name":"Discord-bot",
"type":"prometheus",
"access":"proxy",
"url":"http://localhost:{{PROMETHEUS-PORT}}",
"name": "Discord-bot",
"type": "prometheus",
"typeLogoUrl": "",
"access": "proxy",
"url": "http://localhost:{{PROMETHEUS-PORT}}",
"password": "",
"user": "",
"database": "",
"basicAuth": false,
"basicAuthUser": "",
"basicAuthPassword": "",
"withCredentials": false,
"isDefault": true,
"jsonData": {
"httpMethod": "POST",
"timeInterval": "5s"
"exemplarTraceIdDestinations": [],
"httpMethod": "POST"
},
"basicAuth":false,
"overwrite": true
"secureJsonFields": {},
"readOnly": false
}

0 comments on commit 5368e29

Please sign in to comment.