Grup 5 - 7 Monitorització del sistema Proxmox

De Wiket
Salta a la navegació Salta a la cerca
Monitorización y Alertas
Instalación de InfluxDB

Añadimos la key de InfluxDB a nuestro sistema:

wget -qO- https://repos.influxdata.com/influxdb.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/influxdb.gpg > /dev/null

Instalamos los repositorios:

export DISTRIB_ID=$(lsb_release -si); export DISTRIB_CODENAME=$(lsb_release -sc)
echo "deb [signed-by=/etc/apt/trusted.gpg.d/influxdb.gpg] https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list > /dev/null

Update y install de InfluxDB

sudo apt-get update && sudo apt-get install influxdb2

Hacemos un start del servicio:

sudo systemctl start influxdb

Lo añadimos al inicio del sistema:

sudo systemctl enable influxdb

(Opcional)Añadimos el modo grafico de InfluxDB

sudo apt install -y influxdb2-cli
Instalación de Telegraf

Primero, en InfluxDB vamos a crear un contenedor, para ello, entramos a InfluxDB --> Data --> Buckets --> Create new bucket

Contenedor

Añadimos el gpg de Telegraf y lo instalamos

wget -qO- https://repos.influxdata.com/influxdb.key | sudo tee /etc/apt/trusted.gpg.d/influxdb.asc >/dev/null
source /etc/os-release
echo "deb https://repos.influxdata.com/${ID} ${VERSION_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo apt-get update && sudo apt-get install telegraf

Comprobamos si Telegraf se ha instalado correctamente y está funcionando:

systemctl status telegraf

Ahora tenemos que ir al archivo de configuración de Telegraf y añadir lo siguiente:

- En el apartado url: la url del servidor InfluxDB (Si se está ejecutando en el mismo host, dejar por defecto)

- En el apartado token: añadir el token del administrador de Influxdb

- En bucket: añadir el contenedor donde irán los datos

- En organization: Añadir el nombre de la organización

En nuestro caso:

# Configuration for sending metrics to InfluxDB
[[outputs.influxdb_v2]]
  ## The URLs of the InfluxDB cluster nodes.
  ##
  ## Multiple URLs can be specified for a single cluster, only ONE of the
  ## urls will be written to each interval.
  ##   ex: urls = ["https://us-west-2-1.aws.cloud2.influxdata.com"]
  urls = ["http://localhost:8086"]

  ## Token for authentication.
  token = "xxx"

  ## Organization is the name of the organization you wish to write to; must exist.
  organization = "yyy"

  ## Destination bucket to write into.
  bucket = "zzz"

  ## The value of this tag will be used to determine the bucket.  If this
  ## tag is not set the 'bucket' option is used as the default.
  # bucket_tag = ""

  ## If true, the bucket tag will not be added to the metric.
  # exclude_bucket_tag = false

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

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

  ## 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"

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

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

  ## Enable or disable uint support for writing uints influxdb 2.0.
  # influx_uint_support = false

  ## 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


Si todo está configurado correctamente, en el apartado explore, veremos lo siguiente:

TelegrafPrueba


Instalación Grafana

Instalación de la ultima versión Enterprise de Grafana:

sudo apt-get install -y apt-transport-https
sudo apt-get install -y software-properties-common wget
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -

Y ahora añadimos el repositorio de la versión estable

echo "deb https://packages.grafana.com/enterprise/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list

Tambén podemos añadir el repositorio de una versión beta pero no es recomendable

echo "deb https://packages.grafana.com/enterprise/deb beta main" | sudo tee -a /etc/apt/sources.list.d/grafana.list

Finalmente hacemos un daemon-reload y un restart y un status para comprobar que todo se ha instalado correctamente

sudo systemctl daemon-reload
sudo systemctl start grafana-server
sudo systemctl status grafana-server

Configuración de Grafana

Nos dirigimos a el apartado de Configuration --> Data sources --> Add data source y añadimos InfluxDB

Add

Configuramos el data source:

Flux1

Para esta parte hay que introducir el nombre de la Organización, el token del admin de influxdb y el contenedor

00px

Si todo ha sido configurado correctamente, al acceder a Exploring y elegir el Data source, tendría que salirnos algo como esto:

Fluxdone

Ahora para hacer que InfluxDB funcione, hay que conectar InfluxQL con InfluxDB, para ello creamos una base de datos y luego la configuramos en Grafana

influx v1 dbrp create --db xxx --rp autogen --bucket-id yyy

Y ahora añadimos un nuevo data source en Grafana

En este caso activaremos el Basic Auth

Fluxql

Aquí ponemos el nombre del administrador de Influxdb y su contraseña

Fluxqladmin

Finalmente añadimos un Header


Header: Authorization

Value: Token "Tu token"

Database: Nombre para la base de datos

User: Usuario InfluxDB

Password: Password Admin InfluxDB

Method: GET

Head


Si todo está configurado correctamente, si vamos a Explore y seleccionamos la conexión, veremos lo siguiente:

Bd

Finalmente vamos a importar una template para tener los graficos, para ello hacemos click en Create --> Import y en micaso añadí la template 10048 que sirve para Proxmox

Visual