Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NMS-16986: System Check Utility : Basic Collection #7587

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4c37904
NMS-16986 : Added missing items as required in ticket.
mwajahatabbasi Jan 7, 2025
eb0ea75
NMS-16986 : Updated related test to fix build issues.
mwajahatabbasi Jan 8, 2025
22537a0
NMS-16986 : Updated related fields and tests.
mwajahatabbasi Jan 10, 2025
35ce305
Merge branch 'develop' into mwa/jira/NMS-16986
mwajahatabbasi Jan 13, 2025
63c0d13
NMS-16986 : Updated changes and tests as per requirement provided in …
mwajahatabbasi Jan 14, 2025
10adbae
NMS-16986 : Updated changes and tests as per requirement provided in …
mwajahatabbasi Jan 14, 2025
993520a
NMS-16986 : Updated changes and tests as per requirement provided in …
mwajahatabbasi Jan 14, 2025
867f2e1
Grouping of System Report at front end.
Shahbaz-dataq Jan 15, 2025
2dd8f71
unnecessary comments removed
Shahbaz-dataq Jan 15, 2025
1811ef1
Selenium test cases fix
Shahbaz-dataq Jan 15, 2025
ee9178f
missing ';'
Shahbaz-dataq Jan 15, 2025
4fa6a84
NMS-16986 : Handel Review Changes.
mwajahatabbasi Jan 16, 2025
edf0c3f
Merge pull request #7594 from OpenNMS/Jira/NMS-17002-grouping-system-…
mwajahatabbasi Jan 20, 2025
5d696cd
NMS-16986 : Handel Merge changes as well as changes suggest in standu…
mwajahatabbasi Jan 20, 2025
d2d8cec
NMS-16986 : Handel PR Review Changes.
mwajahatabbasi Jan 21, 2025
02ef846
NMS-16986 : Handel PR Review Changes.
mwajahatabbasi Jan 22, 2025
e24a45a
Merge branch 'develop' into mwa/jira/NMS-16986
mwajahatabbasi Jan 29, 2025
a603edb
grouping changes reverted
Shahbaz-dataq Jan 29, 2025
7e900d0
Merge remote-tracking branch 'refs/remotes/origin/mwa/jira/NMS-16986'…
mwajahatabbasi Jan 29, 2025
14a6da4
NMS-16986 : Handel Changes suggested by Tech Support Changes for syst…
mwajahatabbasi Jan 29, 2025
be51c82
NMS-16986 : Handel PR review changes.
mwajahatabbasi Jan 30, 2025
b3ed5e9
Merge branch 'refs/heads/develop' into mwa/jira/NMS-16986
mwajahatabbasi Jan 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public boolean getOutputsFiles() {
return false;
}

@Override
public boolean isVisible() { return false; }

protected ResourceLocator getResourceLocator() {
return m_resourceLocator;
}
Expand Down Expand Up @@ -143,9 +146,8 @@ protected String slurpCommand(final String[] command) {
is = p.getInputStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
while (br.ready()) {
final String line = br.readLine();
if (line == null) break;
String line=null;
while ((line = br.readLine()) != null) {
sb.append(line);
if (br.ready()) sb.append("\n");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
Expand Down Expand Up @@ -230,14 +231,14 @@ public List<SystemReportPlugin> getPlugins() {
initializeSpring();
final List<SystemReportPlugin> plugins = new ArrayList<SystemReportPlugin>(m_serviceRegistry.findProviders(SystemReportPlugin.class));
Collections.sort(plugins);
return plugins;
return plugins.stream().filter(SystemReportPlugin::isVisible).collect(Collectors.toList());
}

public List<SystemReportFormatter> getFormatters() {
initializeSpring();
final List<SystemReportFormatter> formatters = new ArrayList<SystemReportFormatter>(m_serviceRegistry.findProviders(SystemReportFormatter.class));
Collections.sort(formatters);
return formatters;
return formatters.stream().filter(SystemReportFormatter::isVisible).collect(Collectors.toList());
}

private void initializeSpring() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,7 @@ public interface SystemReportFormatter extends Comparable<SystemReportFormatter>
*/
public boolean canStdout();


public boolean isVisible();

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ public interface SystemReportPlugin extends Comparable<SystemReportPlugin> {
public boolean getFullOutputOnly();

public boolean getOutputsFiles();

public boolean isVisible();
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public void begin() {
@Override
public void end() {
}

@Override
public boolean isVisible() { return false; }

@Override
public final int compareTo(final SystemReportFormatter o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public boolean canStdout() {
return false;
}

@Override
public boolean isVisible() { return true; }

@Override
public void begin() {
super.begin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public int getPriority() {
return 20;
}

@Override
public boolean isVisible() { return true; }

@Override
public boolean getFullOutputOnly() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public boolean getFullOutputOnly() {
return true;
}

@Override
public boolean isVisible() { return true; }

@Override
public boolean getOutputsFiles() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@

import java.io.IOException;
import java.io.InputStream;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;

import org.opennms.core.resource.Vault;
import org.opennms.core.spring.BeanUtils;
import org.opennms.core.utils.SystemInfoUtils;
import org.opennms.core.utils.TimeSeries;
import org.opennms.netmgt.dao.api.AlarmDao;
import org.opennms.netmgt.dao.api.EventDao;
import org.opennms.netmgt.dao.api.IpInterfaceDao;
Expand Down Expand Up @@ -72,6 +76,10 @@ public String getDescription() {
return "OpenNMS core information, version, and basic configuration";
}


@Override
public boolean isVisible() { return true; }

@Override
public int getPriority() {
return 3;
Expand All @@ -80,17 +88,9 @@ public int getPriority() {
@Override
public Map<String, Resource> getEntries() {
final TreeMap<String,Resource> map = new TreeMap<String,Resource>();
final InputStream is = this.getClass().getResourceAsStream("/version.properties");
if (is != null) {
Properties p = new Properties();
try {
p.load(is);
map.put("Version", getResource(p.getProperty("version.display")));
} catch (final IOException e) {
LOG.warn("Unable to load from version.properties", e);
}
}

map.put("OpenNMS Home",getResourceFromProperty("opennms.home"));
cgorantla marked this conversation as resolved.
Show resolved Hide resolved
map.put("Version", getResource(Vault.getProperty("version.display")));

if (m_nodeDao != null) {
map.put("Number of Nodes", getResource(Integer.toString(m_nodeDao.countAll())));
}
Expand All @@ -106,7 +106,35 @@ public Map<String, Resource> getEntries() {
if (m_alarmDao != null) {
map.put("Number of Alarms", getResource(Integer.toString(m_alarmDao.countAll())));
}

RuntimeMXBean runtimeBean = getBean(ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);
if (runtimeBean == null) {
LOG.info("falling back to local VM RuntimeMXBean");
runtimeBean = ManagementFactory.getRuntimeMXBean();
}
addGetters(runtimeBean, map);

map.put("OpenNMS Up Time",getResource( getOnmsUptimeAsString(runtimeBean) ));
map.put("Time-Series Strategy",getResource(TimeSeries.getTimeseriesStrategy().getName()));

return map;
}

private String getOnmsUptimeAsString(RuntimeMXBean runtimeBean){

long startTimeMillis = runtimeBean.getStartTime();

// Get the current time (in milliseconds since epoch)
long currentTimeMillis = System.currentTimeMillis();

// Calculate uptime
long uptimeMillis = currentTimeMillis - startTimeMillis;

long hours = uptimeMillis / (1000 * 60 * 60);
long minutes = (uptimeMillis % (1000 * 60 * 60)) / (1000 * 60);
long seconds = (uptimeMillis % (1000 * 60)) / 1000;

return String.format("%d hours, %d minutes, %d seconds", hours, minutes, seconds);
cgorantla marked this conversation as resolved.
Show resolved Hide resolved
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void afterPropertiesSet() throws Exception {

@Override
public String getName() {
return "TopEvent";
return "TopNEvents";
}

@Override
Expand All @@ -58,6 +58,9 @@ public int getPriority() {
return 4;
}

@Override
public boolean isVisible() { return true; }

@Override
public Map<String, Resource> getEntries() {
final TreeMap<String,Resource> map = new TreeMap<String,Resource>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Licensed to The OpenNMS Group, Inc (TOG) under one or more
* contributor license agreements. See the LICENSE.md file
* distributed with this work for additional information
* regarding copyright ownership.
*
* TOG licenses this file to You under the GNU Affero General
* Public License Version 3 (the "License") or (at your option)
* any later version. You may not use this file except in
* compliance with the License. You may obtain a copy of the
* License at:
*
* https://www.gnu.org/licenses/agpl-3.0.txt
*
* 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.opennms.systemreport.system;
mwajahatabbasi marked this conversation as resolved.
Show resolved Hide resolved

import org.opennms.systemreport.AbstractSystemReportPlugin;
import org.springframework.core.io.Resource;

import java.util.Map;
import java.util.TreeMap;

public class HardDriveReportPlugin extends AbstractSystemReportPlugin {


@Override
public String getName() {
return "Hard Drive Stats";
}

@Override
public String getDescription() { return "Hard Drive Capacity and Performance Information"; }

@Override
public int getPriority() {
return 5;
}

@Override
public boolean isVisible() { return true; }

@Override
public Map<String, Resource> getEntries() {
final Map<String,Resource> map = new TreeMap<String,Resource>();

String[] dfCommand = {"bash", "-c", "df -h"};
cgorantla marked this conversation as resolved.
Show resolved Hide resolved
final String dfOutput = slurpCommand(dfCommand);
if (dfOutput != null) {
map.put("Hard Drive Capacity", getResource("\n"+dfOutput));
}

String[] ioStatCommand = {"bash", "-c", "iostat -d"};
final String iostatOutput = slurpCommand(ioStatCommand);
if (iostatOutput != null) {
map.put("Hard Drive Performance", getResource("\n"+iostatOutput));
}

return map;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public int getPriority() {
return 1;
}

@Override
public boolean isVisible() { return true; }

@Override
public Map<String, Resource> getEntries() {
final TreeMap<String,Resource> map = new TreeMap<String,Resource>();
Expand All @@ -68,6 +71,8 @@ public Map<String, Resource> getEntries() {
memoryBean = ManagementFactory.getMemoryMXBean();
}

map.put("Initial Heap Size", getResource(String.format("%d",memoryBean.getHeapMemoryUsage().getInit())));
map.put("Max Heap Size", getResource(String.format("%d",memoryBean.getHeapMemoryUsage().getMax())));
addGetters(memoryBean, map);

RuntimeMXBean runtimeBean = getBean(ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);
Expand All @@ -86,29 +91,6 @@ public Map<String, Resource> getEntries() {

addGetters(classBean, map);

/* this stuff is really not giving us anything useful
List<GarbageCollectorMXBean> beans = getBeans(ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE, GarbageCollectorMXBean.class);
if (beans == null || beans.size() == 0) {
LOG.info("falling back to local VM MemoryMXBean");
beans = ManagementFactory.getGarbageCollectorMXBeans();
}

LOG.trace("beans = {}", beans);
int collectorNum = 1;
for (final GarbageCollectorMXBean bean : beans) {
final Map<String,Resource> temp = new TreeMap<String,Resource>();
addGetters(bean, map);

final StringBuilder sb = new StringBuilder();
for (final String s : temp.keySet()) {
sb.append(s).append(": ").append(temp.get(s)).append("\n");
}
if (sb.length() > 0) sb.deleteCharAt(sb.length());
map.put("Garbage Collector " + collectorNum, getResource(sb.toString()));
}
*/

return map;
}

}
Loading
Loading