Search code examples
tomcatgrafanatelegraf

Query in Grafana tomcat plugin with telegraf


I have this query that gives result in number but would like to convert it to percentage :

SELECT mean("free") FROM "tomcat_jvm_memory" WHERE ("host" = '$host') AND $timeFilter GROUP BY time($__interval) fill(null)

Result is 4567678899

How would I convert this to percentage in the grafana dashboard.I really want to query good dashboad with tomcat plugin below :

**Metrics
tomcat_jvm_memory
   free
   max
   total
tomcat_jvm_memorypool
   committed
   init
   max
   used
tomcat_connector
   bytes_received
   bytes_sent
   current_thread_busy
   current_thread_count
   error_count
   max_threads
   max_time
   processing_time
   request_count**

Solution

  • following your question, I have setup two Grafana's gauges that show Used Jvm Memory in Gigabytes and Percentage, I attach the screenshot

    enter image description here

    For the first one the query is:

    SELECT last("max")-last("free"), last("max") FROM "tomcat_jvm_memory" 
    WHERE ("host" = '$host') AND $timeFilter 
    GROUP BY time($__interval) fill(null)
    

    rendered with the Gauge Widget with the following settings:

    Value options:
     
    a) Show -> Calculate
    b) Calculation -> Last
    c) Fields -> tomcat_jvm_memory.last_last
    
    ...
    
    Standard options:
    
    a) Unit -> Data: bytes(IEC)
    
    ...
    
    Thresholds:
    
    a) %95 red
    b) %90 yellow
    c) Thresholds mode -> Percentage
    

    For the second one the query is:

    SELECT 1-last("free")/last("max") FROM "tomcat_jvm_memory" 
    WHERE ("host" = '$host') AND $timeFilter 
    GROUP BY time($__interval) fill(null)
    

    And the same Gauge settings but the "Unit" -> misc:Percentage (0.0-1.0)

    I hope to have answered your question, cheers