private static void addAttributeInMb(ProtobufSystemInfo.Section.Builder protobuf, String key, long valueInBytes) { if (valueInBytes >= 0L) { setAttribute(protobuf, key, valueInBytes / MEGABYTE); } } }
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)); } }
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()); }
@Override public Section toProtobuf() { Section.Builder protobuf = Section.newBuilder(); protobuf.setName("Database"); try (DbSession dbSession = dbClient.openSession(false)) { DatabaseMetaData metadata = dbSession.getConnection().getMetaData(); setAttribute(protobuf, "Database", metadata.getDatabaseProductName()); setAttribute(protobuf, "Database Version", metadata.getDatabaseProductVersion()); setAttribute(protobuf, "Username", metadata.getUserName()); setAttribute(protobuf, "URL", metadata.getURL()); setAttribute(protobuf, "Driver", metadata.getDriverName()); setAttribute(protobuf, "Driver Version", metadata.getDriverVersion()); } catch (SQLException e) { throw new IllegalStateException("Fail to get DB metadata", e); } return protobuf.build(); } }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName(name); Map<Object, Object> sortedProperties = new TreeMap<>(System.getProperties()); for (Map.Entry<Object, Object> systemProp : sortedProperties.entrySet()) { if (systemProp.getValue() != null) { setAttribute(protobuf, Objects.toString(systemProp.getKey()), Objects.toString(systemProp.getValue())); } } return protobuf.build(); } }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("System"); setAttribute(protobuf, "Version", server.getVersion()); setAttribute(protobuf, "Official Distribution", officialDistribution.check()); setAttribute(protobuf, "Home Dir", config.get(PATH_HOME.getKey()).orElse(null)); setAttribute(protobuf, "Data Dir", config.get(PATH_DATA.getKey()).orElse(null)); setAttribute(protobuf, "Temp Dir", config.get(PATH_TEMP.getKey()).orElse(null)); setAttribute(protobuf, "Processors", Runtime.getRuntime().availableProcessors()); return protobuf.build(); }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("System"); setAttribute(protobuf, "Server ID", server.getId()); setAttribute(protobuf, "Version", getVersion()); 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, "High Availability", false); setAttribute(protobuf, "Official Distribution", officialDistribution.check()); setAttribute(protobuf, "Force authentication", getForceAuthentication()); setAttribute(protobuf, "Home Dir", config.get(PATH_HOME.getKey()).orElse(null)); setAttribute(protobuf, "Data Dir", config.get(PATH_DATA.getKey()).orElse(null)); setAttribute(protobuf, "Temp Dir", config.get(PATH_TEMP.getKey()).orElse(null)); setAttribute(protobuf, "Processors", Runtime.getRuntime().availableProcessors()); return protobuf.build(); }
@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(); }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("Compute Engine Tasks"); try (DbSession dbSession = dbClient.openSession(false)) { setAttribute(protobuf, "Total Pending", dbClient.ceQueueDao().countByStatus(dbSession, CeQueueDto.Status.PENDING)); setAttribute(protobuf, "Total In Progress", dbClient.ceQueueDao().countByStatus(dbSession, CeQueueDto.Status.IN_PROGRESS)); setAttribute(protobuf, "Max Workers per Node", workerCountProvider == null ? DEFAULT_NB_OF_WORKERS : workerCountProvider.get()); setAttribute(protobuf, "Workers Paused", "true".equals(dbClient.internalPropertiesDao().selectByKey(dbSession, InternalProperties.COMPUTE_ENGINE_PAUSE).orElse(null))); } return protobuf.build(); } }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("Search State"); try { setAttribute(protobuf, "State", getStateAsEnum().name()); completeNodeAttributes(protobuf); } catch (Exception es) { Loggers.get(EsStateSection.class).warn("Failed to retrieve ES attributes. There will be only a single \"state\" attribute.", es); setAttribute(protobuf, "State", es.getCause() instanceof ElasticsearchException ? es.getCause().getMessage() : es.getMessage()); } return protobuf.build(); }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("Search Indexes"); try { completeIndexAttributes(protobuf); } catch (Exception es) { Loggers.get(EsIndexesSection.class).warn("Failed to retrieve ES attributes. There will be only a single \"Error\" attribute.", es); setAttribute(protobuf, "Error", es.getCause() instanceof ElasticsearchException ? es.getCause().getMessage() : es.getMessage()); } return protobuf.build(); }
private void completeIndexAttributes(ProtobufSystemInfo.Section.Builder protobuf) { IndicesStatsResponse indicesStats = esClient.prepareStats().all().get(); for (Map.Entry<String, IndexStats> indexStats : indicesStats.getIndices().entrySet()) { String prefix = "Index " + indexStats.getKey() + " - "; setAttribute(protobuf, prefix + "Docs", indexStats.getValue().getPrimaries().getDocs().getCount()); setAttribute(protobuf, prefix + "Shards", indexStats.getValue().getShards().length); setAttribute(protobuf, prefix + "Store Size", byteCountToDisplaySize(indexStats.getValue().getPrimaries().getStore().getSizeInBytes())); } } }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("Settings"); PropertyDefinitions definitions = settings.getDefinitions(); TreeMap<String, String> orderedProps = new TreeMap<>(settings.getProperties()); for (Map.Entry<String, String> prop : orderedProps.entrySet()) { String key = prop.getKey(); String value = obfuscateValue(definitions, key, prop.getValue()); setAttribute(protobuf, key, value); } return protobuf.build(); }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); if (runtime.getSonarQubeSide() == SonarQubeSide.COMPUTE_ENGINE) { protobuf.setName("Compute Engine Logging"); } else { protobuf.setName("Web Logging"); } SystemInfoUtils.setAttribute(protobuf, "Logs Level", logging.getRootLoggerLevel().name()); SystemInfoUtils.setAttribute(protobuf, "Logs Dir", logging.getLogsDir().getAbsolutePath()); return protobuf.build(); } }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("Search State"); ClusterStatsResponse stats = esClient.prepareClusterStats().get(); setAttribute(protobuf, "State", stats.getStatus().name()); setAttribute(protobuf, "Nodes", stats.getNodesStats().getCounts().getTotal()); return protobuf.build(); }
public static void toProtobuf(NodeStats stats, ProtobufSystemInfo.Section.Builder protobuf) { setAttribute(protobuf, "CPU Usage (%)", stats.getProcess().getCpu().getPercent()); setAttribute(protobuf, "Disk Available", byteCountToDisplaySize(stats.getFs().getTotal().getAvailable().getBytes())); setAttribute(protobuf, "Store Size", byteCountToDisplaySize(stats.getIndices().getStore().getSizeInBytes())); setAttribute(protobuf, "Open File Descriptors", stats.getProcess().getOpenFileDescriptors()); setAttribute(protobuf, "Max File Descriptors", stats.getProcess().getMaxFileDescriptors()); setAttribute(protobuf, "Spinning", stats.getFs().getTotal().getSpins()); setAttribute(protobuf, "JVM Heap Usage", formatPercent(stats.getJvm().getMem().getHeapUsedPercent())); setAttribute(protobuf, "JVM Heap Used", byteCountToDisplaySize(stats.getJvm().getMem().getHeapUsed().getBytes())); setAttribute(protobuf, "JVM Heap Max", byteCountToDisplaySize(stats.getJvm().getMem().getHeapMax().getBytes())); setAttribute(protobuf, "JVM Non Heap Used", byteCountToDisplaySize(stats.getJvm().getMem().getNonHeapUsed().getBytes())); setAttribute(protobuf, "JVM Threads", stats.getJvm().getThreads().getCount()); setAttribute(protobuf, "Field Data Memory", byteCountToDisplaySize(stats.getIndices().getFieldData().getMemorySizeInBytes())); setAttribute(protobuf, "Field Data Circuit Breaker Limit", byteCountToDisplaySize(stats.getBreaker().getStats(CircuitBreaker.FIELDDATA).getLimit())); setAttribute(protobuf, "Field Data Circuit Breaker Estimation", byteCountToDisplaySize(stats.getBreaker().getStats(CircuitBreaker.FIELDDATA).getEstimated())); setAttribute(protobuf, "Request Circuit Breaker Limit", byteCountToDisplaySize(stats.getBreaker().getStats(CircuitBreaker.REQUEST).getLimit())); setAttribute(protobuf, "Request Circuit Breaker Estimation", byteCountToDisplaySize(stats.getBreaker().getStats(CircuitBreaker.REQUEST).getEstimated())); setAttribute(protobuf, "Query Cache Memory", byteCountToDisplaySize(stats.getIndices().getQueryCache().getMemorySizeInBytes())); setAttribute(protobuf, "Request Cache Memory", byteCountToDisplaySize(stats.getIndices().getRequestCache().getMemorySizeInBytes())); }
@Test public void test_setAttribute_with_boolean_parameter() { Section.Builder builder = Section.newBuilder(); SystemInfoUtils.setAttribute(builder, "isNull", (Boolean)null); SystemInfoUtils.setAttribute(builder, "isTrue", true); SystemInfoUtils.setAttribute(builder, "isFalse", false); Section section = builder.build(); assertThat(SystemInfoUtils.attribute(section, "isNull")).isNull(); assertThat(SystemInfoUtils.attribute(section, "isTrue").getBooleanValue()).isTrue(); assertThat(SystemInfoUtils.attribute(section, "isFalse").getBooleanValue()).isFalse(); }
@Test public void write_json() { logInAsSystemAdministrator(); ProtobufSystemInfo.Section.Builder attributes1 = ProtobufSystemInfo.Section.newBuilder() .setName("Section One"); setAttribute(attributes1, "foo", "bar"); when(section1.toProtobuf()).thenReturn(attributes1.build()); ProtobufSystemInfo.Section.Builder attributes2 = ProtobufSystemInfo.Section.newBuilder() .setName("Section Two"); setAttribute(attributes2, "one", 1); setAttribute(attributes2, "two", 2); when(section2.toProtobuf()).thenReturn(attributes2.build()); when(ceHttpClient.retrieveSystemInfo()).thenReturn(Optional.empty()); StringWriter writer = new StringWriter(); JsonWriter jsonWriter = JsonWriter.of(writer); jsonWriter.beginObject(); underTest.write(jsonWriter); jsonWriter.endObject(); // response does not contain empty "Section Three" assertThat(writer.toString()).isEqualTo("{\"Health\":\"GREEN\",\"Health Causes\":[],\"Section One\":{\"foo\":\"bar\"},\"Section Two\":{\"one\":1,\"two\":2}," + "\"Statistics\":{\"id\":\"\",\"version\":\"\",\"database\":{\"name\":\"\",\"version\":\"\"},\"plugins\":[],\"userCount\":0,\"projectCount\":0,\"usingBranches\":false," + "\"ncloc\":0,\"projectCountByLanguage\":[],\"nclocByLanguage\":[]}}"); }
@Override public ProtobufSystemInfo.Section toProtobuf() { ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder(); protobuf.setName("Plugins"); for (PluginInfo plugin : repository.getPluginInfos()) { String label = "[" + plugin.getName() + "]"; Version version = plugin.getVersion(); if (version != null) { label = version.getName() + " " + label; } setAttribute(protobuf, plugin.getKey(), label); } return protobuf.build(); } }