prometheus-community / smartctl_exporter

Export smartctl statistics to prometheus
Apache License 2.0
314 stars 91 forks source link

The exporter support windows deployment? #60

Closed ChaoHsupin closed 1 year ago

ChaoHsupin commented 2 years ago

Thanks for your work!

Because I encountered some mistakes, I would like to know the exporter support Windows deployment?thanks!

This is log about run in Windows server 2016:

[Error] Device /dev/sda unavialable
panic: runtime error: index out of range [0] with length 0

goroutine 36 [running]:
main.(*SMARTctlInfo).mineVersion(0xc0000ebe98)
        /Users/zhaoxubin/IdeaProjects/smartctl_exporter/smartctlinfo.go:59 +0xbaf
main.(*SMARTctlInfo).Collect(...)
        /Users/zhaoxubin/IdeaProjects/smartctl_exporter/smartctlinfo.go:48
main.SMARTctlManagerCollector.Collect({}, 0xc000132060)
        /Users/zhaoxubin/IdeaProjects/smartctl_exporter/main.go:51 +0x90
github.com/prometheus/client_golang/prometheus.DescribeByCollect.func1()
        /Users/zhaoxubin/go/pkg/mod/github.com/prometheus/client_golang@v1.12.2/prometheus/collector.go:90 +0x2b
created by github.com/prometheus/client_golang/prometheus.DescribeByCollect
        /Users/zhaoxubin/go/pkg/mod/github.com/prometheus/client_golang@v1.12.2/prometheus/collector.go:89 +0xa5

C:\Users\Administrator\Desktop>

This is run command smartctl -a /dev/sda

C:\Users\Administrator\Desktop>smartctl -a /dev/sda
smartctl 7.3 2022-02-28 r5338 [x86_64-w64-mingw32-2016-1607] (sf-7.3-1)
Copyright (C) 2002-22, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Seagate Enterprise Capacity 3.5 HDD
Device Model:     ST2000NM0008-2F3100
Serial Number:    ZDS17W6G
LU WWN Device Id: 5 000c50 0c4346fad
Firmware Version: SN02
User Capacity:    2,000,398,934,016 bytes [2.00 TB]
Sector Size:      512 bytes logical/physical
Rotation Rate:    7200 rpm
Form Factor:      3.5 inches
Device is:        In smartctl database 7.3/5319
ATA Version is:   ACS-3 T13/2161-D revision 5
SATA Version is:  SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is:    Mon Aug 15 15:10:10 2022
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

General SMART Values:
Offline data collection status:  (0x82) Offline data collection activity
                                        was completed without error.
                                        Auto Offline Data Collection: Enabled.
Self-test execution status:      ( 241) Self-test routine in progress...
                                        10% of test remaining.
Total time to complete Offline
data collection:                (  592) seconds.
Offline data collection
capabilities:                    (0x7b) SMART execute Offline immediate.
                                        Auto Offline data collection on/off support.
                                        Suspend Offline collection upon new
                                        command.
                                        Offline surface scan supported.
                                        Self-test supported.
                                        Conveyance Self-test supported.
                                        Selective Self-test supported.
SMART capabilities:            (0x0003) Saves SMART data before entering
                                        power-saving mode.
                                        Supports SMART auto save timer.
Error logging capability:        (0x01) Error logging supported.
                                        General Purpose Logging supported.
Short self-test routine
recommended polling time:        (   1) minutes.
Extended self-test routine
recommended polling time:        ( 237) minutes.
Conveyance self-test routine
recommended polling time:        (   2) minutes.
SCT capabilities:              (0x50bd) SCT Status supported.
                                        SCT Error Recovery Control supported.
                                        SCT Feature Control supported.
                                        SCT Data Table supported.

SMART Attributes Data Structure revision number: 10
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000f   081   063   044    Pre-fail  Always       -       144960806
  3 Spin_Up_Time            0x0003   096   096   000    Pre-fail  Always       -       0
  4 Start_Stop_Count        0x0032   100   100   020    Old_age   Always       -       397
  5 Reallocated_Sector_Ct   0x0033   100   100   010    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x000f   081   060   045    Pre-fail  Always       -       142110556
  9 Power_On_Hours          0x0032   085   085   000    Old_age   Always       -       13407h+47m+43.194s
 10 Spin_Retry_Count        0x0013   100   100   097    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   020    Old_age   Always       -       397
184 End-to-End_Error        0x0032   100   100   099    Old_age   Always       -       0
187 Reported_Uncorrect      0x0032   100   100   000    Old_age   Always       -       0
188 Command_Timeout         0x0032   100   099   000    Old_age   Always       -       0 0 1
189 High_Fly_Writes         0x003a   100   100   000    Old_age   Always       -       0
190 Airflow_Temperature_Cel 0x0022   068   053   040    Old_age   Always       -       32 (Min/Max 27/32)
191 G-Sense_Error_Rate      0x0032   100   100   000    Old_age   Always       -       0
192 Power-Off_Retract_Count 0x0032   100   100   000    Old_age   Always       -       854
193 Load_Cycle_Count        0x0032   100   100   000    Old_age   Always       -       954
194 Temperature_Celsius     0x0022   032   047   000    Old_age   Always       -       32 (0 17 0 0 0)
195 Hardware_ECC_Recovered  0x001a   081   063   000    Old_age   Always       -       144960806
197 Current_Pending_Sector  0x0012   100   100   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0010   100   100   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x003e   200   200   000    Old_age   Always       -       0
240 Head_Flying_Hours       0x0000   100   253   000    Old_age   Offline      -       13331h+01m+59.846s
241 Total_LBAs_Written      0x0000   100   253   000    Old_age   Offline      -       11433424138
242 Total_LBAs_Read         0x0000   100   253   000    Old_age   Offline      -       7406397909

SMART Error Log Version: 1
No Errors Logged

SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Extended offline    Self-test routine in progress 10%     13407         -

SMART Selective self-test log data structure revision number 1
 SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS
    1        0        0  Not_testing
    2        0        0  Not_testing
    3        0        0  Not_testing
    4        0        0  Not_testing
    5        0        0  Not_testing
Selective self-test flags (0x0):
  After scanning selected spans, do NOT read-scan remainder of disk.
If Selective self-test is pending on power-up, resume after 0 minute delay.

C:\Users\Administrator\Desktop>
andonovski commented 2 years ago

I have exactly same error. This is command that I run: smartctl_exporter.exe --config=smartctl_exporter.yaml

Contents of smartctl_exporter.yaml:

smartctl_exporter:
  bind_to: "[::1]:9633"
  url_path: "/metrics"
  fake_json: no
  smartctl_location: "smartctl.exe"
  collect_not_more_than_period: 120s
  devices:
  - /dev/sda
  - /dev/sdb

Looks like that smartctl.exe is called properly, the executable is in PATH environment variable, but something is wrong when trying to query disks. I tried with single disk with same error.

ChaoHsupin commented 2 years ago

I have exactly same error. This is command that I run: smartctl_exporter.exe --config=smartctl_exporter.yaml

Contents of smartctl_exporter.yaml:

smartctl_exporter:
  bind_to: "[::1]:9633"
  url_path: "/metrics"
  fake_json: no
  smartctl_location: "smartctl.exe"
  collect_not_more_than_period: 120s
  devices:
  - /dev/sda
  - /dev/sdb

Looks like that smartctl.exe is called properly, the executable is in PATH environment variable, but something is wrong when trying to query disks. I tried with single disk with same error.

@andonovski I read the source code. There is a piece of code that can only be executed in the Linux environment. Because everything is file under Linux, there is a segment code to try hardware as a file to obtain information, and this code is not supported under Windows. So I changed the code and compiled a little, and passed it.

This is the code that needs to be modified:readjson.go

func readData(device string) (gjson.Result, error) {
    if options.SMARTctl.FakeJSON {
        return readFakeSMARTctl(device), nil
    }
       //  "os.Stat(device)" only be executed in the Linux environment.
    if _, err := os.Stat(device); err == nil {
        cacheValue, cacheOk := jsonCache[device]
        if !cacheOk || time.Now().After(cacheValue.LastCollect.Add(options.SMARTctl.CollectPeriodDuration)) {
            json, ok := readSMARTctl(device)
            if ok {
                jsonCache[device] = JSONCache{JSON: json, LastCollect: time.Now()}
                return jsonCache[device].JSON, nil
            }
            return gjson.Parse("{}"), fmt.Errorf("smartctl returned bad data for device %s", device)
        }
        return cacheValue.JSON, nil
    }
    return gjson.Parse("{}"), fmt.Errorf("Device %s unavialable", device)
}
andonovski commented 2 years ago

@ChaoHsupin, great find. I am just a bit confused, the code you posted here is changed code, and it will work on Windows? I am not developer, just ordinary sysadmin, not even sure how would I compile this under Windows. Hopefully this will be merged by devs in the master.

ChaoHsupin commented 2 years ago

@ChaoHsupin, great find. I am just a bit confused, the code you posted here is changed code, and it will work on Windows? I am not developer, just ordinary sysadmin, not even sure how would I compile this under Windows. Hopefully this will be merged by devs in the master. @andonovski

65

NiceGuyIT commented 1 year ago

Hi @ChaoHsupin. It's been a minute since the PR was merged. Is this still an issue?