#author("2020-07-22T19:00:29+09:00","default:dex","dex")
#author("2020-09-04T11:52:24+09:00","default:dex","dex")
#contents

* plugins: プラグイン [#x6746c12]

- https://grafana.com/grafana/plugins
-- panel: Pie Chart, Cal-[[HeatMap]], 他。AWS [[CloudWatch]]はデフォルトで入っている。
-- datasource: Zabbix, Elasticsearch, [[DataDog]] 他。AWSはデフォルトで入っている

-https://grafana.com/orgs/grafana
--Grafana Labs作プラグインはデフォルトで追加しても良いだろう

----
** pluginの開発 [#ub92f50b]

- [[Build a plugin. | Grafana Labs:https://grafana.com/docs/grafana/latest/developers/plugins/]]

- チュートリアル
-- [[Build a data source plugin | Grafana Labs:https://grafana.com/tutorials/build-a-data-source-plugin/#1]]

- 記事
-- [[Grafanaデータソースプラグインの作り方[その1]|ケンジ|note:https://note.com/bakute/n/n2a41aa786047]]

----
** 未登録のpluginを追加する [#q26398c9]

- https://grafana.com/grafana/plugins に未登録なpluginでも、grafana-cliから登録できる
- [[allow_loading_unsigned_plugins:https://grafana.com/docs/grafana/latest/administration/configuration/#plugins-1]] に許可するpluginをカンマ区切りで入力する
-- Grafana v7.xでは unsignedなpluginがloadされない。
-- /var/log/grafana/grafana.log に出るエラー
#geshi(bash){{
[...] lvl=warn msg="Some plugins failed to load" logger=plugins errors="[plugin \"mtanda-aws-athena-datasource\" is unsigned]"
}}

----
*** grafana-aws-athena-datasource [#d6cdce62]

https://github.com/mtanda/grafana-aws-athena-datasource の場合
- https://github.com/mtanda/grafana-aws-athena-datasource/blob/master/src/README.md 以下にREADMEがある
- v2.2.5は、''Grafana v7.0.6 で動作した。'' v7.1.0では動作せず。v7.x未満の場合、データソースの登録画面でエラーが出て、GUIでは消せないデータソースが増えるので、APIで消す。
-- v2.2.5: Grafana v6.5.2 ~ v6.7.4でのエラー
#geshi(bash){{
Error: Object prototype may only be an Object or null: undefined Evaluating
}}
-- [[Memo/Grafana/API]] で壊れたデータソースを消す方法

+ https://github.com/mtanda/grafana-aws-athena-datasource/releases からzipのurlをコピー
#geshi(bash){{
sudo grafana-cli --pluginUrl https://github.com/mtanda/grafana-aws-athena-datasource/releases/download/2.2.5/grafana-aws-athena-datasource-2.2.5.zip plugins install mtanda-aws-athena-datasource
}}
+ CentOS 7の場合: /var/lib/grafana/plugins/ に展開される。
+ Grafanaの再起動
#geshi(bash){{
sudo service grafana-server restart
}}
+ Grafana v7.xでは unsignedなpluginがloadされないため、[[allow_loading_unsigned_plugins:https://grafana.com/docs/grafana/latest/administration/configuration/#plugins-1]] に許可するpluginをカンマ区切りで入力する
#geshi(bash){{
sudo vim /etc/grafana/grafana.ini
--
[plugins]
allow_loading_unsigned_plugins =  mtanda-aws-athena-datasource
--
sudo service grafana-server restart
}}
+ Grafana > Configration > Data Souces > AWS Athena datasourceが選択し、Test&Saveでエラーが出なければOK

- Query stringを実行するのに必要だった権限
#geshi(javascript){{{
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "GrafanaAthena",
            "Effect": "Allow",
            "Action": [
                "athena:StartQueryExecution",
                "athena:ListWorkGroups",
                "athena:ListQueryExecutions",
                "athena:ListNamedQueries",
                "athena:GetWorkGroup",
                "athena:GetQueryResults",
                "athena:BatchGetQueryExecution",
                "athena:BatchGetNamedQuery"
            ],
            "Resource": "*"
        },
        {
            "Sid": "GrafanaAthenaS3",
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:ListMultipartUploadParts",
                "s3:ListBucketMultipartUploads",
                "s3:ListBucket",
                "s3:GetObject",
                "s3:GetBucketLocation"
            ],
            "Resource": [
                "arn:aws:s3:::bucket/*",
                "arn:aws:s3:::bucket"
            ]
        }
    ]
}
}}}

----
** ダウングレード [#x3b94321]

- alexanderzobnin-zabbix-app 3.10.3を入れるとエラーで表示されなくなったため、一つ前のバージョンに戻す場合。
#geshi(bash){{
sudo grafana-cli plugins install alexanderzobnin-zabbix-app 3.10.2
sudo service grafana-server restart
}}

----

** 一覧 [#m841b43d]

#geshi(bash){{
sudo grafana-cli plugins ls
installed plugins:
alexanderzobnin-zabbix-app @ 3.8.1
}}

----

** 更新 [#r468ff4c]

-pluginの更新があると、Home DashboardのInstalled Appsに通知される。
-Up to dateリンクから更新方法の案内が見えるので簡単

-例: CentOS 7
#geshi(bash){{
# 全て更新する場合
sudo grafana-cli plugins update-all

# 指定pluginのみ更新
sudo grafana-cli plugins update alexanderzobnin-zabbix-app

sudo service grafana-server restart
}}

----

** 追加 [#nfa3092b]

-例: CentOS7上の「zabbix」プラグインを追加
#geshi(bash){{
sudo grafana-cli plugins install alexanderzobnin-zabbix-app
sudo service grafana-server restart
}}

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS