PrometheusConfig.cs 992 B

12345678910111213141516171819202122232425262728293031323334
  1. namespace OhmGraphite
  2. {
  3. public class PrometheusConfig
  4. {
  5. public int Port { get; }
  6. public string Host { get; }
  7. public bool UseHttps { get; }
  8. public string Path { get; }
  9. public PrometheusConfig(int port, string host, bool useHttps, string path)
  10. {
  11. Port = port;
  12. Host = host;
  13. UseHttps = useHttps;
  14. Path = path;
  15. }
  16. internal static PrometheusConfig ParseAppSettings(IAppConfig config)
  17. {
  18. string path = config["prometheus_path"] ?? "metrics/";
  19. string host = config["prometheus_host"] ?? "*";
  20. if (!bool.TryParse(config["prometheus_https"], out bool useHttps))
  21. {
  22. useHttps = false;
  23. }
  24. if (!int.TryParse(config["prometheus_port"], out int port))
  25. {
  26. port = 4445;
  27. }
  28. return new PrometheusConfig(port, host, useHttps, path);
  29. }
  30. }
  31. }