Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2022-2023 The Prometheus jmx_exporter Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.prometheus.jmx.common.http;
import com.sun.net.httpserver.Authenticator;
import com.sun.net.httpserver.HttpsConfigurator;
import io.prometheus.jmx.common.configuration.ConvertToInteger;
import io.prometheus.jmx.common.configuration.ConvertToMapAccessor;
import io.prometheus.jmx.common.configuration.ConvertToString;
import io.prometheus.jmx.common.configuration.ValidateIntegerInRange;
import io.prometheus.jmx.common.configuration.ValidateStringIsNotBlank;
import io.prometheus.jmx.common.http.authenticator.MessageDigestAuthenticator;
import io.prometheus.jmx.common.http.authenticator.PBKDF2Authenticator;
import io.prometheus.jmx.common.http.authenticator.PlaintextAuthenticator;
import io.prometheus.jmx.common.http.ssl.SSLContextFactory;
import io.prometheus.jmx.common.yaml.YamlMapAccessor;
import io.prometheus.metrics.exporter.httpserver.HTTPServer;
import io.prometheus.metrics.model.registry.PrometheusRegistry;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.net.InetAddress;
import java.security.GeneralSecurityException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.yaml.snakeyaml.Yaml;
/**
* Class to create the HTTPServer used by both the Java agent exporter and the standalone exporter
*/
public class HTTPServerFactory {
private static final int DEFAULT_MINIMUM_THREADS = 1;
private static final int DEFAULT_MAXIMUM_THREADS = 10;
private static final int DEFAULT_KEEP_ALIVE_TIME_SECONDS = 120;
private static final String REALM = "/";
private static final String PLAINTEXT = "plaintext";
private static final Set SHA_ALGORITHMS;
private static final Set PBKDF2_ALGORITHMS;
private static final Map PBKDF2_ALGORITHM_ITERATIONS;
private static final String JAVAX_NET_SSL_KEY_STORE = "javax.net.ssl.keyStore";
private static final String JAVAX_NET_SSL_KEY_STORE_PASSWORD = "javax.net.ssl.keyStorePassword";
private static final int PBKDF2_KEY_LENGTH_BITS = 128;
static {
SHA_ALGORITHMS = new HashSet<>();
SHA_ALGORITHMS.add("SHA-1");
SHA_ALGORITHMS.add("SHA-256");
SHA_ALGORITHMS.add("SHA-512");
PBKDF2_ALGORITHMS = new HashSet<>();
PBKDF2_ALGORITHMS.add("PBKDF2WithHmacSHA1");
PBKDF2_ALGORITHMS.add("PBKDF2WithHmacSHA256");
PBKDF2_ALGORITHMS.add("PBKDF2WithHmacSHA512");
PBKDF2_ALGORITHM_ITERATIONS = new HashMap<>();
PBKDF2_ALGORITHM_ITERATIONS.put("PBKDF2WithHmacSHA1", 1300000);
PBKDF2_ALGORITHM_ITERATIONS.put("PBKDF2WithHmacSHA256", 600000);
PBKDF2_ALGORITHM_ITERATIONS.put("PBKDF2WithHmacSHA512", 210000);
}
private YamlMapAccessor rootYamlMapAccessor;
/** Constructor */
public HTTPServerFactory() {
// DO NOTHING
}
/**
* Method to create an HTTPServer using the supplied arguments
*
* @param inetAddress inetAddress
* @param port port
* @param prometheusRegistry prometheusRegistry
* @param exporterYamlFile exporterYamlFile
* @return an HTTPServer
* @throws IOException IOException
*/
public HTTPServer createHTTPServer(
InetAddress inetAddress,
int port,
PrometheusRegistry prometheusRegistry,
File exporterYamlFile)
throws IOException {
HTTPServer.Builder httpServerBuilder =
HTTPServer.builder()
.inetAddress(inetAddress)
.port(port)
.registry(prometheusRegistry);
createMapAccessor(exporterYamlFile);
configureThreads(httpServerBuilder);
configureAuthentication(httpServerBuilder);
configureSSL(httpServerBuilder);
return httpServerBuilder.buildAndStart();
}
/**
* Method to create a MapAccessor for accessing YAML configuration
*
* @param exporterYamlFile exporterYamlFile
*/
private void createMapAccessor(File exporterYamlFile) {
try (Reader reader = new FileReader(exporterYamlFile)) {
Map