Browse Source

Completed uname collector

Raymond Edah 7 years ago
parent
commit
0d027d3ff5

+ 4 - 87
README.adoc

@@ -1,89 +1,6 @@
-= Vert.x Gradle Starter
+# SmartOS exporter
 
-This project is a template to start your own Vert.x project using Gradle.
+diskstats,filefd,filesystem,loadavg,meminfo,netdev,netstat,stat,time,uname,vmstat
 
-== Prerequisites
-
-* JDK 8+
-
-== Getting started
-
-Create your project with:
-
-[source]
-----
-git clone https://github.com/vert-x3/vertx-gradle-starter.git PROJECT_NAME
-----
-
-Replace `PROJECT_NAME` with the name of your project.
-
-On Linux and MacOSx (or Windows with `bash`), if you want to go faster and generate an already configured project run:
-
-[source]
-----
-curl http://vertx.io/assets/starter-scripts/create-vertx-project-gradle.sh -o vertx-create-gradle-project.sh; bash vertx-create-gradle-project.sh
-----
-
-== Running the project
-
-Once you have retrieved the project, you can check that everything works with:
-
-[source]
-----
-./gradlew test run
-----
-
-The command compiles the project and runs the tests, then  it launches the application, so you can check by yourself. Open your browser to http://localhost:8080. You should see a _Hello World_ message.
-
-== Anatomy of the project
-
-The project contains:
-
-* the Gradle project and its configuration (`build.gradle`)
-* a _main_ verticle file (src/main/java/io/vertx/starter/MainVerticle.java)
-* a unit test (src/main/test/io/vertx/starter/MainVerticleTest.java)
-
-== Start to hack
-
-1. Delete the `.git` directory
-2. Open the `build.gradle` file and customize the `version`. You can also change the `mainVerticleName` variable to use your own package name and verticle class.
-3. Run `./gradlew run`.
-
-This last command relaunches Gradle and the application as soon as you change something in `src/main`.
-
-== Building the project
-
-To build the project, just use:
-
-----
-./gradlew shadowJar
-----
-
-It generates a _fat-jar_ in the `build/libs` directory.
-
-
-
-
------------
-This project shows how to use the Vert.x 3.2 redeploy feature. Vert.x watches for file changes and will then compile these changes. The hello world verticle will be redeployed automatically.
-Simply start the application with:
-
-    ./gradlew run
-
-Now point your browser at http://localhost:8080. Then you can make changes to the hello world verticle and reload the browser.
-
-The whole configuration for this is rather simple:
-
-    mainClassName = 'io.vertx.core.Launcher'
-    def mainVerticleName = 'io.vertx.example.HelloWorldVerticle'
-
-    // Vert.x watches for file changes in all subdirectories
-    // of src/ but only for files with .java extension
-    def watchForChange = 'src/**/*.java'
-
-    // Vert.x will call this task on changes
-    def doOnChange = './gradlew classes'
-
-    run {
-        args = ['run', mainVerticleName, "--redeploy=$watchForChange", "--launcher-class=$mainClassName", "--on-redeploy=$doOnChange"]
-    }
+uname
+loadavg

+ 18 - 0
src/main/java/nu/ltd/fp/se/collector/AbstractMetricCollector.java

@@ -1,5 +1,9 @@
 package nu.ltd.fp.se.collector;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
 public class AbstractMetricCollector {
   private MetricCollector nextCollector;
 
@@ -7,6 +11,20 @@ public class AbstractMetricCollector {
     this.nextCollector = nextCollector;
   }
 
+  public String runCommand(String command) {
+    StringBuffer stdOut = new StringBuffer();
+    try {
+      Process p = Runtime.getRuntime().exec(command);
+      BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
+      String s = null;
+      while ((s = stdInput.readLine()) != null) { stdOut.append(s); }
+    } catch (IOException io) {
+      stdOut.append(io.getMessage());
+    }
+
+    return stdOut.toString();
+  }
+
   public MetricCollector getNextCollector() {
     return this.nextCollector;
   }

+ 7 - 4
src/main/java/nu/ltd/fp/se/collector/UnameCollector.java

@@ -6,11 +6,16 @@ public class UnameCollector extends AbstractMetricCollector implements MetricCol
   static final Gauge unameGauge = Gauge.build()
     .name("node_uname_info")
     .help("Labeled system information as provided by the uname system call")
-    .labelNames("domainname", "machine", "nodename", "sysname", "version")
+    .labelNames("domainname", "machine", "nodename", "release", "sysname", "version")
     .register();
 
   public UnameCollector() {
-    unameGauge.labels("fp.ltd.nu", "somehostname", "x64", "l4", "l5").set(1);
+    unameGauge.labels(this.runCommand("domainname"),
+      System.getProperty("os.arch"),
+      this.runCommand("hostname"),
+      System.getProperty("os.version"),
+      System.getProperty("os.name"),
+      this.runCommand("uname -v")).set(1);
   }
 
   public UnameCollector(MetricCollector nextCollector) {
@@ -18,8 +23,6 @@ public class UnameCollector extends AbstractMetricCollector implements MetricCol
     this.setNextCollector(nextCollector);
   }
 
-  // node_uname_info{domainname="(none)",machine="x86_64",nodename="lnx-host-01",release="4.4.0-87-generic",sysname="Linux",version="#110-Ubuntu SMP Tue Jul 18 12:55:35 UTC 2017"} 1
-  // node_uname_info{nodename="get",} 1.0
   public void collectMetric() {
     // Nothing to be done, call next collector
     if (this.getNextCollector() != null) {