Last active
December 6, 2019 02:33
-
-
Save dennischen/790a5ba8b38d4a5a5f0617528eed9001 to your computer and use it in GitHub Desktop.
Yingzhun Gear Impl Hint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GearFactory gf = GearFactory.instance(); | |
gf.register(new LinuxGear()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Charts( | |
charts = { | |
// T1 | |
@Chart( | |
name = GearLogEx.CHART_GENERAL_INFO, dataType = DataType.TABLE, | |
description = "l:gear.info", tags = { GearLog.TAG_GENERAL }, | |
priority = 30001 | |
), | |
// T2 | |
@Chart( | |
name = GearLogEx.CHART_DISK_INFO, dataType = DataType.TABLE, | |
description = "l:gear.linux.disk.info", tags = { GearLog.TAG_STORAGE } | |
), | |
// T4 | |
@Chart( | |
name = LinuxGearLog.CHART_DISK_PREF, dataType = DataType.TABLE, | |
description = "l:gear.linux.disk.pref", tags = { GearLog.TAG_STORAGE } | |
), | |
// T3 | |
@Chart( | |
name = GearLogEx.CHART_NETWORK_INFO, dataType = DataType.TABLE, | |
description = "l:gear.network.info", tags = { GearLog.TAG_NETWORK } | |
), | |
// common.Storage Info | |
@Chart( | |
name = GearLogEx.CHART_STORAGE_INFO , dataType = DataType.TABLE, | |
description = "l:gear.common.storage.info", tags = { GearLog.TAG_STORAGE } | |
) | |
}, | |
series = { | |
// S1 | |
@SeriesChart( | |
properties = { | |
@SeriesChartProperty(property = "cpuSystemUsage"), | |
@SeriesChartProperty(property = "cpuUserUsage"), | |
@SeriesChartProperty(property = "cpuIdleUsage") | |
}, | |
description = "l:gear.cpu.usage", tags = { GearLog.TAG_CPU } | |
), | |
// S3 | |
@SeriesChart( | |
properties = { | |
@SeriesChartProperty(property = "totalMemory"), | |
@SeriesChartProperty(property = "availableMemory"), | |
@SeriesChartProperty(property = "usedMemory") | |
}, | |
description = "l:gear.memory.usage", tags = { GearLog.TAG_MEMORY } | |
), | |
// S4 | |
@SeriesChart( | |
properties = { | |
@SeriesChartProperty(property = "virtualMemory"), | |
@SeriesChartProperty(property = "memoryBuffers"), | |
@SeriesChartProperty(property = "memoryCached") | |
}, | |
description = "l:gear.linux.memory.bufferCached", tags = { GearLog.TAG_MEMORY } | |
), | |
// S5 | |
@SeriesChart( | |
properties = { | |
@SeriesChartProperty(property = "totalSWAP"), | |
@SeriesChartProperty(property = "availableSWAP"), | |
@SeriesChartProperty(property = "usedSWAP") | |
}, | |
description = "l:gear.linux.swap.info", tags = { GearLog.TAG_MEMORY } | |
) | |
}, | |
categories = { | |
// not defined in spec | |
// @CategoryChart( | |
// properties = { | |
// @CategoryChartProperty(property = "cpuSystemUsage"), | |
// @CategoryChartProperty(property = "cpuUserUsage"), | |
// @CategoryChartProperty(property = "cpuIdleUsage") | |
// }, description = "l:gear.cpu.usage", tags = { GearTags.CPU }), | |
// P1 | |
@CategoryChart( | |
properties = { | |
@CategoryChartProperty(property = "availableMemory"), | |
@CategoryChartProperty(property = "usedMemory") | |
}, | |
description = "l:gear.memory.usage", tags = { GearLog.TAG_MEMORY } | |
) | |
}) | |
public class JsonLinuxGearLog extends JsonGearReportBase implements LinuxGearLog { | |
public JsonLinuxGearLog() { | |
} | |
public JsonLinuxGearLog(long timestamp, int errCode, String message) { | |
super(timestamp, errCode, message); | |
} | |
public JsonLinuxGearLog(long timestamp) { | |
super(timestamp); | |
} | |
@Expose | |
@SerializedName("a") | |
String kernelVersion; | |
@Expose | |
@SerializedName("b") | |
String systemName; | |
@Expose | |
@SerializedName("c") | |
String defaultGateway; | |
@Expose | |
@SerializedName("d") | |
@RuleProperty | |
@PropertyInfo(unit = GearLog.UNIT_MILLISECONDS, description = "l:gear.uptime", tags = { GearLog.TAG_GENERAL }) | |
Long systemUpTime; | |
@Expose | |
@SerializedName("e") | |
Long cpuSystemCount; | |
@Expose | |
@SerializedName("f") | |
Long cpuUserCount; | |
@Expose | |
@SerializedName("g") | |
Long cpuIdleCount; | |
@Expose | |
@SerializedName("h") | |
Long cpuTotalCount; | |
@Expose | |
@SerializedName("i") | |
@PropertyInfo(unit = GearLog.UNIT_PERCENTAGE, description = "l:gear.cpu.systemUsage", tags = { GearLog.TAG_CPU }) | |
@LogCalculation(value = "cpuSystemCount", calculator = LogLinuxCpuUsageCalculator.class) | |
@ReportCalculation(calculator = ReportAvgNumberCalculator.class) | |
@RuleProperty | |
Float cpuSystemUsage; | |
@Expose | |
@SerializedName("j") | |
@PropertyInfo(unit = GearLog.UNIT_PERCENTAGE, description = "l:gear.cpu.userUsage", tags = { GearLog.TAG_CPU }) | |
@LogCalculation(value = "cpuUserCount", calculator = LogLinuxCpuUsageCalculator.class) | |
@ReportCalculation(calculator = ReportAvgNumberCalculator.class) | |
@RuleProperty | |
Float cpuUserUsage; | |
@Expose | |
@SerializedName("k") | |
@PropertyInfo(unit = GearLog.UNIT_PERCENTAGE, description = "l:gear.cpu.idleUsage", tags = { GearLog.TAG_CPU }) | |
@LogCalculation(value = "cpuIdleCount", calculator = LogLinuxCpuUsageCalculator.class) | |
@ReportCalculation(calculator = ReportAvgNumberCalculator.class) | |
@RuleProperty | |
Float cpuIdleUsage; | |
@Expose | |
@SerializedName("l") | |
@PropertyInfo(unit = GearLog.UNIT_PERCENTAGE, description = "l:gear.cpu.loading", tags = { GearLog.TAG_CPU }) | |
// S2 | |
@ReportCalculation(calculator = ReportAvgNumberCalculator.class) | |
@SeriesChartProperty | |
@RuleProperty | |
Integer cpuLoading; | |
@Expose | |
@SerializedName("m") | |
@PropertyInfo(unit = GearLog.UNIT_BYTES, description = "l:gear.memory.total", tags = { GearLog.TAG_MEMORY }) | |
Long totalMemory; | |
@Expose | |
@SerializedName("n") | |
@PropertyInfo(unit = GearLog.UNIT_BYTES, description = "l:gear.memory.available", tags = { GearLog.TAG_MEMORY }) | |
@RuleProperty | |
Long availableMemory; | |
@Expose | |
@SerializedName("o") | |
@PropertyInfo(unit = GearLog.UNIT_BYTES, description = "l:gear.memory.used", tags = { GearLog.TAG_MEMORY }) | |
@RuleProperty | |
Long usedMemory; | |
@Expose | |
@SerializedName("p") | |
@PropertyInfo(unit = GearLog.UNIT_BYTES, description = "l:gear.linux.memory.virtual", tags = { GearLog.TAG_MEMORY }) | |
@RuleProperty | |
Long virtualMemory; | |
@Expose | |
@SerializedName("q") | |
@PropertyInfo(unit = GearLog.UNIT_BYTES, description = "l:gear.linux.memory.buffer", tags = { GearLog.TAG_MEMORY }) | |
@RuleProperty | |
Long memoryBuffers; | |
@Expose | |
@SerializedName("r") | |
@PropertyInfo(unit = GearLog.UNIT_BYTES, description = "l:gear.linux.memory.cached", tags = { GearLog.TAG_MEMORY }) | |
@RuleProperty | |
Long memoryCached; | |
@Expose | |
@SerializedName("s") | |
@PropertyInfo(unit = GearLog.UNIT_BYTES, description = "l:gear.linux.swap.total", tags = { GearLog.TAG_MEMORY }) | |
Long totalSWAP; | |
@Expose | |
@SerializedName("t") | |
@PropertyInfo(unit = GearLog.UNIT_BYTES, description = "l:gear.linux.swap.available", tags = { GearLog.TAG_MEMORY }) | |
@RuleProperty | |
Long availableSWAP; | |
@Expose | |
@SerializedName("u") | |
@PropertyInfo(unit = GearLog.UNIT_BYTES, description = "l:gear.linux.swap.used", tags = { GearLog.TAG_MEMORY }) | |
@RuleProperty | |
Long usedSWAP; | |
@Expose | |
@SerializedName("v") | |
List<JsonLinuxCpu> cpus; | |
@Expose | |
@SerializedName("w") | |
@PropertyInfo(description = "l:gear.network.ifs", tags = { GearLog.TAG_NETWORK }) | |
@NestedProperty | |
@LogCalculation(calculator = NestedMapLogCalculator.class) | |
@ReportCalculation(calculator = NestedMapReportCalculator.class) | |
Map<String, JsonLinuxNetworkIf> networkIfs; | |
@Expose | |
@SerializedName("x") | |
@PropertyInfo(description = "l:gear.linux.disk.info", tags = { GearLog.TAG_STORAGE }) | |
@NestedProperty | |
Map<String, JsonLinuxDisk> disks; | |
@Expose | |
@SerializedName("y") | |
@PropertyInfo(description = "l:gear.linux.disk.pref", tags = { GearLog.TAG_STORAGE }) | |
@NestedProperty | |
@LogCalculation(calculator = NestedMapLogCalculator.class) | |
@ReportCalculation(calculator = NestedMapReportCalculator.class) | |
Map<String, JsonLinuxDiskPerformance> diskPrefs; | |
@Expose | |
@SerializedName("z") | |
@PropertyInfo(description = "l:gear.common.storage.info", tags = { GearLog.TAG_STORAGE }) | |
@NestedProperty | |
@LogCalculation(calculator = NestedMapLogCalculator.class) | |
@ReportCalculation(calculator = NestedMapReportCalculator.class) | |
Map<String, JsonStorage> storages; | |
@Override | |
public String getKernelVersion() { | |
return value(kernelVersion, UNKNOW); | |
} | |
@Override | |
public String getSystemName() { | |
return value(systemName, UNKNOW); | |
} | |
@Override | |
public String getDefaultGateway() { | |
return value(defaultGateway, UNKNOW); | |
} | |
@Override | |
public long getSystemUpTime() { | |
return value(systemUpTime, (long) NO_INT_DEFAULT); | |
} | |
@SuppressWarnings("unchecked") | |
@Override | |
public Map<String, LinuxDiskPerformance> getDiskPrefs() { | |
return diskPrefs == null ? Collections.EMPTY_MAP : diskPrefs; | |
} | |
@SuppressWarnings("unchecked") | |
@Override | |
public Map<String, LinuxDisk> getDisks() { | |
return disks == null ? Collections.EMPTY_MAP : disks; | |
} | |
@SuppressWarnings("unchecked") | |
@Override | |
public List<LinuxCpu> getCpus() { | |
return cpus == null ? Collections.EMPTY_LIST : cpus; | |
} | |
@SuppressWarnings("unchecked") | |
@Override | |
public Map<String, LinuxNetworkIf> getNetworkIfs() { | |
return networkIfs == null ? Collections.EMPTY_MAP : networkIfs; | |
} | |
@Override | |
public long getTotalMemory() { | |
return value(totalMemory, (long) NO_INT_DEFAULT); | |
} | |
@Override | |
public long getAvailableMemory() { | |
return value(availableMemory, (long) NO_INT_DEFAULT); | |
} | |
@Override | |
public long getUsedMemory() { | |
return value(usedMemory, (long) NO_INT_DEFAULT); | |
} | |
@Override | |
@PropertyInfo(unit = GearLog.UNIT_PERCENTAGE, description = "l:gear.memory.usage.percentage", tags = { GearLog.TAG_MEMORY }) | |
@RuleProperty(relatedProperties={"availableMemory","usedMemory"}) | |
public float getMemoryUsage() { | |
long availableMemory = getAvailableMemory(); | |
long usedMemory = getUsedMemory(); | |
if (availableMemory == (long) NO_INT_DEFAULT || usedMemory == (long) NO_INT_DEFAULT) { | |
return (float) GearLog.NO_ANALYSIS_DEFAULT; | |
} else if ((availableMemory + usedMemory) == 0) { | |
return 0; | |
} else { | |
return (float) usedMemory / (availableMemory + usedMemory) * 100; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LinuxAgentCreator implements AgentCreator { | |
@Override | |
public String getType() { | |
return LinuxGear.TYPE; | |
} | |
@Override | |
public Explorer createExplorer() { | |
return new LinuxExplorer(); | |
} | |
@Override | |
public Recorder createRecorder() { | |
return new LinuxRecorder(); | |
} | |
@Override | |
public RuleInvestigator createRuleInvestigator() { | |
return new LinuxRuleInvestigator(); | |
} | |
@Override | |
public ChartInvestigator createChartInvestigator() { | |
return new LinuxChartInvestigator(); | |
} | |
@Override | |
public ExplorerType getExplorerType() { | |
return ExplorerType.SNMP; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LinuxChartInvestigator extends ChartInvestigatorBase { | |
public LinuxChartInvestigator() { | |
super(LinuxGear.TYPE); | |
} | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LinuxExplorer extends SnmpExplorerBase{ | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LinuxGear extends GearBase { | |
public static final String TYPE = "linux"; | |
public LinuxGear() { | |
super(TYPE,"Linux", "OS", new LinuxAgentCreator()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LinuxRecorder extends RecorderBase{ | |
public LinuxRecorder() { | |
super(LinuxGear.TYPE); | |
} | |
@Override | |
protected Class<? extends GearLogEx> getLogImplClass(){ | |
return JsonLinuxGearLog.class; | |
} | |
@Override | |
protected Class<? extends GearReportEx> getReportImplClass(){ | |
return JsonLinuxGearReport.class; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LinuxRuleInvestigator extends RuleInvestigatorBase{ | |
public LinuxRuleInvestigator() { | |
super(LinuxGear.TYPE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment