Comments (3)
The /dev/disk/by-{id,partlabel,partuuid,path,uuid}
directories are created by udev, and thus probably also somewhat variable from one distro to the next (and also not guaranteed to be present at all).
The only entries that are always going to be there are /dev/md[0-9]*
and /sys/block/md[0-9]*
, as these are created by the md kernel modules, and not dependent on any userspace daemon.
from node-exporter-textfile-collector-scripts.
In that case, is it better not to attempt to get the array names at all?
--- md_info_detail.sh.orig 2021-03-31 10:16:25.593118296 +0100
+++ md_info_detail.sh.new 2021-03-31 10:41:01.406242215 +0100
@@ -6,16 +6,12 @@
set -eu
-for MD_DEVICE in /dev/md/*; do
- if [ -b "$MD_DEVICE" ]; then
+for MD_DEVICE_NUM in /dev/md?*; do
+ if [ -b "$MD_DEVICE_NUM" ]; then
# Subshell to avoid eval'd variables from leaking between iterations
(
- # Resolve symlink to discover device, e.g. /dev/md127
- MD_DEVICE_NUM=$(readlink -f "${MD_DEVICE}")
-
# Remove /dev/ prefix
MD_DEVICE_NUM=${MD_DEVICE_NUM#/dev/}
- MD_DEVICE=${MD_DEVICE#/dev/md/}
# Query sysfs for info about md device
SYSFS_BASE="/sys/devices/virtual/block/${MD_DEVICE_NUM}/md"
@@ -64,13 +60,13 @@
if echo "$line" | grep -E -q "Devices :|Array Size :| Used Dev Size :|Events :"; then
MDADM_DETAIL_KEY=$(echo "$line" | cut -d ":" -f 1 | tr -cd '[a-zA-Z0-9]._-')
MDADM_DETAIL_VALUE=$(echo "$line" | cut -d ":" -f 2 | cut -d " " -f 2 | sed 's:^ ::')
- echo "node_md_info_${MDADM_DETAIL_KEY}{md_device=\"${MD_DEVICE_NUM}\", md_name=\"${MD_DEVICE}\", raid_level=\"${MD_LEVEL}\", md_num_raid_disks=\"${MD_NUM_RAID_DISKS}\", md_metadata_version=\"${MD_METADATA_VERSION}\"} ${MDADM_DETAIL_VALUE}"
+ echo "node_md_info_${MDADM_DETAIL_KEY}{md_device=\"${MD_DEVICE_NUM}\", raid_level=\"${MD_LEVEL}\", md_num_raid_disks=\"${MD_NUM_RAID_DISKS}\", md_metadata_version=\"${MD_METADATA_VERSION}\"} ${MDADM_DETAIL_VALUE}"
fi
done <<< "$MDADM_DETAIL_OUTPUT"
# Output RAID detail metrics info from the output of "mdadm --detail"
# NOTE: Sending this info as labels rather than separate metrics, because some of them can be strings.
- echo -n "node_md_info{md_device=\"${MD_DEVICE_NUM}\", md_name=\"${MD_DEVICE}\", raid_level=\"${MD_LEVEL}\", md_num_raid_disks=\"${MD_NUM_RAID_DISKS}\", md_metadata_version=\"${MD_METADATA_VERSION}\""
+ echo -n "node_md_info{md_device=\"${MD_DEVICE_NUM}\", raid_level=\"${MD_LEVEL}\", md_num_raid_disks=\"${MD_NUM_RAID_DISKS}\", md_metadata_version=\"${MD_METADATA_VERSION}\""
while IFS= read -r line ; do
# Filter for lines with a ":", to use for Key/Value pairs in labels
if echo "$line" | grep -E -q ":" ; then
Or else the code could work multiple ways (one where /dev/md exists, one where it doesn't)
from node-exporter-textfile-collector-scripts.
I think that attempting to obtain the array name is ok, so long as it fails gracefully. But obviously the glob pattern at the start of the for-loop should use a more robust / reliable value than /dev/md/*
.
Also I don't think that the lack of a /dev/md
directory has got anything to do with kernel versions, as that was always a userspace function of the mdadm
tool. The man page describes the various scenarios under which it will create the symlinks in the /dev/md
directory. In some ways, this is duplicating the functionality of udev, but IIRC, mdadm predates udev.
from node-exporter-textfile-collector-scripts.
Related Issues (20)
- apt_info.py, security updates, rules and dashboards HOT 5
- nvme_metrics.sh does not write in given file HOT 2
- nvme_metrics.sh does not work at crontab HOT 2
- smartmon scripts: quote in value HOT 20
- smartmon collector missing node info HOT 2
- monitor LVM cache usage
- Issue with smartmon.sh and type cciss
- freeipmi collector? HOT 2
- Is it possible to run apt_info.py inside a container? HOT 1
- apt_info.py can hang for hours HOT 1
- apt info should report cache age HOT 4
- apt cache age computed incorrectly
- storcli: "BBU Status" field not available in HPE MegaRID controller
- apt_info.py - pending_upgrades always empty
- apt_info.py - wrong cache timestamps
- storcli could not extract drive temperature HOT 1
- mellanox_hca_temp: suppress errors when virtual functions present HOT 2
- Add HP RAID Smart Array support for smartmon.sh
- Cant open smartmon.prom HOT 1
- `smartmon.sh` vs. `smartmon.py` HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-exporter-textfile-collector-scripts.