鈴木  治

鈴木 治

1660488660

使用 Django、Docker 和 CloudWatch 進行集中式日誌記錄的指南

讓我們看看如何配置在 EC2 實例上運行的容器化 Django 應用程序以將日誌發送到 Amazon CloudWatch。

步驟

  1. 創建 IAM 角色
  2. 將 IAM 角色附加到 EC2 實例
  3. 創建 CloudWatch 日誌組
  4. 在 EC2 實例上安裝 CloudWatch Logs 代理
  5. 配置 Django 日誌記錄
  6. 更新 Docker 撰寫

django docker ec2 cloudwatch

創建 IAM 角色

首先創建一個新的 IAM 角色並附加CloudWatchAgentServerPolicy策略以供 Docker 守護程序使用,以便寫入 CloudWatch。

IAM 控制台,選擇“角色”並單擊“創建角色”。選擇“常見用例”下的“EC2”服務:

我創建新角色

單擊下一步按鈕。

在權限頁面上,搜索“CloudWatchAgentServerPolicy”策略並選中復選框以附加它:

我創建新角色

單擊下一步幾次。在審核頁面上,輸入角色名稱——即CloudWatchAgentRole——然後創建角色。

附加 IAM 角色

要將角色附加到 EC2 實例,請導航到EC2 儀表板並選擇實例。單擊“操作”下拉菜單,選擇“實例設置”,然後單擊“附加/替換 IAM 角色”:

附加角色

搜索並選擇您剛剛創建的 IAM 角色,然後單擊“應用”。

您還可以從命令行附加角色,如下所示:

$ aws ec2 associate-iam-instance-profile \    --instance-id <YOUR_INSTANCE_ID> \    --iam-instance-profile Name=CloudWatchAgentRole

創建 CloudWatch 日誌組

現在 Docker 守護程序有權寫入 CloudWatch,讓我們創建一個要寫入的日誌組。在CloudWatch 控制台中,創建一個新的日誌組。也向該新創建的組添加新的日誌流。

安裝 CloudWatch Logs 代理

通過 SSH 連接到 EC2 實例並直接從 S3 下載並安裝 CloudWatch Logs 代理。

例子:

# download
$ curl https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb

# install
$ sudo dpkg -i -E ./amazon-cloudwatch-agent.deb

配置 Django 日誌記錄

由於 Docker 容器將日誌發送到 stdout 和 stderr 輸出流,因此您需要配置 Django 日誌記錄以通過StreamHandler將所有內容記錄到 stderr 。

例如:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler'
        },
    },
    'loggers': {
        '': {
            'handlers': ['console'],
            'level': 'DEBUG',
        },
    },
}

更新 Docker 撰寫

最後,我們可以在單個容器中使用 Docker 的awslogs日誌記錄驅動程序。

例如:

version: "3.8"

services:
  api:
    build: ./project
    command: gunicorn core.wsgi:application --bind 0.0.0.0:8000 --log-level=debug
    logging:
      driver: "awslogs"
      options:
        awslogs-region: "us-east-1"
        awslogs-group: "your-log-group"
        awslogs-stream: "your-log-stream"

不使用撰寫?假設您已經構建並標記了圖像,請像這樣啟動容器:

$ docker run \
    --log-driver="awslogs" \
    --log-opt awslogs-region="use-east-1" \
    --log-opt awslogs-group="your-log-group" \
    --log-opt awslogs-stream="your-log-group" \
    your-image-tag

來源:  https ://testdriven.io

#django #docker #cloudwatch 

What is GEEK

Buddha Community

使用 Django、Docker 和 CloudWatch 進行集中式日誌記錄的指南
Ahebwe  Oscar

Ahebwe Oscar

1620177818

Django admin full Customization step by step

Welcome to my blog , hey everyone in this article you learn how to customize the Django app and view in the article you will know how to register  and unregister  models from the admin view how to add filtering how to add a custom input field, and a button that triggers an action on all objects and even how to change the look of your app and page using the Django suit package let’s get started.

Database

Custom Titles of Django Admin

Exclude in Django Admin

Fields in Django Admin

#django #create super user django #customize django admin dashboard #django admin #django admin custom field display #django admin customization #django admin full customization #django admin interface #django admin register all models #django customization

鈴木  治

鈴木 治

1660488660

使用 Django、Docker 和 CloudWatch 進行集中式日誌記錄的指南

讓我們看看如何配置在 EC2 實例上運行的容器化 Django 應用程序以將日誌發送到 Amazon CloudWatch。

步驟

  1. 創建 IAM 角色
  2. 將 IAM 角色附加到 EC2 實例
  3. 創建 CloudWatch 日誌組
  4. 在 EC2 實例上安裝 CloudWatch Logs 代理
  5. 配置 Django 日誌記錄
  6. 更新 Docker 撰寫

django docker ec2 cloudwatch

創建 IAM 角色

首先創建一個新的 IAM 角色並附加CloudWatchAgentServerPolicy策略以供 Docker 守護程序使用,以便寫入 CloudWatch。

IAM 控制台,選擇“角色”並單擊“創建角色”。選擇“常見用例”下的“EC2”服務:

我創建新角色

單擊下一步按鈕。

在權限頁面上,搜索“CloudWatchAgentServerPolicy”策略並選中復選框以附加它:

我創建新角色

單擊下一步幾次。在審核頁面上,輸入角色名稱——即CloudWatchAgentRole——然後創建角色。

附加 IAM 角色

要將角色附加到 EC2 實例,請導航到EC2 儀表板並選擇實例。單擊“操作”下拉菜單,選擇“實例設置”,然後單擊“附加/替換 IAM 角色”:

附加角色

搜索並選擇您剛剛創建的 IAM 角色,然後單擊“應用”。

您還可以從命令行附加角色,如下所示:

$ aws ec2 associate-iam-instance-profile \    --instance-id <YOUR_INSTANCE_ID> \    --iam-instance-profile Name=CloudWatchAgentRole

創建 CloudWatch 日誌組

現在 Docker 守護程序有權寫入 CloudWatch,讓我們創建一個要寫入的日誌組。在CloudWatch 控制台中,創建一個新的日誌組。也向該新創建的組添加新的日誌流。

安裝 CloudWatch Logs 代理

通過 SSH 連接到 EC2 實例並直接從 S3 下載並安裝 CloudWatch Logs 代理。

例子:

# download
$ curl https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb

# install
$ sudo dpkg -i -E ./amazon-cloudwatch-agent.deb

配置 Django 日誌記錄

由於 Docker 容器將日誌發送到 stdout 和 stderr 輸出流,因此您需要配置 Django 日誌記錄以通過StreamHandler將所有內容記錄到 stderr 。

例如:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler'
        },
    },
    'loggers': {
        '': {
            'handlers': ['console'],
            'level': 'DEBUG',
        },
    },
}

更新 Docker 撰寫

最後,我們可以在單個容器中使用 Docker 的awslogs日誌記錄驅動程序。

例如:

version: "3.8"

services:
  api:
    build: ./project
    command: gunicorn core.wsgi:application --bind 0.0.0.0:8000 --log-level=debug
    logging:
      driver: "awslogs"
      options:
        awslogs-region: "us-east-1"
        awslogs-group: "your-log-group"
        awslogs-stream: "your-log-stream"

不使用撰寫?假設您已經構建並標記了圖像,請像這樣啟動容器:

$ docker run \
    --log-driver="awslogs" \
    --log-opt awslogs-region="use-east-1" \
    --log-opt awslogs-group="your-log-group" \
    --log-opt awslogs-stream="your-log-group" \
    your-image-tag

來源:  https ://testdriven.io

#django #docker #cloudwatch 

Ahebwe  Oscar

Ahebwe Oscar

1620185280

How model queries work in Django

How model queries work in Django

Welcome to my blog, hey everyone in this article we are going to be working with queries in Django so for any web app that you build your going to want to write a query so you can retrieve information from your database so in this article I’ll be showing you all the different ways that you can write queries and it should cover about 90% of the cases that you’ll have when you’re writing your code the other 10% depend on your specific use case you may have to get more complicated but for the most part what I cover in this article should be able to help you so let’s start with the model that I have I’ve already created it.

**Read More : **How to make Chatbot in Python.

Read More : Django Admin Full Customization step by step

let’s just get into this diagram that I made so in here:

django queries aboutDescribe each parameter in Django querset

we’re making a simple query for the myModel table so we want to pull out all the information in the database so we have this variable which is gonna hold a return value and we have our myModel models so this is simply the myModel model name so whatever you named your model just make sure you specify that and we’re gonna access the objects attribute once we get that object’s attribute we can simply use the all method and this will return all the information in the database so we’re gonna start with all and then we will go into getting single items filtering that data and go to our command prompt.

Here and we’ll actually start making our queries from here to do this let’s just go ahead and run** Python manage.py shell** and I am in my project file so make sure you’re in there when you start and what this does is it gives us an interactive shell to actually start working with our data so this is a lot like the Python shell but because we did manage.py it allows us to do things a Django way and actually query our database now open up the command prompt and let’s go ahead and start making our first queries.

#django #django model queries #django orm #django queries #django query #model django query #model query #query with django

Iliana  Welch

Iliana Welch

1595249460

Docker Explained: Docker Architecture | Docker Registries

Following the second video about Docker basics, in this video, I explain Docker architecture and explain the different building blocks of the docker engine; docker client, API, Docker Daemon. I also explain what a docker registry is and I finish the video with a demo explaining and illustrating how to use Docker hub

In this video lesson you will learn:

  • What is Docker Host
  • What is Docker Engine
  • Learn about Docker Architecture
  • Learn about Docker client and Docker Daemon
  • Docker Hub and Registries
  • Simple demo to understand using images from registries

#docker #docker hub #docker host #docker engine #docker architecture #api

Emmy  Monahan

Emmy Monahan

1660510560

Guide to Centralized Logging with Django, Docker and CloudWatch

Let's look at how to configure a containerized Django app running on an EC2 instance to send logs to Amazon CloudWatch.

Source: https://testdriven.io

#django #docker #cloudwatch