12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System;
- namespace OhmGraphite
- {
- public class MetricConfig
- {
- public MetricConfig(TimeSpan interval, GraphiteConfig graphite, InfluxConfig influx, PrometheusConfig prometheus, string timescale)
- {
- Interval = interval;
- Graphite = graphite;
- Influx = influx;
- Prometheus = prometheus;
- Timescale = timescale;
- }
- public TimeSpan Interval { get; }
- public GraphiteConfig Graphite { get; }
- public InfluxConfig Influx { get; }
- public PrometheusConfig Prometheus { get; }
- public string Timescale { get; }
- public static MetricConfig ParseAppSettings(IAppConfig config)
- {
- if (!int.TryParse(config["interval"], out int seconds))
- {
- seconds = 5;
- }
- var interval = TimeSpan.FromSeconds(seconds);
- var type = config["type"] ?? "graphite";
- GraphiteConfig gconfig = null;
- InfluxConfig iconfig = null;
- PrometheusConfig pconfig = null;
- string timescale = null;
- switch (type.ToLowerInvariant())
- {
- case "graphite":
- gconfig = GraphiteConfig.ParseAppSettings(config);
- break;
- case "influxdb":
- case "influx":
- iconfig = InfluxConfig.ParseAppSettings(config);
- break;
- case "prometheus":
- pconfig = PrometheusConfig.ParseAppSettings(config);
- break;
- case "timescale":
- case "timescaledb":
- timescale = config["timescale_connection"];
- break;
- }
- return new MetricConfig(interval, gconfig, iconfig, pconfig, timescale);
- }
- }
- }
|