今回のテーマ
Cursorを使って何か簡単なプログラムを作ってみたかったので、DynatraceのHost情報をAPI経由で取得するスクリプトを作ってみました。
.\Get-DynatraceHosts.ps1
とすると
"HostName","CPUCores","MemoryGB"
"minikube-kvm","6","8.00"
"st-linux-01","4","16.00"
"st-win-01","20","32.00"
というようなCSVファイルを出力します。
サンプルスクリプト
PowerShell版
Python版
/api/v1/entity/infrastructure/hosts
で取得できるHost情報にはメモリサイズが入っていませんので、メトリクスで取得しています。上記のスクリプトでは使っていませんが、 /api/v2/entities
でもメモリサイズを取得可能です。
プロンプト
こんな感じで作りました。多分日本語でも大丈夫だと思います。
下記はPython用ですが、PowerShell用もほぼ同じです。
- Please compose a Python script to fetch host info from Dynatrace and save hostnames, CPU core numbers, and memory sizes into a CSV file.
- Please separate dynatrace URL and API token into a separate file and add template file. Also exclude config file from commit.
- Use the API /api/v1/entity/infrastructure/hosts instead
- Thanks, it worked! Please get the memory sizes of each host and add them to the CSV. Memory sizes should be retrieved from the metrics.
- Please round off the memory size to one decimal place.
- Wrap debugging code with flag
- Please exclude csv files when commit
- Please create a README.md file that includes what this script is, how to use this script, and how to add other attributes to CSV output.
- Translate README.md into Japanese and save it to README.ja.md.
一行目でほとんど完成しています。あとは微調整レベルです。
特に便利だと感じたのは、「README.md
を作って」と言うだけで作ってくれたことです。使用方法や拡張方法も入れてね、と書き添えたらそのように作ってくれて、最終的に日本語版も作ってねと言ったら作ってくれました。本当に便利で強力で効果的ですね!