1xcalibur1

Untitled

Oct 30th, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.46 KB | None | 0 0
  1. ##################################################
  2. # This script automates the installation of #
  3. # the telegraf agent on Windows #
  4. # Last Updated: 05/04/2020 #
  5. # Author: Mahmoud Ghonim [email protected] #
  6. # Version: 1.1 #
  7. ##################################################
  8.  
  9. ############ Params #############################
  10.  
  11. param(
  12. [string]$service
  13. )
  14.  
  15. ######### Functions #############################
  16.  
  17. Add-Type -AssemblyName System.IO.Compression.FileSystem
  18. function Unzip
  19. {
  20. param([string]$zipfile, [string]$outpath)
  21.  
  22. [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
  23. }
  24.  
  25. # Telegraf agent configuration file
  26. $telegrafconf = @'
  27. # Telegraf Configuration
  28. #
  29. # Telegraf is entirely plugin driven. All metrics are gathered from the
  30. # declared inputs, and sent to the declared outputs.
  31. #
  32. # Plugins must be declared in here to be active.
  33. # To deactivate a plugin, comment out the name and any variables.
  34. #
  35. # Use 'telegraf -config telegraf.conf -test' to see what metrics a config
  36. # file would generate.
  37. #
  38. # Environment variables can be used anywhere in this config file, simply surround
  39. # them with ${}. For strings the variable must be within quotes (ie, "${STR_VAR}"),
  40. # for numbers and booleans they should be plain (ie, ${INT_VAR}, ${BOOL_VAR})
  41.  
  42.  
  43. # Global tags can be specified here in key="value" format.
  44. [global_tags]
  45. # dc = "us-east-1" # will tag all metrics with dc=us-east-1
  46. # rack = "1a"
  47. ## Environment variables can be used as tags, and throughout the config file
  48. # user = "$USER"
  49.  
  50.  
  51. # Configuration for telegraf agent
  52. [agent]
  53. ## Default data collection interval for all inputs
  54. interval = "10s"
  55. ## Rounds collection interval to 'interval'
  56. ## ie, if interval="10s" then always collect on :00, :10, :20, etc.
  57. round_interval = true
  58.  
  59. ## Telegraf will send metrics to outputs in batches of at most
  60. ## metric_batch_size metrics.
  61. ## This controls the size of writes that Telegraf sends to output plugins.
  62. metric_batch_size = 1000
  63.  
  64. ## Maximum number of unwritten metrics per output. Increasing this value
  65. ## allows for longer periods of output downtime without dropping metrics at the
  66. ## cost of higher maximum memory usage.
  67. metric_buffer_limit = 10000
  68.  
  69. ## Collection jitter is used to jitter the collection by a random amount.
  70. ## Each plugin will sleep for a random time within jitter before collecting.
  71. ## This can be used to avoid many plugins querying things like sysfs at the
  72. ## same time, which can have a measurable effect on the system.
  73. collection_jitter = "0s"
  74.  
  75. ## Default flushing interval for all outputs. Maximum flush_interval will be
  76. ## flush_interval + flush_jitter
  77. flush_interval = "10s"
  78. ## Jitter the flush interval by a random amount. This is primarily to avoid
  79. ## large write spikes for users running a large number of telegraf instances.
  80. ## ie, a jitter of 5s and interval 10s means flushes will happen every 10-15s
  81. flush_jitter = "0s"
  82.  
  83. ## By default or when set to "0s", precision will be set to the same
  84. ## timestamp order as the collection interval, with the maximum being 1s.
  85. ## ie, when interval = "10s", precision will be "1s"
  86. ## when interval = "250ms", precision will be "1ms"
  87. ## Precision will NOT be used for service inputs. It is up to each individual
  88. ## service input to set the timestamp at the appropriate precision.
  89. ## Valid time units are "ns", "us" (or "µs"), "ms", "s".
  90. precision = ""
  91.  
  92. ## Log at debug level.
  93. # debug = false
  94. ## Log only error level messages.
  95. # quiet = false
  96.  
  97. ## Log target controls the destination for logs and can be one of "file",
  98. ## "stderr" or, on Windows, "eventlog". When set to "file", the output file
  99. ## is determined by the "logfile" setting.
  100. # logtarget = "file"
  101.  
  102. ## Name of the file to be logged to when using the "file" logtarget. If set to
  103. ## the empty string then logs are written to stderr.
  104. # logfile = ""
  105.  
  106. ## The logfile will be rotated after the time interval specified. When set
  107. ## to 0 no time based rotation is performed. Logs are rotated only when
  108. ## written to, if there is no log activity rotation may be delayed.
  109. # logfile_rotation_interval = "0d"
  110.  
  111. ## The logfile will be rotated when it becomes larger than the specified
  112. ## size. When set to 0 no size based rotation is performed.
  113. # logfile_rotation_max_size = "0MB"
  114.  
  115. ## Maximum number of rotated archives to keep, any older logs are deleted.
  116. ## If set to -1, no archives are removed.
  117. # logfile_rotation_max_archives = 5
  118.  
  119. ## Override default hostname, if empty use os.Hostname()
  120. hostname = ""
  121. ## If set to true, do no set the "host" tag in the telegraf agent.
  122. omit_hostname = false
  123.  
  124.  
  125. ###############################################################################
  126. # OUTPUT PLUGINS #
  127. ###############################################################################
  128.  
  129. [[outputs.prometheus_client]]
  130. ## Address to listen on.
  131. listen = ":9126"
  132.  
  133. ## Metric version controls the mapping from Telegraf metrics into
  134. ## Prometheus format. When using the prometheus input, use the same value in
  135. ## both plugins to ensure metrics are round-tripped without modification.
  136. ##
  137. ## example: metric_version = 1; deprecated in 1.13
  138. ## metric_version = 2; recommended version
  139. metric_version = 2
  140.  
  141. ## Use HTTP Basic Authentication.
  142. # basic_username = "Foo"
  143. # basic_password = "Bar"
  144.  
  145. ## If set, the IP Ranges which are allowed to access metrics.
  146. ## ex: ip_range = ["192.168.0.0/24", "192.168.1.0/30"]
  147. # ip_range = []
  148.  
  149. ## Path to publish the metrics on.
  150. # path = "/metrics"
  151.  
  152. ## Expiration interval for each metric. 0 == no expiration
  153. # expiration_interval = "60s"
  154.  
  155. ## Collectors to enable, valid entries are "gocollector" and "process".
  156. ## If unset, both are enabled.
  157. # collectors_exclude = ["gocollector", "process"]
  158.  
  159. ## Send string metrics as Prometheus labels.
  160. ## Unless set to false all string metrics will be sent as labels.
  161. # string_as_label = true
  162.  
  163. ## If set, enable TLS with the given certificate.
  164. # tls_cert = "/etc/ssl/telegraf.crt"
  165. # tls_key = "/etc/ssl/telegraf.key"
  166.  
  167. ## Set one or more allowed client CA certificate file names to
  168. ## enable mutually authenticated TLS connections
  169. # tls_allowed_cacerts = ["/etc/telegraf/clientca.pem"]
  170.  
  171. ## Export metric collection time.
  172. # export_timestamp = false
  173.  
  174. '@
  175.  
  176. # Infrastructure configuration file
  177. $infrastructureconf = @'
  178.  
  179. ###############################################################################
  180. # INPUT PLUGINS #
  181. ###############################################################################
  182.  
  183.  
  184. # Windows Performance Counters plugin.
  185. # These are the recommended method of monitoring system metrics on windows,
  186. # as the regular system plugins (inputs.cpu, inputs.mem, etc.) rely on WMI,
  187. # which utilize more system resources.
  188. #
  189. # See more configuration examples at:
  190. # https://github.com/influxdata/telegraf/tree/master/plugins/inputs/win_perf_counters
  191.  
  192. [[inputs.win_perf_counters]]
  193. [[inputs.win_perf_counters.object]]
  194. # Processor usage, alternative to native, reports on a per core.
  195. ObjectName = "Processor"
  196. Instances = ["*"]
  197. Counters = [
  198. "% Idle Time",
  199. "% Interrupt Time",
  200. "% Privileged Time",
  201. "% User Time",
  202. "% Processor Time",
  203. "% DPC Time",
  204. ]
  205. Measurement = "win_cpu"
  206. # Set to true to include _Total instance when querying for all (*).
  207. IncludeTotal=true
  208.  
  209. [[inputs.win_perf_counters.object]]
  210. # Disk times and queues
  211. ObjectName = "LogicalDisk"
  212. Instances = ["*"]
  213. Counters = [
  214. "% Idle Time",
  215. "% Disk Time",
  216. "% Disk Read Time",
  217. "% Disk Write Time",
  218. "% Free Space",
  219. "Current Disk Queue Length",
  220. "Free Megabytes",
  221. ]
  222. Measurement = "win_disk"
  223. # Set to true to include _Total instance when querying for all (*).
  224. #IncludeTotal=false
  225.  
  226. [[inputs.win_perf_counters.object]]
  227. ObjectName = "PhysicalDisk"
  228. Instances = ["*"]
  229. Counters = [
  230. "Disk Read Bytes/sec",
  231. "Disk Write Bytes/sec",
  232. "Current Disk Queue Length",
  233. "Disk Reads/sec",
  234. "Disk Writes/sec",
  235. "% Disk Time",
  236. "% Disk Read Time",
  237. "% Disk Write Time",
  238. ]
  239. Measurement = "win_diskio"
  240.  
  241. [[inputs.win_perf_counters.object]]
  242. ObjectName = "Network Interface"
  243. Instances = ["*"]
  244. Counters = [
  245. "Bytes Received/sec",
  246. "Bytes Sent/sec",
  247. "Packets Received/sec",
  248. "Packets Sent/sec",
  249. "Packets Received Discarded",
  250. "Packets Outbound Discarded",
  251. "Packets Received Errors",
  252. "Packets Outbound Errors",
  253. ]
  254. Measurement = "win_net"
  255.  
  256. [[inputs.win_perf_counters.object]]
  257. ObjectName = "System"
  258. Counters = [
  259. "Context Switches/sec",
  260. "System Calls/sec",
  261. "Processor Queue Length",
  262. "System Up Time",
  263. ]
  264. Instances = ["------"]
  265. Measurement = "win_system"
  266. # Set to true to include _Total instance when querying for all (*).
  267. #IncludeTotal=false
  268.  
  269. [[inputs.win_perf_counters.object]]
  270. # Example query where the Instance portion must be removed to get data back,
  271. # such as from the Memory object.
  272. ObjectName = "Memory"
  273. Counters = [
  274. "Available Bytes",
  275. "Cache Faults/sec",
  276. "Demand Zero Faults/sec",
  277. "Page Faults/sec",
  278. "Pages/sec",
  279. "Transition Faults/sec",
  280. "Pool Nonpaged Bytes",
  281. "Pool Paged Bytes",
  282. "Standby Cache Reserve Bytes",
  283. "Standby Cache Normal Priority Bytes",
  284. "Standby Cache Core Bytes",
  285. ]
  286. # Use 6 x - to remove the Instance bit from the query.
  287. Instances = ["------"]
  288. Measurement = "win_mem"
  289. # Set to true to include _Total instance when querying for all (*).
  290. #IncludeTotal=false
  291.  
  292. [[inputs.win_perf_counters.object]]
  293. # Example query where the Instance portion must be removed to get data back,
  294. # such as from the Paging File object.
  295. ObjectName = "Paging File"
  296. Counters = [
  297. "% Usage",
  298. ]
  299. Instances = ["_Total"]
  300. Measurement = "win_swap"
  301.  
  302.  
  303. # Windows system plugins using WMI (disabled by default, using
  304. # win_perf_counters over WMI is recommended)
  305.  
  306.  
  307. # # Read metrics about cpu usage
  308. [[inputs.cpu]]
  309. # ## Whether to report per-cpu stats or not
  310. percpu = false
  311. # ## Whether to report total system cpu stats or not
  312. totalcpu = true
  313. # ## If true, collect raw CPU time metrics.
  314. collect_cpu_time = false
  315. # ## If true, compute and report the sum of all non-idle CPU states.
  316. # report_active = false
  317.  
  318.  
  319. # # Read metrics about disk usage by mount point
  320. [[inputs.disk]]
  321. # ## By default stats will be gathered for all mount points.
  322. # ## Set mount_points will restrict the stats to only the specified mount points.
  323. # # mount_points = ["/"]
  324. #
  325. # ## Ignore mount points by filesystem type.
  326. # ignore_fs = ["tmpfs", "devtmpfs", "devfs", "overlay", "aufs", "squashfs"]
  327.  
  328.  
  329. # # Read metrics about disk IO by device
  330. [[inputs.diskio]]
  331. # ## By default, telegraf will gather stats for all devices including
  332. # ## disk partitions.
  333. # ## Setting devices will restrict the stats to the specified devices.
  334. # # devices = ["sda", "sdb", "vd*"]
  335. # ## Uncomment the following line if you need disk serial numbers.
  336. # # skip_serial_number = false
  337. # #
  338. # ## On systems which support it, device metadata can be added in the form of
  339. # ## tags.
  340. # ## Currently only Linux is supported via udev properties. You can view
  341. # ## available properties for a device by running:
  342. # ## 'udevadm info -q property -n /dev/sda'
  343. # # device_tags = ["ID_FS_TYPE", "ID_FS_USAGE"]
  344. # #
  345. # ## Using the same metadata source as device_tags, you can also customize the
  346. # ## name of the device via templates.
  347. # ## The 'name_templates' parameter is a list of templates to try and apply to
  348. # ## the device. The template may contain variables in the form of '$PROPERTY' or
  349. # ## '${PROPERTY}'. The first template which does not contain any variables not
  350. # ## present for the device is used as the device name tag.
  351. # ## The typical use case is for LVM volumes, to get the VG/LV name instead of
  352. # ## the near-meaningless DM-0 name.
  353. # # name_templates = ["$ID_FS_LABEL","$DM_VG_NAME/$DM_LV_NAME"]
  354.  
  355.  
  356. # # Read metrics about memory usage
  357. [[inputs.mem]]
  358. # # no configuration
  359.  
  360.  
  361. # # Read metrics about swap memory usage
  362. [[inputs.swap]]
  363. # # no configuration
  364.  
  365. # # Read metrics about swap memory usage
  366. [[inputs.win_services]]
  367. # no configuration
  368.  
  369. '@
  370.  
  371.  
  372. # Infrastructure configuration file
  373. $activedirectoryconf = @'
  374.  
  375. ###############################################################################
  376. # INPUT PLUGINS #
  377. ###############################################################################
  378. [[inputs.win_perf_counters]]
  379. [inputs.win_perf_counters.tags]
  380. monitorgroup = "ActiveDirectory"
  381. [[inputs.win_perf_counters.object]]
  382. ObjectName = "DirectoryServices"
  383. Instances = ["*"]
  384. Counters = ["Base Searches/sec","Database adds/sec","Database deletes/sec","Database modifys/sec","Database recycles/sec","LDAP Client Sessions","LDAP Searches/sec","LDAP Writes/sec"]
  385. Measurement = "win_ad" # Set an alternative measurement to win_perf_counters if wanted.
  386. #Instances = [""] # Gathers all instances by default, specify to only gather these
  387. #IncludeTotal=false #Set to true to include _Total instance when querying for all (*).
  388.  
  389. [[inputs.win_perf_counters.object]]
  390. ObjectName = "Security System-Wide Statistics"
  391. Instances = ["*"]
  392. Counters = ["NTLM Authentications","Kerberos Authentications","Digest Authentications"]
  393. Measurement = "win_ad"
  394. #IncludeTotal=false #Set to true to include _Total instance when querying for all (*).
  395.  
  396. [[inputs.win_perf_counters.object]]
  397. ObjectName = "Database"
  398. Instances = ["*"]
  399. Counters = ["Database Cache % Hit","Database Cache Page Fault Stalls/sec","Database Cache Page Faults/sec","Database Cache Size"]
  400. Measurement = "win_db"
  401. #IncludeTotal=false #Set to true to include _Total instance when querying for all (*).
  402.  
  403. '@
  404.  
  405. $installdir="C:\windows\Temp"
  406.  
  407. # Download the agent zip file
  408. cd $installdir
  409. #set tls to 1.2
  410. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  411. wget https://dl.influxdata.com/telegraf/releases/telegraf-1.14.0_windows_amd64.zip -OutFile telegraf-1.14.0_windows_amd64.zip
  412.  
  413. # Expand Archive into Program Files
  414. Unzip $installdir\telegraf-1.14.0_windows_amd64.zip "C:\Program Files\"
  415.  
  416. # Telegraf agent configuration file
  417. Set-Content -Path 'C:\Program Files\telegraf\telegraf.conf' -Value $telegrafconf
  418.  
  419. # Make the agents conf.d
  420. mkdir 'C:\Program Files\telegraf\conf'
  421.  
  422. # Infrastructure configuration file
  423. Set-Content -Path 'C:\Program Files\telegraf\conf\infrastructure.conf' -Value $infrastructureconf
  424.  
  425. if($service){
  426. if($service -eq "activedirectory"){
  427. # Active Directory configuration file
  428. Set-Content -Path 'C:\Program Files\telegraf\conf\activedirctory.conf' -Value $activedirectoryconf
  429. }
  430. }
  431.  
  432.  
  433. # Install Telegraf Agent
  434. cd "C:\Program Files\telegraf\"
  435. .\telegraf --service install --config-directory 'C:\Program Files\telegraf\conf'
  436.  
  437. # Start Telegraf Agent
  438. net start telegraf
  439.  
Advertisement
Add Comment
Please, Sign In to add comment