forked from apache/bigtop-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BIGTOP-4299: Add basic Grafana service (apache#121)
- Loading branch information
Showing
7 changed files
with
307 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...r-server/src/main/resources/stacks/infra/1.0.0/services/grafana/configuration/grafana.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
~ Licensed to the Apache Software Foundation (ASF) under one | ||
~ or more contributor license agreements. See the NOTICE file | ||
~ distributed with this work for additional information | ||
~ regarding copyright ownership. The ASF licenses this file | ||
~ to you under the Apache License, Version 2.0 (the | ||
~ "License"); you may not use this file except in compliance | ||
~ with the License. You may obtain a copy of the License at | ||
~ | ||
~ https://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, | ||
~ software distributed under the License is distributed on an | ||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
~ KIND, either express or implied. See the License for the | ||
~ specific language governing permissions and limitations | ||
~ under the License. | ||
--> | ||
|
||
<configuration> | ||
<property> | ||
<name>content</name> | ||
<description>This is the freemarker template for grafana.ini file</description> | ||
<value><![CDATA[ | ||
# TODO | ||
]]> | ||
</value> | ||
<attrs> | ||
<type>longtext</type> | ||
</attrs> | ||
</property> | ||
</configuration> |
67 changes: 67 additions & 0 deletions
67
bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/grafana/metainfo.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
~ Licensed to the Apache Software Foundation (ASF) under one | ||
~ or more contributor license agreements. See the NOTICE file | ||
~ distributed with this work for additional information | ||
~ regarding copyright ownership. The ASF licenses this file | ||
~ to you under the Apache License, Version 2.0 (the | ||
~ "License"); you may not use this file except in compliance | ||
~ with the License. You may obtain a copy of the License at | ||
~ | ||
~ https://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, | ||
~ software distributed under the License is distributed on an | ||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
~ KIND, either express or implied. See the License for the | ||
~ specific language governing permissions and limitations | ||
~ under the License. | ||
--> | ||
|
||
<metainfo> | ||
<service> | ||
<name>grafana</name> | ||
<display-name>Grafana</display-name> | ||
<desc> | ||
The open and composable observability and data visualization platform. | ||
Visualize metrics, logs, and traces from multiple sources like Prometheus, | ||
Loki, Elasticsearch, InfluxDB, Postgres and many more. | ||
</desc> | ||
<version>11.4.0</version> | ||
<user>grafana</user> | ||
|
||
<components> | ||
<component> | ||
<name>grafana_server</name> | ||
<display-name>Grafana Server</display-name> | ||
<category>server</category> | ||
<cardinality>1+</cardinality> | ||
</component> | ||
</components> | ||
|
||
<package-specifics> | ||
<package-specific> | ||
<architectures> | ||
<arch>x86_64</arch> | ||
</architectures> | ||
<packages> | ||
<package> | ||
<name>grafana-11.4.0.linux-amd64.tar.gz</name> | ||
<checksum>SHA-256:3550c73f4455435642976e82cc89aa354f076a75b766a408781107f4f5d4744c</checksum> | ||
</package> | ||
</packages> | ||
</package-specific> | ||
<package-specific> | ||
<architectures> | ||
<arch>aarch64</arch> | ||
</architectures> | ||
<packages> | ||
<package> | ||
<name>grafana-11.4.0.linux-arm64.tar.gz</name> | ||
<checksum>SHA-256:c978b46a61d92883119131641c03b8a1323a284e74ab9a20e7e48207dc1a11e1</checksum> | ||
</package> | ||
</packages> | ||
</package-specific> | ||
</package-specifics> | ||
</service> | ||
</metainfo> |
1 change: 1 addition & 0 deletions
1
bigtop-manager-server/src/main/resources/stacks/infra/1.0.0/services/grafana/order.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
50 changes: 50 additions & 0 deletions
50
...fra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.bigtop.manager.stack.infra.v1_0_0.grafana; | ||
|
||
import org.apache.bigtop.manager.common.message.entity.payload.CommandPayload; | ||
import org.apache.bigtop.manager.stack.core.spi.param.Params; | ||
import org.apache.bigtop.manager.stack.infra.param.InfraParams; | ||
|
||
import com.google.auto.service.AutoService; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.text.MessageFormat; | ||
|
||
@Getter | ||
@Slf4j | ||
@AutoService(Params.class) | ||
@NoArgsConstructor | ||
public class GrafanaParams extends InfraParams { | ||
|
||
public GrafanaParams(CommandPayload commandPayload) { | ||
super(commandPayload); | ||
} | ||
|
||
public String dataDir() { | ||
return MessageFormat.format("{0}/data", serviceHome()); | ||
} | ||
|
||
@Override | ||
public String getServiceName() { | ||
return "grafana"; | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
...c/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaServerScript.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.bigtop.manager.stack.infra.v1_0_0.grafana; | ||
|
||
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.spi.script.AbstractServerScript; | ||
import org.apache.bigtop.manager.stack.core.spi.script.Script; | ||
import org.apache.bigtop.manager.stack.core.utils.linux.LinuxOSUtils; | ||
|
||
import com.google.auto.service.AutoService; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.Properties; | ||
|
||
@AutoService(Script.class) | ||
@Slf4j | ||
public class GrafanaServerScript extends AbstractServerScript { | ||
|
||
@Override | ||
public ShellResult add(Params params) { | ||
Properties properties = new Properties(); | ||
properties.setProperty(PROPERTY_KEY_SKIP_LEVELS, "1"); | ||
|
||
return super.add(params, properties); | ||
} | ||
|
||
@Override | ||
public ShellResult configure(Params params) { | ||
return GrafanaSetup.config(params); | ||
} | ||
|
||
@Override | ||
public ShellResult start(Params params) { | ||
configure(params); | ||
GrafanaParams grafanaParams = (GrafanaParams) params; | ||
String cmd = MessageFormat.format( | ||
"nohup {0}/bin/grafana server --homepath {0} > {0}/nohup.out 2>&1 &", grafanaParams.serviceHome()); | ||
log.info(cmd); | ||
try { | ||
ShellResult shellResult = LinuxOSUtils.sudoExecCmd(cmd, grafanaParams.user()); | ||
if (shellResult.getExitCode() != 0) { | ||
throw new StackException("Failed to start Grafana: {0}", shellResult.getErrMsg()); | ||
} | ||
long startTime = System.currentTimeMillis(); | ||
long maxWaitTime = 5000; | ||
long pollInterval = 500; | ||
|
||
while (System.currentTimeMillis() - startTime < maxWaitTime) { | ||
ShellResult statusResult = status(params); | ||
if (statusResult.getExitCode() == 0) { | ||
return statusResult; | ||
} | ||
Thread.sleep(pollInterval); | ||
} | ||
return status(params); | ||
} catch (Exception e) { | ||
throw new StackException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public ShellResult stop(Params params) { | ||
GrafanaParams grafanaParams = (GrafanaParams) params; | ||
String cmd = MessageFormat.format("pkill -f {0}/bin/grafana", grafanaParams.serviceHome()); | ||
try { | ||
return LinuxOSUtils.sudoExecCmd(cmd, grafanaParams.user()); | ||
} catch (Exception e) { | ||
throw new StackException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public ShellResult status(Params params) { | ||
GrafanaParams grafanaParams = (GrafanaParams) params; | ||
String cmd = MessageFormat.format("pgrep -f {0}/bin/grafana", grafanaParams.serviceHome()); | ||
try { | ||
ShellResult result = LinuxOSUtils.execCmd(cmd); | ||
if (result.getExitCode() == 0) { | ||
return ShellResult.success(); | ||
} else { | ||
return new ShellResult(-1, "", "Grafana is not running"); | ||
} | ||
} catch (Exception e) { | ||
throw new StackException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public String getComponentName() { | ||
return "grafana_server"; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...nfra/src/main/java/org/apache/bigtop/manager/stack/infra/v1_0_0/grafana/GrafanaSetup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.bigtop.manager.stack.infra.v1_0_0.grafana; | ||
|
||
import org.apache.bigtop.manager.common.constants.Constants; | ||
import org.apache.bigtop.manager.common.shell.ShellResult; | ||
import org.apache.bigtop.manager.stack.core.spi.param.Params; | ||
import org.apache.bigtop.manager.stack.core.utils.linux.LinuxFileUtils; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class GrafanaSetup { | ||
|
||
public static ShellResult config(Params params) { | ||
GrafanaParams grafanaParams = (GrafanaParams) params; | ||
String user = grafanaParams.user(); | ||
String group = grafanaParams.group(); | ||
|
||
LinuxFileUtils.createDirectories(grafanaParams.dataDir(), user, group, Constants.PERMISSION_755, true); | ||
|
||
return ShellResult.success("Grafana Configure success!"); | ||
} | ||
} |