WindowsにTelegrafをインストールする

スポンサーリンク

InfluxDBにデータを保存するエージェント(エクスポーター)のTelegrafをWindowsにインストールして、WindowsPCのメトリクスを収集する手順をメモします。

注意:このメモはほぼ自分用の備忘録を兼ねていますので記載が足らなかったり間違っていることがあります。情報を参考にする際はご自身の責任でお願いいたします。

インストール方法は、公式のドキュメントやブログやGitHubに点在していて、記載が微妙に違っています。バージョンによってコマンドやパスが違っているので注意です。

こんなドキュメントや、

Using Telegraf on Windows | Blog | InfluxData
A step-by-step guide for setting up Telegraf on Windows, including how to securely configure it with credentials for pus...

こんなドキュメントがありますが、

Install Telegraf | Telegraf Documentation
Install Telegraf on your operating system.

上記の記載は古いです。下記のGitHubを信用してください。

telegraf/docs/WINDOWS_SERVICE.md at master · influxdata/telegraf
Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data. - influxdata/telegra...

Telegrafのインストール

配布先

InfluxData Downloads

「Telegraf」のPlatformでWindowsを選んでください。

コマンドが書かれているんですが信用せず、zipファイルのリンクだけをコピーしてダウンロードしてください。

執筆日最新のリンクはこちら。

https://dl.influxdata.com/telegraf/releases/telegraf-1.33.1_windows_amd64.zip

これをC:\Program Files\Telegraf\というパスになるように解凍して配置します。

ここで、config準備してください。

そのフォルダで管理者権限でPowerShellを起動してください。

テスト起動して、動作を確かめる

.\telegraf.exe --config "C:\Program Files\Telegraf\telegraf.conf" --test

問題なければ、サービスとしてインストール

.\telegraf.exe service install

サービスをスタート

.\telegraf.exe service start

これで完了です。

アンインストールしたければ

.\telegraf.exe service uninstall

です。

サービスのフラグは下記があります。

.\telegraf.exe service install
.\telegraf.exe service uninstall
.\telegraf.exe service start
.\telegraf.exe service stop
.\telegraf.exe service status

サービスの設定は決め打ちで、

.\telegraf.exe --config "C:\Program Files\Telegraf\telegraf.conf" --service-name telegraf

こうなっていますので、インストールパスをいじる場合は注意です。古いドキュメントはちょっと違ってるんですよね。

以上です。

Windows用のconfig

下記が参考になります。

【Telegraf】CPUやHDDの使用状況を監視しDBに保存する【InfluxDB】 | 謎の技術研究部
InfluxDB周りのプロダクト「Telegraf」を試す。自宅サーバーPCの稼働状況に問題がないかを確認できるようにしたい。
telegraf/plugins/inputs/win_perf_counters at master · influxdata/telegraf
Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data. - influxdata/telegra...

私が使ってるtelegraf.confを載せておきます。

[global_tags]
  # dc = "us-east-1" # will tag all metrics with dc=us-east-1
  # rack = "1a"
  ## Environment variables can be used as tags, and throughout the config file
  # user = "$USER"


[agent]
  interval = "10s"
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  collection_jitter = "0s"
  flush_interval = "10s"
  flush_jitter = "0s"
  precision = "0s"
  ## Log at debug level.
  # debug = false
  ## Log only error level messages.
  # quiet = false
  logfile = "log.log"
  log_with_timezone = "Asia/Tokyo"
  ## Override default hostname, if empty use os.Hostname()
  # hostname = ""
  ## If set to true, do no set the "host" tag in the telegraf agent.
  # omit_hostname = false


[[outputs.influxdb_v2]]
  urls = ["https://influxdb.XXX.net"]
  #urls = ["http://influxdb:8086"]
  token = "3lSDysKjYXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX7n4NA=="
  organization = "organization"
  bucket = "bucket"
  timeout = "5s"


[[inputs.win_perf_counters]]
  [[inputs.win_perf_counters.object]]
    # Processor usage, alternative to native, reports on a per core.
    ObjectName = "Processor"
    Instances = ["*"]
    Counters = ["% Idle Time", "% Interrupt Time", "% Privileged Time", "% User Time", "% Processor Time"]
    Measurement = "win_cpu"
    #IncludeTotal=false #Set to true to include _Total instance when querying for all (*).

  [[inputs.win_perf_counters.object]]
    # Disk times and queues
    ObjectName = "LogicalDisk"
    Instances = ["*"]
    Counters = ["% Idle Time", "% Disk Time","% Disk Read Time", "% Disk Write Time", "% User Time", "Current Disk Queue Length"]
    Measurement = "win_disk"
    #IncludeTotal=false #Set to true to include _Total instance when querying for all (*).

  [[inputs.win_perf_counters.object]]
    ObjectName = "System"
    Counters = ["Context Switches/sec","System Calls/sec", "Processor Queue Length"]
    Instances = ["------"]
    Measurement = "win_system"
    #IncludeTotal=false #Set to true to include _Total instance when querying for all (*).

  [[inputs.win_perf_counters.object]]
    # Example query where the Instance portion must be removed to get data back, such as from the Memory object.
    ObjectName = "Memory"
    Counters = ["Available Bytes","Cache Faults/sec","Demand Zero Faults/sec","Page Faults/sec","Pages/sec","Transition Faults/sec","Pool Nonpaged Bytes","Pool Paged Bytes"]
    Instances = ["------"] # Use 6 x - to remove the Instance bit from the query.
    Measurement = "win_mem"
    #IncludeTotal=false #Set to true to include _Total instance when querying for all (*).

  [[inputs.win_perf_counters.object]]
    # more counters for the Network Interface Object can be found at
    # https://msdn.microsoft.com/en-us/library/ms803962.aspx
    ObjectName = "Network Interface"
    Counters = ["Bytes Received/sec","Bytes Sent/sec","Packets Received/sec","Packets Sent/sec"]
    Instances = ["*"] # Use 6 x - to remove the Instance bit from the query.
    Measurement = "win_net"
    #IncludeTotal=false #Set to true to include _Total instance when querying for all (*).


[[inputs.cpu]]
  ## Whether to report per-cpu stats or not
  percpu = true
  ## Whether to report total system cpu stats or not
  totalcpu = true
  ## If true, collect raw CPU time metrics
  collect_cpu_time = false
  ## If true, compute and report the sum of all non-idle CPU states
  ## NOTE: The resulting 'time_active' field INCLUDES 'iowait'!
  report_active = false
  ## If true and the info is available then add core_id and physical_id tags
  core_tags = false



[[inputs.disk]]
  ## By default stats will be gathered for all mount points.
  ## Set mount_points will restrict the stats to only the specified mount points.
  # mount_points = ["/"]

  ## Ignore mount points by filesystem type.
  ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]

  ## Ignore mount points by mount options.
  ## The 'mount' command reports options of all mounts in parathesis.
  ## Bind mounts can be ignored with the special 'bind' option.
  # ignore_mount_opts = []



[[inputs.diskio]]
  ## Devices to collect stats for
  ## Wildcards are supported except for disk synonyms like '/dev/disk/by-id'.
  ## ex. devices = ["sda", "sdb", "vd*", "/dev/disk/by-id/nvme-eui.00123deadc0de123"]
  # devices = ["*"]

  ## Skip gathering of the disk's serial numbers.
  # skip_serial_number = true

  ## Device metadata tags to add on systems supporting it (Linux only)
  ## Use 'udevadm info -q property -n <device>' to get a list of properties.
  ## Note: Most, but not all, udev properties can be accessed this way. Properties
  ## that are currently inaccessible include DEVTYPE, DEVNAME, and DEVPATH.
  # device_tags = ["ID_FS_TYPE", "ID_FS_USAGE"]

  ## Using the same metadata source as device_tags, you can also customize the
  ## name of the device via templates.
  ## The 'name_templates' parameter is a list of templates to try and apply to
  ## the device. The template may contain variables in the form of '$PROPERTY' or
  ## '${PROPERTY}'. The first template which does not contain any variables not
  ## present for the device is used as the device name tag.
  ## The typical use case is for LVM volumes, to get the VG/LV name instead of
  ## the near-meaningless DM-0 name.
  # name_templates = ["$ID_FS_LABEL","$DM_VG_NAME/$DM_LV_NAME"]


[[inputs.kernel]]
  ## Additional gather options
  ## Possible options include:
  ## * ksm - kernel same-page merging
  ## * psi - pressure stall information
  # collect = []


[[inputs.mem]]
  # no configuration


[[inputs.processes]]
  ## Use sudo to run ps command on *BSD systems. Linux systems will read
  ## /proc, so this does not apply there.
  # use_sudo = false


[[inputs.swap]]
  # no configuration


[[inputs.system]]
  # no configuration


#[[inputs.amd_rocm_smi]]
#  ## Optional: path to rocm-smi binary, defaults to $PATH via exec.LookPath
#  # bin_path = "/opt/rocm/bin/rocm-smi"

#  ## Optional: timeout for GPU polling
#  # timeout = "5s"


[[inputs.nvidia_smi]]
  ## Optional: path to nvidia-smi binary, defaults "/usr/bin/nvidia-smi"
  ## We will first try to locate the nvidia-smi binary with the explicitly specified value (or default value),
  ## if it is not found, we will try to locate it on PATH(exec.LookPath), if it is still not found, an error will be returned
  # bin_path = "/usr/bin/nvidia-smi"

  ## Optional: timeout for GPU polling
  # timeout = "5s"

コメント

タイトルとURLをコピーしました