3 * Copyright (C) 2009-2023 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.platform.monitoring;
22 import org.sonar.api.SonarRuntime;
23 import org.sonar.api.config.Configuration;
24 import org.sonar.api.platform.Server;
25 import org.sonar.process.systeminfo.BaseSectionMBean;
26 import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
27 import org.sonar.server.log.ServerLogging;
28 import org.sonar.server.platform.DockerSupport;
29 import org.sonar.server.platform.OfficialDistribution;
30 import org.sonar.server.platform.StatisticsSupport;
32 import static org.sonar.api.measures.CoreMetrics.NCLOC;
33 import static org.sonar.process.ProcessProperties.Property.PATH_DATA;
34 import static org.sonar.process.ProcessProperties.Property.PATH_HOME;
35 import static org.sonar.process.ProcessProperties.Property.PATH_TEMP;
36 import static org.sonar.process.systeminfo.SystemInfoUtils.addIfNotEmpty;
37 import static org.sonar.process.systeminfo.SystemInfoUtils.setAttribute;
39 public class StandaloneSystemSection extends BaseSectionMBean implements SystemSectionMBean {
41 private final Configuration config;
42 private final Server server;
43 private final ServerLogging serverLogging;
44 private final OfficialDistribution officialDistribution;
45 private final DockerSupport dockerSupport;
46 private final StatisticsSupport statisticsSupport;
47 private final SonarRuntime sonarRuntime;
48 private final CommonSystemInformation commonSystemInformation;
50 public StandaloneSystemSection(Configuration config, Server server, ServerLogging serverLogging,
51 OfficialDistribution officialDistribution, DockerSupport dockerSupport, StatisticsSupport statisticsSupport,
52 SonarRuntime sonarRuntime, CommonSystemInformation commonSystemInformation) {
55 this.serverLogging = serverLogging;
56 this.officialDistribution = officialDistribution;
57 this.dockerSupport = dockerSupport;
58 this.statisticsSupport = statisticsSupport;
59 this.sonarRuntime = sonarRuntime;
60 this.commonSystemInformation = commonSystemInformation;
64 public String getServerId() {
65 return server.getId();
69 public String getVersion() {
70 return server.getVersion();
74 public String getLogLevel() {
75 return serverLogging.getRootLoggerLevel().name();
79 public String name() {
85 public ProtobufSystemInfo.Section toProtobuf() {
86 ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder();
87 protobuf.setName("System");
89 setAttribute(protobuf, "Server ID", server.getId());
90 setAttribute(protobuf, "Version", getVersion());
91 setAttribute(protobuf, "Edition", sonarRuntime.getEdition().getLabel());
92 setAttribute(protobuf, NCLOC.getName(), statisticsSupport.getLinesOfCode());
93 setAttribute(protobuf, "Docker", dockerSupport.isRunningInDocker());
94 setAttribute(protobuf, "External Users and Groups Provisioning", commonSystemInformation.getManagedInstanceProviderName());
95 setAttribute(protobuf, "External User Authentication", commonSystemInformation.getExternalUserAuthentication());
96 addIfNotEmpty(protobuf, "Accepted external identity providers",
97 commonSystemInformation.getEnabledIdentityProviders());
98 addIfNotEmpty(protobuf, "External identity providers whose users are allowed to sign themselves up",
99 commonSystemInformation.getAllowsToSignUpEnabledIdentityProviders());
100 setAttribute(protobuf, "High Availability", false);
101 setAttribute(protobuf, "Official Distribution", officialDistribution.check());
102 setAttribute(protobuf, "Force authentication", commonSystemInformation.getForceAuthentication());
103 setAttribute(protobuf, "Home Dir", config.get(PATH_HOME.getKey()).orElse(null));
104 setAttribute(protobuf, "Data Dir", config.get(PATH_DATA.getKey()).orElse(null));
105 setAttribute(protobuf, "Temp Dir", config.get(PATH_TEMP.getKey()).orElse(null));
106 setAttribute(protobuf, "Processors", Runtime.getRuntime().availableProcessors());
107 return protobuf.build();