├── .codacy.yml
├── .gitignore
├── .mvn
└── wrapper
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── .travis.yml
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── config
├── java.d.conf
└── java.d
│ └── jmx.conf
├── eclipse-formatter.xml
├── installer
└── functions.sh
├── mvnw
├── mvnw.cmd
├── netdata-java-orchestrator-installer.sh
├── pom.xml
└── src
├── main
├── java
│ └── org
│ │ └── firehol
│ │ └── netdata
│ │ ├── CommandLineArgs.java
│ │ ├── Main.java
│ │ ├── exception
│ │ ├── AssertionException.java
│ │ ├── IllegalCommandLineArumentException.java
│ │ ├── InitializationException.java
│ │ ├── NotImplementedException.java
│ │ └── UnreachableCodeException.java
│ │ ├── model
│ │ ├── Chart.java
│ │ ├── ChartType.java
│ │ ├── Dimension.java
│ │ └── DimensionAlgorithm.java
│ │ ├── module
│ │ ├── Module.java
│ │ └── jmx
│ │ │ ├── JmxModule.java
│ │ │ ├── MBeanServerCollector.java
│ │ │ ├── configuration
│ │ │ ├── JmxChartConfiguration.java
│ │ │ ├── JmxDimensionConfiguration.java
│ │ │ ├── JmxModuleConfiguration.java
│ │ │ └── JmxServerConfiguration.java
│ │ │ ├── exception
│ │ │ ├── JmxMBeanServerConnectionException.java
│ │ │ ├── JmxMBeanServerQueryException.java
│ │ │ ├── JmxModuleException.java
│ │ │ └── VirtualMachineConnectionException.java
│ │ │ ├── query
│ │ │ ├── MBeanCompositeDataQuery.java
│ │ │ ├── MBeanDoubleStore.java
│ │ │ ├── MBeanIntegerStore.java
│ │ │ ├── MBeanLongStore.java
│ │ │ ├── MBeanQuery.java
│ │ │ ├── MBeanSimpleQuery.java
│ │ │ └── MBeanValueStore.java
│ │ │ └── utils
│ │ │ ├── MBeanServerUtils.java
│ │ │ └── VirtualMachineUtils.java
│ │ ├── orchestrator
│ │ ├── Collector.java
│ │ ├── Orchestrator.java
│ │ ├── Printer.java
│ │ └── configuration
│ │ │ ├── ConfigurationService.java
│ │ │ ├── EnvironmentConfigurationService.java
│ │ │ ├── exception
│ │ │ ├── ConfigurationSchemeInstantiationException.java
│ │ │ ├── EnvironmentConfigurationException.java
│ │ │ └── ParseException.java
│ │ │ └── schema
│ │ │ └── OrchestratorConfiguration.java
│ │ └── utils
│ │ ├── AlignToTimeIntervalService.java
│ │ ├── ClockService.java
│ │ ├── LoggingUtils.java
│ │ ├── ResourceUtils.java
│ │ ├── StringUtils.java
│ │ └── UnitConversion.java
└── sh
│ └── java.d.plugin
└── test
└── java
└── org
└── firehol
└── netdata
├── MainTest.java
├── module
└── jmx
│ ├── MBeanServerCollectorTest.java
│ ├── query
│ ├── MBeanCompositeDataQueryTest.java
│ ├── MBeanQueryTest.java
│ └── MBeanValueStoreTest.java
│ └── utils
│ └── MBeanServerUtilsTest.java
├── orchestrator
├── PrinterTest.java
└── configuration
│ ├── ConfigurationServiceTest.java
│ ├── EnvironmentConfigurationServiceTest.java
│ ├── NoTestConfiguration.java
│ └── TestConfiguration.java
├── test
└── architecture
│ └── UtilsTest.java
├── testutils
├── ExitException.java
├── NoExitSecurityManager.java
├── ReflectionUtils.java
└── TestObjectBuilder.java
└── utils
├── AlignToTimeIntervalServiceTest.java
├── LoggingUtilsTest.java
├── ResourceUtilsTest.java
└── StringUtilsTest.java
/.codacy.yml:
--------------------------------------------------------------------------------
1 | exclude_paths:
2 | - installer/functions.sh
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 |
3 | # Mobile Tools for Java (J2ME)
4 | .mtj.tmp/
5 |
6 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
7 | hs_err_pid*
8 |
9 | # Eclipse
10 | .classpath
11 | .project
12 | .settings/
13 |
14 | # IntelliJ IDEA
15 | .idea/
16 | *.iml
17 |
18 | # Maven
19 | target/
20 |
21 | # netdata-java-orchestrator-installer.sh
22 | netdata-java-orchestrator-installer.log
23 | netdata-java-orchestrator-uninstaller.sh
24 |
25 | # macOS
26 | .DS_Store
27 |
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/simartn/netdata-java-orchestrator/e03ba0d9b72f31d3cdf23cd474866a6563519b4c/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.6.1/apache-maven-3.6.1-bin.zip
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 |
3 | dist: trusty
4 |
5 | jdk:
6 | - oraclejdk8
7 | - oraclejdk9
8 | - oraclejdk11
9 | - openjdk8
10 |
11 | before_install:
12 | - sudo apt-get install jq
13 | - curl -LSs $(curl -LSs https://api.github.com/repos/codacy/codacy-coverage-reporter/releases/latest | jq -r '.assets | map({content_type, browser_download_url} | select(.content_type | contains("application/java-archive"))) | .[0].browser_download_url') -o codacy-coverage-reporter-assembly.jar
14 |
15 | after_success:
16 | - mvn jacoco:report
17 | - java -jar codacy-coverage-reporter-assembly.jar report -l Java -r target/site/jacoco/jacoco.xml
18 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Java Orchestrator
2 |
3 | ## Code Style
4 |
5 | - Stick to the configured code style
6 | - Eclipse formatter definition: `eclipse-formatter.xml`
7 | - To validate the code base run `./mvnw formatter:validate`
8 | - To reformat the code base run `./mvnw formatter:format`
9 | - Stick to the configured import order
10 | - Import order configuration of plugin `net.revelc.code:impsort-maven-plugin` in `pom.xml`
11 | - To validate import order run `./mvnw impsort:check`
12 | - To organize imports run `./mvnw impsort:sort`
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Netdata Java Orchestrator
2 |
3 | [](https://travis-ci.org/simonnagl/netdata-java-orchestrator.svg?branch=master)
4 | [](https://www.codacy.com/app/simonnagl/netdata-plugin-java-daemon?utm_source=github.com&utm_medium=referral&utm_content=simonnagl/netdata-plugin-java-daemon&utm_campaign=Badge_Coverage)
5 | [](https://www.codacy.com/app/simonnagl/netdata-plugin-java-daemon?utm_source=github.com&utm_medium=referral&utm_content=simonnagl/netdata-plugin-java-daemon&utm_campaign=badger)
6 | [](https://app.fossa.io/projects/git%2Bgithub.com%2Fsimonnagl%2Fnetdata-java-orchestrator?ref=badge_shield)
7 |
8 | netdata-java-orchestrator is a [netdata](https://github.com/firehol/netdata) plugin which can collect any data in java and send it to netdata.
9 |
10 | ## Java Modules
11 |
12 | - JMX Collector
13 |
14 | ## Installation
15 |
16 | ### 1. Prepare your system
17 |
18 | #### Required for compilation
19 |
20 | - netdata
21 | - JDK 8.x
22 |
23 | #### Required to run netdata
24 |
25 | - netdata
26 | - JRE 8.x
27 |
28 | ### 2. Install netdata-java-orchestrator
29 |
30 | Do this to install and run netdata-java-orchestrator:
31 |
32 | ```(sh)
33 | # download it - the directory 'netdata-java-orchestrator' will be created
34 | git clone https://github.com/simonnagl/netdata-java-orchestrator.git --depth=1
35 | cd netdata-java-orchestrator
36 |
37 | # run script with root privileges to build and install the plugin and restart netdata.
38 | netdata-java-orchestrator-installer.sh
39 | ````
40 |
41 | ## Configuration
42 |
43 | Configuration files contain JSON Objects.
44 | Additional to the JSON specification Java/C++ style comments (both '/'+'*' and '//' varieties) are allowed.
45 |
46 | Each module get's it's own configuration file. The standard configuration should have enogh examples and comments to extend or adapt it. The table below references the classes which describe the JSON schemes of the configuration files.
47 |
48 | File | Schema | Purpose
49 | ---------------------------- | ------ | -------
50 | /etc/netdata/java.d/jmx.conf | [JmxModuleConfiguration](https://github.com/simonnagl/netdata-java-orchestrator/blob/master/src/main/java/org/firehol/netdata/module/jmx/configuration/JmxModuleConfiguration.java)| JMX module configuration
51 |
52 |
53 | ## License
54 |
55 | netdata-java-orchestrator is [GPLv3+](LICENSE).
56 |
57 | [](https://app.fossa.io/projects/git%2Bgithub.com%2Fsimonnagl%2Fnetdata-java-orchestrator?ref=badge_large)
58 |
--------------------------------------------------------------------------------
/config/java.d.conf:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-or-later
2 |
3 | {}
--------------------------------------------------------------------------------
/config/java.d/jmx.conf:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-or-later
2 |
3 | // netdata-java-orchestrator JMX module configuration
4 | //
5 | // The comments in this file should help you to extend this configuration.
6 | // Comments starting with '//' are descriptive comments. Uncommenting them leads to syntax errors.
7 | // Block comments ('/* {...} */') are used to exclude configuration examples.
8 | // These can be uncommented.
9 | //
10 | // For a more formal reference user the configuration scheme: org.firehol.netdata.module.jmx.configuration.JmxModuleConfiguration
11 |
12 | {
13 | // If true auto detect and monitor running local virtual machines.
14 | "autoDetectLocalVirtualMachines": "true",
15 | // Configure a list of JMX servers to monitor.
16 | "jmxServers": [
17 | // Example configuration for a java program started on the same host with these flags:
18 | // -Dcom.sun.management.jmxremote.port=9999 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false
19 | /*
20 | {
21 | // Name displayed at the dashboard menu.
22 | "name": "ExampleJMX",
23 | // JMX Service URL used to connect to the JVM.
24 | // service:jmx:rmi://[host[:port]][urlPath]
25 | // @see: https://docs.oracle.com/cd/E19159-01/819-7758/gcnqf/index.html
26 | "serviceUrl": "service:jmx:rmi:///jndi/rmi://:9999/jmxrmi"
27 | }
28 | */
29 | ],
30 | // Global chart configurations.
31 | // Every monitored JMX Servers tries to monitor each chart configuration.
32 | // If a JMX Server does not have the required M(X)Beans we won't try adding it over and over again.
33 | //
34 | // Set of common charts:
35 | // Feel free to open pull requests to share new chart configurations of M(X)Beans distributed with java
36 | // or any open source project.
37 | "commonCharts": [
38 | // ####################################################################
39 | // Chart configuration documentation
40 | // ####################################################################
41 | /*
42 | {
43 | // Unique ID of this chart in this list.
44 | "id": "example",
45 | // Title describing this chart
46 | "title": "Example chart configuration",
47 | // Unit of the collected value
48 | "units": "some_unit",
49 | // orders charts. Lower numbers make the charts appear before the ones with higher numbers
50 | "priority": "8000",
51 | // Possible chart types: AREA, LINE, STACKED
52 | "chartType": "AREA",
53 | // Possible dimension algorithms:
54 | // ABSOLUTE, INCREMENTAL, PERCENTAGE_OF_ABSOLUTE_ROW, PERCENTAGE_OF_INCREMENTAL_ROW
55 | "dimensionAlgorithm": "ABSOLUTE",
56 | // List of dimensions to add to the chart.
57 | "dimensions": [
58 | {
59 | // Object Name of the M(X)Bean to collect a value from.
60 | // @see: http://www.oracle.com/technetwork/java/javase/tech/best-practices-jsp-136021.html#mozTocId509360
61 | "from": "java.lang:type=OperatingSystem",
62 | // M(X)Bean attribute to collect.
63 | // The getter of the attribute must return one of these types.
64 | // - Integer (int)
65 | // - Double (double)
66 | // - Long (long)
67 | "value": "ProcessCpuTime",
68 | // Name at the dashboard
69 | "name": "cpu",
70 | // Tells netdata to multiply the value before displaying it.
71 | "multiplier": "1",
72 | // Tells netdata to divide the value before displaying it.
73 | "divisor": "1",
74 | // Collect the value and handle it in dimensionAlgorithm but do not display it.
75 | "hidden": "false"
76 | }
77 | ]
78 | },
79 | */
80 |
81 | // ####################################################################
82 | // JVM M(X)Beans
83 | // ####################################################################
84 | {
85 | "id": "cpu",
86 | "title": "JVM CPU utilization",
87 | "units": "percentage",
88 | "priority": "8000",
89 | "chartType": "AREA",
90 | "dimensionAlgorithm": "INCREMENTAL",
91 | "dimensions": [
92 | {
93 | "from": "java.lang:type=OperatingSystem",
94 | "value": "ProcessCpuTime",
95 | "name": "cpu",
96 | "divisor": "10000000"
97 | }
98 | ]
99 | },
100 | {
101 | "id": "load",
102 | "title": "JVM Load Average",
103 | "units": "load",
104 | "priority": "8010",
105 | "chartType": "LINE",
106 | "dimensionAlgorithm": "ABSOLUTE",
107 | "dimensions": [
108 | {
109 | "from": "java.lang:type=OperatingSystem",
110 | "value": "ProcessCpuLoad",
111 | "name": "load1"
112 | }
113 | ]
114 | },
115 | {
116 | "id": "memory_heap",
117 | "title": "Memory Usage",
118 | "family": "memory",
119 | "units": "KB",
120 | "priority": "8015",
121 | "chartType": "STACKED",
122 | "dimensionAlgorithm": "ABSOLUTE",
123 | "dimensions": [
124 | {
125 | "from": "java.lang:type=Memory",
126 | "value": "HeapMemoryUsage.used",
127 | "name": "heap",
128 | "divisor": "1000"
129 | },
130 | {
131 | "from": "java.lang:type=Memory",
132 | "value": "NonHeapMemoryUsage.used",
133 | "name": "no_heap",
134 | "divisor": "1000"
135 | }
136 | ]
137 | },
138 | {
139 | "id": "memory_by_pool",
140 | "title": "Heap Memory Usage",
141 | "family": "memory",
142 | "units": "KB",
143 | "priority": "8016",
144 | "chartType": "STACKED",
145 | "dimensionAlgorithm": "ABSOLUTE",
146 | "dimensions": [
147 | {
148 | "from": "java.lang:type=MemoryPool,name=PS Eden Space",
149 | "value": "Usage.used",
150 | "name": "ps_eden_space",
151 | "divisor": "1000"
152 | },
153 | {
154 | "from": "java.lang:type=MemoryPool,name=PS Old Gen",
155 | "value": "Usage.used",
156 | "name": "ps_old_gen",
157 | "divisor": "1000"
158 | },
159 | {
160 | "from": "java.lang:type=MemoryPool,name=PS Survivor Space",
161 | "value": "Usage.used",
162 | "name": "ps_survivor_space",
163 | "divisor": "1000"
164 | },
165 | {
166 | "from": "java.lang:type=MemoryPool,name=Code Cache",
167 | "value": "Usage.used",
168 | "name": "code_cache",
169 | "divisor": "1000"
170 | },
171 | {
172 | "from": "java.lang:type=MemoryPool,name=Compressed Class Space",
173 | "value": "Usage.used",
174 | "name": "compressed_class_space",
175 | "divisor": "1000"
176 | },
177 | {
178 | "from": "java.lang:type=MemoryPool,name=Metaspace",
179 | "value": "Usage.used",
180 | "name": "metaspace",
181 | "divisor": "1000"
182 | }
183 | ]
184 | },
185 | {
186 | "id": "uptime",
187 | "title": "JVM Uptime",
188 | "units": "seconds",
189 | "priority": "8020",
190 | "chartType": "LINE",
191 | "dimensionAlgorithm": "ABSOLUTE",
192 | "dimensions": [
193 | {
194 | "from": "java.lang:type=Runtime",
195 | "value": "Uptime",
196 | "name": "uptime",
197 | "divisor": "1000"
198 | }
199 | ]
200 | },
201 | {
202 | "id": "threads_started",
203 | "title": "Threads started",
204 | "family": "threads",
205 | "units": "threads",
206 | "priority": "8030",
207 | "chartType": "LINE",
208 | "dimensionAlgorithm": "ABSOLUTE",
209 | "dimensions": [
210 | // Returns the total number of threads created and also started since the Java virtual machine started.
211 | {
212 | "from": "java.lang:type=Threading",
213 | "value": "TotalStartedThreadCount",
214 | "name": "threads"
215 | }
216 | ]
217 | },
218 | {
219 | "id": "threads_active",
220 | "title": "Threads active",
221 | "family": "threads",
222 | "units": "threads",
223 | "priority": "8035",
224 | "chartType": "LINE",
225 | "dimensionAlgorithm": "ABSOLUTE",
226 | "dimensions": [
227 | // Returns the peak live thread count since the Java virtual machine started or peak was reset.
228 | {
229 | "from": "java.lang:type=Threading",
230 | "value": "PeakThreadCount",
231 | "name": "peak"
232 | },
233 | // Returns the current number of live daemon threads.
234 | {
235 | "from": "java.lang:type=Threading",
236 | "value": "DaemonThreadCount",
237 | "name": "daemon"
238 | },
239 | // Returns the current number of live threads including both daemon and non-daemon threads.
240 | {
241 | "from": "java.lang:type=Threading",
242 | "value": "ThreadCount",
243 | "name": "current"
244 | }
245 | ]
246 | },
247 | {
248 | "id": "classloading",
249 | "title": "Classes loaded",
250 | "family": "class_loading",
251 | "units": "classes",
252 | "priority": "8040",
253 | "chartType": "LINE",
254 | "dimensionAlgorithm": "ABSOLUTE",
255 | "dimensions": [
256 | {
257 | "from": "java.lang:type=ClassLoading",
258 | "value": "TotalLoadedClassCount",
259 | "name": "loaded_since_start"
260 | },
261 | {
262 | "from": "java.lang:type=ClassLoading",
263 | "value": "LoadedClassCount",
264 | "name": "current"
265 | },
266 | {
267 | "from": "java.lang:type=ClassLoading",
268 | "value": "UnloadedClassCount",
269 | "name": "unloaded_since_start"
270 | }
271 | ]
272 | },
273 | {
274 | "id": "compilation",
275 | "title": "Compilation Time",
276 | "units": "percentage",
277 | "priority": "8050",
278 | "chartType": "LINE",
279 | "dimensionAlgorithm": "INCREMENTAL",
280 | "dimensions": [
281 | {
282 | "from": "java.lang:type=Compilation",
283 | // Returns the approximate accumlated elapsed time (in milliseconds) spent in compilation.
284 | "value": "TotalCompilationTime",
285 | "name": "total",
286 | // Convert ms/s to percent
287 | "divisor": "10"
288 | }
289 | ]
290 | },
291 | {
292 | "id": "garbagecount",
293 | "title": "Garbage Collection Number",
294 | "family": "garbage_collection",
295 | "units": "collection/s",
296 | "priority": "8060",
297 | "chartType": "LINE",
298 | "dimensionAlgorithm": "ABSOLUTE",
299 | "dimensions": [
300 | {
301 | "from": "java.lang:type=GarbageCollector,name=PS Scavenge",
302 | "value": "CollectionCount",
303 | "name": "PS_Scavenge"
304 | },
305 | {
306 | "from": "java.lang:type=GarbageCollector,name=PS MarkSweep",
307 | "value": "CollectionCount",
308 | "name": "PS_MarkSweep"
309 | }
310 | ]
311 | },
312 | {
313 | "id": "garbagetime",
314 | "title": "Time spent collecting garbage",
315 | "family": "garbage_collection",
316 | "units": "percentage",
317 | "priority": "8070",
318 | "chartType": "LINE",
319 | "dimensionAlgorithm": "INCREMENTAL",
320 | "dimensions": [
321 | {
322 | "from": "java.lang:type=GarbageCollector,name=PS Scavenge",
323 | "value": "CollectionTime",
324 | "name": "PS_Scavenge",
325 | "divisor": "10"
326 | },
327 | {
328 | "from": "java.lang:type=GarbageCollector,name=PS MarkSweep",
329 | "value": "CollectionTime",
330 | "name": "PS_MarkSweep",
331 | "divisor": "10"
332 | }
333 | ]
334 | },
335 | {
336 | "id": "bufferpool_direct",
337 | "title": "Direct Buffer Pool",
338 | "family": "buffer_pool",
339 | "units": "byte",
340 | "priority": "8080",
341 | "chartType": "LINE",
342 | "dimensionAlgorithm": "ABSOLUTE",
343 | "dimensions": [
344 | {
345 | "from": "java.nio:type=BufferPool,name=direct",
346 | "value": "TotalCapacity",
347 | "name": "capacity"
348 | },
349 | {
350 | "from": "java.nio:type=BufferPool,name=direct",
351 | "value": "MemoryUsed",
352 | "name": "used"
353 | }
354 | ]
355 | },
356 | {
357 | "id": "bufferpool_mapped",
358 | "title": "Mapped Buffer Pool",
359 | "family": "buffer_pool",
360 | "units": "byte",
361 | "priority": "8090",
362 | "chartType": "LINE",
363 | "dimensionAlgorithm": "ABSOLUTE",
364 | "dimensions": [
365 | {
366 | "from": "java.nio:type=BufferPool,name=mapped",
367 | "value": "TotalCapacity",
368 | "name": "capacity"
369 | },
370 | {
371 | "from": "java.nio:type=BufferPool,name=mapped",
372 | "value": "MemoryUsed",
373 | "name": "used"
374 | }
375 | ]
376 | }
377 | ]
378 | }
379 |
--------------------------------------------------------------------------------
/installer/functions.sh:
--------------------------------------------------------------------------------
1 | # no shebang necessary - this is a library to be sourced
2 | # SPDX-License-Identifier: GPL-3.0-or-later
3 |
4 | # make sure we have a UID
5 | [ -z "${UID}" ] && UID="$(id -u)"
6 |
7 |
8 | # -----------------------------------------------------------------------------
9 | # checking the availability of commands
10 |
11 | which_cmd() {
12 | which "${1}" 2>/dev/null || \
13 | command -v "${1}" 2>/dev/null
14 | }
15 |
16 | check_cmd() {
17 | which_cmd "${1}" >/dev/null 2>&1 && return 0
18 | return 1
19 | }
20 |
21 |
22 | # -----------------------------------------------------------------------------
23 |
24 | setup_terminal() {
25 | TPUT_RESET=""
26 | TPUT_BLACK=""
27 | TPUT_RED=""
28 | TPUT_GREEN=""
29 | TPUT_YELLOW=""
30 | TPUT_BLUE=""
31 | TPUT_PURPLE=""
32 | TPUT_CYAN=""
33 | TPUT_WHITE=""
34 | TPUT_BGBLACK=""
35 | TPUT_BGRED=""
36 | TPUT_BGGREEN=""
37 | TPUT_BGYELLOW=""
38 | TPUT_BGBLUE=""
39 | TPUT_BGPURPLE=""
40 | TPUT_BGCYAN=""
41 | TPUT_BGWHITE=""
42 | TPUT_BOLD=""
43 | TPUT_DIM=""
44 | TPUT_UNDERLINED=""
45 | TPUT_BLINK=""
46 | TPUT_INVERTED=""
47 | TPUT_STANDOUT=""
48 | TPUT_BELL=""
49 | TPUT_CLEAR=""
50 |
51 | # Is stderr on the terminal? If not, then fail
52 | test -t 2 || return 1
53 |
54 | if check_cmd tput
55 | then
56 | if [ $(( $(tput colors 2>/dev/null) )) -ge 8 ]
57 | then
58 | # Enable colors
59 | TPUT_RESET="$(tput sgr 0)"
60 | TPUT_BLACK="$(tput setaf 0)"
61 | TPUT_RED="$(tput setaf 1)"
62 | TPUT_GREEN="$(tput setaf 2)"
63 | TPUT_YELLOW="$(tput setaf 3)"
64 | TPUT_BLUE="$(tput setaf 4)"
65 | TPUT_PURPLE="$(tput setaf 5)"
66 | TPUT_CYAN="$(tput setaf 6)"
67 | TPUT_WHITE="$(tput setaf 7)"
68 | TPUT_BGBLACK="$(tput setab 0)"
69 | TPUT_BGRED="$(tput setab 1)"
70 | TPUT_BGGREEN="$(tput setab 2)"
71 | TPUT_BGYELLOW="$(tput setab 3)"
72 | TPUT_BGBLUE="$(tput setab 4)"
73 | TPUT_BGPURPLE="$(tput setab 5)"
74 | TPUT_BGCYAN="$(tput setab 6)"
75 | TPUT_BGWHITE="$(tput setab 7)"
76 | TPUT_BOLD="$(tput bold)"
77 | TPUT_DIM="$(tput dim)"
78 | TPUT_UNDERLINED="$(tput smul)"
79 | TPUT_BLINK="$(tput blink)"
80 | TPUT_INVERTED="$(tput rev)"
81 | TPUT_STANDOUT="$(tput smso)"
82 | TPUT_BELL="$(tput bel)"
83 | TPUT_CLEAR="$(tput clear)"
84 | fi
85 | fi
86 |
87 | return 0
88 | }
89 | setup_terminal || echo >/dev/null
90 |
91 | progress() {
92 | echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "
93 | }
94 |
95 | # -----------------------------------------------------------------------------
96 |
97 | netdata_banner() {
98 | local l1=" ^" \
99 | l2=" |.-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-. .-" \
100 | l3=" | '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' '-' " \
101 | l4=" +----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--->" \
102 | sp=" " \
103 | netdata="netdata-java-orchestrator" start end msg="${*}" chartcolor="${TPUT_DIM}"
104 |
105 | [ ${#msg} -lt ${#netdata} ] && msg="${msg}${sp:0:$(( ${#netdata} - ${#msg}))}"
106 | [ ${#msg} -gt $(( ${#l2} - 20 )) ] && msg="${msg:0:$(( ${#l2} - 23 ))}..."
107 |
108 | start="$(( ${#l2} / 2 - 4 ))"
109 | [ $(( start + ${#msg} + 4 )) -gt ${#l2} ] && start=$((${#l2} - ${#msg} - 4))
110 | end=$(( ${start} + ${#msg} + 4 ))
111 |
112 | echo >&2
113 | echo >&2 "${chartcolor}${l1}${TPUT_RESET}"
114 | echo >&2 "${chartcolor}${l2:0:start}${sp:0:2}${TPUT_RESET}${TPUT_BOLD}${TPUT_GREEN}${netdata}${TPUT_RESET}${chartcolor}${sp:0:$((end - start - 2 - ${#netdata}))}${l2:end:$((${#l2} - end))}${TPUT_RESET}"
115 | echo >&2 "${chartcolor}${l3:0:start}${sp:0:2}${TPUT_RESET}${TPUT_BOLD}${TPUT_CYAN}${msg}${TPUT_RESET}${chartcolor}${sp:0:2}${l3:end:$((${#l2} - end))}${TPUT_RESET}"
116 | echo >&2 "${chartcolor}${l4}${TPUT_RESET}"
117 | echo >&2
118 | }
119 |
120 | # -----------------------------------------------------------------------------
121 | # portable service command
122 |
123 | service_cmd="$(which_cmd service)"
124 | systemctl_cmd="$(which_cmd systemctl)"
125 | service() {
126 | local cmd="${1}" action="${2}"
127 |
128 | if [ ! -z "${systemctl_cmd}" ]
129 | then
130 | run "${systemctl_cmd}" "${action}" "${cmd}"
131 | return $?
132 | elif [ ! -z "${service_cmd}" ]
133 | then
134 | run "${service_cmd}" "${cmd}" "${action}"
135 | return $?
136 | fi
137 | return 1
138 | }
139 |
140 | # -----------------------------------------------------------------------------
141 |
142 | run_ok() {
143 | printf >&2 "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET} ${*} \n\n"
144 | }
145 |
146 | run_failed() {
147 | printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET} ${*} \n\n"
148 | }
149 |
150 | ESCAPED_PRINT_METHOD=
151 | printf "%q " test >/dev/null 2>&1
152 | [ $? -eq 0 ] && ESCAPED_PRINT_METHOD="printfq"
153 | escaped_print() {
154 | if [ "${ESCAPED_PRINT_METHOD}" = "printfq" ]
155 | then
156 | printf "%q " "${@}"
157 | else
158 | printf "%s" "${*}"
159 | fi
160 | return 0
161 | }
162 |
163 | run_logfile="/dev/null"
164 | run() {
165 | local user="${USER--}" dir="${PWD}" info info_console
166 |
167 | if [ "${UID}" = "0" ]
168 | then
169 | info="[root ${dir}]# "
170 | info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]# "
171 | else
172 | info="[${user} ${dir}]$ "
173 | info_console="[${TPUT_DIM}${dir}${TPUT_RESET}]$ "
174 | fi
175 |
176 | printf >> "${run_logfile}" "${info}"
177 | escaped_print >> "${run_logfile}" "${@}"
178 | printf >> "${run_logfile}" " ... "
179 |
180 | printf >&2 "${info_console}${TPUT_BOLD}${TPUT_YELLOW}"
181 | escaped_print >&2 "${@}"
182 | printf >&2 "${TPUT_RESET}\n"
183 |
184 | "${@}"
185 |
186 | local ret=$?
187 | if [ ${ret} -ne 0 ]
188 | then
189 | run_failed
190 | printf >> "${run_logfile}" "FAILED with exit code ${ret}\n"
191 | else
192 | run_ok
193 | printf >> "${run_logfile}" "OK\n"
194 | fi
195 |
196 | return ${ret}
197 | }
198 |
199 | getent_cmd="$(which_cmd getent)"
200 | portable_check_user_exists() {
201 | local username="${1}" found=
202 |
203 | if [ ! -z "${getent_cmd}" ]
204 | then
205 | "${getent_cmd}" passwd "${username}" >/dev/null 2>&1
206 | return $?
207 | fi
208 |
209 | found="$(cut -d ':' -f 1 /dev/null 2>&1
220 | return $?
221 | fi
222 |
223 | found="$(cut -d ':' -f 1 &2 "User '${username}' already exists." && return 0
247 |
248 | echo >&2 "Adding ${username} user account ..."
249 |
250 | local nologin="$(which nologin 2>/dev/null || command -v nologin 2>/dev/null || echo '/bin/false')"
251 |
252 | # Linux
253 | if check_cmd useradd
254 | then
255 | run useradd -r -g "${username}" -c "${username}" -s "${nologin}" -d / "${username}" && return 0
256 | fi
257 |
258 | # FreeBSD
259 | if check_cmd pw
260 | then
261 | run pw useradd "${username}" -d / -g "${username}" -s "${nologin}" && return 0
262 | fi
263 |
264 | # BusyBox
265 | if check_cmd adduser
266 | then
267 | run adduser -D -G "${username}" "${username}" && return 0
268 | fi
269 |
270 | echo >&2 "Failed to add ${username} user account !"
271 |
272 | return 1
273 | }
274 |
275 | portable_add_group() {
276 | local groupname="${1}"
277 |
278 | portable_check_group_exists "${groupname}"
279 | [ $? -eq 0 ] && echo >&2 "Group '${groupname}' already exists." && return 0
280 |
281 | echo >&2 "Adding ${groupname} user group ..."
282 |
283 | # Linux
284 | if check_cmd groupadd
285 | then
286 | run groupadd -r "${groupname}" && return 0
287 | fi
288 |
289 | # FreeBSD
290 | if check_cmd pw
291 | then
292 | run pw groupadd "${groupname}" && return 0
293 | fi
294 |
295 | # BusyBox
296 | if check_cmd addgroup
297 | then
298 | run addgroup "${groupname}" && return 0
299 | fi
300 |
301 | echo >&2 "Failed to add ${groupname} user group !"
302 | return 1
303 | }
304 |
305 | portable_add_user_to_group() {
306 | local groupname="${1}" username="${2}"
307 |
308 | portable_check_group_exists "${groupname}"
309 | [ $? -ne 0 ] && echo >&2 "Group '${groupname}' does not exist." && return 1
310 |
311 | # find the user is already in the group
312 | if portable_check_user_in_group "${username}" "${groupname}"
313 | then
314 | # username is already there
315 | echo >&2 "User '${username}' is already in group '${groupname}'."
316 | return 0
317 | else
318 | # username is not in group
319 | echo >&2 "Adding ${username} user to the ${groupname} group ..."
320 |
321 | # Linux
322 | if check_cmd usermod
323 | then
324 | run usermod -a -G "${groupname}" "${username}" && return 0
325 | fi
326 |
327 | # FreeBSD
328 | if check_cmd pw
329 | then
330 | run pw groupmod "${groupname}" -m "${username}" && return 0
331 | fi
332 |
333 | # BusyBox
334 | if check_cmd addgroup
335 | then
336 | run addgroup "${username}" "${groupname}" && return 0
337 | fi
338 |
339 | echo >&2 "Failed to add user ${username} to group ${groupname} !"
340 | return 1
341 | fi
342 | }
343 |
344 | iscontainer() {
345 | # man systemd-detect-virt
346 | local cmd=$(which_cmd systemd-detect-virt)
347 | if [ ! -z "${cmd}" -a -x "${cmd}" ]
348 | then
349 | "${cmd}" --container >/dev/null 2>&1 && return 0
350 | fi
351 |
352 | # /proc/1/sched exposes the host's pid of our init !
353 | # http://stackoverflow.com/a/37016302
354 | local pid=$( cat /proc/1/sched 2>/dev/null | head -n 1 | { IFS='(),#:' read name pid th threads; echo $pid; } )
355 | pid=$(( pid + 0 ))
356 | [ ${pid} -ne 1 ] && return 0
357 |
358 | # lxc sets environment variable 'container'
359 | [ ! -z "${container}" ] && return 0
360 |
361 | # docker creates /.dockerenv
362 | # http://stackoverflow.com/a/25518345
363 | [ -f "/.dockerenv" ] && return 0
364 |
365 | # ubuntu and debian supply /bin/running-in-container
366 | # https://www.apt-browse.org/browse/ubuntu/trusty/main/i386/upstart/1.12.1-0ubuntu4/file/bin/running-in-container
367 | if [ -x "/bin/running-in-container" ]
368 | then
369 | "/bin/running-in-container" >/dev/null 2>&1 && return 0
370 | fi
371 |
372 | return 1
373 | }
374 |
375 | issystemd() {
376 | local pids p myns ns systemctl
377 |
378 | # if the directory /etc/systemd/system does not exit, it is not systemd
379 | [ ! -d /etc/systemd/system ] && return 1
380 |
381 | # if there is no systemctl command, it is not systemd
382 | systemctl=$(which systemctl 2>/dev/null || command -v systemctl 2>/dev/null)
383 | [ -z "${systemctl}" -o ! -x "${systemctl}" ] && return 1
384 |
385 | # if pid 1 is systemd, it is systemd
386 | [ "$(basename $(readlink /proc/1/exe) 2>/dev/null)" = "systemd" ] && return 0
387 |
388 | # if systemd is not running, it is not systemd
389 | pids=$(pidof systemd 2>/dev/null)
390 | [ -z "${pids}" ] && return 1
391 |
392 | # check if the running systemd processes are not in our namespace
393 | myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
394 | for p in ${pids}
395 | do
396 | ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
397 |
398 | # if pid of systemd is in our namespace, it is systemd
399 | [ ! -z "${myns}" && "${myns}" = "${ns}" ] && return 0
400 | done
401 |
402 | # else, it is not systemd
403 | return 1
404 | }
405 |
406 | install_non_systemd_init() {
407 | [ "${UID}" != 0 ] && return 1
408 |
409 | local key="unknown"
410 | if [ -f /etc/os-release ]
411 | then
412 | source /etc/os-release || return 1
413 | key="${ID}-${VERSION_ID}"
414 |
415 | elif [ -f /etc/redhat-release ]
416 | then
417 | key=$(&2 "Installing OpenRC init file..."
425 | run cp system/netdata-openrc /etc/init.d/netdata && \
426 | run chmod 755 /etc/init.d/netdata && \
427 | run rc-update add netdata default && \
428 | return 0
429 |
430 | elif [ "${key}" = "debian-7" \
431 | -o "${key}" = "ubuntu-12.04" \
432 | -o "${key}" = "ubuntu-14.04" \
433 | ]
434 | then
435 | echo >&2 "Installing LSB init file..."
436 | run cp system/netdata-lsb /etc/init.d/netdata && \
437 | run chmod 755 /etc/init.d/netdata && \
438 | run update-rc.d netdata defaults && \
439 | run update-rc.d netdata enable && \
440 | return 0
441 | elif [[ "${key}" =~ ^(amzn-201[567]|ol|CentOS release 6|Red Hat Enterprise Linux Server release 6).* ]]
442 | then
443 | echo >&2 "Installing init.d file..."
444 | run cp system/netdata-init-d /etc/init.d/netdata && \
445 | run chmod 755 /etc/init.d/netdata && \
446 | run chkconfig netdata on && \
447 | return 0
448 | else
449 | echo >&2 "I don't know what init file to install on system '${key}'. Open a github issue to help us fix it."
450 | return 1
451 | fi
452 | elif [ -f /etc/init.d/netdata ]
453 | then
454 | echo >&2 "file '/etc/init.d/netdata' already exists."
455 | return 0
456 | else
457 | echo >&2 "I don't know what init file to install on system '${key}'. Open a github issue to help us fix it."
458 | fi
459 |
460 | return 1
461 | }
462 |
463 | NETDATA_START_CMD="netdata"
464 | NETDATA_STOP_CMD="killall netdata"
465 |
466 | install_netdata_service() {
467 | if [ "${UID}" -eq 0 ]
468 | then
469 | if issystemd
470 | then
471 | # systemd is running on this system
472 | NETDATA_START_CMD="systemctl start netdata"
473 | NETDATA_STOP_CMD="systemctl stop netdata"
474 |
475 | if [ ! -f /etc/systemd/system/netdata.service ]
476 | then
477 | echo >&2 "Installing systemd service..."
478 | run cp system/netdata.service /etc/systemd/system/netdata.service && \
479 | run systemctl daemon-reload && \
480 | run systemctl enable netdata && \
481 | return 0
482 | else
483 | echo >&2 "file '/etc/systemd/system/netdata.service' already exists."
484 | return 0
485 | fi
486 | else
487 | install_non_systemd_init
488 | local ret=$?
489 |
490 | if [ ${ret} -eq 0 ]
491 | then
492 | NETDATA_START_CMD="service netdata start"
493 | NETDATA_STOP_CMD="service netdata stop"
494 | fi
495 |
496 | return ${ret}
497 | fi
498 | fi
499 |
500 | return 1
501 | }
502 |
503 |
504 | # -----------------------------------------------------------------------------
505 | # stop netdata
506 |
507 | pidisnetdata() {
508 | if [ -d /proc/self ]
509 | then
510 | [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
511 | [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
512 | return 1
513 | fi
514 | return 0
515 | }
516 |
517 | stop_netdata_on_pid() {
518 | local pid="${1}" ret=0 count=0
519 |
520 | pidisnetdata ${pid} || return 0
521 |
522 | printf >&2 "Stopping netdata on pid ${pid} ..."
523 | while [ ! -z "$pid" -a ${ret} -eq 0 ]
524 | do
525 | if [ ${count} -gt 45 ]
526 | then
527 | echo >&2 "Cannot stop the running netdata on pid ${pid}."
528 | return 1
529 | fi
530 |
531 | count=$(( count + 1 ))
532 |
533 | run kill ${pid} 2>/dev/null
534 | ret=$?
535 |
536 | test ${ret} -eq 0 && printf >&2 "." && sleep 2
537 | done
538 |
539 | echo >&2
540 | if [ ${ret} -eq 0 ]
541 | then
542 | echo >&2 "SORRY! CANNOT STOP netdata ON PID ${pid} !"
543 | return 1
544 | fi
545 |
546 | echo >&2 "netdata on pid ${pid} stopped."
547 | return 0
548 | }
549 |
550 | stop_all_netdata() {
551 | local p myns ns
552 |
553 | myns="$(readlink /proc/self/ns/pid 2>/dev/null)"
554 |
555 | # echo >&2 "Stopping a (possibly) running netdata (namespace '${myns}')..."
556 |
557 | for p in \
558 | $(cat /var/run/netdata.pid 2>/dev/null) \
559 | $(cat /var/run/netdata/netdata.pid 2>/dev/null) \
560 | $(pidof netdata 2>/dev/null)
561 | do
562 | ns="$(readlink /proc/${p}/ns/pid 2>/dev/null)"
563 |
564 | if [ -z "${myns}" -o -z "${ns}" -o "${myns}" = "${ns}" ]
565 | then
566 | stop_netdata_on_pid ${p}
567 | fi
568 | done
569 | }
570 |
571 | # -----------------------------------------------------------------------------
572 | # restart netdata
573 |
574 | restart_netdata() {
575 | local netdata="${1}"
576 | shift
577 |
578 | local started=0
579 |
580 | progress "Start netdata"
581 |
582 | if [ "${UID}" -eq 0 ]
583 | then
584 | service netdata stop
585 | stop_all_netdata
586 | service netdata restart && started=1
587 |
588 | if [ ${started} -eq 0 ]
589 | then
590 | service netdata start && started=1
591 | fi
592 | fi
593 |
594 | if [ ${started} -eq 0 ]
595 | then
596 | # still not started...
597 |
598 | run stop_all_netdata
599 | run "${netdata}" "${@}"
600 | return $?
601 | fi
602 |
603 | return 0
604 | }
605 |
606 | # -----------------------------------------------------------------------------
607 | # install netdata logrotate
608 |
609 | install_netdata_logrotate() {
610 | if [ ${UID} -eq 0 ]
611 | then
612 | if [ -d /etc/logrotate.d ]
613 | then
614 | if [ ! -f /etc/logrotate.d/netdata ]
615 | then
616 | run cp system/netdata.logrotate /etc/logrotate.d/netdata
617 | fi
618 |
619 | if [ -f /etc/logrotate.d/netdata ]
620 | then
621 | run chmod 644 /etc/logrotate.d/netdata
622 | fi
623 |
624 | return 0
625 | fi
626 | fi
627 |
628 | return 1
629 | }
630 |
631 | # -----------------------------------------------------------------------------
632 | # add netdata user and group
633 |
634 | NETDATA_ADDED_TO_DOCKER=0
635 | NETDATA_ADDED_TO_NGINX=0
636 | NETDATA_ADDED_TO_VARNISH=0
637 | NETDATA_ADDED_TO_HAPROXY=0
638 | NETDATA_ADDED_TO_ADM=0
639 | NETDATA_ADDED_TO_NSD=0
640 | NETDATA_ADDED_TO_PROXY=0
641 | NETDATA_ADDED_TO_SQUID=0
642 | add_netdata_user_and_group() {
643 | if [ ${UID} -eq 0 ]
644 | then
645 | portable_add_group netdata || return 1
646 | portable_add_user netdata || return 1
647 | portable_add_user_to_group docker netdata && NETDATA_ADDED_TO_DOCKER=1
648 | portable_add_user_to_group nginx netdata && NETDATA_ADDED_TO_NGINX=1
649 | portable_add_user_to_group varnish netdata && NETDATA_ADDED_TO_VARNISH=1
650 | portable_add_user_to_group haproxy netdata && NETDATA_ADDED_TO_HAPROXY=1
651 | portable_add_user_to_group adm netdata && NETDATA_ADDED_TO_ADM=1
652 | portable_add_user_to_group nsd netdata && NETDATA_ADDED_TO_NSD=1
653 | portable_add_user_to_group proxy netdata && NETDATA_ADDED_TO_PROXY=1
654 | portable_add_user_to_group squid netdata && NETDATA_ADDED_TO_SQUID=1
655 | return 0
656 | fi
657 |
658 | return 1
659 | }
--------------------------------------------------------------------------------
/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Migwn, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | # TODO classpath?
118 | fi
119 |
120 | if [ -z "$JAVA_HOME" ]; then
121 | javaExecutable="`which javac`"
122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123 | # readlink(1) is not available as standard on Solaris 10.
124 | readLink=`which readlink`
125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126 | if $darwin ; then
127 | javaHome="`dirname \"$javaExecutable\"`"
128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129 | else
130 | javaExecutable="`readlink -f \"$javaExecutable\"`"
131 | fi
132 | javaHome="`dirname \"$javaExecutable\"`"
133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134 | JAVA_HOME="$javaHome"
135 | export JAVA_HOME
136 | fi
137 | fi
138 | fi
139 |
140 | if [ -z "$JAVACMD" ] ; then
141 | if [ -n "$JAVA_HOME" ] ; then
142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 | # IBM's JDK on AIX uses strange locations for the executables
144 | JAVACMD="$JAVA_HOME/jre/sh/java"
145 | else
146 | JAVACMD="$JAVA_HOME/bin/java"
147 | fi
148 | else
149 | JAVACMD="`which java`"
150 | fi
151 | fi
152 |
153 | if [ ! -x "$JAVACMD" ] ; then
154 | echo "Error: JAVA_HOME is not defined correctly." >&2
155 | echo " We cannot execute $JAVACMD" >&2
156 | exit 1
157 | fi
158 |
159 | if [ -z "$JAVA_HOME" ] ; then
160 | echo "Warning: JAVA_HOME environment variable is not set."
161 | fi
162 |
163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164 |
165 | # traverses directory structure from process work directory to filesystem root
166 | # first directory with .mvn subdirectory is considered project base directory
167 | find_maven_basedir() {
168 |
169 | if [ -z "$1" ]
170 | then
171 | echo "Path not specified to find_maven_basedir"
172 | return 1
173 | fi
174 |
175 | basedir="$1"
176 | wdir="$1"
177 | while [ "$wdir" != '/' ] ; do
178 | if [ -d "$wdir"/.mvn ] ; then
179 | basedir=$wdir
180 | break
181 | fi
182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183 | if [ -d "${wdir}" ]; then
184 | wdir=`cd "$wdir/.."; pwd`
185 | fi
186 | # end of workaround
187 | done
188 | echo "${basedir}"
189 | }
190 |
191 | # concatenates all lines of a file
192 | concat_lines() {
193 | if [ -f "$1" ]; then
194 | echo "$(tr -s '\n' ' ' < "$1")"
195 | fi
196 | }
197 |
198 | BASE_DIR=`find_maven_basedir "$(pwd)"`
199 | if [ -z "$BASE_DIR" ]; then
200 | exit 1;
201 | fi
202 |
203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
204 | echo $MAVEN_PROJECTBASEDIR
205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
206 |
207 | # For Cygwin, switch paths to Windows format before running java
208 | if $cygwin; then
209 | [ -n "$M2_HOME" ] &&
210 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
211 | [ -n "$JAVA_HOME" ] &&
212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
213 | [ -n "$CLASSPATH" ] &&
214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
215 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
217 | fi
218 |
219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
220 |
221 | exec "$JAVACMD" \
222 | $MAVEN_OPTS \
223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
226 |
--------------------------------------------------------------------------------
/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40 |
41 | @REM set %HOME% to equivalent of $HOME
42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43 |
44 | @REM Execute a user defined script before this one
45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49 | :skipRcPre
50 |
51 | @setlocal
52 |
53 | set ERROR_CODE=0
54 |
55 | @REM To isolate internal variables from possible post scripts, we use another setlocal
56 | @setlocal
57 |
58 | @REM ==== START VALIDATION ====
59 | if not "%JAVA_HOME%" == "" goto OkJHome
60 |
61 | echo.
62 | echo Error: JAVA_HOME not found in your environment. >&2
63 | echo Please set the JAVA_HOME variable in your environment to match the >&2
64 | echo location of your Java installation. >&2
65 | echo.
66 | goto error
67 |
68 | :OkJHome
69 | if exist "%JAVA_HOME%\bin\java.exe" goto init
70 |
71 | echo.
72 | echo Error: JAVA_HOME is set to an invalid directory. >&2
73 | echo JAVA_HOME = "%JAVA_HOME%" >&2
74 | echo Please set the JAVA_HOME variable in your environment to match the >&2
75 | echo location of your Java installation. >&2
76 | echo.
77 | goto error
78 |
79 | @REM ==== END VALIDATION ====
80 |
81 | :init
82 |
83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
84 | @REM Fallback to current working directory if not found.
85 |
86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
88 |
89 | set EXEC_DIR=%CD%
90 | set WDIR=%EXEC_DIR%
91 | :findBaseDir
92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
93 | cd ..
94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
95 | set WDIR=%CD%
96 | goto findBaseDir
97 |
98 | :baseDirFound
99 | set MAVEN_PROJECTBASEDIR=%WDIR%
100 | cd "%EXEC_DIR%"
101 | goto endDetectBaseDir
102 |
103 | :baseDirNotFound
104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
105 | cd "%EXEC_DIR%"
106 |
107 | :endDetectBaseDir
108 |
109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
110 |
111 | @setlocal EnableExtensions EnableDelayedExpansion
112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
114 |
115 | :endReadAdditionalConfig
116 |
117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
118 |
119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121 |
122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
123 | if ERRORLEVEL 1 goto error
124 | goto end
125 |
126 | :error
127 | set ERROR_CODE=1
128 |
129 | :end
130 | @endlocal & set ERROR_CODE=%ERROR_CODE%
131 |
132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
136 | :skipRcPost
137 |
138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
140 |
141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
142 |
143 | exit /B %ERROR_CODE%
144 |
--------------------------------------------------------------------------------
/netdata-java-orchestrator-installer.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | # SPDX-License-Identifier: GPL-3.0-or-later
3 |
4 | source_dir="$(pwd)"
5 | installer_dir="$(dirname "${0}")"
6 |
7 | if [ "${source_dir}" != "${installer_dir}" -a "${installer_dir}" != "." ]
8 | then
9 | echo >&2 "Warning: you are currently in '${source_dir}' but the installer is in '${installer_dir}'."
10 | fi
11 |
12 |
13 | # -----------------------------------------------------------------------------
14 | # reload the user profile
15 |
16 | [ -f /etc/profile ] && . /etc/profile
17 |
18 | # make sure /etc/profile does not change our current directory
19 | cd "${source_dir}" || exit 1
20 |
21 |
22 | # -----------------------------------------------------------------------------
23 | # load the required functions
24 |
25 | if [ -f "${installer_dir}/installer/functions.sh" ]
26 | then
27 | source "${installer_dir}/installer/functions.sh" || exit 1
28 | else
29 | source "${source_dir}/installer/functions.sh" || exit 1
30 | fi
31 |
32 | run_logfile="netdata-java-orchestrator-installer.log"
33 |
34 | umask 002
35 |
36 | # Be nice on production environments
37 | renice 19 $$ >/dev/null 2>/dev/null
38 |
39 | ME="$0"
40 | DONOTSTART=0
41 | DONOTWAIT=0
42 | NETDATA_PREFIX=
43 | NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS-}"
44 |
45 | usage() {
46 | netdata_banner "installer command line options"
47 | cat <
42 | * The module also attatches to the local JMX server to monitor the orchestrator
43 | * process.
44 | *
56 | * Warning: Only use this when you do not want to close the
57 | * underlying JMXConnetor when closing the generated MBeanServerCollector.
58 | *
74 | * Calling {@link #close()}} on the resulting {@code MBeanServerCollector}
75 | * closes {@code jmxConnector} too.
76 | *
90 | * Queries MBean {@code java.lang:type=Runtime} for attribute {@code Name}.
91 | *
94 | * This attribute can be used as a unique identifier of the underlying JMX
95 | * agent
96 | *
37 | * Every monitored JMX Servers tries to monitor each chart in this list. If
38 | * a JMX Server does not have the required M(X)Beans we won't try adding it
39 | * over and over again.
40 | *
22 | * Supported attributes are
23 | *
24 | * property.compositeDataKey
28 | */
29 | private String value;
30 |
31 | /**
32 | * Multiply the collected value before displaying it.
33 | */
34 | private int multiplier = 1;
35 | /**
36 | * Divide the collected value before displaying it.
37 | */
38 | private int divisor = 1;
39 |
40 | /**
41 | * Name displayed to user.
42 | */
43 | private String name;
44 |
45 | /**
46 | * If true the value get's collected but not displayed.
47 | */
48 | private boolean hidden = false;
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/org/firehol/netdata/module/jmx/configuration/JmxModuleConfiguration.java:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-or-later
2 |
3 | package org.firehol.netdata.module.jmx.configuration;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | import org.firehol.netdata.module.jmx.JmxModule;
9 |
10 | import lombok.Getter;
11 | import lombok.Setter;
12 |
13 | /**
14 | * Configuration scheme to configure {@link JmxModule}
15 | *
16 | * @since 1.0.0
17 | * @author Simon Nagl
18 | */
19 | @Getter
20 | @Setter
21 | public class JmxModuleConfiguration {
22 |
23 | /**
24 | * If true auto detect and monitor running local virtual machines.
25 | */
26 | private boolean autoDetectLocalVirtualMachines = true;
27 |
28 | /**
29 | * A list of JMX servers to monitor.
30 | */
31 | private List {@code service:jmx:rmi://[host[:port]][urlPath]}
22 | *
23 | *
24 | * @see Oracle
26 | * Developer's Guide for JMX Clients
27 | *
28 | */
29 | private String serviceUrl;
30 |
31 | /**
32 | * Name displayed at the dashboard.
33 | */
34 | private String name;
35 |
36 | @JsonIgnore
37 | // This property is not part of the configuration scheme.
38 | // This is a technical property used by the module.
39 | private List
25 | *
30 | *
38 | * Attribute must match {@link #getAttribute()} or be more precise.
39 | *
40 | * @param dimension
41 | * to add to the list of dimensions
42 | * @param attribute
43 | * of the MBean which should be queried
44 | */
45 | @Override
46 | public void addDimension(Dimension dimension, final String attribute) {
47 | if (!this.getAttribute().equals(attribute)) {
48 | throw new IllegalArgumentException(
49 | String.format("attribute '%s' must match this.attribute '%s'", attribute, this.getAttribute()));
50 | }
51 |
52 | this.valueStore.addDimension(dimension);
53 | }
54 |
55 | @Override
56 | public void query() throws JmxMBeanServerQueryException {
57 | Object result = MBeanServerUtils.getAttribute(getMBeanServer(), this.getName(), this.getAttribute());
58 | valueStore.updateValue(result);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/org/firehol/netdata/module/jmx/query/MBeanValueStore.java:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-or-later
2 |
3 | package org.firehol.netdata.module.jmx.query;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 | import java.util.stream.Stream;
8 |
9 | import org.firehol.netdata.model.Dimension;
10 |
11 | public abstract class MBeanValueStore {
12 |
13 | final List
61 | * If the file cannot be parsed for some reason this methods tries to use a
62 | * default configuration. This is the default instance of the configuration
63 | * scheme.
64 | *
29 | *
42 | */
43 | public static Object getPrivateField(Object object, String fieldName)
44 | throws NoSuchFieldException, IllegalAccessException, SecurityException {
45 | Field field = object.getClass().getDeclaredField(fieldName);
46 | field.setAccessible(true);
47 | return field.get(object);
48 | }
49 |
50 | /**
51 | * Setter for private filed {@code filedName} of {@code object}.
52 | *
53 | * @param object
54 | * to modify
55 | * @param fieldName
56 | * Name of field to set.
57 | * @param value
58 | * to set
59 | * @throws NoSuchFieldException
60 | * if a field with the specified name is not found.
61 | * @throws NullPointerException
62 | * If any of the following conditions is met:
63 | *
64 | *
68 | * @throws SecurityException
69 | * If a security manager, s, is present and any of the
70 | * following conditions is met:
71 | *
72 | *
73 | *
86 | * @throws IllegalArgumentException
87 | * if the specified object is not an instance of the class or
88 | * interface declaring the underlying field (or a subclass or
89 | * implementor thereof), or if an unwrapping conversion fails.
90 | * @throws IllegalAccessException
91 | * if this Field object is enforcing Java language access
92 | * control and the underlying field is either inaccessible or
93 | * final.
94 | * @throws ExceptionInInitializerError
95 | * if the initialization provoked by this method fails.
96 | */
97 | public static void setPrivateFiled(Object object, String fieldName, Object value)
98 | throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException,
99 | NullPointerException, ExceptionInInitializerError {
100 | Field field = object.getClass().getDeclaredField(fieldName);
101 | field.setAccessible(true);
102 | field.set(object, value);
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/test/java/org/firehol/netdata/testutils/TestObjectBuilder.java:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-or-later
2 |
3 | package org.firehol.netdata.testutils;
4 |
5 | import org.firehol.netdata.model.Chart;
6 | import org.firehol.netdata.model.ChartType;
7 | import org.firehol.netdata.model.Dimension;
8 | import org.firehol.netdata.module.jmx.configuration.JmxChartConfiguration;
9 | import org.firehol.netdata.module.jmx.configuration.JmxDimensionConfiguration;
10 |
11 | /**
12 | * Build standard Test Objects.
13 | *
14 | * A standard Test Object is a instance of a Class where all Properties are set:
15 | *
16 | *
22 | *
23 | * @author Simon Nagl
24 | */
25 | public abstract class TestObjectBuilder {
26 | public static Chart buildChart() {
27 | Chart chart = new Chart();
28 | chart.setType("type");
29 | chart.setId("id");
30 | chart.setName("name");
31 | chart.setTitle("title");
32 | chart.setUnits("units");
33 | chart.setFamily("family");
34 | chart.setContext("context");
35 | chart.setChartType(ChartType.LINE);
36 | return chart;
37 | }
38 |
39 | public static Dimension buildDimension() {
40 | Dimension dim = new Dimension();
41 | dim.setId("id");
42 | dim.setName("name");
43 | dim.setHidden(true);
44 | dim.setCurrentValue(1L);
45 | return dim;
46 | }
47 |
48 | public static JmxChartConfiguration buildJmxChartConfiguration() {
49 | JmxChartConfiguration chartConfig = new JmxChartConfiguration();
50 | chartConfig.setId("id");
51 | chartConfig.setTitle("title");
52 | chartConfig.setFamily("family");
53 | chartConfig.setUnits("units");
54 | return chartConfig;
55 | }
56 |
57 | public static JmxDimensionConfiguration buildJmxDimensionConfiguration() {
58 | JmxDimensionConfiguration dimensionConfig = new JmxDimensionConfiguration();
59 | dimensionConfig.setFrom("from");
60 | dimensionConfig.setValue("value");
61 | dimensionConfig.setName("name");
62 | return dimensionConfig;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/test/java/org/firehol/netdata/utils/AlignToTimeIntervalServiceTest.java:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-or-later
2 |
3 | package org.firehol.netdata.utils;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | import java.sql.Time;
8 | import java.util.concurrent.TimeUnit;
9 |
10 | import org.firehol.netdata.testutils.ReflectionUtils;
11 | import org.junit.Rule;
12 | import org.junit.Test;
13 | import org.junit.contrib.java.lang.system.SystemErrRule;
14 |
15 | public class AlignToTimeIntervalServiceTest {
16 |
17 | @Rule
18 | public final SystemErrRule systemErrRule = new SystemErrRule().enableLog();
19 |
20 | @Test
21 | public void testAlignToTimeIntervalService()
22 | throws NoSuchFieldException, IllegalAccessException, SecurityException {
23 |
24 | // Test
25 | AlignToTimeIntervalService service = new AlignToTimeIntervalService(100, TimeUnit.NANOSECONDS);
26 |
27 | // Verify
28 | assertEquals(100L, ReflectionUtils.getPrivateField(service, "intervalInNSec"));
29 | }
30 |
31 | @Test
32 | public void testAlignToTimeIntervalServiceSeconds()
33 | throws NoSuchFieldException, IllegalAccessException, SecurityException {
34 |
35 | // Test
36 | AlignToTimeIntervalService service = new AlignToTimeIntervalService(100, TimeUnit.SECONDS);
37 |
38 | // Verify
39 | assertEquals(TimeUnit.SECONDS.toNanos(100), ReflectionUtils.getPrivateField(service, "intervalInNSec"));
40 | }
41 |
42 | @Test(timeout = 2000)
43 | // Just test it does not fail.
44 | public void testAlignToNextInterval() throws InterruptedException {
45 | // Build object under test
46 | AlignToTimeIntervalService service = new AlignToTimeIntervalService(UnitConversion.NANO_PER_PLAIN / 100,
47 | TimeUnit.NANOSECONDS);
48 |
49 | for (int i = 0; i < 100; i++) {
50 | service.alignToNextInterval();
51 | }
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/test/java/org/firehol/netdata/utils/LoggingUtilsTest.java:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-3.0-or-later
2 |
3 | package org.firehol.netdata.utils;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | import java.util.function.Supplier;
8 |
9 | import org.junit.Before;
10 | import org.junit.Test;
11 |
12 | public class LoggingUtilsTest {
13 |
14 | private Exception exception;
15 |
16 | @Before
17 | public void init() {
18 | Exception fine = new Exception("Here are the details.");
19 | Exception detail = new Exception("This is the reason.", fine);
20 | exception = new Exception("Something went wrong.", detail);
21 | }
22 |
23 | @Test
24 | public void testBuildMessageThrowable() {
25 | // Test
26 | String message = LoggingUtils.buildMessage(exception);
27 |
28 | // Verify
29 | assertEquals(
30 | "[java.lang.Exception] Something went wrong. Detail: This is the reason. Detail: Here are the details.",
31 | message);
32 | }
33 |
34 | @Test
35 | public void testBuildMessageStringThrowable() {
36 | // Test
37 | String message = LoggingUtils.buildMessage("Could not do it.", exception);
38 |
39 | // Verify
40 | assertEquals(
41 | "Could not do it. Reason: [java.lang.Exception] Something went wrong. Detail: This is the reason. Detail: Here are the details.",
42 | message);
43 | }
44 |
45 | @Test
46 | public void testBuildMessageStrings() {
47 | // Test
48 | String message = LoggingUtils.buildMessage("This ", "should ", "be ", "one ", "message.");
49 |
50 | // Verify
51 | assertEquals("This should be one message.", message);
52 | }
53 |
54 | @Test
55 | public void testBuildMessageStringsNoArg() {
56 | // Test
57 | String message = LoggingUtils.buildMessage();
58 |
59 | // Verify
60 | assertEquals("", message);
61 | }
62 |
63 | @Test
64 | public void testBuildMessageStringsOneArg() {
65 | // Test
66 | String message = LoggingUtils.buildMessage("One Argument.");
67 |
68 | // Verify
69 | assertEquals("One Argument.", message);
70 | }
71 |
72 | @Test
73 | public void getMessageSupplierThrowable() {
74 | // Test
75 | Supplier