Tech Girl
Tech Girl

Reputation: 199

grafana- get values from dashboard with mysql as data source with API

I am trying to extract values from the dashboard from Grafana Dashboard. I have MySQL as data source and I have a query to extract values from a particular table in MySQL.

I am trying to get these values shown on dashboard with some API.

For prometheus, I have came across this API of Instant Queries and it works well. Similarly I want to get the for grafana dashboard. I went through these Grafana HTTP APIs, but did not find any to get mysql records displayed on dashboard.

Are there any other APIs? Or any other way to get these records?

Upvotes: 0

Views: 1534

Answers (3)

X42S_Destiny
X42S_Destiny

Reputation: 11

emmmm, i found that is chrome problem, which cant add custom header... replace with PHANTOMJS that it work. bur PHANTOMJS cant see full data(download png see that)....

......................

oh, can you tell me how do that? i use selenium but cant get the data...that is my code.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options


chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--no-sandbox')    

url="http://<IP:PORT>/d/SsYvTg6Wk/rights?orgId=1&from=now-1h&to=now" 
#url copy from browser chrome

browser=webdriver.Chrome(executable_path="./chromedriver", chrome_options=chrome_options)
browser.header_overrides = {
    'Authorization': 'Bearer xxx'
}
browser.implicitly_wait(10)
browser.get(url)
# browser.execute_script("return document.body.innerHTML")
browser.find_element_by_id('flotGagueValue0')

Upvotes: 0

Tech Girl
Tech Girl

Reputation: 199

I found a way to extract the record. It is using "Chro Path Utility", get the XPath for needed row/column/cell and use them in your Selenium code.

Upvotes: 0

shil88
shil88

Reputation: 1519

The only way I found was to:

  1. Open the dashboard and then inspect the panel
  2. Open the query tab and click on refresh
  3. Use the url and parameters on your own query to the api

note: First you need to create an API key in the UI with the proper role and add the bearer to the request headers

Upvotes: 1

Related Questions