Przeglądaj źródła

Merge pull request #394 from roy-spark/feature/custom-path-prometheus-metrics

Feature/custom path prometheus metrics
Nick Babcock 1 rok temu
rodzic
commit
74b8f1bbb2
3 zmienionych plików z 7 dodań i 3 usunięć
  1. 1 1
      OhmGraphite/Program.cs
  2. 5 2
      OhmGraphite/PrometheusConfig.cs
  3. 1 0
      README.md

+ 1 - 1
OhmGraphite/Program.cs

@@ -111,7 +111,7 @@ namespace OhmGraphite
             {
                 Logger.Info($"Prometheus port: {config.Prometheus.Port}");
                 var registry = PrometheusCollection.SetupDefault(collector);
-                var server = new MetricServer(config.Prometheus.Host, config.Prometheus.Port, registry: registry, useHttps: config.Prometheus.UseHttps);
+                var server = new MetricServer(config.Prometheus.Host, config.Prometheus.Port, url: config.Prometheus.Path, registry: registry, useHttps: config.Prometheus.UseHttps);
                 return new PrometheusServer(server, collector);
             }
             else if (config.Timescale != null)

+ 5 - 2
OhmGraphite/PrometheusConfig.cs

@@ -5,16 +5,19 @@ namespace OhmGraphite
         public int Port { get; }
         public string Host { get; }
         public bool UseHttps { get; }
+        public string Path { get; }
 
-        public PrometheusConfig(int port, string host, bool useHttps)
+        public PrometheusConfig(int port, string host, bool useHttps, string path)
         {
             Port = port;
             Host = host;
             UseHttps = useHttps;
+            Path = path;
         }
 
         internal static PrometheusConfig ParseAppSettings(IAppConfig config)
         {
+            string path = config["prometheus_path"] ?? "metrics/";
             string host = config["prometheus_host"] ?? "*";
             if (!bool.TryParse(config["prometheus_https"], out bool useHttps))
             {
@@ -25,7 +28,7 @@ namespace OhmGraphite
                 port = 4445;
             }
 
-            return new PrometheusConfig(port, host, useHttps);
+            return new PrometheusConfig(port, host, useHttps, path);
         }
     }
 }

+ 1 - 0
README.md

@@ -135,6 +135,7 @@ Configuring the Prometheus exporter will create a server that listens on `promet
          `*` means that it will listen on all interfaces.
          Consider restricting to a given IP address -->
     <add key="prometheus_host" value="*" />
+    <add key="prometheus_path" value="metrics/" /> 
   </appSettings>
 </configuration>
 ```