之前寫過技術(shù)文檔畫圖工具箱,diagrams屬于diagram as code工具派別。mac安裝brew install graphvizpip ins" />

日韩成人免费在线_国产成人一二_精品国产免费人成电影在线观..._日本一区二区三区久久久久久久久不

當(dāng)前位置:首頁(yè) > 科技  > 軟件

使用Diagrams畫架構(gòu)圖,你會(huì)嗎?

來源: 責(zé)編: 時(shí)間:2023-09-20 21:55:42 281觀看
導(dǎo)讀序最近發(fā)現(xiàn)一個(gè)畫架構(gòu)圖的神器diagrams,提供了很多云廠商及開源組件的圖標(biāo),相比于C4-PlantUML顯得更專業(yè)一點(diǎn)。
之前寫過技術(shù)文檔畫圖工具箱,diagrams屬于diagram as code工具派別。mac安裝brew install graphvizpip ins

8bX28資訊網(wǎng)——每日最新資訊28at.com

最近發(fā)現(xiàn)一個(gè)畫架構(gòu)圖的神器diagrams,提供了很多云廠商及開源組件的圖標(biāo),相比于C4-PlantUML顯得更專業(yè)一點(diǎn)。
之前寫過技術(shù)文檔畫圖工具箱,diagrams屬于diagram as code工具派別。
8bX28資訊網(wǎng)——每日最新資訊28at.com

mac安裝

brew install graphvizpip install diagramsbrew install python@3.11

示例1

from diagrams import Diagramfrom diagrams.aws.compute import EC2from diagrams.aws.database import RDSfrom diagrams.awswork import ELB# python aws_example.pywith Diagram("Grouped Workers", show=False, direction="TB"):    ELB("lb") >> [EC2("worker1"),                  EC2("worker2"),                  EC2("worker3"),                  EC2("worker4"),                  EC2("worker5")] >> RDS("events")

執(zhí)行python example.py即可以在當(dāng)前目錄生成png圖片。8bX28資訊網(wǎng)——每日最新資訊28at.com

8bX28資訊網(wǎng)——每日最新資訊28at.com

示例2

from diagrams import Cluster, Diagramfrom diagrams.aws.compute import ECSfrom diagrams.aws.database import ElastiCache, RDSfrom diagrams.awswork import ELBfrom diagrams.awswork import Route53with Diagram("Clustered Web Services", show=False):    dns = Route53("dns")    lb = ELB("lb")    with Cluster("Services"):        svc_group = [ECS("web1"),                     ECS("web2"),                     ECS("web3")]    with Cluster("DB Cluster"):        db_primary = RDS("userdb")        db_primary - [RDS("userdb ro")]    memcached = ElastiCache("memcached")    dns >> lb >> svc_group    svc_group >> db_primary    svc_group >> memcached

8bX28資訊網(wǎng)——每日最新資訊28at.com

基本語法就是import node,以with Diagram開始,之后聲明組件,然后使用with來進(jìn)行分組,最后通過>>來串聯(lián)。
默認(rèn)文件名是Diagram名,空格替換為下劃線,可以用filename指定。
圖片格式默認(rèn)是png,可以用outformat=[“jpg”, “png”, “dot”]來指定要生成的圖片類型。
show默認(rèn)為True,也就是python生成完圖片會(huì)默認(rèn)打開圖片。8bX28資訊網(wǎng)——每日最新資訊28at.com

k8s示例

from diagrams import Cluster, Diagramfrom diagrams.k8s.compute import Pod, StatefulSetfrom diagrams.k8swork import Servicefrom diagrams.k8s.storage import PV, PVC, StorageClasswith Diagram("Stateful Architecture", show=False):    with Cluster("Apps"):        svc = Service("svc")        sts = StatefulSet("sts")        apps = []        for _ in range(3):            pod = Pod("pod")            pvc = PVC("pvc")            pod - sts - pvc            apps.append(svc >> pod >> pvc)    apps << PV("pv") << StorageClass("sc")

8bX28資訊網(wǎng)——每日最新資訊28at.com

開源組件示例

from diagrams import Cluster, Diagramfrom diagrams.onprem.analytics import Sparkfrom diagrams.onprem.compute import Serverfrom diagrams.onprem.database import PostgreSQLfrom diagrams.onprem.inmemory import Redisfrom diagrams.onprem.aggregator import Fluentdfrom diagrams.onprem.monitoring import Grafana, Prometheusfrom diagrams.onpremwork import Nginxfrom diagrams.onprem.queue import Kafkawith Diagram("Advanced Web Service with On-Premise", show=False):    ingress = Nginx("ingress")    metrics = Prometheus("metric")    metrics << Grafana("monitoring")    with Cluster("Service Cluster"):        grpcsvc = [            Server("grpc1"),            Server("grpc2"),            Server("grpc3")]    with Cluster("Sessions HA"):        primary = Redis("session")        primary - Redis("replica") << metrics        grpcsvc >> primary    with Cluster("Database HA"):        primary = PostgreSQL("users")        primary - PostgreSQL("replica") << metrics        grpcsvc >> primary    aggregator = Fluentd("logging")    aggregator >> Kafka("stream") >> Spark("analytics")    ingress >> grpcsvc >> aggregator

8bX28資訊網(wǎng)——每日最新資訊28at.com

主要結(jié)構(gòu)

node

# aws resourcesfrom diagrams.aws.compute import ECS, Lambdafrom diagrams.aws.database import RDS, ElastiCachefrom diagrams.awswork import ELB, Route53, VPC...# azure resourcesfrom diagrams.azure.compute import FunctionAppsfrom diagrams.azure.storage import BlobStorage...# alibaba cloud resourcesfrom diagrams.alibabacloud.compute import ECSfrom diagrams.alibabacloud.storage import ObjectTableStore...# gcp resourcesfrom diagrams.gcp.compute import AppEngine, GKEfrom diagrams.gcp.ml import AutoML ...# k8s resourcesfrom diagrams.k8s.compute import Pod, StatefulSetfrom diagrams.k8swork import Servicefrom diagrams.k8s.storage import PV, PVC, StorageClass...# oracle resourcesfrom diagrams.oci.compute import VirtualMachine, Containerfrom diagrams.ociwork import Firewallfrom diagrams.oci.storage import FileStorage, StorageGateway

完整版見nodes8bX28資訊網(wǎng)——每日最新資訊28at.com

數(shù)據(jù)流及布局

  • >>表示從左到右連接
  • <<表示從右到左連接
  • -表示無方向的連接

Diagram有個(gè)屬性direction來表示整體布局,可選的值有TB, BT, LR及RL,默認(rèn)是LR,即從左到右8bX28資訊網(wǎng)——每日最新資訊28at.com

TB: top to bottom
BT: bottom to top
LR: left to right
RL: right to left
8bX28資訊網(wǎng)——每日最新資訊28at.com

Cluster用于分組,也支持內(nèi)嵌,比如8bX28資訊網(wǎng)——每日最新資訊28at.com

with Cluster("Event Flows"):        with Cluster("Event Workers"):            workers = [ECS("worker1"),                       ECS("worker2"),                       ECS("worker3")]        queue = SQS("event queue")        with Cluster("Processing"):            handlers = [Lambda("proc1"),                        Lambda("proc2"),                        Lambda("proc3")]

連接符之間可以用Edge來銜接,用于個(gè)性化處理邊的屬性,比如8bX28資訊網(wǎng)——每日最新資訊28at.com

metrics = Prometheus("metric")    metrics << Edge(color="firebrick", style="dashed") << Grafana("monitoring")

小結(jié)

diagrams是基于python的一款diagram as code工具,它最大的特點(diǎn)就是提供了很多云廠商及開源組件的圖標(biāo),畫出來的圖顯得更專業(yè)一點(diǎn),也更易懂一點(diǎn)。8bX28資訊網(wǎng)——每日最新資訊28at.com

doc

  • diagrams
  • Diagrams: Diagram as Code
  • diagrams examples
  • 技術(shù)文檔畫圖工具箱

本文鏈接:http://www.www897cc.com/showinfo-26-10566-0.html使用Diagrams畫架構(gòu)圖,你會(huì)嗎?

聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。郵件:2376512515@qq.com

上一篇: 圖解「正向代理」的原理 + 實(shí)踐應(yīng)用

下一篇: 優(yōu)秀實(shí)踐:CPU核心數(shù)和線程池大小之間的關(guān)系

標(biāo)簽:
  • 熱門焦點(diǎn)
Top 主站蜘蛛池模板: 辽阳县| 东辽县| 新宁县| 古浪县| 阿拉善右旗| 洛阳市| 堆龙德庆县| 鲁甸县| 定远县| 得荣县| 颍上县| 镇宁| 科尔| 红原县| 广安市| 建阳市| 诸城市| 正镶白旗| 水富县| 海伦市| 迁安市| 平塘县| 榆中县| 宝丰县| 丘北县| 枝江市| 瓮安县| 南开区| 文水县| 顺昌县| 黑山县| 三都| 孟州市| 洪泽县| 和硕县| 吉水县| 高雄县| 当涂县| 南涧| 平顺县| 蛟河市|