-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from AdysTech/wip
Project file hierarchy updated
- Loading branch information
Showing
24 changed files
with
269 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
################################################################################################## | ||
#This script downloads the latest nightly InfluxDB build, starts the db engine, and creates basic | ||
#data structures so that 'show databases' query will not fail during tests if the query gets | ||
#executed before CreateDatabase test | ||
# | ||
################################################################################################## | ||
|
||
$source = "https://dl.influxdata.com/influxdb/nightlies/influxdb-nightly_windows_amd64.zip" | ||
$destination = "$env:Temp\influxdb-nightly_windows_amd64.zip" | ||
$influx = "$env:Temp\influxdb" | ||
$influxdata = "$env:UserProfile\.influxdb" | ||
|
||
if(!(test-path $destination) -or ((Get-ItemProperty -Path $destination -Name LastWriteTime).lastwritetime -lt $(get-date).AddDays(-1))) | ||
{ Invoke-WebRequest $source -OutFile $destination } | ||
|
||
if(test-path $influx) | ||
{ rmdir -recurse $influx} | ||
|
||
Add-Type -As System.IO.Compression.FileSystem | ||
[System.IO.Compression.ZipFile]::ExtractToDirectory($destination,$influx) | ||
$influxd = Get-ChildItem $influx -File -filter "influxd.exe" -Recurse | % { $_.FullName } | ||
|
||
#$x = 7z e $destination -o"$env:Temp\influxdb" -y | ||
if(test-path $influxdata) | ||
{ rmdir -recurse "$env:UserProfile\.influxdb" } | ||
|
||
Start-Process -FilePath $influxd | ||
#let the engine start | ||
Start-Sleep -s 10 | ||
|
||
$r = Invoke-WebRequest -Method Post -Uri http://localhost:8086/query -Body "q=CREATE DATABASE prereq" | ||
if($r.StatusCode -ne 200) | ||
{ | ||
throw "Unable to create DB" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="AdysTech.InfluxDB.Client.Net" version="0.5.3" targetFramework="net452" /> | ||
<package id="AdysTech.InfluxDB.Client.Net" version="0.5.9.1" targetFramework="net452" /> | ||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
using AdysTech.Influxer.Logging; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
|
||
namespace AdysTech.Influxer.Config | ||
{ | ||
public static class CommandLineProcessor | ||
{ | ||
private static InfluxerConfigSection _settings; | ||
public static InfluxerConfigSection Settings | ||
{ | ||
get | ||
{ | ||
return _settings; | ||
} | ||
} | ||
|
||
public static bool ProcessArguments (string[] args) | ||
{ | ||
if (args.Length == 0) | ||
{ | ||
throw new ArgumentException ("Command line arguments not valid, try --help to see valid ones!"); | ||
} | ||
#region Parse command line arguments | ||
Dictionary<string, string> cmdArgs = new Dictionary<string, string> (); | ||
Regex commandSwitch = new Regex ("^-[a-zA-Z+]|^/[a-zA-Z+]", RegexOptions.Compiled); | ||
for (int i = 0; i < args.Length; i++) | ||
{ | ||
if (commandSwitch.IsMatch (args[i])) | ||
{ | ||
var key = args[i].ToLower (); | ||
if (i + 1 < args.Length && !commandSwitch.IsMatch (args[i + 1])) | ||
{ | ||
cmdArgs.Add (key.ToLower (), args[i + 1]); | ||
i++; | ||
} | ||
else | ||
cmdArgs.Add (key.ToLower (), "true"); | ||
} | ||
} | ||
|
||
var totalArguments = cmdArgs.Count; | ||
|
||
if (cmdArgs.ContainsKey ("--help") || cmdArgs.ContainsKey ("/help") || cmdArgs.ContainsKey ("/?")) | ||
{ | ||
var help = new StringBuilder (); | ||
help.AppendLine ("Influxer is an application to parse log files, push data to Influx for later visualization."); | ||
help.AppendLine ("It currently supports Windows Perfmon and any generic delimited file formats"); | ||
help.AppendLine ("It uses InfluxDB.Client.Net to interact with Influx."); | ||
help.AppendLine (new String ('-', 180)); | ||
help.AppendLine ("Supported command line arguments"); | ||
help.AppendLine ("--help /? or /help shows this help text\n"); | ||
help.AppendLine (); | ||
help.AppendLine ("/export to print possible config section, pipe it to a file to edit and reuse the config"); | ||
help.AppendLine (); | ||
help.AppendLine ("-config <configuration file path> to load the config file."); | ||
help.AppendLine (); | ||
help.AppendLine ("Any configuration entries can be overridden by command line switches shown below\n"); | ||
help.AppendLine (new String ('-', 180)); | ||
help.Append (InfluxerConfigSection.LoadDefault ().PrintHelpText ()); | ||
Logger.Log (LogLevel.Info, help.ToString ()); | ||
return false; | ||
} | ||
|
||
if (cmdArgs.ContainsKey ("-config")) | ||
{ | ||
try | ||
{ | ||
var configFile = Path.GetFullPath (cmdArgs["-config"]); | ||
_settings = InfluxerConfigSection.Load (configFile); | ||
cmdArgs.Remove ("-config"); | ||
totalArguments -= 1; | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new FileLoadException ($"Error Loading config file:{e.GetType ().Name},{e.Message}", e); | ||
} | ||
} | ||
else | ||
{ | ||
_settings = InfluxerConfigSection.LoadDefault (); | ||
} | ||
#endregion | ||
|
||
if (totalArguments >= 1) | ||
{ | ||
if (!(cmdArgs.Count == 1 && cmdArgs.ContainsKey ("/export"))) | ||
{ | ||
try | ||
{ | ||
if (!_settings.ProcessCommandLineArguments (cmdArgs)) | ||
{ | ||
throw new ArgumentException ("Invalid commandline arguments!! Use /help to see valid ones"); | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new ArgumentException ($"Error processing arguments :{e.GetType ().Name}, {e.Message}", e); | ||
} | ||
} | ||
} | ||
|
||
if (cmdArgs.ContainsKey ("/export")) | ||
{ | ||
if (cmdArgs.ContainsKey ("/autolayout")) | ||
{ | ||
if (string.IsNullOrWhiteSpace (_settings.InputFileName)) | ||
throw new ArgumentException ("No Input file name mentioned!!"); | ||
|
||
var g = new GenericFile (); | ||
g.GetFileLayout (_settings.InputFileName); | ||
g.ValidateData (_settings.InputFileName); | ||
} | ||
InfluxerConfigSection.Export (Console.OpenStandardOutput (), totalArguments > 1 ? false : true); | ||
return false; | ||
} | ||
|
||
|
||
if (cmdArgs.Count > 0) | ||
{ | ||
throw new ArgumentException ($"Unknown command line arguments: {String.Join (", ", cmdArgs.Select (c => c.Key))}"); | ||
} | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.