Instalación y Configuración de Telegraf para la obtencion de metricas.

Telegraf es un agente multiplataformas que se encarga de recoger datos y enviarlos a la database seleccionada.

Windows

Descargaremos la última versión https://portal.influxdata.com/downloads/, lo descomprimimos y copiamos la carpeta donde deseemos.

La imagen tiene un atributo ALT vacío; su nombre de archivo es imagen-32.png
Ficheros Telegraf

Para instalar telegraf como servicio, ejecutaremos (telegraf.exe --service install --config "path_telegraf.conf") https://github.com/influxdata/telegraf/blob/master/docs/WINDOWS_SERVICE.md

#################################################################################################
#                              		  OUTPUTS                             			#
#################################################################################################
[agent]
  ## Default data collection interval for all inputs
  interval = "600s"
  ## Rounds collection interval to 'interval'
  ## ie, if interval="0s" then always collect on :00, :10, :20, etc.
  round_interval = true

  ## Telegraf will send metrics to outputs in batches of at most
  ## metric_batch_size metrics.
  ## This controls the size of writes that Telegraf sends to output plugins.
  metric_batch_size = 1000

  ## For failed writes, telegraf will cache metric_buffer_limit metrics for each
  ## output, and will flush this buffer on a successful write. Oldest metrics
  ## are dropped first when this buffer fills.
  ## This buffer only fills when writes fail to output plugin(s).
  metric_buffer_limit = 10000

  ## Collection jitter is used to jitter the collection by a random amount.
  ## Each plugin will sleep for a random time within jitter before collecting.
  ## This can be used to avoid many plugins querying things like sysfs at the
  ## same time, which can have a measurable effect on the system.
  collection_jitter = "0s"

  ## Default flushing interval for all outputs. Maximum flush_interval will be
  ## flush_interval + flush_jitter
  flush_interval = "10s"
  ## Jitter the flush interval by a random amount. This is primarily to avoid
  ## large write spikes for users running a large number of telegraf instances.
  ## ie, a jitter of 5s and interval 10s means flushes will happen every 10-15s
  flush_jitter = "0s"

  ## By default or when set to "0s", precision will be set to the same
  ## timestamp order as the collection interval, with the maximum being 1s.
  ##   ie, when interval = "10s", precision will be "1s"
  ##       when interval = "250ms", precision will be "1ms"
  ## Precision will NOT be used for service inputs. It is up to each individual
  ## service input to set the timestamp at the appropriate precision.
  ## Valid time units are "ns", "us" (or "µs"), "ms", "s".
  precision = ""

  ## Logging configuration:
  ## Run telegraf with debug log messages.
  debug = false
  ## Run telegraf in quiet mode (error log messages only).
  quiet = false
  ## Specify the log file name. The empty string means to log to stderr.
  logfile = "/Program Files/Telegraf/telegraf.log"

  ## 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]]
  ## 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://IP_:8086"]  ###*********IP O NOMBRE SERVIDOR INFLUX
  
  ## The target database for metrics; will be created as needed.
  database = "CTX_VDI"
  
  ## HTTP Basic Auth
  username = "VDI"                     ###*********USUARIO DATABASE
  password = "VDI"                     ###*********PASSWORD DATABASE
  
  ## 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 = true
#################################################################################################
#                             		  INPUTS                                    		#
#################################################################################################
#                             		  INPUTS WINDOWS                                    	#
#################################################################################################
  [[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]]
    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"
	
  [[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",
      "Avg. Disk Queue Length",
      "Avg. Disk sec/Read",
      "Avg. Disk sec/Write",
      "Split IO/sec",
    ]
    Measurement = "win_diskio"

Para agregar más counters se agrupa de la siguiente forma.

  [[inputs.win_perf_counters.object]]     # Tipo de objeto counter
    ObjectName = "Paging File"            # Nombre del Objeto
    Counters = [                          # Datos a capturar
      "% Usage",
    ]
    Instances = ["_Total"]                # Instancia
    Measurement = "win_swap"              # Nombre de la tabla en donde guardar los datos.

Para ver los contadores de Windows, ejecutar "Perfmon".

Para ver los contadores usar sistema operativo en inglés.

Linux

Para instalar en Linux ejecutaremos los siguientes comandos.

1. sudo curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
2. source /etc/lsb-release
3. echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
4. apt install telegraf

Los ficheros de configuración de Linux tendrá más contenido que el de Windows, podremos habilitar la captura de datos de Vmware, smtp, dockers, ... y multitud de soluciones en remotos o locales.

Configuración

Podremos ejecutar telegraf con diferentes configuración o comando para cambiar el fichero de configuración o la ruta, ....

  --aggregator-filter <filter>   filter the aggregators to enable, separator is :
  --config <file>                configuration file to load
  --config-directory <directory> directory containing additional *.conf files
  --debug                        turn on debug logging
  --input-filter <filter>        filter the inputs to enable, separator is :
  --input-list                   print available input plugins.
  --output-filter <filter>       filter the outputs to enable, separator is :
  --output-list                  print available output plugins.
  --pidfile <file>               file to write our pid to
  --pprof-addr <address>         pprof address to listen on, don't activate pprof if empty
  --processor-filter <filter>    filter the processors to enable, separator is :
  --quiet                        run in quiet mode
  --sample-config                print out full sample configuration
  --test                         gather metrics, print them out, and exit;
                                 processors, aggregators, and outputs are not run
  --usage <plugin>               print usage for a plugin, ie, 'telegraf --usage mysql'
  --version                      display the version and exit

  --console                      run as console application (windows only)
  --service <service>            operate on the service (windows only)
  --service-name                 service name (windows only)

El fichero de configuración se separa en [Agent] configuración del agente (intervalo de tiempo, log, ...), [output] destino de los datos (influxdb, ElasticSearch, ...) y [Input] datos a capturar (red, disco, CPU, ...).

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *