Splunk Search

Is there a way to remove the digits from columns in Splunk Dashboard?

niks987
Explorer

Hello,

I am currently working is on one use case where i have to display store number on the basis of avg cpu, avg ram and avg iowait.
I have used stats command and created a table and used eval command to put threshold.
I want to display only the color in the column based on the value of avg cpu, avg ram and avg iowait but not there values in the column. Is there any way which i can use to display only colors.

Secondly i was trying to add a 4th column which will display number of days the store's are in red(threshold above 90).

Thanks in advance.

Tags (3)
0 Karma

vnravikumar
Champion

Hi

Try this

<dashboard script="test.js">
  <label>color</label>
  <row>
    <panel>
      <table id="my_table">
        <search>
          <query>| makeresults 
| eval "avg cpu" =30, "avg ram"=40 , "avg iowait"=50, threshold=92 
| append 
    [| makeresults 
    | eval "avg cpu" =60, "avg ram"=90 , "avg iowait"=10, threshold=80] 
| table "avg cpu", "avg ram" , "avg iowait", threshold</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
      </table>
    </panel>
  </row>
  <row>
    <html>
    <style>
      .css_high { 
 background-color:red;
 }
 .css_low { 
 background-color:orange;
 }
 .css_medium { 
 background-color:green;
 }
    </style>
  </html>
  </row>
</dashboard>

js:

require([
    'underscore',
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/tableview',
    'splunkjs/mvc/simplexml/ready!'
], function(_, $, mvc, TableView) {

    var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
        canRender: function(cell) {
            return _(['avg cpu','avg ram','avg iowait','threshold']).contains(cell.field);
        },
        render: function($td, cell) {
            var value = cell.value;
            var label=" ";
            if(cell.field=="avg cpu" || cell.field=="avg ram" || cell.field=="avg iowait"){
                if(value >0 && value<=30){
                    $td.html("<div class='css_low'>"+label+"</div>")
                }else if(value >30 && value<=60){
                    $td.html("<div class='css_medium'>"+label+"</div>")
                }else if(value >60){
                    $td.html("<div class='css_high'>"+label+"</div>")
                }
            }else{
                if(value >90){
                    $td.html("<div class='css_high'>"+value+"</div>")
                }else{
                    $td.html("<div class='align_center'>"+value+"</div>")
                }
             }
        }
    });

    var tableIDs = ["my_table"];
    for (i=0;i<tableIDs.length;i++) {
        var sh = mvc.Components.get(tableIDs[i]);
        if(typeof(sh)!="undefined") {
            sh.getVisualization(function(tableView) {
                tableView.table.addCellRenderer(new CustomRangeRenderer());
                tableView.table.render();
            });
        }
    }    
});
0 Karma
Get Updates on the Splunk Community!

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

March Community Office Hours Security Series Uncovered!

Hello Splunk Community! In March, Splunk Community Office Hours spotlighted our fabulous Splunk Threat ...

Stay Connected: Your Guide to April Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars in April. This post ...