How do I add a php code in Grafana?

  • What Grafana version and what operating system are you using? * [v9.2.5 (042e4d216b)]

  • What are you trying to achieve? I’m trying to create a panel in dashboard wherein I can enter an ID and upon hitting search/submit, certain data from mysql table will populate for that specific ID

  • How are you trying to achieve it? I tried coding it in php code and it works outside grafana.

  • What happened? However, I don’t see in text, dynamic text, html, html graphics panels, etc capability of it accepting php

  • What did you expect to happen? I’m expecting my php code to work. Here’s an attachment on how I’m expecting it to work

  • Can you copy/paste the configuration(s) that you are having problems with?


//I’m entering this code in HTML panel for grafana via HTML plugin.

<?php if(isset($_POST['search'])) { $valueToSearch = $_POST['valueToSearch']; // search in all table columns // using concat mysql function $query = "Select * from KeepConnect.Resetti where id LIKE '%".$valueToSearch."%'"; $search_result = filterTable($query); } else { $query = "SELECT * FROM KeepConnect.Resetti order by id desc limit 20"; $search_result = filterTable($query); } // function to connect and execute the query function filterTable($query) { $connect = mysqli_connect("/*PARAMETERS HIDDEN AS PURPOSED*/"); $filter_Result = mysqli_query($connect, $query); return $filter_Result; } ?>

Test DB pull up

Keep Connect Device Info table,tr,th,td { border:1px solid blue; }



	<!-- populate table from mysql database -->
    <?php while($row = mysqli_fetch_array($search_result)):?>
    <tr>
        <td><?php echo $row['id'];?></td>
        <td><?php echo $row['customSSID'];?></td>
        <td><?php echo $row['numberOfResets'];?></td>
        <td><?php echo $row['localIP'];?></td>
    <td><?php echo $row['firmware'];?></td>
    </tr>
    <?php endwhile;?>
</table>

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    I don’t see any errors nor know where to find it.

  • Did you follow any online instructions? If so, what is the URL?
    I don’t see anywhere where I can use my php code in grafana

ID Custom SSID Number Of Resets local IP Firmware Version