Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced new Maven module: Insights.
- Loading branch information
1 parent
e5d3127
commit bb84706
Showing
10 changed files
with
250 additions
and
22 deletions.
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
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 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.rapidoid</groupId> | ||
<artifactId>rapidoid</artifactId> | ||
<version>4.1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>rapidoid-insights</artifactId> | ||
<packaging>jar</packaging> | ||
<description>Rapidoid Insights</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.rapidoid</groupId> | ||
<artifactId>rapidoid-u</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.rapidoid</groupId> | ||
<artifactId>rapidoid-log</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.rapidoid</groupId> | ||
<artifactId>rapidoid-test-commons</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
63 changes: 63 additions & 0 deletions
63
rapidoid-insights/src/main/java/org/rapidoid/AbstractInsightful.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,63 @@ | ||
package org.rapidoid; | ||
|
||
import org.rapidoid.log.Log; | ||
|
||
/* | ||
* #%L | ||
* rapidoid-insights | ||
* %% | ||
* Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors | ||
* %% | ||
* Licensed 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 | ||
* | ||
* http://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. | ||
* #L% | ||
*/ | ||
|
||
/** | ||
* @author Nikolche Mihajlovski | ||
* @since 4.1.0 | ||
*/ | ||
public abstract class AbstractInsightful implements Insightful { | ||
|
||
private final String kind; | ||
|
||
private final String name; | ||
|
||
private final Thread creatorThread; | ||
|
||
public AbstractInsightful(String kind, String name) { | ||
this.creatorThread = Thread.currentThread(); | ||
this.kind = kind; | ||
this.name = name; | ||
|
||
Log.info("Creating object", "kind", kind, "name", name, "creatorThread", creatorThread.getName(), "class", | ||
getClass().getSimpleName()); | ||
|
||
Insights.register(this); | ||
} | ||
|
||
@Override | ||
public String getKind() { | ||
return kind; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public Thread getCreatorThread() { | ||
return creatorThread; | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
rapidoid-insights/src/main/java/org/rapidoid/Insightful.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,35 @@ | ||
package org.rapidoid; | ||
|
||
/* | ||
* #%L | ||
* rapidoid-insights | ||
* %% | ||
* Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors | ||
* %% | ||
* Licensed 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 | ||
* | ||
* http://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. | ||
* #L% | ||
*/ | ||
|
||
/** | ||
* @author Nikolche Mihajlovski | ||
* @since 4.1.0 | ||
*/ | ||
public interface Insightful { | ||
|
||
String getKind(); | ||
|
||
String getName(); | ||
|
||
Thread getCreatorThread(); | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
rapidoid-insights/src/main/java/org/rapidoid/Insights.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,58 @@ | ||
package org.rapidoid; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.rapidoid.util.U; | ||
|
||
/* | ||
* #%L | ||
* rapidoid-insights | ||
* %% | ||
* Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors | ||
* %% | ||
* Licensed 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 | ||
* | ||
* http://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. | ||
* #L% | ||
*/ | ||
|
||
/** | ||
* @author Nikolche Mihajlovski | ||
* @since 4.1.0 | ||
*/ | ||
public class Insights { | ||
|
||
private static final Map<String, List<Insightful>> RESOURCES = U.autoExpandingMap(ArrayList.class); | ||
|
||
public static void register(Insightful resource) { | ||
RESOURCES.get(resource.getKind()).add(resource); | ||
} | ||
|
||
public static String getInfo() { | ||
return RESOURCES.toString(); | ||
} | ||
|
||
public static String getCpuMemStats() { | ||
Runtime rt = Runtime.getRuntime(); | ||
|
||
long totalMem = rt.totalMemory(); | ||
long maxMem = rt.maxMemory(); | ||
long freeMem = rt.freeMemory(); | ||
long usedMem = totalMem - freeMem; | ||
int megs = 1024 * 1024; | ||
|
||
String msg = "MEM [total=%s MB, used=%s MB, max=%s MB]"; | ||
return String.format(msg, totalMem / megs, usedMem / megs, maxMem / megs); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
rapidoid-insights/src/main/java/org/rapidoid/InsightsThread.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,54 @@ | ||
package org.rapidoid; | ||
|
||
import org.rapidoid.log.Log; | ||
import org.rapidoid.util.U; | ||
|
||
/* | ||
* #%L | ||
* rapidoid-insights | ||
* %% | ||
* Copyright (C) 2014 - 2015 Nikolche Mihajlovski and contributors | ||
* %% | ||
* Licensed 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 | ||
* | ||
* http://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. | ||
* #L% | ||
*/ | ||
|
||
/** | ||
* @author Nikolche Mihajlovski | ||
* @since 4.1.0 | ||
*/ | ||
public class InsightsThread extends Thread { | ||
|
||
public InsightsThread() { | ||
super("stats"); | ||
} | ||
|
||
private String lastStats; | ||
|
||
@Override | ||
public void run() { | ||
Log.info("Starting Insights thread..."); | ||
|
||
while (!Thread.interrupted()) { | ||
U.sleep(1000); | ||
String stats = Insights.getCpuMemStats() + "\n" + Insights.getInfo(); | ||
if (!stats.equals(lastStats)) { | ||
System.out.println(stats); | ||
lastStats = stats; | ||
} | ||
} | ||
|
||
Log.info("Stopped Insights thread."); | ||
} | ||
|
||
} |
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
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
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
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