Using the ZedGraph library

The TailExpert installation also includes a copy of the zedGraph library (http://sourceforge.net/projects/zedgraph) . ZedGraph is a class library, user control, and web control for .net, written in C#, for drawing 2D Line, Bar, and Pie Charts. It features full, detailed customization capabilities. All functions of zedGraph are avalaible to the script engine of TailExpert, which makes it possible to visualize your logfile data in graphs while your logfile grows. You could use this for example to count the number of warnings and error of some kind and directly show them in a bargraph next to the log being examined. The bargraph can be updated when new loglines arrive. The example below shows a script the displays the function usage of TailExpert from the TailExpert logfile in C:\Temp\TailExpert.log in a bargraph, when you select the functions listed in the bargraph, you will see the bargraph change.

Code:

--[[

    This is an example script for the lua engine in TailExpert

   

    Purpose:

    This script demonstrates the use of the ZedGraph library available within TailExpert.

    It will plot a histogram based upon occurrences of actions detected in the TailExpert

    log file.

]]--

require("Config")

 

-- Import WIndows Assemblies

import("System")

import("System.Windows.Forms")

import("System.Drawing")

import("System.Drawing.Drawing2D")

import("ZedGraph")

 

local form = Form()

form.Height = 600

form.Width = 800

form.Text = "Output window of HistoExample.lua"

form.HelpButton=false

form.MaximizeBox=true

form.MinimizeBox=true

 

local graph = ZedGraphControl()

graph.Dock = DockStyle.Fill

myPane = graph.GraphPane

 

-- Set the titles and axis labels

myPane.Title.Text = "Bar Graph Example"

myPane.XAxis.Title.Text = "Categories"

myPane.YAxis.Title.Text = "Nr of Hits"

 

local label = String[5]

local dbl_arr = Double[5]

 

for i=0, 4,1 do

    dbl_arr[i] = 0.0

end

 

label[0] = "Pause"

label[1] = "Scroll"

label[2] = "Filter"

label[3] = "Compare"

label[4] = "Bookmarks"

 

-- Create the three BarItems, change the fill properties so the angle is at 90

-- degrees for horizontal bars

bar = myPane:AddBar( "Function usage", nil, dbl_arr, Color.Red )

bar.Bar.Fill = Fill( Color.Red, Color.White, Color.Red, 0 )

 

-- Set BarBase to the YAxis for horizontal bars

myPane.BarSettings.Base = BarBase.X

-- Make the bars stack instead of cluster

myPane.BarSettings.Type = BarType.Stack

 

-- Fill the axis background with a color gradient

myPane.Chart.Fill = Fill( Color.White, Color.LightGoldenrodYellow, 45.0 )

myPane.XAxis.Scale.TextLabels = label

myPane.XAxis.Type = AxisType.Text

graph:AxisChange()

 

form.Controls:Add(graph)

form:Show()

 

--[[

Script starts here

]]--

 

local filename = 'c:\\temp\\TailExpert.log'

local file = nill

 

local linenr = 0

function ReadFile(f)

      -- Do not put message here as it will make a recurring effect when you have log enabled and load TailExpert.log

      outputBuffer = {}

      if ScriptInitialized == true then

             if feof(f) ~= nill then

                   while feof(f) ~= true do

                         local line = f:read("*line")

                         if line ~= nill then

                                PutLogLine( line )

                                if string.match(line, "ButtonPause_Click") ~= nil then

                                      dbl_arr[0] = dbl_arr[0] + 1.0

                                end

                                if string.match(line, "ButtonScroll_Click") ~= nil then

                                      dbl_arr[1] = dbl_arr[1] + 1.0

                                end

                                if string.match(line, "ButtonFilter_Click") ~= nil then

                                      dbl_arr[2] = dbl_arr[2] + 1.0

                                end

                                if string.match(line, "compareTabsToolStripMenuItem_Click") ~= nil then

                                      dbl_arr[3] = dbl_arr[3] + 1.0

                                end

                                if string.match(line, "NextBookmark_Click") ~= nil then

                                      dbl_arr[4] = dbl_arr[4] + 1.0

                                end

                                if string.match(line, "PrevBookmark_Click") ~= nil then

                                    dbl_arr[4] = dbl_arr[4] + 1.0

                                end

                         end

                -- Create new pointPairList

                pointPairList = PointPairList()

                pointPairList:Add(nil, dbl_arr)

                curveItem = myPane.CurveList[0]

                curveItem.Points = pointPairList

                graph:AxisChange()

                graph:Refresh()

                   end

             end

end

end

 

--[[

Required predefined functions: Are called from TailExpert, adapt to your needs

]]--

 

function OnEvaluate(loglines)

    -- Do not put LogMessage() here this will overflow your logs as

    -- Evaluate is called every tail cycle

    -- If you need log make sure it's not output every cycle

    if ScriptInitialized == true then

        ReadFile(file)

    end

end

 

function OnEnter()

      LogMessage(INFO, "HistoExample.lua script OnEnter()")

      ScriptInitialized = true

 

    -- tests the functions above

    if file_exists(filename) then

        file = assert(io.open(filename, "r"))

    end

    file:seek("set", 0)

    ScriptInitialized = true

end

 

function OnExit()

      LogMessage(INFO, "HistoExample.lua script OnExit()")

      ScriptInitialized = false  -- prevent Evaluate to be called

      graph:Dispose()

      form:Close()

      file:close()

end

 

The engine used to enable .NET access from lua is luaInterface. Lua interface translates lua call to C# calls in .NET components and vise versa.