Differences between telegraph and influx metrics

Hello, thank you for reading me, could you help me?

I am using the telegraf exec plugin to collect information about used disk space.

This is my telegraf.conf

[[inputs.exec]]
  commands = [ "sh /etc/telegraf/telegraf.d/calc_espai_nfs.sh" ]
  interval  = "120s"
  timeout = "240s"
  name_override = "du"
  name_suffix = ""
  data_format = "json"
  tag_keys = [ "path","short_name" ]

This it my script

echo "["
du -bs /mnt/tesi-nfs_tesi61/integra_abaco/* | awk '{if (NR!=1) {printf ",\n"}; short_name = substr($2, index($2, "/mnt/tesi-nfs_tesi61/") + 20); printf "  { \"dir_size\": "$1", \"path\": \""$2"\", \"short_name\": \""short_name"\" }";}'
echo
echo "]"

Both, the script and the plugin debug give me the same information.

Script output:

[
  { "dir_size": 36132652, "path": "/mnt/tesi-nfs_tesi61/integra_abaco/contactos", "short_name": "/integra_abaco/contactos" },
  { "dir_size": 3988352, "path": "/mnt/tesi-nfs_tesi61/integra_abaco/customfiles", "short_name": "/integra_abaco/customfiles" },
  { "dir_size": 33547786000, "path": "/mnt/tesi-nfs_tesi61/integra_abaco/estudios", "short_name": "/integra_abaco/estudios" },
  { "dir_size": 130727580, "path": "/mnt/tesi-nfs_tesi61/integra_abaco/ramdisk", "short_name": "/integra_abaco/ramdisk" },
  { "dir_size": 5051621225, "path": "/mnt/tesi-nfs_tesi61/integra_abaco/recordings", "short_name": "/integra_abaco/recordings" }
]

Plugin output:

telegraf --debug --config /etc/telegraf/telegraf.d/telegraf.conf --input-filter exec --test

2023-09-19T14:26:59Z I! Loading config: /etc/telegraf/telegraf.d/telegraf.conf
> du,host=X,path=/mnt/tesi-nfs_tesi61/integra_abaco/contactos,short_name=/integra_abaco/contactos dir_size=36132652 1695133658000000000
> du,host=X,path=/mnt/tesi-nfs_tesi61/integra_abaco/customfiles,short_name=/integra_abaco/customfiles dir_size=3988352 1695133658000000000
> du,host=X,path=/mnt/tesi-nfs_tesi61/integra_abaco/estudios,short_name=/integra_abaco/estudios dir_size=33547786000 1695133658000000000
> du,host=X,path=/mnt/tesi-nfs_tesi61/integra_abaco/ramdisk,short_name=/integra_abaco/ramdisk dir_size=130727580 1695133658000000000
> du,host=X,path=/mnt/tesi-nfs_tesi61/integra_abaco/recordings,short_name=/integra_abaco/recordings dir_size=5051621225 1695133658000000000

However, when I query the “du” table, the stored metrics regarding size are not correct. As you can see, the sizes are not those obtained by the plugin, but rather what seems to be obtained by executing “ls -h”

Influx metrics

> select * from du;
name: du
time                dir_size host                  path                                           short_name
----                -------- ----                  ----                                           ----------
1695133680000000000 12288    X    /mnt/tesi-nfs_tesi61/integra_abaco/contactos   /integra_abaco/contactos
1695133680000000000 4096     X    /mnt/tesi-nfs_tesi61/integra_abaco/recordings  /integra_abaco/recordings
1695133680000000000 4096     X    /mnt/tesi-nfs_tesi61/integra_abaco/customfiles /integra_abaco/customfiles
1695133680000000000 12288    X    /mnt/tesi-nfs_tesi61/integra_abaco/ramdisk     /integra_abaco/ramdisk

image

Does anyone know why is this happening or how I could separate it?

Thank you very much

Are you testing with the same user as when telegraf is running as a service? Probably just a permissions issue for the user running telegraf…

1 Like

Hello, when telegraf is run as a service, it is configured like this:

[Unit]
Description=Telegraf
Documentation=https://github.com/influxdata/telegraf
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
EnvironmentFile=-/etc/default/telegraf
User=telegraf
ExecStart=/usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d $TELEGRAF_OPTS
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartForceExitStatus=SIGPIPE
KillMode=mixed
TimeoutStopSec=5
LimitMEMLOCK=8M:8M

[Install]
WantedBy=multi-user.target

When I have directly executed the script, I have done it as root, therefore telegraf does not have a shell on my system:

telegraf:x:998:998::/etc/telegraf:/bin/false

Okay, so can you run the command as telegraf user and then also telegraf —test as telegraf user.

1 Like

Hello!

You were right, I enabled a shell for the telegraf user and I saw the error, it is funny that by not being able to do the “du” it put the inode values.

Thank you so much.

No need to enable a shell when you can do it with sudo -u telegraf COMMAND, right?

I enabled it to directly do with the telegraf user the du command

Hello, I modified the script so that it also wrote a log with the times and possible errors and I have errors again.

I have given 777 permissions to the entire directory structure involved in the creation of the “log file” and I still get this error.

2023-09-26T07:48:00Z E! [inputs.exec] Error in plugin: exec: exit status 1 for command "sh /etc/telegraf/telegraf.d/calc_espai_nfs.sh": /etc/telegraf/telegraf.d/calc_espai_nfs.sh: 27: cannot create calc_espai_nfs.log: Permission denied...

This is working:

sudo -u telegraf COMMAND

image

But when it is executed by the telegraf.service directly, it does not

Can you try this?

sudo -u telegraf telegraf --debug --test --config telegraf.conf

The log file seems already created, maybe telegraf user is not allowed to read/write to it?
What does ls -l calc_espai_nfs.log say?

Also, it seems like you are running the script directly from the command line, but in telegraf config you prefix it with sh?

Thank you for your quick answer

sudo -u telegraf telegraf --debug --test --config telegraf.conf

2023-09-26T08:21:14Z I! Loading config: telegraf.conf
> mem,host=tesi61.tesintegra.net active=619032576i,available=2980229120i,available_percent=72.30175757280657,buffered=66613248i,cached=2733998080i,commit_limit=6355927040i,committed_as=1813954560i,dirty=667648i,free=612163584i,high_free=0i,high_total=0i,huge_page_size=2097152i,huge_pages_free=0i,huge_pages_total=0i,inactive=460742656i,low_free=0i,low_total=0i,mapped=226324480i,page_tables=13127680i,shared=19435520i,slab=2259546112i,sreclaimable=2025820160i,sunreclaim=233725952i,swap_cached=51429376i,swap_free=4153503744i,swap_total=4294963200i,total=4121931776i,used=709156864i,used_percent=17.204478446952344,vmalloc_chunk=0i,vmalloc_total=35184372087808i,vmalloc_used=45043712i,write_back=0i,write_back_tmp=0i 1695716475000000000
> swap,host=tesi61.tesintegra.net free=4153503744i,total=4294963200i,used=141459456i,used_percent=3.2936127601745224 1695716475000000000
> swap,host=tesi61.tesintegra.net in=9398853632i,out=16377540608i 1695716475000000000
> kernel,host=tesi61.tesintegra.net boot_time=1679077373i,context_switches=38404494425i,entropy_avail=256i,interrupts=23458499989i,processes_forked=41959284i 1695716475000000000
> system,host=tesi61.tesintegra.net load1=0.61,load15=0.45,load5=0.36,n_cpus=4i,n_unique_users=1i,n_users=2i 1695716475000000000
> system,host=tesi61.tesintegra.net uptime=16639101i 1695716475000000000
> system,host=tesi61.tesintegra.net uptime_format="192 days, 13:58" 1695716475000000000
> disk,device=dm-0,fstype=ext4,host=tesi61.tesintegra.net,label=tesi--vg-root,mode=rw,path=/ free=6878404608i,inodes_free=2667130i,inodes_total=3186688i,inodes_used=519558i,total=51001221120i,used=41498861568i,used_percent=85.78174181447983 1695716475000000000
> disk,device=tesi-nfs.local:/tesi-nfs/tesi61,fstype=nfs4,host=tesi61.tesintegra.net,mode=rw,path=/mnt/tesi-nfs_tesi61 free=251710144512i,inodes_free=248233222i,inodes_total=273416192i,inodes_used=25182970i,total=4408182571008i,used=3948903137280i,used_percent=94.00777630249696 1695716475000000000
> disk,device=tesi-nfs.local:/tesi-nfs/tesi61/integra_eorandom/recordings/archive,fstype=nfs4,host=tesi61.tesintegra.net,mode=rw,path=/home/sftp/ftp_random/archivos/recordings free=251710144512i,inodes_free=248233222i,inodes_total=273416192i,inodes_used=25182970i,total=4408182571008i,used=3948903137280i,used_percent=94.00777630249696 1695716475000000000
> disk,device=dm-0,fstype=ext4,host=tesi61.tesintegra.net,label=tesi--vg-root,mode=rw,path=/home/sftp/ftp_conectarc/archivos free=6878404608i,inodes_free=2667130i,inodes_total=3186688i,inodes_used=519558i,total=51001221120i,used=41498861568i,used_percent=85.78174181447983 1695716475000000000
> disk,device=dm-0,fstype=ext4,host=tesi61.tesintegra.net,label=tesi--vg-root,mode=rw,path=/home/sftp/ftp_conectarc/archivos free=6878404608i,inodes_free=2667130i,inodes_total=3186688i,inodes_used=519558i,total=51001221120i,used=41498861568i,used_percent=85.78174181447983 1695716475000000000
> disk,device=dm-0,fstype=ext4,host=tesi61.tesintegra.net,label=tesi--vg-root,mode=rw,path=/home/integra_conectarc/repsol free=6878404608i,inodes_free=2667130i,inodes_total=3186688i,inodes_used=519558i,total=51001221120i,used=41498861568i,used_percent=85.78174181447983 1695716475000000000
> disk,device=tesi-nfs.local:/tesi-nfs/tesi61/integra_opinometre/recordings/archive,fstype=nfs4,host=tesi61.tesintegra.net,mode=rw,path=/home/sftp/ftp_opinometre/archivos free=251710144512i,inodes_free=248233222i,inodes_total=273416192i,inodes_used=25182970i,total=4408182571008i,used=3948903137280i,used_percent=94.00777630249696 1695716475000000000
> diskio,host=tesi61.tesintegra.net,name=sda io_time=112956664i,iops_in_progress=0i,merged_reads=7481653i,merged_writes=135495675i,read_bytes=1373663062016i,read_time=28598385i,reads=41371328i,weighted_io_time=211420513i,write_bytes=1991526020096i,write_time=182822127i,writes=181109077i 1695716475000000000
> diskio,host=tesi61.tesintegra.net,name=sda5 io_time=112951084i,iops_in_progress=0i,merged_reads=7476254i,merged_writes=135494473i,read_bytes=1373521810432i,read_time=28595921i,reads=41364201i,weighted_io_time=211411587i,write_bytes=1991223558144i,write_time=182815666i,writes=181107803i 1695716475000000000
> diskio,host=tesi61.tesintegra.net,name=loop5 io_time=88568i,iops_in_progress=0i,merged_reads=0i,merged_writes=0i,read_bytes=632537088i,read_time=11879i,reads=69369i,weighted_io_time=11879i,write_bytes=0i,write_time=0i,writes=0i 1695716475000000000
> diskio,host=tesi61.tesintegra.net,name=loop6 io_time=2048i,iops_in_progress=0i,merged_reads=0i,merged_writes=0i,read_bytes=6075392i,read_time=224i,reads=1850i,weighted_io_time=224i,write_bytes=0i,write_time=0i,writes=0i 1695716475000000000
> diskio,host=tesi61.tesintegra.net,name=loop8 io_time=60108i,iops_in_progress=0i,merged_reads=0i,merged_writes=0i,read_bytes=610458624i,read_time=7669i,reads=17002i,weighted_io_time=7669i,write_bytes=0i,write_time=0i,writes=0i 1695716475000000000
> diskio,host=tesi61.tesintegra.net,name=sda1 io_time=3920i,iops_in_progress=0i,merged_reads=5399i,merged_writes=1202i,read_bytes=68596736i,read_time=996i,reads=3293i,weighted_io_time=7458i,write_bytes=302461952i,write_time=6461i,writes=1274i 1695716475000000000

I have a lot of metrics in this server.

ls -l calc_espai_nfs.log

image

And yes this is my config file:

image

This is not the complete output of telegraf test. I also see no sign of inputs.exec in the logs. Is that the correct config file being loaded? Maybe test with a file only having the inputs.exec config in it, to reduce other outputs…

So yeah, why is the sh in your config, but when you test you do sudo -u telegraf . /calc_espai_nfs.sh, so without the extra sh?

Oh sorry, this is the full output:

2023-09-26T08:37:08Z I! Loading config: telegraf.conf
> kernel,host=tesi61.tesintegra.net boot_time=1679077373i,context_switches=38413313188i,entropy_avail=256i,interrupts=23467132502i,processes_forked=41962079i 1695717428000000000
> diskio,host=tesi61.tesintegra.net,name=loop0 io_time=255544i,iops_in_progress=0i,merged_reads=0i,merged_writes=0i,read_bytes=1763862528i,read_time=31834i,reads=195496i,weighted_io_time=31834i,write_bytes=0i,write_time=0i,writes=0i 1695717428000000000
> diskio,host=tesi61.tesintegra.net,name=loop2 io_time=212152i,iops_in_progress=0i,merged_reads=0i,merged_writes=0i,read_bytes=2155347968i,read_time=16310i,reads=59480i,weighted_io_time=16310i,write_bytes=0i,write_time=0i,writes=0i 1695717428000000000
> swap,host=tesi61.tesintegra.net free=4149952512i,total=4294963200i,used=145010688i,used_percent=3.37629640226021 1695717428000000000
> swap,host=tesi61.tesintegra.net in=9400758272i,out=16383938560i 1695717428000000000
> diskio,host=tesi61.tesintegra.net,name=loop4 io_time=67912i,iops_in_progress=0i,merged_reads=0i,merged_writes=0i,read_bytes=747206656i,read_time=6653i,reads=19561i,weighted_io_time=6653i,write_bytes=0i,write_time=0i,writes=0i 1695717428000000000
> diskio,host=tesi61.tesintegra.net,name=dm-0 io_time=113000096i,iops_in_progress=0i,merged_reads=0i,merged_writes=0i,read_bytes=1373212722176i,read_time=35202400i,reads=48685553i,weighted_io_time=381827592i,write_bytes=1991347560448i,write_time=346625192i,writes=316355354i 1695717428000000000
> diskio,host=tesi61.tesintegra.net,name=sda2 io_time=48i,iops_in_progress=0i,merged_reads=0i,merged_writes=0i,read_bytes=12288i,read_time=2i,reads=12i,weighted_io_time=2i,write_bytes=0i,write_time=0i,writes=0i 1695717428000000000
> mem,host=tesi61.tesintegra.net active=579125248i,available=2934034432i,available_percent=71.18105275500804,buffered=50683904i,cached=3007406080i,commit_limit=6355927040i,committed_as=1835827200i,dirty=1470464i,free=383488000i,high_free=0i,high_total=0i,huge_page_size=2097152i,huge_pages_free=0i,huge_pages_total=0i,inactive=459018240i,low_free=0i,low_total=0i,mapped=218107904i,page_tables=13307904i,shared=18034688i,slab=2534764544i,sreclaimable=2298347520i,sunreclaim=236417024i,swap_cached=50200576i,swap_free=4149952512i,swap_total=4294963200i,total=4121931776i,used=680353792i,used_percent=16.505702398117517,vmalloc_chunk=0i,vmalloc_total=35184372087808i,vmalloc_used=44896256i,write_back=0i,write_back_tmp=0i 1695717428000000000
> diskio,host=tesi61.tesintegra.net,name=sda5 io_time=112961532i,iops_in_progress=0i,merged_reads=7477225i,merged_writes=135505983i,read_bytes=1373689394176i,read_time=28599292i,reads=41370153i,weighted_io_time=211424578i,write_bytes=1991347560448i,write_time=182825285i,writes=181121132i 1695717428000000000
> diskio,host=tesi61.tesintegra.net,name=loop6 io_time=2048i,iops_in_progress=0i,merged_reads=0i,merged_writes=0i,read_bytes=6075392i,read_time=224i,reads=1850i,weighted_io_time=224i,write_bytes=0i,write_time=0i,writes=0i 1695717428000000000
> diskio,host=tesi61.tesintegra.net,name=loop7 io_time=66088i,iops_in_progress=0i,merged_reads=0i,merged_writes=0i,read_bytes=527387648i,read_time=8573i,reads=37705i,weighted_io_time=8573i,write_bytes=0i,write_time=0i,writes=0i 1695717428000000000
> diskio,host=tesi61.tesintegra.net,name=loop8 io_time=60108i,iops_in_progress=0i,merged_reads=0i,merged_writes=0i,read_bytes=610458624i,read_time=7669i,reads=17002i,weighted_io_time=7669i,write_bytes=0i,write_time=0i,writes=0i 1695717428000000000
> diskio,host=tesi61.tesintegra.net,name=sda io_time=112967112i,iops_in_progress=0i,merged_reads=7482624i,merged_writes=135507185i,read_bytes=1373830645760i,read_time=28601756i,reads=41377280i,weighted_io_time=211433503i,write_bytes=1991650022400i,write_time=182831747i,writes=181122406i 1695717428000000000
> diskio,host=tesi61.tesintegra.net,name=loop5 io_time=88568i,iops_in_progress=0i,merged_reads=0i,merged_writes=0i,read_bytes=632537088i,read_time=11879i,reads=69369i,weighted_io_time=11879i,write_bytes=0i,write_time=0i,writes=0i 1695717428000000000
> diskio,host=tesi61.tesintegra.net,name=sda1 io_time=3920i,iops_in_progress=0i,merged_reads=5399i,merged_writes=1202i,read_bytes=68596736i,read_time=996i,reads=3293i,weighted_io_time=7458i,write_bytes=302461952i,write_time=6461i,writes=1274i 1695717428000000000
> disk,device=dm-0,fstype=ext4,host=tesi61.tesintegra.net,label=tesi--vg-root,mode=rw,path=/ free=6853730304i,inodes_free=2667100i,inodes_total=3186688i,inodes_used=519588i,total=51001221120i,used=41523535872i,used_percent=85.83274573832752 1695717428000000000
> disk,device=tesi-nfs.local:/tesi-nfs/tesi61,fstype=nfs4,host=tesi61.tesintegra.net,mode=rw,path=/mnt/tesi-nfs_tesi61 free=248974409728i,inodes_free=248208823i,inodes_total=273416192i,inodes_used=25207369i,total=4408182571008i,used=3951638872064i,used_percent=94.07290333515809 1695717428000000000
> disk,device=tesi-nfs.local:/tesi-nfs/tesi61/integra_eorandom/recordings/archive,fstype=nfs4,host=tesi61.tesintegra.net,mode=rw,path=/home/sftp/ftp_random/archivos/recordings free=248974409728i,inodes_free=248208823i,inodes_total=273416192i,inodes_used=25207369i,total=4408182571008i,used=3951638872064i,used_percent=94.07290333515809 1695717428000000000
> diskio,host=tesi61.tesintegra.net,name=loop1 io_time=55824i,iops_in_progress=0i,merged_reads=0i,merged_writes=0i,read_bytes=589588480i,read_time=5232i,reads=16431i,weighted_io_time=5232i,write_bytes=0i,write_time=0i,writes=0i 1695717428000000000
> system,host=tesi61.tesintegra.net load1=0.15,load15=0.49,load5=0.41,n_cpus=4i,n_unique_users=1i,n_users=2i 1695717428000000000
> system,host=tesi61.tesintegra.net uptime=16640055i 1695717428000000000
> disk,device=dm-0,fstype=ext4,host=tesi61.tesintegra.net,label=tesi--vg-root,mode=rw,path=/home/sftp/ftp_conectarc/archivos free=6853730304i,inodes_free=2667100i,inodes_total=3186688i,inodes_used=519588i,total=51001221120i,used=41523535872i,used_percent=85.83274573832752 1695717428000000000
> system,host=tesi61.tesintegra.net uptime_format="192 days, 14:14" 1695717428000000000
> diskio,host=tesi61.tesintegra.net,name=loop3 io_time=98224i,iops_in_progress=0i,merged_reads=0i,merged_writes=0i,read_bytes=1018474496i,read_time=7443i,reads=28824i,weighted_io_time=7443i,write_bytes=0i,write_time=0i,writes=0i 1695717428000000000
> disk,device=dm-0,fstype=ext4,host=tesi61.tesintegra.net,label=tesi--vg-root,mode=rw,path=/home/sftp/ftp_conectarc/archivos free=6853730304i,inodes_free=2667100i,inodes_total=3186688i,inodes_used=519588i,total=51001221120i,used=41523535872i,used_percent=85.83274573832752 1695717428000000000
> diskio,host=tesi61.tesintegra.net,name=loop9 io_time=44i,iops_in_progress=0i,merged_reads=0i,merged_writes=0i,read_bytes=79872i,read_time=4i,reads=57i,weighted_io_time=4i,write_bytes=0i,write_time=0i,writes=0i 1695717428000000000
> disk,device=dm-0,fstype=ext4,host=tesi61.tesintegra.net,label=tesi--vg-root,mode=rw,path=/home/integra_conectarc/repsol free=6853730304i,inodes_free=2667100i,inodes_total=3186688i,inodes_used=519588i,total=51001221120i,used=41523535872i,used_percent=85.83274573832752 1695717428000000000
> disk,device=tesi-nfs.local:/tesi-nfs/tesi61/integra_opinometre/recordings/archive,fstype=nfs4,host=tesi61.tesintegra.net,mode=rw,path=/home/sftp/ftp_opinometre/archivos free=248974409728i,inodes_free=248208823i,inodes_total=273416192i,inodes_used=25207369i,total=4408182571008i,used=3951638872064i,used_percent=94.07290333515809 1695717428000000000
> diskio,host=tesi61.tesintegra.net,name=sr0 io_time=32i,iops_in_progress=0i,merged_reads=0i,merged_writes=0i,read_bytes=2560i,read_time=1i,reads=19i,weighted_io_time=1i,write_bytes=0i,write_time=0i,writes=0i 1695717428000000000
> processes,host=tesi61.tesintegra.net blocked=0i,dead=0i,idle=92i,paging=0i,running=0i,sleeping=211i,stopped=0i,total=304i,total_threads=377i,unknown=0i,zombies=1i 1695717428000000000
> cpu,cpu=cpu0,host=tesi61.tesintegra.net usage_guest=0,usage_guest_nice=0,usage_idle=97.95918372001613,usage_iowait=0,usage_irq=0,usage_nice=0,usage_softirq=0,usage_steal=0,usage_system=2.040816324530557,usage_user=0 1695717429000000000
> cpu,cpu=cpu1,host=tesi61.tesintegra.net usage_guest=0,usage_guest_nice=0,usage_idle=93.87755116004837,usage_iowait=0,usage_irq=0,usage_nice=0,usage_softirq=0,usage_steal=0,usage_system=2.040816324530557,usage_user=4.081632655000671 1695717429000000000
> cpu,cpu=cpu2,host=tesi61.tesintegra.net usage_guest=0,usage_guest_nice=0,usage_idle=100,usage_iowait=0,usage_irq=0,usage_nice=0,usage_softirq=0,usage_steal=0,usage_system=0,usage_user=0 1695717429000000000
> cpu,cpu=cpu3,host=tesi61.tesintegra.net usage_guest=0,usage_guest_nice=0,usage_idle=96.00000008940697,usage_iowait=0,usage_irq=0,usage_nice=0,usage_softirq=0,usage_steal=0,usage_system=2.000000001862645,usage_user=2.000000001862645 1695717429000000000
> cpu,cpu=cpu-total,host=tesi61.tesintegra.net usage_guest=0,usage_guest_nice=0,usage_idle=96.9543145979445,usage_iowait=0,usage_irq=0,usage_nice=0,usage_softirq=0,usage_steal=0,usage_system=1.522842641933674,usage_user=1.5228426301148594 1695717429000000000

Well I changed it without the extra sh but it keeps telling me that permission is denied

2023-09-26T08:37:08Z I! Loaded processors:
2023-09-26T08:37:08Z I! Loaded secretstores:
2023-09-26T08:37:08Z W! Outputs are not used in testing mode!
2023-09-26T08:37:08Z I! Tags enabled: host=tesi61.tesintegra.net
2023-09-26T08:37:08Z D! [agent] Initializing plugins
2023-09-26T08:37:08Z D! [agent] Starting service inputs
2023-09-26T08:37:08Z E! [inputs.exec] Error in plugin: exec: fork/exec ./etc/telegraf/telegraf.d/calc_espai_nfs.sh: no such file or directory for command "./etc/telegraf/telegraf.d/calc_espai_nfs.sh":
2023-09-26T08:37:08Z D! [inputs.disk] [SystemPS] => unable to get disk usage ("/sys/kernel/debug/tracing"): permission denied
2023-09-26T08:37:08Z D! [agent] Stopping service inputs
2023-09-26T08:37:08Z D! [agent] Input channel closed
2023-09-26T08:37:08Z D! [agent] Stopped Successfully
2023-09-26T08:37:08Z E! [telegraf] Error running agent: input plugins recorded 1 errors
2023-09-26T08:38:00Z E! [inputs.exec] Error in plugin: exec: exit status 1 for command "./etc/telegraf/telegraf.d/calc_espai_nfs.sh": ./etc/telegraf/telegraf.d/calc_espai_nfs.sh: línea 27: calc_espai_nfs.log: Permiso denegado...
2023-09-26T08:38:01Z E! [outputs.influxdb] When writing to [http://localhost:8086]: failed doing req: Post "http://localhost:8086/write?db=telegraf": dial tcp [::1]:8086: connect: connection refused
2023-09-26T08:38:01Z E! [agent] Error writing to outputs.influxdb: could not write any address
2023-09-26T08:39:01Z E! [outputs.influxdb] When writing to [http://localhost:8086]: failed doing req: Post "http://localhost:8086/write?db=telegraf": dial tcp [::1]:8086: connect: connection refused
2023-09-26T08:39:01Z E! [agent] Error writing to outputs.influxdb: could not write any address
2023-09-26T08:40:00Z E! [inputs.exec] Error in plugin: exec: exit status 1 for command "./etc/telegraf/telegraf.d/calc_espai_nfs.sh": ./etc/telegraf/telegraf.d/calc_espai_nfs.sh: línea 27: calc_espai_nfs.log: Permiso denegado...
2023-09-26T08:40:01Z E! [outputs.influxdb] When writing to [http://localhost:8086]: failed doing req: Post "http://localhost:8086/write?db=telegraf": dial tcp [::1]:8086: connect: connection refused
2023-09-26T08:40:01Z E! [agent] Error writing to outputs.influxdb: could not write any address

This is still not the complete output, but we are getting a bit closer… The command is still wrong, there seems to be a . before, please make it an actual absolute path.

I believe it represents the complete output of the command :confused:

sudo -u telegraf telegraf --debug --test --config telegraf.conf

About the dot it’s true, I have removed it

Now the log shows this, I think we are getting closer yes

2023-09-26T08:59:51Z I! Tags enabled: host=tesi61.tesintegra.net
2023-09-26T08:59:51Z D! [agent] Initializing plugins
2023-09-26T08:59:51Z D! [agent] Starting service inputs
2023-09-26T08:59:51Z D! [inputs.disk] [SystemPS] => unable to get disk usage ("/sys/kernel/debug/tracing"): permission denied
2023-09-26T09:02:11Z D! [agent] Stopping service inputs
2023-09-26T09:02:11Z D! [agent] Input channel closed
2023-09-26T09:02:11Z D! [agent] Stopped Successfully

And this

2023-09-26T09:25:37Z E! [inputs.exec] Error in plugin: exec: exit status 1 for command "/etc/telegraf/telegraf.d/calc_espai_nfs.sh": /etc/telegraf/telegraf.d/calc_espai_nfs.sh: línea 28: calc_espai_nfs.log: Permiso denegado...

But calc_espai_nfs.log has permissions:

image

I believe it represents the complete output of the command :confused:

Weird that your version of telegraf randomly gives other debug and informational messages. I would expect more (and consistent) messages at the beginning of the command.

/etc/telegraf/telegraf.d/calc_espai_nfs.sh: línea 28: calc_espai_nfs.log: Permiso denegado…

Why is it suddenly in a different language? It seems like testing is not always done with the same commands/parameters/environment?
Anyway, does your script write to the file with a relative path or absolute path?

I guess the language is because my script has “echos” in Spanish and uses a relative path, I just changed it to see if that’s how it works:

#!/bin/bash
# Author: Maria Bacete
# Date: 19/09/2023
# Comentarios:
#       +  El script calcula el espacio utilizado por las instalaciones en el disco NFS y le da formato JSON para que pueda ser utilizado por Telegraf/InfluxDB

# VARIABLES SCRIPT
log="/etc/telegraf/telegraf.d/calc_espai_nfs.log"
log2="/etc/telegraf/telegraf.d/calc_espai_nfs_aux.log"
usuario="$(whoami)"
ruta_script="$(readlink -f "$0")"

# FUNCIONES
hora_actual() {
    echo $(date '+%F %T')
}


#Comprobar que el archivo de log exista con los permisos correctos
# EXISTE
if [ -e "$log" ]; then 

    permisos=$(stat -c "%a" "$log")
	grupo_log=$(stat -c %G "$log")

	# PERMISOS MAL
	if [ "$permisos" -ne 664 ] ; then
	
		echo >> "$log"
		# Registrar el nombre de usuario que está ejecutando el script
		echo -e "Script $ruta_script executat per: $usuario \n"  >> "$log"
	  
		echo "El fitxer de log no té els permisos i/o grup propietari adecuats"  >> "$log"
        echo "$(hora_actual) -- chmod 664 "$log"" >> "$log"
        chmod 664 "$log"
		
		if [ "$?" -ne 0 ]; then
			echo "$(hora_actual) -- No s'han pogut canviar els permissos de "$log"" >> "$log2"
			echo -e "$(hora_actual) -- S'ha abortat l'script \n " >> "$log2"
			exit 1
		fi
	elif [ "$grupo_log" != "telegraf" ]; then
	
		echo >> "$log"
		# Registrar el nombre de usuario que está ejecutando el script
		echo -e "Script $ruta_script executat per: $usuario \n"  >> "$log"
		
		echo -e "$(hora_actual) -- chgrp telegraf "$log" \n" >> "$log"
		chgrp telegraf "$log"
		
		if [ "$?" -ne 0 ]; then
			echo "$(hora_actual) -- No s'ha pogut canviar el grup propietari de "$log"" >> "$log2"
			echo -e "$(hora_actual) -- S'ha abortat l'script \n " >> "$log2"
			exit 1
		fi
	else #PERMISOS OK
		echo >> "$log"
		# Registrar el nombre de usuario que está ejecutando el script
		echo -e "$(hora_actual) -- Script $ruta_script executat per: $usuario \n"  >> "$log"	
    fi
# NO EXISTE
else
	echo >> "$log"
	
	# Registrar el nombre de usuario que está ejecutando el script
	echo -e "$(hora_actual) -- Script $ruta_script executat per: $usuario \n"  >> "$log"
	
	echo "El fitxer de log no existeix"  >> "$log"
	echo "$(hora_actual) -- touch "$log"" >> "$log"
	touch "$log"
	if [ "$?" -ne 0 ]; then
		echo "$(hora_actual) -- No s'ha pogut crear l'arxiu "$log"" >> "$log"
		exit 1
	fi
	echo "$(hora_actual) -- chmod 664 "$log"" >> "$log"
    chmod 664 "$log" 
	if [ "$?" -ne 0 ]; then
		echo "$(hora_actual) -- No s'han pogut canviar els permissos de "$log"" >> "$log"
		exit 1
	fi
	echo -e "$(hora_actual) -- chgrp telegraf "$log" \n" >> "$log"
	chgrp telegraf "$log"
	if [ "$?" -ne 0 ]; then
		echo "$(hora_actual) -- No s'ha pogut canviar el grupo propietari de "$log"" >> "$log"
		exit 1
	fi	
		
fi


#Calcular el espacio en disco ocupado por las instalaciones en el disco NFS
echo -e "$(hora_actual) -- INICIE SCRIPT: \n" >> "$log"
hora_inicio="$(hora_actual)"
echo -e "$(hora_actual) -- du -bs /mnt/tesi-nfs_tesi61/* | awk '{if (NR != 1) {printf \",\\n\"}; short_name = substr(\$2, index(\$2, \"/mnt/tesi-nfs_tesi61/\") + 20); printf \"  { \\\"dir_size\\\": \"\$1\", \\\"path\\\": \\\"\$2\\\", \\\"short_name\\\": \\\"\"short_name\"\\\" }\";}' \n" >> "$log"

du_output=$(du -bs /mnt/tesi-nfs_tesi61/* 2>&1)

if [ "$?" -ne 0 ]; then # DU ERROR
    echo -e "$(hora_actual) -- Error al calcular l'espai:\n$du_output " >> "$log"
	hora_fin="$(hora_actual)"
	# Calcular la diferencia de tiempo en segundos
	hora_inicio_seg=$(date -d "$hora_inicio" +%s)
	hora_fin_seg=$(date -d "$hora_fin" +%s)
	duracion_seg=$((hora_fin_seg - hora_inicio_seg))
	# Convertir la duración de segundos a un formato HH:MM:SS
	duracion_hms=$(date -u -d "@$duracion_seg" +"%H:%M:%S")

	# Mostrar la duración en el log
	echo "El script ha tardar $duracion_hms en executar-se" >> "$log"
	echo "$hora -- FI SCRIPT: " >> "$log"
	echo "=============================================================================== " >> "$log"
    exit 1
else  # DU OK
	echo -e "$(hora_actual) -- RESULTAT: " >> "$log"
	echo "[" >> "$log"
    echo "$du_output" | awk '{if (NR != 1) {printf ",\n"}; short_name = substr($2, index($2, "/mnt/tesi-nfs_tesi61/") + 20); printf "  { \"dir_size\": "$1", \"path\": \""$2"\", \"short_name\": \""short_name"\" }";}' >> "$log"
	echo >> "$log"
	echo "]"  >> "$log"
	
	hora_fin="$(hora_actual)"
	# Calcular la diferencia de tiempo en segundos
	hora_inicio_seg=$(date -d "$hora_inicio" +%s)
	hora_fin_seg=$(date -d "$hora_fin" +%s)
	duracion_seg=$((hora_fin_seg - hora_inicio_seg))
	# Convertir la duración de segundos a un formato HH:MM:SS
	duracion_hms=$(date -u -d "@$duracion_seg" +"%H:%M:%S")

	# Mostrar la duración en el log
	echo "El script ha tardar $duracion_hms en executar-se" >> "$log"
	echo "$hora -- FI SCRIPT: " >> "$log"
	echo "=============================================================================== " >> "$log"
fi

#Fi script