Elastic output improvements

FIX  Existing implementation only took one element from the queue per loop rather than clearing the queue.
ADD  Clients can submit a custom index that is being leveraged if specified. If not specified, the output reverts to a statically configured index name.
This commit is contained in:
Philipp Sumi
2014-11-11 12:28:32 +01:00
parent 448a5613b2
commit 387bd6c7f9

View File

@@ -46,8 +46,7 @@ namespace TimberWinR.Outputs
for (int i = 0; i < eo.NumThreads; i++)
{
var elsThread = new Task(ElasticsearchSender, cancelToken);
elsThread.Start();
Task.Factory.StartNew(ElasticsearchSender, cancelToken, TaskCreationOptions.LongRunning, TaskScheduler.Current);
}
}
@@ -80,8 +79,9 @@ namespace TimberWinR.Outputs
JObject[] messages;
lock (_locker)
{
messages = _jsonQueue.Take(1).ToArray();
_jsonQueue.RemoveRange(0, messages.Length);
var count = _jsonQueue.Count;
messages = _jsonQueue.Take(count).ToArray();
_jsonQueue.RemoveRange(0, count);
if (messages.Length > 0)
_manager.IncrementMessageCount(messages.Length);
}
@@ -105,10 +105,13 @@ namespace TimberWinR.Outputs
string typeName = "Win32-Elasticsearch";
if (json["type"] != null)
typeName = json["type"].ToString();
string indexName = _index;
////check if the submitted JSON object provides a custom index. If yes, use this one
var token = json["_index"];
string indexName = token == null ? _index : token.Value<string>();
if (string.IsNullOrEmpty(indexName))
{
DateTime now = DateTime.UtcNow;
indexName = string.Format("logstash-{0}", DateTime.UtcNow.ToString("yyyy.MM.dd"));
}
var req = new RestRequest(string.Format("/{0}/{1}/", indexName, typeName), Method.POST);