in community/front-end/ofe/website/ghpcfe/grafana.py [0:0]
def create_cluster_dashboard(cluster):
cred_info = json.loads(cluster.cloud_credential.detail)
# pylint: disable=line-too-long
panels = [
{
"datasource": cluster.cloud_credential.name,
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 0,
},
"lines": True,
"linewidth": 1,
"renderer": "flot",
"seriesOverrides": [],
"targets": [
{
"metricQuery": {
"aliasBy": "{{metric.label.instance_name}}",
"alignmentPeriod": "cloud-monitoring-auto",
"crossSeriesReducer": "REDUCE_NONE",
"editorMode": "visual",
"filters": [
"metadata.user_labels.ghpc_deployment",
"=",
f"{cluster.cloud_id}"
],
"groupBys": [],
"metricKind": "GAUGE",
"metricType": "compute.googleapis.com/instance/cpu/utilization",
"perSeriesAligner": "ALIGN_INTERPOLATE",
"projectName": cred_info["project_id"],
"query": "",
"unit": "10^2.%",
"valueType": "DOUBLE",
},
"queryType": "metrics",
"refId": "CPU Utilization",
}
],
"title": "CPU Utilization",
"type": "graph",
"xaxis": {
"buckets": None,
"mode": "time",
"name": None,
"show": True,
"values": [],
},
"yaxes": [
{
"format": "percent",
"label": None,
"logBase": 1,
"max": None,
"min": None,
"show": True,
},
{
"format": "short",
"label": None,
"logBase": 1,
"max": None,
"min": None,
"show": False,
},
],
},
{
"datasource": cluster.cloud_credential.name,
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 0,
},
"lines": True,
"linewidth": 1,
"renderer": "flot",
"seriesOverrides": [],
"targets": [
{
"metricQuery": {
"aliasBy": "{{resource.label.instance_id}} - {{metric.label.state}}",
"alignmentPeriod": "cloud-monitoring-auto",
"crossSeriesReducer": "REDUCE_NONE",
"editorMode": "visual",
"filters": [
"metadata.user_labels.ghpc_deployment",
"=",
f"{cluster.cloud_id}"
],
"groupBys": [],
"metricKind": "GAUGE",
"metricType": "agent.googleapis.com/memory/bytes_used",
"perSeriesAligner": "ALIGN_INTERPOLATE",
"projectName": cred_info["project_id"],
"query": "",
"unit": "By",
"valueType": "DOUBLE",
},
"queryType": "metrics",
"refId": "Memory Used",
}
],
"title": "Memory Used",
"type": "graph",
"xaxis": {
"buckets": None,
"mode": "time",
"name": None,
"show": True,
"values": [],
},
"yaxes": [
{
"format": "bytes",
"label": None,
"logBase": 1,
"max": None,
"min": None,
"show": True,
},
{
"format": "short",
"label": None,
"logBase": 1,
"max": None,
"min": None,
"show": False,
},
],
},
{
"datasource": cluster.cloud_credential.name,
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 8,
},
"lines": True,
"linewidth": 1,
"renderer": "flot",
"seriesOverrides": [],
"targets": [
{
"metricQuery": {
"aliasBy": "{{metric.label.instance_name}}",
"alignmentPeriod": "cloud-monitoring-auto",
"crossSeriesReducer": "REDUCE_NONE",
"editorMode": "visual",
"filters": [
"metadata.user_labels.ghpc_deployment",
"=",
f"{cluster.cloud_id}"
],
"groupBys": [],
"metricKind": "DELTA",
"metricType": "compute.googleapis.com/instance/network/sent_bytes_count",
"perSeriesAligner": "ALIGN_DELTA",
"projectName": cred_info["project_id"],
"query": "",
"unit": "By",
"valueType": "INT64",
},
"queryType": "metrics",
"refId": "DataOut",
}
],
"title": "Network Bytes Out",
"type": "graph",
"xaxis": {
"buckets": None,
"mode": "time",
"name": None,
"show": True,
"values": [],
},
"yaxes": [
{
"format": "bytes",
"label": None,
"logBase": 1,
"max": None,
"min": None,
"show": True,
},
{
"format": "short",
"label": None,
"logBase": 1,
"max": None,
"min": None,
"show": False,
},
],
},
{
"datasource": cluster.cloud_credential.name,
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 8,
},
"lines": True,
"linewidth": 1,
"renderer": "flot",
"seriesOverrides": [],
"targets": [
{
"metricQuery": {
"aliasBy": "{{metric.label.instance_name}}",
"alignmentPeriod": "cloud-monitoring-auto",
"crossSeriesReducer": "REDUCE_NONE",
"editorMode": "visual",
"filters": [
"metadata.user_labels.ghpc_deployment",
"=",
f"{cluster.cloud_id}"
],
"groupBys": [],
"metricKind": "DELTA",
"metricType": "compute.googleapis.com/instance/network/received_bytes_count",
"perSeriesAligner": "ALIGN_DELTA",
"projectName": cred_info["project_id"],
"query": "",
"unit": "By",
"valueType": "INT64",
},
"queryType": "metrics",
"refId": "DataIn",
}
],
"title": "Network Bytes In",
"type": "graph",
"xaxis": {
"buckets": None,
"mode": "time",
"name": None,
"show": True,
"values": [],
},
"yaxes": [
{
"format": "bytes",
"label": None,
"logBase": 1,
"max": None,
"min": None,
"show": True,
},
{
"format": "short",
"label": None,
"logBase": 1,
"max": None,
"min": None,
"show": False,
},
],
},
]
# pylint: enable=line-too-long
dashboard = {
"dashboard": {
"id": None,
"uid": None,
"title": f"Cluster {cluster.name}",
"panels": panels,
"version": 0,
},
"filderId": 0,
"overwrite": True,
}
auth = ("admin", settings.SECRET_KEY)
api = GrafanaFace(auth=auth, host="localhost:3000")
dash = api.dashboard.update_dashboard(dashboard)
# {id, slug, status: success, uid, url, version}
if dash["status"] != "success":
logger.error("Grafana Dashboard creation failed! Ret: %s", dash)
return dash