Merge pull request #130 from weideng1/master

fixed a number of bugs with docker-metrics on Mac
This commit is contained in:
Jonathan Shook 2020-05-01 12:45:29 -05:00 committed by GitHub
commit c4b054a1e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 9 deletions

View File

@ -186,11 +186,9 @@ public class NBCLI {
logger.info("Docker metrics is enabled. Docker must be installed for this to work");
DockerMetricsManager dmh = new DockerMetricsManager();
dmh.startMetrics();
String info = "Docker Containers are started, for grafana and prometheus, hit" +
"these urls in your browser: http://<host>:3000 and http://<host>:9090" +
"the default grafana creds are admin/admin";
logger.info(info);
System.out.println(info);
String warn = "Docker Containers are started, for grafana and prometheus, hit" +
"these urls in your browser: http://<host>:3000 and http://<host>:9090";
logger.warn(warn);
if (reportGraphiteTo != null) {
logger.warn(String.format("Docker metrics are enabled (--docker-metrics)" +
" but graphite reporting (--report-graphite-to) is set to %s \n" +

View File

@ -213,7 +213,11 @@ public class DockerHelper {
logger.info(String.format("Hupping config"));
if (reload != null) {
post(reload, null, false, "reloading config");
try {
post(reload, null, false, "reloading config");
} catch (Exception e) {
logger.error(String.format("Unexpected config/state for docker container %s, consider removing the container", name));
}
}
return runningContainers.get(0);

View File

@ -54,7 +54,10 @@ public class DockerMetricsManager {
String name = "grafana";
List<Integer> port = Arrays.asList(3000);
setupGrafanaFiles(ip);
boolean grafanaFilesExist = grafanaFilesExist();
if (!grafanaFilesExist) {
setupGrafanaFiles(ip);
}
List<String> volumeDescList = Arrays.asList(
userHome + "/.nosqlbench/grafana:/var/lib/grafana:rw"
@ -80,7 +83,9 @@ public class DockerMetricsManager {
logger.info("grafana container started, http listening");
configureGrafana();
if (!grafanaFilesExist) {
configureGrafana();
}
}
private void startPrometheus(String ip) {
@ -91,7 +96,9 @@ public class DockerMetricsManager {
String name = "prom";
List<Integer> port = Arrays.asList(9090);
setupPromFiles(ip);
if (!promFilesExist()) {
setupPromFiles(ip);
}
List<String> volumeDescList = Arrays.asList(
//cwd+"/docker-metrics/prometheus:/prometheus",
@ -170,6 +177,9 @@ public class DockerMetricsManager {
"/prometheus");
Set<PosixFilePermission> perms = new HashSet<>();
perms.add(PosixFilePermission.OWNER_READ);
perms.add(PosixFilePermission.OWNER_WRITE);
perms.add(PosixFilePermission.OWNER_EXECUTE);
perms.add(PosixFilePermission.OTHERS_READ);
perms.add(PosixFilePermission.OTHERS_WRITE);
perms.add(PosixFilePermission.OTHERS_EXECUTE);
@ -215,6 +225,24 @@ public class DockerMetricsManager {
}
}
private boolean grafanaFilesExist() {
File nosqlbenchDir = new File(userHome, "/.nosqlbench/");
boolean exists = nosqlbenchDir.exists();
if (exists) {
File grafana = new File(userHome, "/.nosqlbench/grafana");
exists = grafana.exists();
}
return exists;
}
private boolean promFilesExist() {
File nosqlbenchDir = new File(userHome, "/.nosqlbench/");
boolean exists = nosqlbenchDir.exists();
if (exists) {
File prom = new File(userHome, "/.nosqlbench/grafana");
exists = prom.exists();
}
return exists;
}
private void setupGrafanaFiles(String ip) {
@ -243,6 +271,7 @@ public class DockerMetricsManager {
private void configureGrafana() {
post("http://localhost:3000/api/dashboards/db", "docker/dashboards/analysis.json", true, "load analysis dashboard");
post("http://localhost:3000/api/datasources", "docker/datasources/prometheus-datasource.yaml", true, "configure data source");
logger.warn("default grafana creds are admin/admin");
}