Coverage Summary for Class: SystemUtils (co.rsk.util)
Class |
Class, %
|
Method, %
|
Line, %
|
SystemUtils |
0%
(0/1)
|
0%
(0/6)
|
0%
(0/14)
|
1 /*
2 * This file is part of RskJ
3 * Copyright (C) 2020 RSK Labs Ltd.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 package co.rsk.util;
19
20 import org.apache.commons.lang3.tuple.Pair;
21 import org.slf4j.Logger;
22
23 import java.util.Arrays;
24 import java.util.List;
25 import java.util.stream.Collectors;
26 import java.util.stream.Stream;
27
28 public class SystemUtils {
29
30 private static final List<String> SYSTEM_PROPERTIES = Arrays.asList(
31 "java.version",
32 "java.runtime.name", "java.runtime.version",
33 "java.vm.name", "java.vm.version", "java.vm.vendor",
34 "os.name", "os.version", "os.arch"
35 );
36
37 private SystemUtils() { /* hidden */ }
38
39 /**
40 * Helper method that prints some system and runtime properties available to JVM.
41 */
42 public static void printSystemInfo(Logger logger) {
43 String sysInfo = Stream.concat(
44 systemPropsStream(),
45 runtimePropsStream()
46 ).map(p -> p.getKey() + ": " + p.getValue()).collect(Collectors.joining("\r "));
47
48 logger.info("System info:\r {}", sysInfo);
49 }
50
51 private static Stream<Pair<String, String>> systemPropsStream() {
52 return SYSTEM_PROPERTIES.stream().map(sp -> Pair.of(sp, System.getProperty(sp)));
53 }
54
55 private static Stream<Pair<String, String>> runtimePropsStream() {
56 Runtime runtime = Runtime.getRuntime();
57 return Stream.of(
58 Pair.of("processors", Integer.toString(runtime.availableProcessors())),
59 Pair.of("memory.free", Long.toString(runtime.freeMemory())),
60 Pair.of("memory.max", Long.toString(runtime.maxMemory())),
61 Pair.of("memory.total", Long.toString(runtime.totalMemory()))
62 );
63 }
64 }