@Override
  public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject(Fields.COUNT);
    counts.toXContent(builder, params);
    builder.endObject();

    builder.startArray(Fields.VERSIONS);
    for (Version v : versions) {
      builder.value(v.toString());
    }
    builder.endArray();

    builder.startObject(Fields.OS);
    os.toXContent(builder, params);
    builder.endObject();

    builder.startObject(Fields.PROCESS);
    process.toXContent(builder, params);
    builder.endObject();

    builder.startObject(Fields.JVM);
    jvm.toXContent(builder, params);
    builder.endObject();

    builder.field(Fields.FS);
    fs.toXContent(builder, params);

    builder.startArray(Fields.PLUGINS);
    for (PluginInfo pluginInfo : plugins) {
      pluginInfo.toXContent(builder, params);
    }
    builder.endArray();
    return builder;
  }
Example #2
0
  @Override
  public OsStats osStats() {
    final long uptime = -1L;
    final double systemLoadAverage =
        ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage();
    final double[] loadAverage =
        systemLoadAverage < 0.0d ? new double[0] : new double[] {systemLoadAverage};
    final Processor processor =
        Processor.create(
            "Unknown",
            "Unknown",
            -1,
            -1,
            -1,
            -1,
            -1L,
            (short) -1,
            (short) -1,
            (short) -1,
            (short) -1);
    final Memory memory = Memory.create(-1L, -1L, (short) -1, -1L, (short) -1, -1L, -1L);
    final Swap swap = Swap.create(-1L, -1L, -1L);

    return OsStats.create(loadAverage, uptime, processor, memory, swap);
  }
 @Override
 public void writeTo(StreamOutput out) throws IOException {
   counts.writeTo(out);
   out.writeVInt(versions.size());
   for (Version v : versions) Version.writeVersion(v, out);
   os.writeTo(out);
   process.writeTo(out);
   jvm.writeTo(out);
   fs.writeTo(out);
   out.writeVInt(plugins.size());
   for (PluginInfo p : plugins) {
     p.writeTo(out);
   }
 }
  @Override
  public void readFrom(StreamInput in) throws IOException {
    counts = Counts.readCounts(in);

    int size = in.readVInt();
    versions = new HashSet<Version>(size);
    for (; size > 0; size--) {
      versions.add(Version.readVersion(in));
    }

    os = OsStats.readOsStats(in);
    process = ProcessStats.readStats(in);
    jvm = JvmStats.readJvmStats(in);
    fs = FsStats.Info.readInfoFrom(in);

    size = in.readVInt();
    plugins = new HashSet<PluginInfo>(size);
    for (; size > 0; size--) {
      plugins.add(PluginInfo.readPluginInfo(in));
    }
  }
  public ClusterStatsNodes(ClusterStatsNodeResponse[] nodeResponses) {
    this.counts = new Counts();
    this.versions = new HashSet<Version>();
    this.os = new OsStats();
    this.jvm = new JvmStats();
    this.fs = new FsStats.Info();
    this.plugins = new HashSet<PluginInfo>();
    this.process = new ProcessStats();

    Set<InetAddress> seenAddresses = new HashSet<InetAddress>(nodeResponses.length);

    for (ClusterStatsNodeResponse nodeResponse : nodeResponses) {

      counts.addNodeInfo(nodeResponse.nodeInfo());
      versions.add(nodeResponse.nodeInfo().getVersion());
      process.addNodeStats(nodeResponse.nodeStats());
      jvm.addNodeInfoStats(nodeResponse.nodeInfo(), nodeResponse.nodeStats());
      plugins.addAll(nodeResponse.nodeInfo().getPlugins().getInfos());

      // now do the stats that should be deduped by hardware (implemented by ip deduping)
      TransportAddress publishAddress =
          nodeResponse.nodeInfo().getTransport().address().publishAddress();
      InetAddress inetAddress = null;
      if (publishAddress.uniqueAddressTypeId() == 1) {
        inetAddress = ((InetSocketTransportAddress) publishAddress).address().getAddress();
      }

      if (!seenAddresses.add(inetAddress)) {
        continue;
      }

      os.addNodeInfo(nodeResponse.nodeInfo());
      if (nodeResponse.nodeStats().getFs() != null) {
        fs.add(nodeResponse.nodeStats().getFs().total());
      }
    }
  }
Example #6
0
 /* (non-Javadoc)
  * @see cn.com.rebirth.search.core.monitor.os.OsProbe#osStats()
  */
 @Override
 public OsStats osStats() {
   OsStats stats = new OsStats();
   stats.timestamp = System.currentTimeMillis();
   return stats;
 }
 public static OsStats readOsStats(StreamInput in) throws IOException {
   OsStats os = new OsStats();
   os.readFrom(in);
   return os;
 }