Exemplo n.º 1
0
        private static int Main(string[] args)
        {
            try
            {
                if (!CommandLineProcessor.ProcessArguments(args))
                {
                    return((int)ExitCode.Success);
                }
                settings = CommandLineProcessor.Settings;
            }
            catch (ArgumentException e)
            {
                Logger.LogLine(LogLevel.Error, e.Message);
                return((int)ExitCode.InvalidArgument);
            }
            catch (FileLoadException e)
            {
                Logger.LogLine(LogLevel.Error, e.Message);
                Logger.LogLine(LogLevel.Info, "Problem loading config file, regenerate it with /config option");
                return((int)ExitCode.InvalidFilename);
            }
            catch (Exception e)
            {
                Logger.LogLine(LogLevel.Error, "Error processing arguments {0}: {1}", e.GetType().Name, e.Message);
                return((int)ExitCode.InvalidArgument);
            }

            #region Validate inputs

            if (String.IsNullOrWhiteSpace(settings.InputFileName))
            {
                Logger.LogLine(LogLevel.Error, "Input File Name is not specified!! Can't continue");
                return((int)ExitCode.InvalidArgument);
            }

            try
            {
                settings.InputFileName = Path.GetFullPath(settings.InputFileName);
            }
            catch (Exception e)
            {
                Logger.LogLine(LogLevel.Error, "Error with input file:{0},{1}", e.GetType().Name, e.Message);
                Logger.LogLine(LogLevel.Info, "Problem with inputfile name, check path");
                return((int)ExitCode.InvalidFilename);
            }

            if (String.IsNullOrWhiteSpace(settings.InfluxDB.InfluxUri))
            {
                Logger.LogLine(LogLevel.Error, "Influx DB Uri is not configured!!");
                return((int)ExitCode.InvalidArgument);
            }

            if (String.IsNullOrWhiteSpace(settings.InfluxDB.DatabaseName))
            {
                Logger.LogLine(LogLevel.Error, "Influx DB name is not configured!!");
                return((int)ExitCode.InvalidArgument);
            }

            #endregion Validate inputs

            ProcessStatus result = new ProcessStatus()
            {
                ExitCode = ExitCode.UnknownError
            };
            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                var client = new InfluxDBClient(settings.InfluxDB.InfluxUri, settings.InfluxDB.UserName, settings.InfluxDB.Password);

                if (!VerifyDatabaseAsync(client, settings.InfluxDB.DatabaseName).Result)
                {
                    Logger.LogLine(LogLevel.Info, "Unable to create DB {0}", settings.InfluxDB.DatabaseName);
                    return((int)ExitCode.UnableToProcess);
                }
                switch (settings.FileFormat)
                {
                case FileFormats.Perfmon:
                    result = new PerfmonFile().ProcessPerfMonLog(settings.InputFileName, client).Result;
                    break;

                case FileFormats.Generic:
                    if (String.IsNullOrWhiteSpace(settings.InfluxDB.Measurement))
                    {
                        throw new ArgumentException("Generic format needs TableName input");
                    }
                    result = new GenericFile().ProcessGenericFile(settings.InputFileName, client).Result;
                    break;
                }

                stopwatch.Stop();
                Logger.LogLine(LogLevel.Info, "\n Finished!! Processed {0} points (Success: {1}, Failed:{2}) in {3}", result.PointsFound, result.PointsProcessed, result.PointsFailed, stopwatch.Elapsed.ToString());
            }
            catch (AggregateException e)
            {
                Logger.LogLine(LogLevel.Error, "Error!! {0}:{1} - {2}", e.InnerException.GetType().Name, e.InnerException.Message, e.InnerException.StackTrace);
            }
            catch (Exception e)
            {
                Logger.LogLine(LogLevel.Error, "Error!! {0}:{1} - {2}", e.GetType().Name, e.Message, e.StackTrace);
            }
            return((int)result.ExitCode);
        }
Exemplo n.º 2
0
        static int Main (string[] args)
        {
            try
            {
                if (!CommandLineProcessor.ProcessArguments (args))
                    return (int) ExitCode.Success;
                settings = CommandLineProcessor.Settings;
            }
            catch (ArgumentException e)
            {
                Logger.LogLine (LogLevel.Error, e.Message);
                return (int) ExitCode.InvalidArgument;
            }
            catch (FileLoadException e)
            {
                Logger.LogLine (LogLevel.Error, e.Message);
                Logger.LogLine (LogLevel.Info, "Problem loading config file, regenerate it with /config option");
                return (int) ExitCode.InvalidFilename;
            }
            catch (Exception e)
            {
                Logger.LogLine (LogLevel.Error, "Error processing arguments {0}: {1}", e.GetType ().Name, e.Message);
                return (int) ExitCode.InvalidArgument;
            }

            #region Validate inputs
            
            if (String.IsNullOrWhiteSpace (settings.InputFileName))
            {
                Logger.LogLine (LogLevel.Error, "Input File Name is not specified!! Can't continue");
                return (int) ExitCode.InvalidArgument;
            }

            try
            {
                settings.InputFileName = Path.GetFullPath (settings.InputFileName);
            }
            catch (Exception e)
            {
                Logger.LogLine (LogLevel.Error, "Error with input file:{0},{1}", e.GetType ().Name, e.Message);
                Logger.LogLine (LogLevel.Info, "Problem with inputfile name, check path");
                return (int) ExitCode.InvalidFilename;
            }

            if (String.IsNullOrWhiteSpace (settings.InfluxDB.InfluxUri))
            {
                Logger.LogLine (LogLevel.Error, "Influx DB Uri is not configured!!");
                return (int) ExitCode.InvalidArgument;
            }

            if (String.IsNullOrWhiteSpace (settings.InfluxDB.DatabaseName))
            {
                Logger.LogLine (LogLevel.Error, "Influx DB name is not configured!!");
                return (int) ExitCode.InvalidArgument;
            }

            #endregion

            ProcessStatus result = new ProcessStatus () { ExitCode = ExitCode.UnknownError };
            try
            {
                Stopwatch stopwatch = new Stopwatch ();
                stopwatch.Start ();

                var client = new InfluxDBClient (settings.InfluxDB.InfluxUri, settings.InfluxDB.UserName, settings.InfluxDB.Password);

                if (!VerifyDatabaseAsync (client, settings.InfluxDB.DatabaseName).Result)
                {
                    Logger.LogLine (LogLevel.Info, "Unable to create DB {0}", settings.InfluxDB.DatabaseName);
                    return (int) ExitCode.UnableToProcess;
                }
                switch (settings.FileFormat)
                {
                    case FileFormats.Perfmon:
                        result = new PerfmonFile ().ProcessPerfMonLog (settings.InputFileName, client).Result;
                        break;
                    case FileFormats.Generic:
                        if (String.IsNullOrWhiteSpace (settings.InfluxDB.Measurement))
                            throw new ArgumentException ("Generic format needs TableName input");
                        result = new GenericFile ().ProcessGenericFile (settings.InputFileName, client).Result;
                        break;
                }

                stopwatch.Stop ();
                Logger.LogLine (LogLevel.Info, "\n Finished!! Processed {0} points (Success: {1}, Failed:{2}) in {3}", result.PointsFound, result.PointsProcessed, result.PointsFailed, stopwatch.Elapsed.ToString ());

            }

            catch (AggregateException e)
            {
                Logger.LogLine (LogLevel.Error, "Error!! {0}:{1} - {2}", e.InnerException.GetType ().Name, e.InnerException.Message, e.InnerException.StackTrace);
            }

            catch (Exception e)
            {
                Logger.LogLine (LogLevel.Error, "Error!! {0}:{1} - {2}", e.GetType ().Name, e.Message, e.StackTrace);
            }
            return (int) result.ExitCode;
        }