Exemple #1
0
        private static IManage CreateManager(MetricConfig config, SensorCollector collector)
        {
            double seconds = config.Interval.TotalSeconds;

            if (config.Graphite != null)
            {
                Logger.Info(
                    $"Graphite host: {config.Graphite.Host} port: {config.Graphite.Port} interval: {seconds} tags: {config.Graphite.Tags}");
                var writer = new GraphiteWriter(config.Graphite.Host,
                                                config.Graphite.Port,
                                                Environment.MachineName,
                                                config.Graphite.Tags);
                return(new MetricTimer(config.Interval, collector, writer));
            }
            else if (config.Prometheus != null)
            {
                Logger.Info($"Prometheus port: {config.Prometheus.Port}");
                var prometheusCollection = new PrometheusCollection(collector, Environment.MachineName);
                var server = new MetricServer(config.Prometheus.Host, config.Prometheus.Port);
                return(new PrometheusServer(server, collector, prometheusCollection));
            }
            else if (config.Timescale != null)
            {
                var writer = new TimescaleWriter(config.Timescale.Connection, config.Timescale.SetupTable, Environment.MachineName);
                return(new MetricTimer(config.Interval, collector, writer));
            }
            else
            {
                Logger.Info($"Influxdb address: {config.Influx.Address} db: {config.Influx.Db}");
                var writer = new InfluxWriter(config.Influx, Environment.MachineName);
                return(new MetricTimer(config.Interval, collector, writer));
            }
        }
Exemple #2
0
        private static IManage CreateManager(MetricConfig config, SensorCollector collector)
        {
            var    hostname = config.LookupName();
            double seconds  = config.Interval.TotalSeconds;

            if (config.Graphite != null)
            {
                Logger.Info(
                    $"Graphite host: {config.Graphite.Host} port: {config.Graphite.Port} interval: {seconds} tags: {config.Graphite.Tags}");
                var writer = new GraphiteWriter(config.Graphite.Host,
                                                config.Graphite.Port,
                                                hostname,
                                                config.Graphite.Tags);
                return(new MetricTimer(config.Interval, collector, writer));
            }
            else if (config.Prometheus != null)
            {
                Logger.Info($"Prometheus port: {config.Prometheus.Port}");
                var registry = PrometheusCollection.SetupDefault(collector);
                var server   = new MetricServer(config.Prometheus.Host, config.Prometheus.Port, registry: registry);
                return(new PrometheusServer(server, collector));
            }
            else if (config.Timescale != null)
            {
                var writer = new TimescaleWriter(config.Timescale.Connection, config.Timescale.SetupTable, hostname);
                return(new MetricTimer(config.Interval, collector, writer));
            }
            else
            {
                Logger.Info($"Influxdb address: {config.Influx.Address} db: {config.Influx.Db}");
                var writer = new InfluxWriter(config.Influx, hostname);
                return(new MetricTimer(config.Interval, collector, writer));
            }
        }
Exemple #3
0
 public MetricTimer(TimeSpan interval, SensorCollector collector, IWriteMetrics writer)
 {
     _timer = new Timer(interval.TotalMilliseconds)
     {
         AutoReset = true
     };
     _timer.Elapsed += ReportMetrics;
     _collector      = collector;
     _writer         = writer;
 }
Exemple #4
0
        private static void Main(string[] args)
        {
            HostFactory.Run(x =>
            {
                x.Service <MetricTimer>(s =>
                {
                    // We need to know where the graphite server lives and how often
                    // to poll the hardware
                    var config     = Logger.LogFunction("parse config", MetricConfig.ParseAppSettings);
                    double seconds = config.Interval.TotalSeconds;
                    IWriteMetrics writer;
                    if (config.Graphite != null)
                    {
                        Logger.Info($"Graphite host: {config.Graphite.Host} port: {config.Graphite.Port} interval: {seconds} tags: {config.Graphite.Tags}");
                        writer = new GraphiteWriter(config.Graphite.Host,
                                                    config.Graphite.Port,
                                                    Environment.MachineName,
                                                    config.Graphite.Tags);
                    }
                    else
                    {
                        Logger.Info($"Influxdb address: {config.Influx.Address} db: {config.Influx.Db}");
                        writer = new InfluxWriter(config.Influx, Environment.MachineName);
                    }

                    // We'll want to capture all available hardware metrics
                    // to send to graphite
                    var computer = new Computer
                    {
                        GPUEnabled           = true,
                        MainboardEnabled     = true,
                        CPUEnabled           = true,
                        RAMEnabled           = true,
                        FanControllerEnabled = true,
                        HDDEnabled           = true
                    };

                    var collector = new SensorCollector(computer);

                    s.ConstructUsing(name =>
                                     Logger.LogFunction("creating timer",
                                                        () => new MetricTimer(config.Interval, collector, writer)));
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Stop());
                });
                x.UseNLog();
                x.RunAsLocalSystem();
                x.SetDescription(
                    "Extract hardware sensor data and exports it to a given host and port in a graphite compatible format");
                x.SetDisplayName("Ohm Graphite");
                x.SetServiceName("OhmGraphite");
                x.OnException(ex => Logger.Error(ex, "OhmGraphite TopShelf encountered an error"));
            });
        }
Exemple #5
0
        private static void Main()
        {
            string configPath = string.Empty;

            HostFactory.Run(x =>
            {
                x.Service <IManage>(s =>
                {
                    // We'll want to capture all available hardware metrics
                    // to send to graphite
                    var computer = new Computer
                    {
                        IsGpuEnabled         = true,
                        IsMotherboardEnabled = true,
                        IsCpuEnabled         = true,
                        IsMemoryEnabled      = true,
                        IsNetworkEnabled     = true,
                        IsStorageEnabled     = true,
                        IsControllerEnabled  = true
                    };

                    s.ConstructUsing(name =>
                    {
                        var configDisplay = string.IsNullOrEmpty(configPath) ? "default" : configPath;
                        var config        = Logger.LogFunction($"parse config {configDisplay}", () => MetricConfig.ParseAppSettings(CreateConfiguration(configPath)));
                        var collector     = new SensorCollector(computer, config);
                        return(CreateManager(config, collector));
                    });
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Dispose());
                });

                // Allow one to specify a command line argument when running interactively
                x.AddCommandLineDefinition("config", v => configPath = v);
                x.UseNLog();
                x.RunAsLocalSystem();
                x.SetDescription(
                    "Extract hardware sensor data and exports it to a given host and port in a graphite compatible format");
                x.SetDisplayName("Ohm Graphite");
                x.SetServiceName("OhmGraphite");
                x.OnException(ex => Logger.Error(ex, "OhmGraphite TopShelf encountered an error"));
            });
        }
Exemple #6
0
        private static void Main()
        {
            HostFactory.Run(x =>
            {
                x.Service <IManage>(s =>
                {
                    // We'll want to capture all available hardware metrics
                    // to send to graphite
                    var computer = new Computer
                    {
                        GPUEnabled           = true,
                        MainboardEnabled     = true,
                        CPUEnabled           = true,
                        RAMEnabled           = true,
                        FanControllerEnabled = true,
                        HDDEnabled           = true,
                        NICEnabled           = true
                    };

                    var collector = new SensorCollector(computer);

                    // We need to know where the graphite server lives and how often
                    // to poll the hardware
                    var config         = Logger.LogFunction("parse config", () => MetricConfig.ParseAppSettings(new AppConfigManager()));
                    var metricsManager = CreateManager(config, collector);

                    s.ConstructUsing(name => metricsManager);
                    s.WhenStarted(tc => tc.Start());
                    s.WhenStopped(tc => tc.Dispose());
                });
                x.UseNLog();
                x.RunAsLocalSystem();
                x.SetDescription(
                    "Extract hardware sensor data and exports it to a given host and port in a graphite compatible format");
                x.SetDisplayName("Ohm Graphite");
                x.SetServiceName("OhmGraphite");
                x.OnException(ex => Logger.Error(ex, "OhmGraphite TopShelf encountered an error"));
            });
        }
Exemple #7
0
 public PrometheusCollection(SensorCollector collector, string localHost)
 {
     _collector = collector;
     _localHost = localHost;
 }
 public PrometheusServer(MetricServer server, SensorCollector collector, PrometheusCollection prometheusCollection)
 {
     _server               = server;
     _collector            = collector;
     _prometheusCollection = prometheusCollection;
 }