org.apache.brooklyn.entity.machine.MachineAttributes Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of brooklyn-software-base Show documentation
Show all versions of brooklyn-software-base Show documentation
Base classes for Brooklyn software process entities
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package org.apache.brooklyn.entity.machine;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.Nullable;
import org.apache.brooklyn.api.sensor.AttributeSensor;
import org.apache.brooklyn.core.config.render.RendererHints;
import org.apache.brooklyn.core.sensor.Sensors;
import org.apache.brooklyn.util.guava.Functionals;
import org.apache.brooklyn.util.math.MathFunctions;
import org.apache.brooklyn.util.text.ByteSizeStrings;
import org.apache.brooklyn.util.time.Duration;
import com.google.common.base.Function;
public class MachineAttributes {
/**
* Do not instantiate.
*/
private MachineAttributes() {}
/*
* Sensor attributes for machines.
*/
public static final AttributeSensor UPTIME = Sensors.newSensor(Duration.class, "machine.uptime", "Current uptime");
public static final AttributeSensor LOAD_AVERAGE = Sensors.newDoubleSensor("machine.loadAverage", "Current load average");
public static final AttributeSensor CPU_USAGE = Sensors.newDoubleSensor("machine.cpu", "Current CPU usage");
public static final AttributeSensor AVERAGE_CPU_USAGE = Sensors.newDoubleSensor("cpu.average", "Average CPU usage across the cluster");
public static final AttributeSensor FREE_MEMORY = Sensors.newLongSensor("machine.memory.free", "Current free memory");
public static final AttributeSensor TOTAL_MEMORY = Sensors.newLongSensor("machine.memory.total", "Total memory");
public static final AttributeSensor USED_MEMORY = Sensors.newLongSensor("machine.memory.used", "Current memory usage");
public static final AttributeSensor USED_MEMORY_DELTA_PER_SECOND_LAST = Sensors.newDoubleSensor("memory.used.delta", "Change in memory usage per second");
public static final AttributeSensor USED_MEMORY_DELTA_PER_SECOND_IN_WINDOW = Sensors.newDoubleSensor("memory.used.windowed", "Average change in memory usage over 30s");
public static final AttributeSensor USED_MEMORY_PERCENT = Sensors.newDoubleSensor("memory.used.percent", "The percentage of memory used");
public static final AttributeSensor AVERAGE_USED_MEMORY_PERCENT = Sensors.newDoubleSensor("memory.used.percent.average", "Average percentage of memory used across the cluster");
private static AtomicBoolean initialized = new AtomicBoolean(false);
/**
* Setup renderer hints.
*/
public static void init() {
if (initialized.getAndSet(true)) return;
final Function longValue = new Function() {
@Override
public Long apply(@Nullable Double input) {
if (input == null) return null;
return input.longValue();
}
};
RendererHints.register(CPU_USAGE, RendererHints.displayValue(MathFunctions.percent(2)));
RendererHints.register(AVERAGE_CPU_USAGE, RendererHints.displayValue(MathFunctions.percent(2)));
RendererHints.register(USED_MEMORY_PERCENT, RendererHints.displayValue(MathFunctions.percent(2)));
RendererHints.register(AVERAGE_USED_MEMORY_PERCENT, RendererHints.displayValue(MathFunctions.percent(2)));
RendererHints.register(FREE_MEMORY, RendererHints.displayValue(Functionals.chain(MathFunctions.times(1000L), ByteSizeStrings.metric())));
RendererHints.register(TOTAL_MEMORY, RendererHints.displayValue(Functionals.chain(MathFunctions.times(1000L), ByteSizeStrings.metric())));
RendererHints.register(USED_MEMORY, RendererHints.displayValue(Functionals.chain(MathFunctions.times(1000L), ByteSizeStrings.metric())));
RendererHints.register(USED_MEMORY_DELTA_PER_SECOND_LAST, RendererHints.displayValue(Functionals.chain(longValue, ByteSizeStrings.metric())));
RendererHints.register(USED_MEMORY_DELTA_PER_SECOND_IN_WINDOW, RendererHints.displayValue(Functionals.chain(longValue, ByteSizeStrings.metric())));
}
static {
init();
}
}