Overview
The PaaS platform I’ve been maintaining introduced Kubernetes as underlying support; the Kubernetes ecosystem enables doing more things. This blog mainly introduces how to provide chart monitoring services to ordinary users (following the last post, providing dashboard support). It assumes readers can build a
Kubernetescluster and a basic monitoring system themselves, and can usePromQLsimply, because that’s not what this blog mainly wants to introduce.
I added this feature even before the dashboard, but explaining it is really complex. I kept putting it off; today I have time, so let’s share it.
Solution Topology
I’ll be lazy here — no desire to draw diagrams.

The image shows the left half of the whole solution: collection tools gather machine and container information, uploading it to Prometheus; the Grafana at bottom right queries and displays data via PromQL.
The two parts below briefly introduce Prometheus and Grafana, but the focus comes later.
The Plain Collection and Display Tool - Prometheus
This is an Ingress CPU utilization chart:

“Plain” mainly because this tool’s job is collecting data; each query takes only one statement, there’s little history functionality, and permission control is nearly nonexistent. Such a basic tool certainly can’t be provided to users directly.
The Beautiful Display Tool - Grafana

Compared with the crude image above, Grafana‘s functionality is much more powerful: it can display multiple charts and has permission control — very suitable for building big-picture monitoring. For each user of a PaaS platform,
being able to see their own application’s monitoring is truly a wonderful thing.
Dividing Line ———
If the introduction ended here, everyone could quickly get it working by tinkering in their own Kubernetes clusters. As PaaS platform developers, we naturally must consider the organization and management of multiple users and multiple applications: presenting users the data they need while ensuring users and applications don’t affect each other. Yes — like the last post’s dashboard support solution, permission design and control are also needed.
Permission Synchronization Strategy
The PaaS Platform’s Permission System
In the PaaS platform, suppose we have a user A who owns one or more application groups (G1, G2); each group deploys a series of applications (a1, a2…).
Grafana’s Permission System
In Grafana’s permission system there are some Teams; a user can belong to one or more Teams.

Each Folder can own one or more dashboards.

Mapping
Considering the relationships above, our approach becomes clear. My design is:
- Each of the user’s groups corresponds to one Team, and that Team has access permission to one Folder
- Each application has one dashboard
You can also use other designs (e.g. no Folder, each Team owning some dashboards). The scheme above is just what I find convenient to manage — each Team has its own Folder.
Grafana-Related Libraries and Their Use (tl;dr)
I use Python to periodically sync permissions and chart information. I considered Golang at the time, but honestly, this kind of code suits Python far too well.
The parts below are quite niche; I suggest not agonizing over them — you most likely won’t use them and will definitely have to read the docs yourself.
1 | grafana-api==1.0.3 # for communicating with the Grafana API |
Creating Users, Teams, Folders
1 | # below is creating a team; the others are similar |
Syncing Folder and Team Permissions
1 | # below syncs the team and its users; since users may increase or decrease, corresponding additions/removals are needed |
Dashboard Page Design and Syncing
This part is actually quite hard. I wanted to use a declarative style, like kubectl apply -f xxx.yaml, but Grafana‘s API is too hard to use. One solution: import dashboard chart data — you can see the apis here were added manually.
1 | def sync_dashboard_data(dashboard_uid, folder_id, dashboard_json_data, inputs=[]): |
Final Effect
For each application in our system, there’s basically a chart like this:

Recommended Common Charts
As administrator I normally don’t look at every application either — maybe just a rough overview.
ingress
https://github.com/kubernetes/ingress-nginx/blob/master/deploy/grafana/dashboards/nginx.json

node_exporter
https://github.com/rfrail3/grafana-dashboards/blob/master/prometheus/node-exporter-full.json

Summary
In this article I mainly wanted to introduce how our system is designed, hoping to provide some reference when you design system integration solutions. Comments and discussion are welcome.
By the way, a complaint about Grafana: it actually can’t set a URL avatar (I even went and read grafana’s code to change the avatar, and found it can’t be modified) — really infuriating!!!