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!

Earn a $35 Gift Card for Answering our Splunk Admins & App Developer Survey

Survey for Splunk Admins and App Developers is open now! | Earn a $35 gift card!      Hello there,  Splunk ...

Continuing Innovation & New Integrations Unlock Full Stack Observability For Your ...

You’ve probably heard the latest about AppDynamics joining the Splunk Observability portfolio, deepening our ...

Monitoring Amazon Elastic Kubernetes Service (EKS)

As we’ve seen, integrating Kubernetes environments with Splunk Observability Cloud is a quick and easy way to ...