Exemple #1
0
        public static void Main(string[] args)
        {
            CommandLine.Parser.Default.ParseArguments <Config>(args)
            .WithParsed(options => {
                var collectorConfig = new CollectorConfiguration()
                                      .WriteTo.InfluxDB(options.InfluxUri, options.InfluxDatabase, options.InfluxUsername, options.InfluxPassword);

                CollectorLog.RegisterErrorHandler((message, exception) => {
                    Console.Error.WriteLine($"Error when recording influx stats: \"{message}\"");
                    Console.Error.WriteLine(exception);
                });

                using (var influxCollector = collectorConfig.CreateCollector()) {
                    if (options.Mode.Equals(PriceMode, StringComparison.InvariantCultureIgnoreCase))
                    {
                        RecordCurrentPrice(options, influxCollector).GetAwaiter().GetResult();
                    }
                    else if (options.Mode.Equals(UsageSimpleMode, StringComparison.InvariantCultureIgnoreCase))
                    {
                        RecordSimpleHistoricUsage(options, influxCollector).GetAwaiter().GetResult();
                    }
                    else if (options.Mode.Equals(UsageDetailedMode, StringComparison.InvariantCultureIgnoreCase))
                    {
                        RecordDetailedHistoricUsage(options, influxCollector).GetAwaiter().GetResult();
                    }
                    else
                    {
                        Console.Error.WriteLine($"Unrecognized mode \"{options.Mode}\" A valid --mode of either \"{PriceMode}\", \"{UsageSimpleMode}\" or \"{UsageDetailedMode}\" must be specified");
                        Environment.Exit(1);
                    }
                }
            });
        }
Exemple #2
0
        public static void StartMetrics()
        {
            Metrics.Collector?.Dispose();

            var settings = Properties.Settings.Default;

            if (string.IsNullOrWhiteSpace(settings.InfluxUrl))
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(settings.InfluxDatabase))
            {
                return;
            }

            var decodedPass = DecodeInfluxPassword();
            var insecure    = string.IsNullOrWhiteSpace(decodedPass);
            var nouser      = string.IsNullOrWhiteSpace(settings.InfluxUser);

            try
            {
                var collectorconfig = new CollectorConfiguration()
                                      .Batch.AtInterval(settings.InfluxInterval)
                                      .WriteTo.InfluxDB(
                    settings.InfluxUrl, settings.InfluxDatabase,
                    nouser ? null : settings.InfluxUser,
                    insecure ? null : decodedPass
                    );

                foreach (var tagkey in GlobalTags.Keys)
                {
                    var tagval = GlobalTags[tagkey];
                    collectorconfig.Tag.With(tagkey, tagval);
                }

                Metrics.Collector = collectorconfig.CreateCollector();
            }
            catch (Exception e) { }
        }
        /// <summary>
        /// Create the actual reporter (according to the builder state).
        /// </summary>
        /// <returns></returns>
        IMetricsReporter IMetricsReporterBuilder.Build()
        {
            var influxClient = _influxConfiguration.CreateCollector();

            return(new MetricsReporter(_activation, _tagContext, _measurementName, _tags, influxClient));
        }