Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

examples.md 8.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. ---
  2. id: examples
  3. title: Examples
  4. ---
  5. Here are some more examples.
  6. ## Grouped Workers on AWS
  7. ```python
  8. from diagrams import Diagram
  9. from diagrams.aws.compute import EC2
  10. from diagrams.aws.database import RDS
  11. from diagrams.aws.network import ELB
  12. with Diagram("Grouped Workers", show=False, direction="TB"):
  13. ELB("lb") >> [EC2("worker1"),
  14. EC2("worker2"),
  15. EC2("worker3"),
  16. EC2("worker4"),
  17. EC2("worker5")] >> RDS("events")
  18. ```
  19. ![grouped workers diagram](/img/grouped_workers_diagram.png)
  20. ## Clustered Web Services
  21. ```python
  22. from diagrams import Cluster, Diagram
  23. from diagrams.aws.compute import ECS
  24. from diagrams.aws.database import ElastiCache, RDS
  25. from diagrams.aws.network import ELB
  26. from diagrams.aws.network import Route53
  27. with Diagram("Clustered Web Services", show=False):
  28. dns = Route53("dns")
  29. lb = ELB("lb")
  30. with Cluster("Services"):
  31. svc_group = [ECS("web1"),
  32. ECS("web2"),
  33. ECS("web3")]
  34. with Cluster("DB Cluster"):
  35. db_master = RDS("userdb")
  36. db_master - [RDS("userdb ro")]
  37. memcached = ElastiCache("memcached")
  38. dns >> lb >> svc_group
  39. svc_group >> db_master
  40. svc_group >> memcached
  41. ```
  42. ![clustered web services diagram](/img/clustered_web_services_diagram.png)
  43. ## Event Processing on AWS
  44. ```python
  45. from diagrams import Cluster, Diagram
  46. from diagrams.aws.compute import ECS, EKS, Lambda
  47. from diagrams.aws.database import Redshift
  48. from diagrams.aws.integration import SQS
  49. from diagrams.aws.storage import S3
  50. with Diagram("Event Processing", show=False):
  51. source = EKS("k8s source")
  52. with Cluster("Event Flows"):
  53. with Cluster("Event Workers"):
  54. workers = [ECS("worker1"),
  55. ECS("worker2"),
  56. ECS("worker3")]
  57. queue = SQS("event queue")
  58. with Cluster("Processing"):
  59. handlers = [Lambda("proc1"),
  60. Lambda("proc2"),
  61. Lambda("proc3")]
  62. store = S3("events store")
  63. dw = Redshift("analytics")
  64. source >> workers >> queue >> handlers
  65. handlers >> store
  66. handlers >> dw
  67. ```
  68. ![event processing diagram](/img/event_processing_diagram.png)
  69. ## Message Collecting System on GCP
  70. ```python
  71. from diagrams import Cluster, Diagram
  72. from diagrams.gcp.analytics import BigQuery, Dataflow, PubSub
  73. from diagrams.gcp.compute import AppEngine, Functions
  74. from diagrams.gcp.database import BigTable
  75. from diagrams.gcp.iot import IotCore
  76. from diagrams.gcp.storage import GCS
  77. with Diagram("Message Collecting", show=False):
  78. pubsub = PubSub("pubsub")
  79. with Cluster("Source of Data"):
  80. [IotCore("core1"),
  81. IotCore("core2"),
  82. IotCore("core3")] >> pubsub
  83. with Cluster("Targets"):
  84. with Cluster("Data Flow"):
  85. flow = Dataflow("data flow")
  86. with Cluster("Data Lake"):
  87. flow >> [BigQuery("bq"),
  88. GCS("storage")]
  89. with Cluster("Event Driven"):
  90. with Cluster("Processing"):
  91. flow >> AppEngine("engine") >> BigTable("bigtable")
  92. with Cluster("Serverless"):
  93. flow >> Functions("func") >> AppEngine("appengine")
  94. pubsub >> flow
  95. ```
  96. ![message collecting diagram](/img/message_collecting_diagram.png)
  97. ## Exposed Pod with 3 Replicas on Kubernetes
  98. ```python
  99. from diagrams import Diagram
  100. from diagrams.k8s.clusterconfig import HPA
  101. from diagrams.k8s.compute import Deployment, Pod, ReplicaSet
  102. from diagrams.k8s.network import Ingress, Service
  103. with Diagram("Exposed Pod with 3 Replicas", show=False):
  104. net = Ingress("domain.com") >> Service("svc")
  105. net >> [Pod("pod1"),
  106. Pod("pod2"),
  107. Pod("pod3")] << ReplicaSet("rs") << Deployment("dp") << HPA("hpa")
  108. ```
  109. ![exposed pod with 3 replicas diagram](/img/exposed_pod_with_3_replicas_diagram.png)
  110. ## Stateful Architecture on Kubernetes
  111. ```python
  112. from diagrams import Cluster, Diagram
  113. from diagrams.k8s.compute import Pod, StatefulSet
  114. from diagrams.k8s.network import Service
  115. from diagrams.k8s.storage import PV, PVC, StorageClass
  116. with Diagram("Stateful Architecture", show=False):
  117. with Cluster("Apps"):
  118. svc = Service("svc")
  119. sts = StatefulSet("sts")
  120. apps = []
  121. for _ in range(3):
  122. pod = Pod("pod")
  123. pvc = PVC("pvc")
  124. pod - sts - pvc
  125. apps.append(svc >> pod >> pvc)
  126. apps << PV("pv") << StorageClass("sc")
  127. ```
  128. ![stateful architecture diagram](/img/stateful_architecture_diagram.png)
  129. ## Advanced Web Service with On-Premise
  130. ```python
  131. from diagrams import Cluster, Diagram
  132. from diagrams.onprem.analytics import Spark
  133. from diagrams.onprem.compute import Server
  134. from diagrams.onprem.database import PostgreSQL
  135. from diagrams.onprem.inmemory import Redis
  136. from diagrams.onprem.logging import Fluentd
  137. from diagrams.onprem.monitoring import Grafana, Prometheus
  138. from diagrams.onprem.network import Nginx
  139. from diagrams.onprem.queue import Kafka
  140. with Diagram("Advanced Web Service with On-Premise", show=False):
  141. ingress = Nginx("ingress")
  142. metrics = Prometheus("metric")
  143. metrics << Grafana("monitoring")
  144. with Cluster("Service Cluster"):
  145. grpcsvc = [
  146. Server("grpc1"),
  147. Server("grpc2"),
  148. Server("grpc3")]
  149. with Cluster("Sessions HA"):
  150. master = Redis("session")
  151. master - Redis("replica") << metrics
  152. grpcsvc >> master
  153. with Cluster("Database HA"):
  154. master = PostgreSQL("users")
  155. master - PostgreSQL("slave") << metrics
  156. grpcsvc >> master
  157. aggregator = Fluentd("logging")
  158. aggregator >> Kafka("stream") >> Spark("analytics")
  159. ingress >> grpcsvc >> aggregator
  160. ```
  161. ![advanced web service with on-premise diagram](/img/advanced_web_service_with_on-premise.png)
  162. ## Advanced Web Service with On-Premise (with colors and labels)
  163. ```python
  164. from diagrams import Cluster, Diagram, Edge
  165. from diagrams.onprem.analytics import Spark
  166. from diagrams.onprem.compute import Server
  167. from diagrams.onprem.database import PostgreSQL
  168. from diagrams.onprem.inmemory import Redis
  169. from diagrams.onprem.logging import Fluentd
  170. from diagrams.onprem.monitoring import Grafana, Prometheus
  171. from diagrams.onprem.network import Nginx
  172. from diagrams.onprem.queue import Kafka
  173. with Diagram(name="Advanced Web Service with On-Premise (colored)", show=False):
  174. ingress = Nginx("ingress")
  175. metrics = Prometheus("metric")
  176. metrics << Edge(color="firebrick", style="dashed") << Grafana("monitoring")
  177. with Cluster("Service Cluster"):
  178. grpcsvc = [
  179. Server("grpc1"),
  180. Server("grpc2"),
  181. Server("grpc3")]
  182. with Cluster("Sessions HA"):
  183. master = Redis("session")
  184. master - Edge(color="brown", style="dashed") - Redis("replica") << Edge(label="collect") << metrics
  185. grpcsvc >> Edge(color="brown") >> master
  186. with Cluster("Database HA"):
  187. master = PostgreSQL("users")
  188. master - Edge(color="brown", style="dotted") - PostgreSQL("slave") << Edge(label="collect") << metrics
  189. grpcsvc >> Edge(color="black") >> master
  190. aggregator = Fluentd("logging")
  191. aggregator >> Edge(label="parse") >> Kafka("stream") >> Edge(color="black", style="bold") >> Spark("analytics")
  192. ingress >> Edge(color="darkgreen") << grpcsvc >> Edge(color="darkorange") >> aggregator
  193. ```
  194. ![advanced web service with on-premise diagram colored](/img/advanced_web_service_with_on-premise_colored.png)
  195. ## RabbitMQ Consumers with Custom Nodes
  196. ```python
  197. from urllib.request import urlretrieve
  198. from diagrams import Cluster, Diagram
  199. from diagrams.aws.database import Aurora
  200. from diagrams.custom import Custom
  201. from diagrams.k8s.compute import Pod
  202. # Download an image to be used into a Custom Node class
  203. rabbitmq_url = "https://jpadilla.github.io/rabbitmqapp/assets/img/icon.png"
  204. rabbitmq_icon = "rabbitmq.png"
  205. urlretrieve(rabbitmq_url, rabbitmq_icon)
  206. with Diagram("Broker Consumers", show=False):
  207. with Cluster("Consumers"):
  208. consumers = [
  209. Pod("worker"),
  210. Pod("worker"),
  211. Pod("worker")]
  212. queue = Custom("Message queue", rabbitmq_icon)
  213. queue >> consumers >> Aurora("Database")
  214. ```
  215. ![rabbitmq consumers diagram](/img/rabbitmq_consumers_diagram.png)