“This is the 23rd day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021”

One, foreword

This article introduces how to install and monitor Telegraf on Windows

Two, installation & deployment

1. Find the download address: portal.influxdata.com/downloads/

2. Create directory C:\Program Files\Telegraf (if installed in another location, specify -config with the required location parameter) 3. Unpack the package and put the telegraf.exe and telegraf.conf Files into C: Program Files\ telegraf

4. To install the service in Windows Service Manager, run the following command in CMD as an administrator: If necessary, wrap any Spaces in file directories with ”

” with double quotation marks:

C:\"Program Files"\Telegraf\telegraf.exe --service install
Copy the code

or

C:\Program Files\Telegraf>telegraf.exe --service install
Copy the code

5. Edit the telegraf.conf configuration file to meet the requirements.

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# INPUTS #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# Windows Performance Counters plugin.
# These are the recommended method of monitoring system metrics on windows,
# as the regular system plugins (inputs.cpu, inputs.mem, etc.) rely on WMI,
# which utilize more system resources.
#
# See more configuration examples at:
# https://github.com/influxdata/telegraf/tree/master/plugins/inputs/win_perf_counters

[[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"."% DPC Time",
    ]
    Measurement = "win_cpu"
    # Set to true to include _Total instance when querying for all (*).
    IncludeTotal=true

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

  [[inputs.win_perf_counters.object]]
    ObjectName = "PhysicalDisk"
    Instances = ["*"]
    Counters = [
      "Disk Read Bytes/sec"."Disk Write Bytes/sec"."Current Disk Queue Length"."Disk Reads/sec"."Disk Writes/sec"."% Disk Time"."% Disk Read Time"."% Disk Write Time",
    ]
    Measurement = "win_diskio"

  [[inputs.win_perf_counters.object]]
    ObjectName = "Network Interface"
    Instances = ["*"]
    Counters = [
      "Bytes Received/sec"."Bytes Sent/sec"."Packets Received/sec"."Packets Sent/sec"."Packets Received Discarded"."Packets Outbound Discarded"."Packets Received Errors"."Packets Outbound Errors",
    ]
    Measurement = "win_net"

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

  [[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"."Standby Cache Reserve Bytes"."Standby Cache Normal Priority Bytes"."Standby Cache Core Bytes",]# Use 6 x - to remove the Instance bit from the query.
    Instances = ["-- -- -- -- -- -"]
    Measurement = "win_mem"
    # Set to true to include _Total instance when querying for all (*).
    #IncludeTotal=false

  [[inputs.win_perf_counters.object]]
    # Example query where the Instance portion must be removed to get data back,
    # such as from the Paging File object.
    ObjectName = "Paging File"
    Counters = [
      "% Usage",
    ]
    Instances = ["_Total"]
    Measurement = "win_swap"

Copy the code

6. To verify that it works, run:

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

or

C:\Program Files\Telegraf>telegraf.exe --config telegraf.conf --test
Copy the code

To start collecting data, run:

net start telegraf
Copy the code

Telegraf can use –service to manage its own services:

telegraf.exe --service install		# Install service
telegraf.exe --service uninstall	# delete service
telegraf.exe --service start		# start service
telegraf.exe --service stop			# stop service
Copy the code

3. Integrate the Influxdb

Locate the OUTPUTS configuration item

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# OUTPUTS #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

# Configuration for sending metrics to InfluxDB
[[outputs.influxdb]]
  ## The full HTTP or UDP URL for your InfluxDB instance.
  # #
  ## Multiple URLs can be specified for a single cluster, only ONE of the
  ## urls will be written to each interval.
  # urls = ["unix:///var/run/influxdb.sock"]
  # urls = [udp: / / 127.0.0.1:8089 ""]
  urls = ["http://172.16.14.111:8086"]

  ## The target database for metrics; will be created as needed.
  database = "bigscreen"

  ## If true, no CREATE DATABASE queries will be sent. Set to true when using
  ## Telegraf with a user without permissions to create databases or when the
  ## database already exists.
  # skip_database_creation = false

  ## Name of existing retention policy to write to. Empty string writes to
  ## the default retention policy. Only takes effect when using HTTP.
  # retention_policy = ""

  ## Write consistency (clusters only), can be: "any", "one", "quorum", "all".
  ## Only takes effect when using HTTP.
  # write_consistency = "any"

  ## Timeout for HTTP messages.
  timeout = "5s"

  ## HTTP Basic Auth
   username = "telegraf"
   password = "telegraf"

  ## HTTP User-Agent
  # user_agent = "telegraf"

  ## UDP payload size is the maximum packet size to send.
  # udp_payload = "512B"

  ## Optional TLS Config for use on HTTP connections.
  # tls_ca = "/etc/telegraf/ca.pem"
  # tls_cert = "/etc/telegraf/cert.pem"
  # tls_key = "/etc/telegraf/key.pem"
  ## Use TLS but skip chain & host verification
  # insecure_skip_verify = false

  ## HTTP Proxy override, if unset values the standard proxy environment
  ## variables are consulted to determine which proxy, if any, should be used.
  # http_proxy = "http://corporate.proxy:3128"

  ## Additional HTTP headers
  # http_headers = {"X-Special-Header" = "Special-Value"}

  ## HTTP Content-Encoding for write request body, can be set to "gzip" to
  ## compress body or "identity" to apply no encoding.
  # content_encoding = "identity"

  ## When true, Telegraf will output unsigned integers as unsigned values,
  ## i.e.: "42u". You will need a version of InfluxDB supporting unsigned
  ## integer values. Enabling this option will result in field type errors if
  ## existing data has been written.
  # influx_uint_support = false
Copy the code

1. Verify the database

[root@localhost tools]# sudo influx
Connected to http://localhost:8086 version 1.7.4
InfluxDB shell version: 1.7.4
Enter an InfluxQL query
> use bigscreen
Using database bigscreen
> SHOW MEASUREMENTS
name: measurements
name
----
bigscreen
nvidia_smi
win_cpu
win_disk
win_diskio
win_mem
win_net
win_perf_counters
win_swap
win_system
> SELECT * FROM "win_cpu" limit1 name: win_cpu time Percent_DPC_Time Percent_Idle_Time Percent_Interrupt_Time Percent_Privileged_Time Percent_Processor_Time Percent_User_Time host instance objectname ---- ---------------- ----------------- ---------------------- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 1552012501000000000 81.72647857666016 0 4.6642279624938965 9.824928283691406 4.6642279624938965 DESKTOP-MLD0KTS 0 ProcessorCopy the code

Integrate the Grafana Dashboard

Visit grafana.com/dashboards?… Download an appropriate Dashboard template

Grafana imports the Dashboard template

For details, see Real-time Monitoring of the Telegraf+InfluxDB+Grafana Server in Performance Monitoring

5. Monitoring effect

The Grafana Dashboard looks like this:

Related information:

  • Github.com/zuozewei/bl…