Skip to content

Commit

Permalink
grafana ok
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Dec 9, 2024
1 parent b630ff0 commit 053c86f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
results, and can trigger alerts when specified conditions are observed.
</desc>
<version>2.54.0</version>
<user>prometheus</user>
<user>lhp</user>

<components>
<component>
Expand Down
5 changes: 5 additions & 0 deletions bigtop-manager-stack/bigtop-manager-stack-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,10 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public Map<String, T> getSPIMap() {

private void resolveConflict(T newSPI) {
T oldSPI = map.get(newSPI.getName());
log.info(String.valueOf(oldSPI.getPriority()));
log.info(String.valueOf(oldSPI.getName()));
log.info(String.valueOf(newSPI.getName()));

if (newSPI.compareTo(oldSPI.getPriority()) == 0) {
throw new IllegalArgumentException(String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public String dataDir() {

@Override
public String getServiceName() {
return "prometheus";
return "grafana";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.bigtop.manager.stack.infra.v1_0_0.grafana;

import lombok.extern.slf4j.Slf4j;
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;
Expand All @@ -31,6 +32,7 @@
import java.util.Properties;

@AutoService(Script.class)
@Slf4j
public class GrafanaServerScript extends AbstractServerScript {

@Override
Expand All @@ -49,14 +51,15 @@ public ShellResult configure(Params params) {
@Override
public ShellResult start(Params params) {
configure(params);
GrafanaParams prometheusParams = (GrafanaParams) params;
GrafanaParams grafanaParams = (GrafanaParams) params;
String cmd = MessageFormat.format(
"nohup {0}/prometheus --config.file={0}/prometheus.yml --storage.tsdb.path={0}/data > {0}/nohup.out 2>&1 &",
prometheusParams.serviceHome());
"nohup {0}/bin/grafana server --config {0}/conf/defaults.ini --homepath {0} > {0}/nohup.out 2>&1 &",
grafanaParams.serviceHome());
log.info(cmd);
try {
ShellResult shellResult = LinuxOSUtils.sudoExecCmd(cmd, prometheusParams.user());
ShellResult shellResult = LinuxOSUtils.sudoExecCmd(cmd, grafanaParams.user());
if (shellResult.getExitCode() != 0) {
throw new StackException("Failed to start Prometheus: {0}", shellResult.getErrMsg());
throw new StackException("Failed to start Grafana: {0}", shellResult.getErrMsg());
}
long startTime = System.currentTimeMillis();
long maxWaitTime = 5000;
Expand All @@ -77,25 +80,26 @@ public ShellResult start(Params params) {

@Override
public ShellResult stop(Params params) {
GrafanaParams prometheusParams = (GrafanaParams) params;
String cmd = MessageFormat.format("pkill -f {0}/prometheus", prometheusParams.serviceHome());
GrafanaParams grafanaParams = (GrafanaParams) params;
String cmd = MessageFormat.format("pkill -f {0}/bin/grafana", grafanaParams.serviceHome());
try {
return LinuxOSUtils.sudoExecCmd(cmd, prometheusParams.user());
return LinuxOSUtils.sudoExecCmd(cmd, grafanaParams.user());
} catch (Exception e) {
throw new StackException(e);
}
}

@Override
public ShellResult status(Params params) {
GrafanaParams prometheusParams = (GrafanaParams) params;
String cmd = MessageFormat.format("pgrep -f {0}/prometheus", prometheusParams.serviceHome());
GrafanaParams grafanaParams = (GrafanaParams) params;
String cmd = MessageFormat.format("pgrep -f {0}/bin/grafana", grafanaParams.serviceHome());
log.info(cmd);
try {
ShellResult result = LinuxOSUtils.execCmd(cmd);
if (result.getExitCode() == 0) {
return ShellResult.success();
} else {
return new ShellResult(-1, "", "Prometheus is not running");
return new ShellResult(-1, "", "Grafana is not running");
}
} catch (Exception e) {
throw new StackException(e);
Expand All @@ -104,6 +108,6 @@ public ShellResult status(Params params) {

@Override
public String getComponentName() {
return "prometheus_server";
return "grafana_server";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.bigtop.manager.stack.infra.v1_0_0.prometheus;

import lombok.extern.slf4j.Slf4j;
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;
Expand All @@ -31,6 +32,7 @@
import java.util.Properties;

@AutoService(Script.class)
@Slf4j
public class PrometheusServerScript extends AbstractServerScript {

@Override
Expand All @@ -53,6 +55,7 @@ public ShellResult start(Params params) {
String cmd = MessageFormat.format(
"nohup {0}/prometheus --config.file={0}/prometheus.yml --storage.tsdb.path={0}/data > {0}/nohup.out 2>&1 &",
prometheusParams.serviceHome());
log.info(cmd);
try {
ShellResult shellResult = LinuxOSUtils.sudoExecCmd(cmd, prometheusParams.user());
if (shellResult.getExitCode() != 0) {
Expand Down

0 comments on commit 053c86f

Please sign in to comment.