Skip to content

Commit 135a412

Browse files
authored
Peering dashboard (#6)
* add peering dashboard to visualize graph
1 parent 731d5f1 commit 135a412

File tree

2 files changed

+249
-42
lines changed
  • firewheel/model-components

2 files changed

+249
-42
lines changed

firewheel/model-components/network-monitor/vm_resources/setup.py

Lines changed: 174 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def fetch(resource, data=None):
4040

4141
url = os.environ["PROMETHEUS"]
4242

43-
result = fetch( #
43+
result = fetch(
4444
"api/datasources",
4545
{
4646
"name": "journals",
@@ -50,9 +50,22 @@ def fetch(resource, data=None):
5050
},
5151
)
5252

53-
uid = result["datasource"]["uid"]
53+
journal_source_uid = result["datasource"]["uid"]
54+
print(f"Created datasource with uid: {journal_source_uid}")
55+
56+
result = fetch(
57+
"api/datasources",
58+
{
59+
"name": "agents",
60+
"type": "prometheus",
61+
"url": os.environ["PROMETHEUS"],
62+
"access": "proxy",
63+
},
64+
)
65+
66+
agent_source_uid = result["datasource"]["uid"]
67+
print(f"Created datasource with uid: {agent_source_uid}")
5468

55-
print(f"Created datasource with uid: {uid}")
5669

5770
result = fetch(
5871
"apis/dashboard.grafana.app/v1beta1/namespaces/default/dashboards",
@@ -63,7 +76,7 @@ def fetch(resource, data=None):
6376
"links": [],
6477
"panels": [
6578
{
66-
"datasource": {"type": "prometheus", "uid": uid},
79+
"datasource": {"type": "prometheus", "uid": journal_source_uid},
6780
"description": "",
6881
"fieldConfig": {
6982
"defaults": {
@@ -125,7 +138,10 @@ def fetch(resource, data=None):
125138
"pluginVersion": "12.2.0-17567790421",
126139
"targets": [
127140
{
128-
"datasource": {"type": "prometheus", "uid": uid},
141+
"datasource": {
142+
"type": "prometheus",
143+
"uid": journal_source_uid,
144+
},
129145
"editorMode": "builder",
130146
"expr": 'sum by(instance) (rate(node_cpu_seconds_total{job="journal-monitor",mode!="idle"}[1m]))',
131147
"hide": False,
@@ -139,7 +155,7 @@ def fetch(resource, data=None):
139155
"type": "timeseries",
140156
},
141157
{
142-
"datasource": {"type": "prometheus", "uid": uid},
158+
"datasource": {"type": "prometheus", "uid": journal_source_uid},
143159
"description": "",
144160
"fieldConfig": {
145161
"defaults": {
@@ -176,7 +192,6 @@ def fetch(resource, data=None):
176192
"mode": "absolute",
177193
"steps": [
178194
{"color": "green", "value": 0},
179-
180195
{"color": "red", "value": 80},
181196
],
182197
},
@@ -210,7 +225,10 @@ def fetch(resource, data=None):
210225
"refId": "A",
211226
},
212227
{
213-
"datasource": {"type": "prometheus", "uid": uid},
228+
"datasource": {
229+
"type": "prometheus",
230+
"uid": journal_source_uid,
231+
},
214232
"editorMode": "builder",
215233
"expr": 'sum by(instance) (node_memory_MemTotal_bytes{job="journal-monitor"})',
216234
"hide": True,
@@ -235,7 +253,7 @@ def fetch(resource, data=None):
235253
"type": "timeseries",
236254
},
237255
{
238-
"datasource": {"type": "prometheus", "uid": uid},
256+
"datasource": {"type": "prometheus", "uid": journal_source_uid},
239257
"description": "",
240258
"fieldConfig": {
241259
"defaults": {
@@ -306,7 +324,10 @@ def fetch(resource, data=None):
306324
"refId": "A",
307325
},
308326
{
309-
"datasource": {"type": "prometheus", "uid": uid},
327+
"datasource": {
328+
"type": "prometheus",
329+
"uid": journal_source_uid,
330+
},
310331
"editorMode": "builder",
311332
"expr": 'sum by(instance) (node_filesystem_size_bytes{job="journal-monitor"})',
312333
"hide": True,
@@ -331,7 +352,7 @@ def fetch(resource, data=None):
331352
"type": "timeseries",
332353
},
333354
{
334-
"datasource": {"type": "prometheus", "uid": uid},
355+
"datasource": {"type": "prometheus", "uid": journal_source_uid},
335356
"description": "",
336357
"fieldConfig": {
337358
"defaults": {
@@ -433,25 +454,8 @@ def fetch(resource, data=None):
433454
)
434455

435456
uid = result["metadata"]["uid"]
436-
437457
print(f"Created dashboard with uid: {uid}")
438458

439-
url = os.environ["PROMETHEUS"]
440-
441-
result = fetch( #
442-
"api/datasources",
443-
{
444-
"name": "agents",
445-
"type": "prometheus",
446-
"url": os.environ["PROMETHEUS"],
447-
"access": "proxy",
448-
},
449-
)
450-
451-
uid = result["datasource"]["uid"]
452-
453-
print(f"Created datasource with uid: {uid}")
454-
455459
window_variable = {
456460
"name": "window",
457461
"label": "Window",
@@ -481,14 +485,17 @@ def fetch(resource, data=None):
481485
"id": 1,
482486
"title": "Request Throughput",
483487
"type": "timeseries",
484-
"datasource": {"type": "prometheus", "uid": uid},
488+
"datasource": {"type": "prometheus", "uid": agent_source_uid},
485489
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 0},
486490
"fieldConfig": {"defaults": {"unit": "ops"}, "overrides": []},
487491
"pluginVersion": "12.2.0-17567790421",
488492
"targets": [
489493
{
490494
"refId": "A",
491-
"datasource": {"type": "prometheus", "uid": uid},
495+
"datasource": {
496+
"type": "prometheus",
497+
"uid": agent_source_uid,
498+
},
492499
"expr": 'sum by(instance) (rate(social_agent_activity_cycles_success_total{job="agent-monitor"}[$window]))',
493500
"editorMode": "code",
494501
"legendFormat": "{{instance}}",
@@ -501,14 +508,20 @@ def fetch(resource, data=None):
501508
"id": 2,
502509
"title": "Success Rate",
503510
"type": "timeseries",
504-
"datasource": {"type": "prometheus", "uid": uid},
511+
"datasource": {"type": "prometheus", "uid": agent_source_uid},
505512
"gridPos": {"h": 8, "w": 12, "x": 12, "y": 0},
506-
"fieldConfig": {"defaults": {"unit": "percentunit"}, "overrides": []},
513+
"fieldConfig": {
514+
"defaults": {"unit": "percentunit"},
515+
"overrides": [],
516+
},
507517
"pluginVersion": "12.2.0-17567790421",
508518
"targets": [
509519
{
510520
"refId": "A",
511-
"datasource": {"type": "prometheus", "uid": uid},
521+
"datasource": {
522+
"type": "prometheus",
523+
"uid": agent_source_uid,
524+
},
512525
"expr": 'sum by(instance) (rate(social_agent_activity_cycles_success_total{job="agent-monitor"}[$window])) / clamp_min(sum by(instance) (rate(social_agent_activity_cycles_total{job="agent-monitor"}[$window])), 1e-9)',
513526
"editorMode": "code",
514527
"legendFormat": "{{instance}}",
@@ -521,14 +534,17 @@ def fetch(resource, data=None):
521534
"id": 3,
522535
"title": "Get Latency",
523536
"type": "timeseries",
524-
"datasource": {"type": "prometheus", "uid": uid},
537+
"datasource": {"type": "prometheus", "uid": agent_source_uid},
525538
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 8},
526539
"fieldConfig": {"defaults": {"unit": "s"}, "overrides": []},
527540
"pluginVersion": "12.2.0-17567790421",
528541
"targets": [
529542
{
530543
"refId": "A",
531-
"datasource": {"type": "prometheus", "uid": uid},
544+
"datasource": {
545+
"type": "prometheus",
546+
"uid": agent_source_uid,
547+
},
532548
"expr": 'sum by(instance) (rate(social_agent_get_latency_seconds_sum{job="agent-monitor"}[$window])) / clamp_min(sum by(instance) (rate(social_agent_get_latency_seconds_count{job="agent-monitor"}[$window])), 1e-9)',
533549
"editorMode": "code",
534550
"legendFormat": "{{instance}}",
@@ -541,14 +557,17 @@ def fetch(resource, data=None):
541557
"id": 4,
542558
"title": "Set Latency",
543559
"type": "timeseries",
544-
"datasource": {"type": "prometheus", "uid": uid},
560+
"datasource": {"type": "prometheus", "uid": agent_source_uid},
545561
"gridPos": {"h": 8, "w": 12, "x": 12, "y": 8},
546562
"fieldConfig": {"defaults": {"unit": "s"}, "overrides": []},
547563
"pluginVersion": "12.2.0-17567790421",
548564
"targets": [
549565
{
550566
"refId": "A",
551-
"datasource": {"type": "prometheus", "uid": uid},
567+
"datasource": {
568+
"type": "prometheus",
569+
"uid": agent_source_uid,
570+
},
552571
"expr": 'sum by(instance) (rate(social_agent_set_latency_seconds_sum{job="agent-monitor"}[$window])) / clamp_min(sum by(instance) (rate(social_agent_set_latency_seconds_count{job="agent-monitor"}[$window])), 1e-9)',
553572
"editorMode": "code",
554573
"legendFormat": "{{instance}}",
@@ -574,3 +593,121 @@ def fetch(resource, data=None):
574593

575594
agent_uid = result["metadata"]["uid"]
576595
print(f"Created dashboard with uid: {agent_uid}")
596+
597+
result = fetch(
598+
"apis/dashboard.grafana.app/v1beta1/namespaces/default/dashboards",
599+
{
600+
"metadata": {"name": "peering-graph"},
601+
"spec": {
602+
"editable": True,
603+
"links": [],
604+
"panels": [
605+
{
606+
"id": 1,
607+
"title": "Journal Peering Activity",
608+
"description": "Edge values are inferred successful journal-hop message rates (messages per second), aggregated across agents over the selected window.",
609+
"type": "nodeGraph",
610+
"datasource": {"type": "prometheus", "uid": agent_source_uid},
611+
"gridPos": {"h": 20, "w": 24, "x": 0, "y": 0},
612+
"fieldConfig": {
613+
"defaults": {
614+
"unit": "ops",
615+
"color": {"mode": "thresholds"},
616+
"thresholds": {
617+
"mode": "absolute",
618+
"steps": [
619+
{"color": "green", "value": 0},
620+
{"color": "orange", "value": 1},
621+
{"color": "red", "value": 5},
622+
],
623+
},
624+
},
625+
"overrides": [],
626+
},
627+
"options": {
628+
"nodes": {"arcs": []},
629+
},
630+
"pluginVersion": "12.2.0-17567790421",
631+
"targets": [
632+
{
633+
"refId": "A",
634+
"datasource": {
635+
"type": "prometheus",
636+
"uid": agent_source_uid,
637+
},
638+
"expr": 'max by(id, title) (social_agent_peering_journal_node_info{job="agent-monitor"})',
639+
"editorMode": "code",
640+
"instant": True,
641+
"range": False,
642+
"format": "table",
643+
"legendFormat": "__auto",
644+
},
645+
{
646+
"refId": "B",
647+
"datasource": {
648+
"type": "prometheus",
649+
"uid": agent_source_uid,
650+
},
651+
"expr": 'sum by(id, source, target, secondaryStat) (rate(social_agent_inferred_journal_hop_requests_total{job="agent-monitor"}[$window]))',
652+
"editorMode": "code",
653+
"instant": True,
654+
"range": False,
655+
"format": "table",
656+
"legendFormat": "__auto",
657+
},
658+
],
659+
"transformations": [
660+
{
661+
"id": "labelsToFields",
662+
"options": {"mode": "columns"},
663+
}
664+
],
665+
},
666+
{
667+
"id": 2,
668+
"title": "Edge Rates",
669+
"description": "Per-edge inferred successful journal-hop message rate (messages per second).",
670+
"type": "table",
671+
"datasource": {"type": "prometheus", "uid": agent_source_uid},
672+
"gridPos": {"h": 8, "w": 24, "x": 0, "y": 20},
673+
"fieldConfig": {"defaults": {"unit": "ops"}, "overrides": []},
674+
"pluginVersion": "12.2.0-17567790421",
675+
"targets": [
676+
{
677+
"refId": "A",
678+
"datasource": {
679+
"type": "prometheus",
680+
"uid": agent_source_uid,
681+
},
682+
"expr": 'sum by(source, target) (rate(social_agent_inferred_journal_hop_requests_total{job="agent-monitor"}[$window]))',
683+
"editorMode": "code",
684+
"instant": True,
685+
"range": False,
686+
"format": "table",
687+
"legendFormat": "__auto",
688+
}
689+
],
690+
"transformations": [
691+
{
692+
"id": "labelsToFields",
693+
"options": {"mode": "columns"},
694+
}
695+
],
696+
},
697+
],
698+
"preload": False,
699+
"refresh": "10s",
700+
"schemaVersion": 42,
701+
"tags": [],
702+
"templating": {"list": [window_variable]},
703+
"time": {"from": "now-1h", "to": "now"},
704+
"timepicker": {},
705+
"timezone": "browser",
706+
"title": "Peering Graph",
707+
},
708+
"status": {},
709+
},
710+
)
711+
712+
peering_uid = result["metadata"]["uid"]
713+
print(f"Created dashboard with uid: {peering_uid}")

0 commit comments

Comments
 (0)