2021/05/27

AWSのAMPとは?AWSのAMPの利点・基礎知識や使用方法などを紹介!

 
  

AWSのAMPとは?


この記事では、AWSのAMP(Amazon Managed Service for Prometheus)というサービスについて詳しく説明していきます。

まず、Prometheusというオープンソースのシステム監視ツールのことを指し、構築にあまり手間を取らないという特徴があります。しかし、取り込んだデータの処理や保存などに気を取られ、監視に集中することができません。

そこで、このAMPを使用することにより、ユーザーはセキュリティ等のインフラ管理を気にせず、Prometheusのシステム監視に集中できるようになります。

AWSのAMPの利点


AWSのAMPの利点としては、Prometheusの機能を受け継いでおり、同様のメトリクスやクエリをサポートしており、150以上のPrometheusエクスポータを利用できることなどがあげられます。

このAMPによって、従来の効率的にメトリクスやクエリを格納したり、モニタリングデータの管理をするという課題を解決することができ、運用コストを抑えることも可能です。

AWSのAMPの使用方法


ここでは、AWSのAMPを使用する流れを実際のコードを通して、説明していきます。

使用するものは、us-east-1リージョンのAWSやap-northeast-1リージョンのEKSです。

IAMリソースの作成

AWSのAMPを使用するためには、メトリクスデータの格納や取得をするAWSのIAMリソースの機能を必要とします。

以下のコードを参考にIAMのロールやプロパイダーを作成しましょう。

✦ ❯ bash init.sh 
Creating a new trust policy

An error occurred (NoSuchEntity) when calling the GetRole operation: The role with name EKS-AMP-ServiceAccount-Role cannot be found.
Appending to the existing trust policy

An error occurred (NoSuchEntity) when calling the GetPolicy operation: Policy arn:aws:iam::XXXXXXXXXX:policy/AWSManagedPrometheusWriteAccessPolicy was not found.
Creating a new permission policy AWSManagedPrometheusWriteAccessPolicy
{
    "Policy": {
        "PolicyName": "AWSManagedPrometheusWriteAccessPolicy",
        "PolicyId": "ANPARVSLQ63UWTO7GOCOY",
        "Arn": "arn:aws:iam::XXXXXXXXXX:policy/AWSManagedPrometheusWriteAccessPolicy",
        "Path": "/",
        "DefaultVersionId": "v1",
        "AttachmentCount": 0,
        "PermissionsBoundaryUsageCount": 0,
        "IsAttachable": true,
        "CreateDate": "2020-12-17T12:50:08+00:00",
        "UpdateDate": "2020-12-17T12:50:08+00:00"
    }
}

An error occurred (NoSuchEntity) when calling the GetRole operation: The role with name EKS-AMP-ServiceAccount-Role cannot be found.
EKS-AMP-ServiceAccount-Role role does not exist. Creating a new role with a trust and permission policy
arn:aws:iam::XXXXXXXXXX:role/EKS-AMP-ServiceAccount-Role
[ℹ]  eksctl version 0.30.0
[ℹ]  using region ap-northeast-1
[ℹ]  will create IAM Open ID Connect provider for cluster "eks-cluster" in "ap-northeast-1"
[✔]  created IAM Open ID Connect provider for cluster "eks-cluster" in "ap-northeast-1"

Prometheusのインストール

AWSのAMPを使用するためには、何らかのデータを入れる必要があります。

以下のコードを参考にPrometheusをEKSにインストールしましょう。

$ helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
"prometheus-community" has been added to your repositories

$ kubectl create ns prometheus
namespace/prometheus created

$ helm install prometheus-for-amp prometheus-community/prometheus -n prometheus
NAME: prometheus-for-amp
LAST DEPLOYED: Thu Dec 17 12:56:30 2020
NAMESPACE: prometheus
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
The Prometheus server can be accessed via port 80 on the following DNS name from within your cluster:
prometheus-for-amp-server.prometheus.svc.cluster.local


Get the Prometheus server URL by running these commands in the same shell:
  export POD_NAME=$(kubectl get pods --namespace prometheus -l "app=prometheus,component=server" -o jsonpath="{.items[0].metadata.name}")
  kubectl --namespace prometheus port-forward $POD_NAME 9090


The Prometheus alertmanager can be accessed via port 80 on the following DNS name from within your cluster:
prometheus-for-amp-alertmanager.prometheus.svc.cluster.local


Get the Alertmanager URL by running these commands in the same shell:
  export POD_NAME=$(kubectl get pods --namespace prometheus -l "app=prometheus,component=alertmanager" -o jsonpath="{.items[0].metadata.name}")
  kubectl --namespace prometheus port-forward $POD_NAME 9093
#################################################################################
######   WARNING: Pod Security Policy has been moved to a global property.  #####
######            use .Values.podSecurityPolicy.enabled with pod-based      #####
######            annotations                                               #####
######            (e.g. .Values.nodeExporter.podSecurityPolicy.annotations) #####
#################################################################################


The Prometheus PushGateway can be accessed via port 9091 on the following DNS name from within your cluster:
prometheus-for-amp-pushgateway.prometheus.svc.cluster.local


Get the PushGateway URL by running these commands in the same shell:
  export POD_NAME=$(kubectl get pods --namespace prometheus -l "app=prometheus,component=pushgateway" -o jsonpath="{.items[0].metadata.name}")
  kubectl --namespace prometheus port-forward $POD_NAME 9091

For more information on running Prometheus, visit:
https://prometheus.io/

すると、Prometheus関連のPODが作成されています。

$ k get po -n prometheus
NAME                                                    READY   STATUS    RESTARTS   AGE
prometheus-for-amp-alertmanager-5cb9f4478c-km4ht        2/2     Running   0          6m26s
prometheus-for-amp-kube-state-metrics-bc9cb958f-l7p7k   1/1     Running   0          6m26s
prometheus-for-amp-node-exporter-69qsw                  1/1     Running   0          6m27s
prometheus-for-amp-node-exporter-bg4ss                  1/1     Running   0          6m26s
prometheus-for-amp-node-exporter-fs74x                  1/1     Running   0          6m26s
prometheus-for-amp-pushgateway-56ff9d9d99-4z2sf         1/1     Running   0          6m26s
prometheus-for-amp-server-7f6d6fcf59-kpl5m              2/2     Running   0          6m26s

実際にAWSのAMPを使ってみよう!


いかがだったでしょうか?

今回はAWSのAMPを使うことの利点やどのように使うかなどを実際のコードを元に解説しました。

AMPを使うと、データの管理や処理に時間を割く必要もなくなり、作業効率がかなり上がるので、ぜひ実際に使ってみてください。

ITエンジニアへのキャリアチェンジならキャリアチェンジアカデミー

この記事の監修者・著者

株式会社オープンアップITエンジニア
株式会社オープンアップITエンジニア
未経験からITエンジニアへのキャリアチェンジを支援するサイト「キャリアチェンジアカデミー」を運営。これまで4500人以上のITエンジニアを未経験から育成・排出してきました。
・AWS、salesforce、LPICの合計認定資格取得件数:2100以上(2023年6月時点)
・AWS Japan Certification Award 2020 ライジングスター of the Year 受賞

おすすめの動画

  • 【未経験からIT業界へ転職するなら】相談窓口とスキルの獲得はここで解決!IT転職が一気に有利に!【キャリアチェンジアカデミー】

  • 【費用一切不要】未経験からIT業界へ転職するならまずはここへ相談!【キャリアチェンジアカデミー】

  • 【何のエンジニアになれるのか?】未経験からITエンジニアを目指すとこんな道がある【キャリアチェンジアカデミー】