====== Show Static File(Log) in Grafana ======
Grafana cannot show static file(log file etc.) from the file system by native. The example we have currently is we are going to create status logs file for idmsscripts to show some basic info, like if the process running successful or failed. But there are some ways to do it. The way descript below will be using node_exporter to read the file content to show in Grafana.
* Make sure the permission of log directory and log file are all 755, also make sure the location of log directory is open for all the users/groups to read
* Change your log file content format to satisfy node-exporter requirements(https://prometheus.io/docs/instrumenting/exposition_formats/), some examples:
# HELP http_requests_total The total number of HTTP requests.
# TYPE http_requests_total counter
http_requests_total{method="post",code="200"} 1027 1395066363000
http_requests_total{method="post",code="400"} 3 1395066363000
# Escaping in label values:
msdos_file_access_time_seconds{path="C:\\DIR\\FILE.TXT",error="Cannot find file:\n\"FILE.TXT\""} 1.458255915e9
# Minimalistic line:
metric_without_timestamp_and_labels 12.47
* Restart/re-install node_exporter with defining the directory of the log file(https://github.com/prometheus/node_exporter#textfile-collector)
Restart: /path/to/install/dir/node_exporter --collector.textfile.directory=
Re-install: ansible playbooks install-node-exporter.yml under prometheus-monitoring-config to install with cloudalchemy.node-exporter
Install Dependencies: ansible-galaxy install -r requirements.yml
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES #required for MacOS Mojave and higher.
Change var:node_exporter_textfile_dir to be the log dir in install-node-exporter.yml
Run: ansible-playbook -i ../env-configuration/$1/hosts --diff --vault-id @prompt install-node-exporter.yml
More variables of cloudalchemy.node-exporter can be found at https://github.com/cloudalchemy/ansible-node-exporter
* Access node_exporter of the env which hold the log file via url, like http://sfqaapps2.err:10000/metrics, make sure you can find values like below, this mean the textfile has been loaded to node-exporter
node_scrape_collector_success{collector="textfile"} 1
node_scrape_collector_duration_seconds{collector="textfile"} 0.000109648
# HELP node_textfile_scrape_error 1 if there was an error opening or reading a file, 0 otherwise
# TYPE node_textfile_scrape_error gauge
node_textfile_scrape_error 0
* Also, you should be able to see the your variables there as well
* Then, just create Grafana dashboard/panel based on the variables from Prometheus