Browse Source

Created skeleton app

Raymond Edah 7 years ago
parent
commit
5cf622d467

+ 10 - 0
.gitignore

@@ -17,3 +17,13 @@ gradle-app.setting
 
 # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
 # gradle/wrapper/gradle-wrapper.properties
+
+# User-specific stuff:
+.idea/**/workspace.xml
+.idea/**/tasks.xml
+.idea/dictionaries
+.idea/libraries
+.idea/modules
+
+
+

+ 5 - 0
.idea/inspectionProfiles/Project_Default.xml

@@ -0,0 +1,5 @@
+<component name="InspectionProjectProfileManager">
+  <profile version="1.0" is_locked="false">
+    <option name="myName" value="Project Default" />
+  </profile>
+</component>

+ 15 - 0
.idea/misc.xml

@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="EmacsSettings">
+    <option name="emacsPath" value="/usr/bin/emacs" />
+  </component>
+  <component name="ErlangCompilerOptions">
+    <useRebarCompiler>true</useRebarCompiler>
+  </component>
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
+    <output url="file://$PROJECT_DIR$/out" />
+  </component>
+  <component name="RebarSettings">
+    <rebarPath>/usr/bin/rebar</rebarPath>
+  </component>
+</project>

+ 10 - 0
.idea/modules.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/smartos_exporter.iml" filepath="$PROJECT_DIR$/smartos_exporter.iml" />
+      <module fileurl="file://$PROJECT_DIR$/.idea/modules/smartos_exporter_main.iml" filepath="$PROJECT_DIR$/.idea/modules/smartos_exporter_main.iml" group="smartos_exporter" />
+      <module fileurl="file://$PROJECT_DIR$/.idea/modules/smartos_exporter_test.iml" filepath="$PROJECT_DIR$/.idea/modules/smartos_exporter_test.iml" group="smartos_exporter" />
+    </modules>
+  </component>
+</project>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 6 - 1
build.gradle

@@ -12,12 +12,14 @@ sourceCompatibility = '1.8'
 mainClassName = 'io.vertx.core.Launcher'
 
 def vertxVersion = '3.5.1'
-def mainVerticleName = 'io.vertx.starter.MainVerticle'
+def mainVerticleName = 'nu.ltd.fp.se.SmartOSExporter'
 def watchForChange = 'src/**/*'
 def doOnChange = './gradlew classes'
 
 dependencies {
   compile "io.vertx:vertx-core:$vertxVersion"
+  compile "io.vertx:vertx-web:$vertxVersion"
+  compile "io.vertx:vertx-config:$vertxVersion"
   testCompile "junit:junit:4.12"
   testCompile "io.vertx:vertx-unit:$vertxVersion"
 }
@@ -39,3 +41,6 @@ run {
 task wrapper(type: Wrapper) {
   gradleVersion = '4.5.1'
 }
+
+
+

+ 3 - 0
conf/config.json

@@ -0,0 +1,3 @@
+{
+  "service.port": 18089
+}

+ 2 - 1
gradle/wrapper/gradle-wrapper.properties

@@ -1,5 +1,6 @@
+#Fri Apr 06 15:56:49 BST 2018
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-all.zip

+ 14 - 0
smartos_exporter.iml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module external.linked.project.id="smartos_exporter" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="1.0-SNAPSHOT" type="JAVA_MODULE" version="4">
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <excludeFolder url="file://$MODULE_DIR$/.gradle" />
+      <excludeFolder url="file://$MODULE_DIR$/build" />
+      <excludeFolder url="file://$MODULE_DIR$/out" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="library" name="groovy-2.4.13" level="application" />
+  </component>
+</module>

+ 5 - 0
src/main/java/nu/ltd/fp/se/Constant.java

@@ -0,0 +1,5 @@
+package nu.ltd.fp.se;
+
+public class Constant {
+  public static final String SERVICE_PORT = "service.port";
+}

+ 53 - 0
src/main/java/nu/ltd/fp/se/SmartOSExporter.java

@@ -0,0 +1,53 @@
+package nu.ltd.fp.se;
+
+import io.vertx.core.AbstractVerticle;
+import io.vertx.core.Future;
+import io.vertx.core.http.HttpServerResponse;
+import io.vertx.ext.web.Router;
+import io.vertx.ext.web.handler.BodyHandler;
+
+public class SmartOSExporter extends AbstractVerticle {
+
+  private SmartOSExporter smartOSExporter;
+  private String mainPage;
+
+  @Override
+  public void start(Future<Void> future) {
+    initializeVars();
+    Router router = Router.router(vertx);
+    router.route().handler(BodyHandler.create());
+
+    // Route / url
+    router.route("/").handler(routingContext ->  {
+      HttpServerResponse response = routingContext.response();
+      response.putHeader("content-type", "text/html").end(mainPage);
+    });
+
+    // Route /metrics url
+
+    // Set up HTTP server
+    createHttpServer(future, router);
+  }
+
+  private void initializeVars() {
+    smartOSExporter = this;
+    mainPage = "<h1>SmartOS Node exporter</h1>\n<p><a href=\"/metrics\">Metrics</a></p>";
+  }
+
+  private void createHttpServer(Future<Void> future, Router router) {
+    vertx
+      .createHttpServer()
+      .requestHandler(router::accept)
+      .listen(
+        config().getInteger(Constant.SERVICE_PORT, 8080),
+        result -> {
+          if (result.succeeded()) {
+            future.complete();
+          } else {
+            future.fail(result.cause());
+          }
+        }
+      );
+  }
+
+}