Page tree
Skip to end of metadata
Go to start of metadata

Use Graylog Plugin for Confluence to add Graylog charts, maps and reports to your Confluence pages. This is particularly useful to create system or service status pages with online data from your log server.

You start by setting connection to your Graylog server at the plugin configuration page:

After you have successfully connected to your Graylog server you can start using the addon.



Graylog Chart

You can use the Graylog Chart macro to draw a pie chart or a histogram.

You can select specific date to draw a chart for by clicking calendar icon in the top left corner or you can click a 'period' link in a calendar popup to select a period:




Graylog Chart macro has the following parameters:

  • Query is a mandatory parameter that is exactly the same that you would use with your Graylog search (see screenshot of Graylog page to the right)
  • Range is a time range in seconds
  • Field If Field parameter is set than Graylog Chart is a pie chart grouped by the field specified. If Field parameter is missing than Graylog Chart is a bar chart with messages grouped by an hour of the day

Graylog Chart macro sends parameters to Graylog server to query for message statistics. The macro may also have options that are not sent to Graylog server, but rather modify the behaviour of the macro itself. You specify options as Javascript object inside the body of the macro. Currently the following options are supported:

  • colors You may specify the color of the pie chart segments or the color of the bar chart
  • onclick You may provide a function to handle click events for a chart
  • timeFormat (valid for bar chart only) Specifies time format for x-axis

Take a look the following examples:

Pie chart options
data: {
  // There are only two possible values with this field: 'info' and 'error'
  colors: {
    error:'#FAD7A0',
    info:'#ABEBC6'
  },
  // Redraw a bar chart when a user clicks on this pie chart
  onclick: function(d,e,params,options){
    // Import the charting library
    var GC = require('com.mesilat.graylog:chart');
    // Find the target bar chart
    var $div = $('div.graylog-chart[graylog-plugin-data-macroid="26bf56c9-aeda-4a24-a3bc-c94792ac084f"]');
    // Fill params and options objects for the target bar chart
    // 'command' option can be one of 'relative' or 'absolute'; copy it from original options for the pie chart
    var _params = {}, _options = {
      command: options.command
    };
    // Initially there is no 'selectedDate' option for a chart: it is only set when a user selects a date by clicking a calendar icon
    // in the top left corner of a chart. We want our bar chart to be the same date as the pie chart, so copy the option if present
    if ('selectedDate' in options){
      _options.selectedDate = options.selectedDate;
    }
    // Copy 'range' parameter if present
    if ('range' in params){
      _params.range = params.range;
    }
    // 'from' and 'to' parameters are set only if a user had previously selected a period for the source chart.
    // The period starts at 00:00 of the 'from' date and ends at 23:59.999 of the 'to' date
    if ('from' in params){
      _params.from = params.from;
    }
    if ('to' in params){
      _params.to = params.to;
    }
    // For a pie chart d.id contains the value that has been clicked
    if (d.id === 'info'){
      // Set a query for the target bar chart
      _params.query = 'Metric:PARP2029 AND Level:info';
      // Set color of the target chart. Bar charts use 'messages' attribute to get their color from
      $.extend(true, _options, {
        data: {
          colors: {
            messages:'#ABEBC6'
          }
        }
      });
    } else if (d.id === 'error'){
      _params.query = 'Metric:PARP2029 AND Level:error';
      $.extend(true, _options, {
        data: {
          colors: {
            messages:'#FAD7A0'
          }
        }
      });
    }
 // Redraw the target bar chart
    GC.drawChart($div, _params, _options);
  }
}
Bar chart options
data: {
  // Use neutral color in the beginning
  colors: {
    messages:'#E5E7E9'
  },
  // Redraw a list of messages when a user clicks a bar on the source chart
  onclick: function(d,e,params,options){
    // Load the list library
    var GL = require('com.mesilat.graylog:list');
    // Find the target list macro
    var $div = $('div.graylog-list[graylog-plugin-data-macroid="af5e47da-555a-4f54-aadd-278a4f2f1c74"]');
    var _params = {}, _options = {};
    // When bar chart is clicked d.x.getTime() will return the beginning of the hour that was selected
    if (options.command === 'relative'){
      _params = $.extend({}, params, {
        from: (new Date( Math.max(d.x.getTime(), Date.now() - params.range * 1000) )).toISOString(),
        to: (new Date( d.x.getTime() + 60 * 60 * 1000 /* +1h */ )).toISOString()
      });
    } else {
      _params = $.extend({}, params, {
        from: d.x.toISOString(),
        to: (new Date( d.x.getTime() + 60 * 60 * 1000 /* +1h */ )).toISOString()
      });
    }
    // Make it absolute, so that a list will show only one hour messages
    _options = {
        command: 'absolute'
    };
    // Redraw the target message list
    GL.printList($div, _params, _options);
  }
},
// Hour and minute
timeFormat: '%H:%M'

Graylog Map

You can use the Graylog Map macro if your Graylog server is configured to support geolocation. You specify a geolocation field to draw a circle on a map. Circle radius is proportional to the number of messages originating from this location.


Gralylog List

You can use Graylog List macro to print selected messages from your Graylog server

Hope you find it useful.



Your Rating: Results: PatheticBadOKGoodOutstanding! 14 rates

Legal notice

This addon is free under MIT license

Full source code for this addon is available on GitHub. To report a bug please use the Issue Tracker

  • No labels