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