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