"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "server/src/main/java/org/elasticsearch/monitor/os/OsStats.java" between
elasticsearch-6.8.14-src.tar.gz and elasticsearch-6.8.15-src.tar.gz

About: elasticsearch is a Distributed, RESTful, Search Engine built on top of Apache Lucene. Source package (GitHub).

OsStats.java  (elasticsearch-6.8.14-src):OsStats.java  (elasticsearch-6.8.15-src)
skipping to change at line 22 skipping to change at line 22
* Unless required by applicable law or agreed to in writing, * Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an * software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.elasticsearch.monitor.os; package org.elasticsearch.monitor.os;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.xcontent.ToXContentFragment; import org.elasticsearch.common.xcontent.ToXContentFragment;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
skipping to change at line 190 skipping to change at line 192
} }
builder.endObject(); builder.endObject();
} }
builder.endObject(); builder.endObject();
return builder; return builder;
} }
} }
public static class Swap implements Writeable, ToXContentFragment { public static class Swap implements Writeable, ToXContentFragment {
private static final Logger logger = LogManager.getLogger(Swap.class);
private final long total; private final long total;
private final long free; private final long free;
public Swap(long total, long free) { public Swap(long total, long free) {
assert total >= 0 : "expected total swap to be positive, got: " + to
tal;
assert free >= 0 : "expected free swap to be positive, got: " + tota
l;
this.total = total; this.total = total;
this.free = free; this.free = free;
} }
public Swap(StreamInput in) throws IOException { public Swap(StreamInput in) throws IOException {
this.total = in.readLong(); this.total = in.readLong();
assert total >= 0 : "expected total swap to be positive, got: " + to tal;
this.free = in.readLong(); this.free = in.readLong();
assert free >= 0 : "expected free swap to be positive, got: " + tota l;
} }
@Override @Override
public void writeTo(StreamOutput out) throws IOException { public void writeTo(StreamOutput out) throws IOException {
out.writeLong(total); out.writeLong(total);
out.writeLong(free); out.writeLong(free);
} }
public ByteSizeValue getFree() { public ByteSizeValue getFree() {
return new ByteSizeValue(free); return new ByteSizeValue(free);
} }
public ByteSizeValue getUsed() { public ByteSizeValue getUsed() {
if (total == 0) {
// The work in https://github.com/elastic/elasticsearch/pull/427
25 established that total memory
// can be reported as negative in some cases. Swap can similarly
be reported as negative and in
// those cases, we force it to zero in which case we can no long
er correctly report the used swap
// as (total-free) and should report it as zero.
//
// We intentionally check for (total == 0) rather than (total -
free < 0) so as not to hide
// cases where (free > total) which would be a different bug.
logger.warn("cannot compute used swap when total swap is 0 and f
ree swap is " + free);
return new ByteSizeValue(0);
}
return new ByteSizeValue(total - free); return new ByteSizeValue(total - free);
} }
public ByteSizeValue getTotal() { public ByteSizeValue getTotal() {
return new ByteSizeValue(total); return new ByteSizeValue(total);
} }
@Override @Override
public XContentBuilder toXContent(XContentBuilder builder, Params params ) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params ) throws IOException {
builder.startObject(Fields.SWAP); builder.startObject(Fields.SWAP);
builder.humanReadableField(Fields.TOTAL_IN_BYTES, Fields.TOTAL, getT otal()); builder.humanReadableField(Fields.TOTAL_IN_BYTES, Fields.TOTAL, getT otal());
builder.humanReadableField(Fields.FREE_IN_BYTES, Fields.FREE, getFre e()); builder.humanReadableField(Fields.FREE_IN_BYTES, Fields.FREE, getFre e());
builder.humanReadableField(Fields.USED_IN_BYTES, Fields.USED, getUse d()); builder.humanReadableField(Fields.USED_IN_BYTES, Fields.USED, getUse d());
builder.endObject(); builder.endObject();
return builder; return builder;
} }
} }
public static class Mem implements Writeable, ToXContentFragment { public static class Mem implements Writeable, ToXContentFragment {
private static final Logger logger = LogManager.getLogger(Mem.class);
private final long total; private final long total;
private final long free; private final long free;
public Mem(long total, long free) { public Mem(long total, long free) {
assert total >= 0 : "expected total memory to be positive, got: " + total; assert total >= 0 : "expected total memory to be positive, got: " + total;
assert free >= 0 : "expected free memory to be positive, got: " + to tal; assert free >= 0 : "expected free memory to be positive, got: " + to tal;
this.total = total; this.total = total;
this.free = free; this.free = free;
} }
skipping to change at line 262 skipping to change at line 283
public void writeTo(StreamOutput out) throws IOException { public void writeTo(StreamOutput out) throws IOException {
out.writeLong(total); out.writeLong(total);
out.writeLong(free); out.writeLong(free);
} }
public ByteSizeValue getTotal() { public ByteSizeValue getTotal() {
return new ByteSizeValue(total); return new ByteSizeValue(total);
} }
public ByteSizeValue getUsed() { public ByteSizeValue getUsed() {
if (total == 0) {
// The work in https://github.com/elastic/elasticsearch/pull/427
25 established that total memory
// can be reported as negative in some cases. In those cases, we
force it to zero in which case
// we can no longer correctly report the used memory as (total-f
ree) and should report it as zero.
//
// We intentionally check for (total == 0) rather than (total -
free < 0) so as not to hide
// cases where (free > total) which would be a different bug.
logger.warn("cannot compute used memory when total memory is 0 a
nd free memory is " + free);
return new ByteSizeValue(0);
}
return new ByteSizeValue(total - free); return new ByteSizeValue(total - free);
} }
public short getUsedPercent() { public short getUsedPercent() {
return calculatePercentage(getUsed().getBytes(), total); return calculatePercentage(getUsed().getBytes(), total);
} }
public ByteSizeValue getFree() { public ByteSizeValue getFree() {
return new ByteSizeValue(free); return new ByteSizeValue(free);
} }
 End of changes. 8 change blocks. 
0 lines changed or deleted 43 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)