Kubernetes - Failed to read textfile collector directory

23 views
Skip to first unread message

rohith vallabhaneni

unread,
Jan 21, 2021, 4:15:28 AM1/21/21
to Prometheus Users
Hi 

I have a kubernetes cluster running in Amazon EKS, we are using the prometheus node-exporter docker image and running it as daemonset across all k8s nodes to fetch the node metrics. We had a use case to monitor the docker volumes usage on each node, I have written a shell script to fetch the data in the prometheus readable format

```
#! /bin/bash

voulume_size=`df -Ph /var/lib/docker | awk '{if(NR>1)print $2}' | sed 's/G//g'`
voulume_usage=`df -Ph /var/lib/docker | awk '{if(NR>1)print $5}' | sed 's/%//g'`

`mkdir -p /home/ec2-user/node_exporter/textfile_collector`
`rm -f /home/ec2-user/node_exporter/textfile_collector/docker_volume.prom`

echo "# HELP _docker_volume_usage hostip usage." >> /home/ec2-user/node_exporter/textfile_collector/docker_volume.prom 2>&1
echo "# TYPE _docker_volume_usage gauge" >> /home/ec2-user/node_exporter/textfile_collector/docker_volume.prom 2>&1

echo "_docker_volume_usage{hostip=\"$hostip\",host=\"`hostname`\"} $voulume_usage" >> /home/ec2-user/node_exporter/textfile_collector/docker_volume.prom 2>&1


echo "# HELP _docker_volume_size hostip size." >> /home/ec2-user/node_exporter/textfile_collector/docker_volume.prom 2>&1
echo "# TYPE _docker_volume_size gauge" >> /home/ec2-user/node_exporter/textfile_collector/docker_volume.prom 2>&1

echo "_docker_volume_size{hostip=\"$hostip\",host=\"`hostname`\"} $voulume_size" >> /home/ec2-user/node_exporter/textfile_collector/docker_volume.prom 2>&1
```

I'm running the script on each node and adding the data to
/home/ec2-user/node_exporter/textfile_collector/docker_volume.prom file.

On the docker logs I see the below ERROR:
```
level=error ts=2021-01-21T08:44:45.125Z caller=textfile.go:197 collector=textfile msg="failed to read textfile collector directory" path=/home/ec2-user/node_exporter/textfile_collector err="open /home/ec2-user/node_exporter/textfile_collector: no such file or directory"
```
Let me know where am I going wrong, I now had a doubt that whether the textfile-collector from the docker container colect data from the node in which the container is running! 

Any help over here would be appreciated.
Thanks,
Rohith Vallabhaneni.
Reply all
Reply to author
Forward
0 new messages