Grafana は、アラート機能を使用するための GUI を備えています。 Grafana で通知チャネルを追加すると、Grafana から Log Service のアラートシステムにアラートを送信できます。 アラートシステムは、受信したアラートのノイズ除去やアラート通知の送信など、アラートの処理を行います。

始める前に

アラート取り込みアプリケーションが作成済みである必要があります。 詳細については、「アラート取り込み用 Webhook URL の設定」をご参照ください。

Grafana の設定

[New notification channel] ページで、以下のパラメーターを設定します。 Grafana の設定
パラメーター 説明
Name 通知チャネル名。
Type 通知チャネルのタイプ。 この例では、[webhook] を選択しています。
Url 通知チャネルの URL。 この例では、Log Service のアラート取り込みシステムでアラート取り込みサービスとアラート取り込みアプリケーションを作成すると生成される Webhook URL の完全な URL を入力しています。 詳細については、「Webhook URL の取得」をご参照ください。
Grafana サーバーが Elastic Compute Service (ECS) インスタンスにデプロイされている場合は、ECS インスタンスが存在するリージョンを選択し、LAN または Virtual Private Cloud (VPC) 経由でアクセスできる内部エンドポイントを使用してリージョン情報を設定することを推奨します。 Grafana サーバーが ECS インスタンスにデプロイされていない場合は、インターネット経由でリージョンにアクセス可能なパブリックエンドポイントを使用できます。

Grafana アラート

以下に、Grafana アラートのサンプルコードを示します。

Grafana アラートにseverity フィールドが存在する場合、Log Service は、アラートの取り込み後、このフィールドの値を対応する重大度にマッピングします。 Grafana アラートに severity フィールドが存在しない場合、アラートの重大度はデフォルトで中レベルに設定されます。 詳細については、「重大度レベル」をご参照ください。
{
    "dashboardId": 1,
    "evalMatches": [
        {
            "value": 173.14285714285714,
            "metric": "go_gc_duration_seconds_count{instance=\"localhost: 9090\", job=\"prometheus\"}",
            "tags": {
                "__name__": "go_gc_duration_seconds_count",
                "instance": "localhost:9090",
                "job": "prometheus"
            }
        }
    ],
    "message": "sadfasdf",
    "orgId": 1,
    "panelId": 4,
    "ruleId": 2,
    "ruleName": "fuxasdfasd",
    "ruleUrl": "http://localhost:3000/d/biSKHC8Mz/new-dashboard-copy?tab=alert&viewPanel=4&orgId=1",
    "state": "alerting",
    "tags": {
        "severity" : "crit",
        "xasdfasdf": "mveonasdf"
    },
    "title": "[Alerting] fuxasdfasd"
}

フィールドマッピング

Grafana アラートが Log Service に取り込まれると、フィールドマッピングを使用してアラートが Log Service アラートに変換されます。 以下に、Log Service アラートのサンプルコードを示します。

{
    "aliuid": "{The ID of the Alibaba Cloud account to which the alert ingestion application belongs}",
    "alert_instance_id": "{The alert instance ID that is automatically generated}",
    "project": "{The project to which Alert Center belongs}",
    "region": "{The region of the project to which Alert Center belongs}",
    "alert_id": "2",
    "alert_type": "sls_pub",
    "alert_name": "sadfasdf",
    "next_eval_interval": 0,
    "alert_time": 1603859020,
    "fire_time": 1603859020,
    "resolve_time": 0,
    "status": "firing",
    "labels": {
        "xasdfasdf": "mveonasdf"
    },
    "annotations": {
        "__pub_alert_region__": "{The region of the endpoint to which the alert is sent}",
        "__config_app__": "sls_pub_alert",
        "__pub_alert_service__": "{The ID of the alert ingestion service}",
        "__pub_alert_app__": "{The ID of the alert ingestion application}",
        "__pub_alert_protocol__": "grafana",
        "severity" : "crit",
        "orgId": "1",
        "dashboardId": "1",
        "panelId": "4",
        "ruleUrl": "http://localhost:3000/d/biSKHC8Mz/new-dashboard-copy?tab=alert&viewPanel=4&orgId=1",
        "imageUrl": "",
        "desc": "sadfasdf",
        "title": "[Alerting] fuxasdfasd"
    },
    "severity": 10,
    "policy": {
        "alert_policy_id": "{The alert policy that is specified for the alert ingestion application}",
        "action_policy_id": "{The action policy that is specified for the alert ingestion application}",
        "repeat_interval": "{The cycle that is specified for the alert ingestion application}"
    },
    "drill_down_query": "http://localhost:3000/d/biSKHC8Mz/new-dashboard-copy?tab=alert&viewPanel=4&orgId=1",
    "results": [{
        "query": "go_gc_duration_seconds_count{instance=\"localhost: 9090\", job=\"prometheus\"}",
        "fire_result": {
            "__name__": "go_gc_duration_seconds_count",
            "instance": "localhost:9090",
            "job": "prometheus",
            "value": "173.142",
        }
    }]
}

下表に、Log Service と Grafana 間のフィールドマッピングを示します。

Log Service のフィールド Grafana のフィールド 説明
aliuid なし アラート取り込みアプリケーションが属する Alibaba Cloud アカウントの ID。
alert_id ruleId アラートモニタリングルールの ID。
alert_type なし アラートタイプ。 値は sls_pub に固定されています。
alert_name ruleName アラートモニタリングルールのルール名。
status state アラートのステータス。
  • Grafana アラートの state フィールドの値が ok の場合、Log Service の status フィールドの値が解決されます。
  • Grafana アラートの state フィールドの値が、alerting などの別の値の場合、Log Service のstatus フィールドは firing です。
next_eval_interval なし アラートが評価される間隔。 値は 0 に固定されています。
alert_time なし Log Service が Grafana アラートを受信する時刻。
fire_time なし Log Service が Grafana アラートを受信する時刻。
resolve_time なし アラートが作成された時刻。 値は 0 に固定されています。
labels tags アラートのラベル。
  • Grafana アラートの tags フィールドに severity フィールドが存在する場合、Log Service によるアラート取り込み後、severity フィールドが annotation フィールドに追加されます。
  • アラート取り込みアプリケーションの作成時に [エンリッチメント] タブでラベルを追加した場合、ラベルは labels フィールドに追加されます。
    [エンリッチメント] タブで指定したラベルのキーが Grafana アラートの tags フィールドと同じ場合、[エンリッチメント] タブが優先されます。
annotations なし Grafana アラートが Log Service に取り込まれると、以下のフィールドが Log Service アラートのannotations フィールドに追加されます。
  • __config_app__: "sls_pub_alert"
  • __pub_alert_service__: {アラート取り込みサービスの ID}
  • __pub_alert_app__: {アラート取り込みアプリケーションの ID}
  • __pub_alert_protocol__: "grafana"
  • __pub_alert_region__: {アラートが送信されるエンドポイントのリージョン}
  • orgId: {Grafana アラートの orgId フィールド}
  • dashboardId: {Grafana アラートの dashboardId フィールド}
  • panelId: {Grafana アラートの panelId フィールド}
  • ruleUrl: {Grafana アラートの ruleUrl フィールド}
  • imageUrl: {Grafana アラートの imageUrl フィールド}
  • desc: {Grafana アラートの message フィールド}
  • title: {Grafana アラートの title フィールド}
アラート取り込みアプリケーションの作成時に [エンリッチメント] タブで注釈を追加した場合、注釈は annotations フィールドに追加されます。
[エンリッチメント] タブで指定したラベルのキーが Grafana アラートの tags フィールドと同じ場合、[エンリッチメント] タブが優先されます。
severity severity アラートの重大度。 詳細については、「重大度レベル」をご参照ください。
policy なし アラート取り込みアプリケーションに指定されているアラートポリシー。 詳細については、「ポリシー変数のデータ構造」をご参照ください。
project なし アラートセンターが属するプロジェクト。 詳細については、「プロジェクト」をご参照ください。
drill_down_query ruleUrl Log Service アラートの drill_down_query フィールドには、Grafana アラートの ruleUrl フィールドの値が表示されます。
results evalMatches 結果セット。 evalMatches 配列の各要素は、results フィールドの QueryData 構造にマッピングされます。 マッピングの詳細については、「表 1」をご参照ください。 results フィールドの詳細については、「結果変数のデータ構造」をご参照ください。
表 1. 結果セットのマッピング
QueryData 構造 evalMatches フィールド 説明
query metric クエリ 文。
fire_result tags および value Grafana アラートの tags フィールドはキーと値のペアに展開され、 fire_result フィールド格納されます。 value フィールドは fire_result フィールドに格納されます。

value フィールドの値は小数第 3 位に四捨五入されます。