GithubHelp home page GithubHelp logo

md_info.sh / md_info_detail.sh: /dev/md/ directory does not exist on newer kernels about node-exporter-textfile-collector-scripts HOT 3 OPEN

prometheus-community avatar prometheus-community commented on June 9, 2024 1
md_info.sh / md_info_detail.sh: /dev/md/ directory does not exist on newer kernels

from node-exporter-textfile-collector-scripts.

Comments (3)

dswarbrick avatar dswarbrick commented on June 9, 2024

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.

candlerb avatar candlerb commented on June 9, 2024

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.

dswarbrick avatar dswarbrick commented on June 9, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.