Grafana
easy 26 minGrafana is a web application that queries many kinds of stores, draws the answers on dashboards and evaluates alert rules on them.
See it run
A dashboard opens, a step is chosen, a variable changes, a rule runs, and screens make load.
Operations
A dashboard opens
One panel on Prometheus, one on PostgreSQL.
Step 1 of 5
Load the page
The dashboard comes from Grafana's own database. There are no measurements in it.
Step 1: Load the page
def open_dashboard(uid): dash = own_db.load(uid) for panel in dash.panels: q = fill(panel.query, variables, time_range) frame = source(panel).query(q, credentials) browser.draw(transform(frame))- When
- At each refresh
- Who does the work
- The stores
An empty panel is a question for the store first.
In the real world
The same grafana doing real jobs. Pick one and step through it.
Prometheus stops during an incident.
Step 1 of 3
Both answer
Metrics on the left, orders on the right.
Step 1: Both answer
Common mistakes
The bugs interviewers watch for, with the fix beside each.
Trusting the Viewer role with secrets
criticalBy default any user can send any query to any data source of the organization.
Wrongdata source user: adminrole of people: ViewerRightdata source user: read only,only the tables all may seeTwo servers on SQLite
majorEach has its own file: dashboards and sessions differ.
Wrong[database]type = sqlite3 # on bothRight[database]type = postgres # one, sharedA fixed short rate window
majorWith slower scrapes or a longer range the panel has gaps or misses peaks.
Wrongrate(x_total[30s])Rightrate(x_total[$__rate_interval])Refresh every five seconds
majorPanels times screens makes load that nobody reads.
Wrongrefresh: 5s # hourly dataRightrefresh: 5mmin_refresh_interval = 30sA copy for every service
minorTwelve copies drift apart and each fix is made twelve times.
Wrongcart, pay, search: 3 copiesRightone dashboard, $service
Interview tips
How to explain it
- It asks other stores.
- It draws what they answer.
- It keeps only its own settings.
Where state lives
- Measurements: the stores.
- Dashboards, users, rules: its database.
- Secrets: encrypted with secret_key.
Reach for it when
- Several stores need one view.
- Dashboards should be code.
- Prometheus needs a screen.
Before production
- Change admin / admin.
- PostgreSQL instead of SQLite.
- Read-only accounts for data sources.