Ejemplo n.º 1
0
        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;

            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;
            }

            return(new MetricConfig(interval, gconfig, iconfig, pconfig));
        }
Ejemplo n.º 2
0
        public static MetricConfig ParseAppSettings()
        {
            if (!int.TryParse(ConfigurationManager.AppSettings["interval"], out int seconds))
            {
                seconds = 5;
            }

            var interval = TimeSpan.FromSeconds(seconds);

            var            type    = ConfigurationManager.AppSettings["type"] ?? "graphite";
            GraphiteConfig gconfig = null;
            InfluxConfig   iconfig = null;

            switch (type.ToLowerInvariant())
            {
            case "graphite":
                gconfig = GraphiteConfig.ParseAppSettings();
                break;

            case "influxdb":
            case "influx":
                iconfig = InfluxConfig.ParseAppSettings();
                break;
            }

            return(new MetricConfig(interval, gconfig, iconfig));
        }
Ejemplo n.º 3
0
        public static MetricConfig ParseAppSettings(IAppConfig config)
        {
            if (!int.TryParse(config["interval"], out int seconds))
            {
                seconds = 5;
            }

            var interval = TimeSpan.FromSeconds(seconds);

            INameResolution nameLookup = NameLookup(config["name_lookup"] ?? "netbios");

            var              type      = config["type"] ?? "graphite";
            GraphiteConfig   gconfig   = null;
            InfluxConfig     iconfig   = null;
            PrometheusConfig pconfig   = null;
            TimescaleConfig  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 = TimescaleConfig.ParseAppSettings(config);
                break;
            }

            // Trim off the LibreHardwareMonitor "/name" suffix so that it is just the
            // the sensor ID.
            var aliases = config.GetKeys().Where(x => x.EndsWith("/name"))
                          .ToDictionary(
                x => x.Remove(x.LastIndexOf("/name", StringComparison.Ordinal)),
                x => config[x]
                );

            var hidden = config.GetKeys().Where(x => x.EndsWith("/hidden"))
                         .Select(x => x.Remove(x.LastIndexOf("/hidden", StringComparison.Ordinal)));
            var hiddenSensors = new HashSet <string>(hidden);

            return(new MetricConfig(interval, nameLookup, gconfig, iconfig, pconfig, timescale, aliases, hiddenSensors));
        }
Ejemplo n.º 4
0
        public static MetricConfig ParseAppSettings(IAppConfig config)
        {
            if (!int.TryParse(config["interval"], out int seconds))
            {
                seconds = 5;
            }

            var interval = TimeSpan.FromSeconds(seconds);

            var             lookup = config["name_lookup"] ?? "netbios";
            INameResolution nameLookup;

            switch (lookup.ToLowerInvariant())
            {
            case "dns":
                nameLookup = new DnsResolution();
                break;

            default:
                nameLookup = new NetBiosResolution();
                break;
            }

            var              type      = config["type"] ?? "graphite";
            GraphiteConfig   gconfig   = null;
            InfluxConfig     iconfig   = null;
            PrometheusConfig pconfig   = null;
            TimescaleConfig  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 = TimescaleConfig.ParseAppSettings(config);
                break;
            }

            return(new MetricConfig(interval, nameLookup, gconfig, iconfig, pconfig, timescale));
        }
Ejemplo n.º 5
0
        public static MetricConfig ParseAppSettings(IAppConfig config)
        {
            if (!int.TryParse(config["interval"], out int seconds))
            {
                seconds = 5;
            }

            var interval = TimeSpan.FromSeconds(seconds);

            INameResolution nameLookup = NameLookup(config["name_lookup"] ?? "netbios");

            InstallCertificateVerification(config["certificate_verification"] ?? "True");

            var              type      = config["type"] ?? "graphite";
            GraphiteConfig   gconfig   = null;
            InfluxConfig     iconfig   = null;
            PrometheusConfig pconfig   = null;
            TimescaleConfig  timescale = null;
            Influx2Config    influx2   = null;

            switch (type.ToLowerInvariant())
            {
            case "graphite":
                gconfig = GraphiteConfig.ParseAppSettings(config);
                break;

            case "influxdb":
            case "influx":
                iconfig = InfluxConfig.ParseAppSettings(config);
                break;

            case "influx2":
                influx2 = Influx2Config.ParseAppSettings(config);
                break;

            case "prometheus":
                pconfig = PrometheusConfig.ParseAppSettings(config);
                break;

            case "timescale":
            case "timescaledb":
                timescale = TimescaleConfig.ParseAppSettings(config);
                break;
            }

            // Trim off the LibreHardwareMonitor "/name" suffix so that it is just the
            // the sensor ID.
            var aliases = config.GetKeys().Where(x => x.EndsWith("/name"))
                          .ToDictionary(
                x => x.Remove(x.LastIndexOf("/name", StringComparison.Ordinal)),
                x => config[x]
                );

            // Do a similar trim with "/hidden" suffix except treat the prefix as a glob to hide
            // a group of sensors like if one wants to hide all power sensors they can do:
            // /*/power/*/hidden
            // Code to detect interpret strings as globs is shamelessly taken from stackoverflow:
            // https://stackoverflow.com/a/4146349/433785
            var hiddenSensors = config.GetKeys().Where(x => x.EndsWith("/hidden"))
                                .Select(x => x.Remove(x.LastIndexOf("/hidden", StringComparison.Ordinal)))
                                .Select(pattern => new Regex(
                                            "^" + Regex.Escape(pattern).Replace(@"\*", ".*").Replace(@"\?", ".") + "$",
                                            RegexOptions.IgnoreCase | RegexOptions.Singleline
                                            )).ToList();

            return(new MetricConfig(interval, nameLookup, gconfig, iconfig, pconfig, timescale, aliases, hiddenSensors, influx2));
        }