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.cluster;
22 import com.google.common.base.Joiner;
23 import org.sonar.api.SonarRuntime;
24 import org.sonar.api.platform.Server;
25 import org.sonar.api.server.ServerSide;
26 import org.sonar.process.systeminfo.Global;
27 import org.sonar.process.systeminfo.SystemInfoSection;
28 import org.sonar.process.systeminfo.protobuf.ProtobufSystemInfo;
29 import org.sonar.server.platform.DockerSupport;
30 import org.sonar.server.platform.StatisticsSupport;
31 import org.sonar.server.platform.monitoring.CommonSystemInformation;
33 import static org.sonar.api.measures.CoreMetrics.NCLOC;
34 import static org.sonar.process.systeminfo.SystemInfoUtils.setAttribute;
37 public class GlobalSystemSection implements SystemInfoSection, Global {
39 private static final Joiner COMMA_JOINER = Joiner.on(", ");
41 private final Server server;
42 private final DockerSupport dockerSupport;
43 private final StatisticsSupport statisticsSupport;
44 private final SonarRuntime sonarRuntime;
45 private final CommonSystemInformation commonSystemInformation;
47 public GlobalSystemSection(Server server, DockerSupport dockerSupport, StatisticsSupport statisticsSupport, SonarRuntime sonarRuntime,
48 CommonSystemInformation commonSystemInformation) {
50 this.dockerSupport = dockerSupport;
51 this.statisticsSupport = statisticsSupport;
52 this.sonarRuntime = sonarRuntime;
53 this.commonSystemInformation = commonSystemInformation;
57 public ProtobufSystemInfo.Section toProtobuf() {
58 ProtobufSystemInfo.Section.Builder protobuf = ProtobufSystemInfo.Section.newBuilder();
59 protobuf.setName("System");
61 setAttribute(protobuf, "Server ID", server.getId());
62 setAttribute(protobuf, "Edition", sonarRuntime.getEdition().getLabel());
63 setAttribute(protobuf, NCLOC.getName() ,statisticsSupport.getLinesOfCode());
64 setAttribute(protobuf, "Docker", dockerSupport.isRunningInDocker());
65 setAttribute(protobuf, "High Availability", true);
66 setAttribute(protobuf, "External Users and Groups Provisioning", commonSystemInformation.getManagedProvider());
67 setAttribute(protobuf, "External User Authentication", commonSystemInformation.getExternalUserAuthentication());
68 setAttribute(protobuf, "Accepted external identity providers", COMMA_JOINER.join(commonSystemInformation.getEnabledIdentityProviders()));
69 setAttribute(protobuf, "External identity providers whose users are allowed to sign themselves up", COMMA_JOINER.join(commonSystemInformation.getAllowsToSignUpEnabledIdentityProviders()));
70 setAttribute(protobuf, "Force authentication", commonSystemInformation.getForceAuthentication());
71 return protobuf.build();