示例#1
0
        public OutputFilter CreateFilter(IEnumerable <IOutputConfiguration> configurations)
        {
            Lazy <GraphiteBackend> graphite = new Lazy <GraphiteBackend>(() => new GraphiteBackend(this.graphiteConfiguration));
            Lazy <StatsDBackend>   statsD   = new Lazy <StatsDBackend>(() => new StatsDBackend(this.statsDConfiguration));
            Lazy <ConsoleBackend>  console  = new Lazy <ConsoleBackend>(() => new ConsoleBackend());

            List <OutputTarget> targets = new List <OutputTarget>();

            foreach (var configuration in configurations)
            {
                IOutputBackend backend = null;

                if ("graphite".Equals(configuration.Target, StringComparison.OrdinalIgnoreCase))
                {
                    backend = graphite.Value;
                }
                else if ("statsd".Equals(configuration.Target, StringComparison.OrdinalIgnoreCase))
                {
                    backend = statsD.Value;
                }
                else if ("console".Equals(configuration.Target, StringComparison.OrdinalIgnoreCase))
                {
                    backend = console.Value;
                }
                else
                {
                    throw new ArgumentException("Unknown output target \"{0}\".".FormatWith(configuration.Target), "configurations");
                }

                var target = new OutputTarget(
                    configuration.PathPattern,
                    configuration.Type,
                    configuration.MetricsPrefix,
                    backend);

                targets.Add(target);
            }

            List <IOutputBackend> backends = new List <IOutputBackend>();

            if (graphite.IsValueCreated)
            {
                backends.Add(graphite.Value);
            }

            if (statsD.IsValueCreated)
            {
                backends.Add(statsD.Value);
            }

            if (console.IsValueCreated)
            {
                backends.Add(console.Value);
            }

            var filter = new OutputFilter(targets, backends);

            return(filter);
        }
示例#2
0
        public OutputFilter CreateFilter(IEnumerable<IOutputConfiguration> configurations)
        {
            Lazy<GraphiteBackend> graphite = new Lazy<GraphiteBackend>(() => new GraphiteBackend(this.graphiteConfiguration));
            Lazy<StatsDBackend> statsD = new Lazy<StatsDBackend>(() => new StatsDBackend(this.statsDConfiguration));
            Lazy<ConsoleBackend> console = new Lazy<ConsoleBackend>(() => new ConsoleBackend());

            List<OutputTarget> targets = new List<OutputTarget>();

            foreach (var configuration in configurations)
            {
                IOutputBackend backend = null;

                if ("graphite".Equals(configuration.Target, StringComparison.OrdinalIgnoreCase))
                {
                    backend = graphite.Value;
                }
                else if ("statsd".Equals(configuration.Target, StringComparison.OrdinalIgnoreCase))
                {
                    backend = statsD.Value;
                }
                else if ("console".Equals(configuration.Target, StringComparison.OrdinalIgnoreCase))
                {
                    backend = console.Value;
                }
                else
                {
                    throw new ArgumentException("Unknown output target \"{0}\".".FormatWith(configuration.Target), "configurations");
                }

                var target = new OutputTarget(
                    configuration.PathPattern,
                    configuration.Type,
                    configuration.MetricsPrefix,
                    backend);

                targets.Add(target);
            }

            List<IOutputBackend> backends = new List<IOutputBackend>();

            if (graphite.IsValueCreated)
                backends.Add(graphite.Value);

            if (statsD.IsValueCreated)
                backends.Add(statsD.Value);

            if (console.IsValueCreated)
                backends.Add(console.Value);

            var filter = new OutputFilter(targets, backends);

            return filter;
        }
        public ConfigurationAppStarter()
        {
            var processorsFactory = new ProcessorFactory();

            LogMonitorConfiguration configuration = LogMonitorConfiguration.Instance;

            this.processors = new List<IProcessor>();

            // Set to right "context"
            Environment.CurrentDirectory = Path.GetDirectoryName(typeof(Kernel).Assembly.Location);

            foreach (ParserElement parser in configuration.Parser)
            {
                processors.Add(processorsFactory.Create(parser.ScriptPath, parser.Pattern));
            }

            var outputFactory = new OutputFactory(
                GraphiteConfiguration.Instance == null ? null : GraphiteConfiguration.Instance.Graphite,
                GraphiteConfiguration.Instance == null ? null : GraphiteConfiguration.Instance.StatsD);

            this.outputFilter = outputFactory.CreateFilter(
                configuration.Output.Cast<IOutputConfiguration>());
        }
示例#4
0
        public Kernel(IEnumerable<IProcessor> processors, IEnumerable<IWatchConfiguration> watchList, OutputFilter outputFilter)
        {
            if (watchList == null)
                throw new ArgumentNullException("watchList");

            if (processors == null)
                throw new ArgumentNullException("processors");

            this.manager = new ChangeManager(processors, outputFilter);

            Lazy<W3CProcessor> w3CProcessor = new Lazy<W3CProcessor>(() => new W3CProcessor());
            DefaultPreProcessor preProcessor = new DefaultPreProcessor();

            foreach (var item in watchList)
            {
                FileNotificationService watcher = this.CreateWatcher(item);

                if (watcher != null)
                {
                    this.watchers.Add(watcher);

                    IPreProcessor selectedPreProcessor;

                    if (!string.IsNullOrEmpty(item.Type) && "w3c".Equals(item.Type, StringComparison.OrdinalIgnoreCase))
                    {
                        selectedPreProcessor = w3CProcessor.Value;
                    }
                    else
                    {
                        selectedPreProcessor = preProcessor;
                    }

                    watcher.ContentAdded += (object o, ContentEventArgs e) => this.manager.Add(selectedPreProcessor.Process(e.FileName, e.AddedContent));
                }
            }
        }