private static void addAttributeInMb(ProtobufSystemInfo.Section.Builder protobuf, String key, long valueInBytes) { if (valueInBytes >= 0L) { setAttribute(protobuf, key, valueInBytes / MEGABYTE); } } }
@Override protected void configureModule() { add( CeConfigurationImpl.class, CeTaskLogging.class, CeDatabaseMBeanImpl.class, new JvmStateSection("Compute Engine JVM State"), new JvmPropertiesSection("Compute Engine JVM Properties"), LoggingSection.class); } }
@Override public ProtobufSystemInfo.Section toProtobuf() { return toProtobuf(ManagementFactory.getMemoryMXBean()); }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("System"); setAttribute(protobuf, "Server ID", server.getId()); setAttribute(protobuf, "High Availability", true); setAttribute(protobuf, "External User Authentication", getExternalUserAuthentication()); addIfNotEmpty(protobuf, "Accepted external identity providers", getEnabledIdentityProviders()); addIfNotEmpty(protobuf, "External identity providers whose users are allowed to sign themselves up", getAllowsToSignUpEnabledIdentityProviders()); setAttribute(protobuf, "Force authentication", getForceAuthentication()); return protobuf.build(); }
public static ProtobufSystemInfo.SystemInfo provide() { ProtobufSystemInfo.SystemInfo.Builder protobuf = ProtobufSystemInfo.SystemInfo.newBuilder(); if (instance != null) { instance.sections.forEach(section -> protobuf.addSections(section.toProtobuf())); } return protobuf.build(); } }
@Test public void index_attributes() { ProtobufSystemInfo.Section section = underTest.toProtobuf(); // one index "issues" assertThat(attribute(section, "Index issues - Docs").getLongValue()).isEqualTo(0L); assertThat(attribute(section, "Index issues - Shards").getLongValue()).isGreaterThan(0); assertThat(attribute(section, "Index issues - Store Size").getStringValue()).isNotNull(); }
public static void assertThatAttributeIs(ProtobufSystemInfo.Section section, String key, long expectedValue) { ProtobufSystemInfo.Attribute value = attribute(section, key); assertThat(value).as(key).isNotNull(); assertThat(value.getLongValue()).isEqualTo(expectedValue); } }
@Test public void name_is_not_empty() { assertThat(underTest.toProtobuf().getName()).isEqualTo("Web JVM Properties"); }
public static void assertThatAttributeIs(ProtobufSystemInfo.Section section, String key, String expectedValue) { ProtobufSystemInfo.Attribute value = attribute(section, key); assertThat(value).as(key).isNotNull(); assertThat(value.getStringValue()).isEqualTo(expectedValue); }
public static void assertThatAttributeIs(ProtobufSystemInfo.Section section, String key, boolean expectedValue) { ProtobufSystemInfo.Attribute value = attribute(section, key); assertThat(value).as(key).isNotNull(); assertThat(value.getBooleanValue()).isEqualTo(expectedValue); }
@Test public void test_order() { Collection<Section> sections = asList( newSection("end2"), newSection("bar"), newSection("end1"), newSection("foo")); List<String> ordered = SystemInfoUtils.order(sections, "foo", "bar").stream() .map(Section::getName) .collect(Collectors.toList()); assertThat(ordered).isEqualTo(asList("foo", "bar", "end1", "end2")); }
protected void writeSections(Collection<ProtobufSystemInfo.Section> sections, JsonWriter json) { SystemInfoUtils .order(sections, ORDERED_SECTION_NAMES) .forEach(section -> writeSection(section, json)); }
@Test public void test_attributes() { ProtobufSystemInfo.Section section = underTest.toProtobuf(); assertThat(attribute(section, "Nodes").getLongValue()).isGreaterThan(0); assertThat(attribute(section, "State").getStringValue()).isIn("RED", "YELLOW", "GREEN"); } }
@Test public void return_nb_of_processors() { ProtobufSystemInfo.Section section = underTest.toProtobuf(); assertThat(attribute(section, "Processors").getLongValue()).isGreaterThan(0); }
new JvmPropertiesSection("Web JVM Properties"), new JvmStateSection("Web JVM State"), DbSection.class, DbConnectionSection.class,
private void completePoolAttributes(Section.Builder protobuf) { setAttribute(protobuf, "Pool Active Connections", getPoolActiveConnections()); setAttribute(protobuf, "Pool Max Connections", getPoolMaxActiveConnections()); setAttribute(protobuf, "Pool Initial Size", getPoolInitialSize()); setAttribute(protobuf, "Pool Idle Connections", getPoolIdleConnections()); setAttribute(protobuf, "Pool Min Idle Connections", getPoolMinIdleConnections()); setAttribute(protobuf, "Pool Max Idle Connections", getPoolMaxIdleConnections()); setAttribute(protobuf, "Pool Max Wait (ms)", getPoolMaxWaitMillis()); setAttribute(protobuf, "Pool Remove Abandoned", getPoolRemoveAbandoned()); setAttribute(protobuf, "Pool Remove Abandoned Timeout (seconds)", getPoolRemoveAbandonedTimeoutSeconds()); }
@Test public void return_nb_of_processors() { ProtobufSystemInfo.Section protobuf = underTest.toProtobuf(); assertThat(attribute(protobuf, "Processors").getLongValue()).isGreaterThan(0); } }
private static void addIfNotEmpty(ProtobufSystemInfo.Section.Builder protobuf, String key, @Nullable List<String> values) { if (values != null && !values.isEmpty()) { setAttribute(protobuf, key, COMMA_JOINER.join(values)); } } }
private static void addIfNotEmpty(ProtobufSystemInfo.Section.Builder protobuf, String key, @Nullable List<String> values) { if (values != null && !values.isEmpty()) { setAttribute(protobuf, key, COMMA_JOINER.join(values)); } }