Smart.go is a pure Golang library to access disk low-level S.M.A.R.T. information

smart.go

Smart.go is a pure Golang library to access disk low-level S.M.A.R.T. information. Smart.go tries to match functionality provided by smartctl but with golang API.

Currently this library support SATA, SCSI and NVMe drives. Different drive types provide different set of monitoring information and API reflects it.

Example

Here is an example of code that demonstrates the library usage.

<< ns.Lbaf[ns.Flbas&0xf].Ds fmt.Println("Namespace 1 utilization: ", ns.Nuse*lbaSize) sm, _ := dev.ReadSMART() fmt.Println("Temperature: ", sm.Temperature, "K") // PowerOnHours is reported as 128-bit value and represented by this library as an array of uint64 fmt.Println("Power-on hours: ", sm.PowerOnHours.Val[0]) fmt.Println("Power cycles: ", sm.PowerCycles.Val[0])">
// skip the error handling for more compact API example
dev, _ := smart.OpenNVMe("/dev/nvme0n1")
c, nss, _ := dev.Identify()
fmt.Println("Model number: ", string(bytes.TrimSpace(c.ModelNumber[:])))
fmt.Println("Serial number: ", string(bytes.TrimSpace(c.SerialNumber[:])))
fmt.Println("Size: ", c.Tnvmcap.Val[0])

// namespace #1
ns := nss[0]
lbaSize := uint64(1) << ns.Lbaf[ns.Flbas&0xf].Ds
fmt.Println("Namespace 1 utilization: ", ns.Nuse*lbaSize)

sm, _ := dev.ReadSMART()
fmt.Println("Temperature: ", sm.Temperature, "K")
// PowerOnHours is reported as 128-bit value and represented by this library as an array of uint64
fmt.Println("Power-on hours: ", sm.PowerOnHours.Val[0])
fmt.Println("Power cycles: ", sm.PowerCycles.Val[0])

The output looks like

Model number:  SAMSUNG MZVLB512HBJQ-000L7
Serial number:  S4ENNF0M741521
Size:  512110190592
Namespace 1 utilization:  387524902912
Temperature:  327 K
Power-on hours:  499
Power cycles:  1433

Credit

This project is inspired by https://github.com/dswarbrick/smart

Owner
Comments
  • smart raw values support in AtaSmartAttr struct

    smart raw values support in AtaSmartAttr struct

    Hi,

    Thanks for the great work on this project!

    I have a question: Is it possible to have the raw values available in the AtaSmartAttr struct? I'm asking because in the case of querying for disk temperatures, the number present in the normalized value needs to be computed in order to reflect the real temperature.

    See more details/context about this question here: https://github.com/xxxserxxx/gotop/pull/221#issue-1262364291

  • too many open files error when using smart.go in gotop client

    too many open files error when using smart.go in gotop client

    I'm integrating smart.go with gotop (cli activity monitor) to gather info about the disks temperature in a machine in this PR: https://github.com/xxxserxxx/gotop/pull/221

    Unfortunately after a few minutes, either smart.Open() or sm.ReadSMARTData() or sm.ReadSMART() end up causing a "too many open files" error. Any idea on what might be the cause for this issue?

  • Fix non-linux builds

    Fix non-linux builds

    Adding build tags for linux and added stubs for other operating systems. This should ensure that code using it will always compile, but only work on linux.

    I am unsure if FreeBSD and friends are expected to work, but for now it is "linux or nothing".

  • Add functionality to get SATA SMART attribute flag prefailure and online bits

    Add functionality to get SATA SMART attribute flag prefailure and online bits

    Functionality to provide the same output as smartctl does for prefailure (TYPE) and online (UPDATED) bits:

    ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
      1 Raw_Read_Error_Rate     0x000b   100   100   050    Pre-fail  Always       -       0
      2 Throughput_Performance  0x0005   100   100   050    Pre-fail  Offline      -       0
      4 Start_Stop_Count        0x0032   100   100   000    Old_age   Always       -       192
    
  • new ReadGenericAttributes() api is missing attribute id 190

    new ReadGenericAttributes() api is missing attribute id 190 "Temperature_Celsius"

    I think the new ReadGenericAttributes() api is not handling correctly devices that don't provide an Airflow_Temperature_Cel attribute. The SSDs and HDDs in my machines only provide Attr ID 194 "Temperature_Celsius":

    sudo smartctl -a /dev/sdc | grep 'ID#\|Temp'
    ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
    194 Temperature_Celsius     0x0002   175   175   000    Old_age   Always       -       37 (Min/Max 24/59)`
    

    Running the latest gotop release that makes use of the ReadGenericAttributes() api fails to display the temps correctly: image

    Relevant code: https://github.com/anatol/smart.go/blob/main/sata.go#L468

  • Fix/file descriptor leak

    Fix/file descriptor leak

    Hi,

    Thanks very much for this useful library.

    I'm using it in a long time running process and observed some file descriptors leak (too many open files errors) after some time. I reduced the error rate with this few fixes.

    I'm not sure all the issue conditions are covered but I think it can help ;-)

    Regards.

  • Add support for Windows platform

    Add support for Windows platform

    To implement it please look at darwin's Go-C interface https://github.com/anatol/smart.go/blob/main/nvme_darwin.cpp window's interface should look similar.

    And as of C implementation itself it is a good idea to check smartmontools implementation here https://github.com/mirror/smartmontools/blob/master/os_win32.cpp

OpenZeppelin Contracts is a library for secure smart contract development.

A library for secure smart contract development. Build on a solid foundation of community-vetted code. Implementations of standards like ERC20 and ERC

Jan 5, 2023
LEO (Low Ethereum Orbit) is an Ethereum Portal Network client.

LEO LEO (Low Ethereum Orbit) is an Ethereum Portal Network client. What makes LEO different from other Portal Network clients is that it uses libp2p f

Apr 19, 2022
Golang libraries for generating QR codes for Smart Health Cards representing COVID-19 Immunizations
Golang libraries for generating QR codes for Smart Health Cards representing COVID-19 Immunizations

go-smarthealthcards Golang libraries for generating QR codes for Smart Health Cards representing COVID-19 Immunizations. Usage Individual Libraries Yo

Dec 5, 2021
Disk Usage/Free Utility - a better 'df' alternative
Disk Usage/Free Utility - a better 'df' alternative

duf Disk Usage/Free Utility (Linux, BSD, macOS & Windows) Features User-friendly, colorful output Adjusts to your terminal's width Sort the results ac

Jan 9, 2023
An interoperable smart contract hub
An interoperable smart contract hub

Juno An interoperable smart contract hub which automatically executes, controls or documents a procedure of relevant events and actions according to t

Jan 1, 2023
DERO: Secure, Anonymous Blockchain with Smart Contracts. Subscribe to Dero announcements by sending mail to [email protected] with subject: subscribe announcements
DERO: Secure, Anonymous Blockchain with Smart Contracts.  Subscribe to Dero announcements by sending mail to lists@dero.io with subject: subscribe announcements

Welcome to the Dero Project DERO News Forum Wiki Explorer Source Twitter Discord Github Stats WebWallet Medium Table of Contents ABOUT DERO PROJECT DE

Dec 7, 2022
The bare metal Go smart card
The bare metal Go smart card

Authors Andrea Barisani [email protected] | [email protected] Introduction The GoKey application implements a USB smartcard in pure Go

Dec 8, 2022
Yet another Binance Smart Chain client based on TrustFi Network

TrustFi Smart Chain The goal of TrustFi Smart Chain is to bring programmability and interoperability to Binance Chain. In order to embrace the existin

Mar 27, 2021
The Fabric Smart Client is a new Fabric Client that lets you focus on the business processes and simplifies the development of Fabric-based distributed application.

Fabric Smart Client The Fabric Smart Client (FSC, for short) is a new Fabric client-side component whose objective is twofold. FSC aims to simplify th

Dec 14, 2022
Arbitrum is a Layer 2 cryptocurrency platform that makes smart contracts scalable, fast, and private.
Arbitrum is a Layer 2 cryptocurrency platform that makes smart contracts scalable, fast, and private.

Arbitrum is a Layer 2 cryptocurrency platform that makes smart contracts scalable, fast, and private. Arbitrum interoperates closely with Ethereum, so Ethereum developers can easily cross-compile their contracts to run on Arbitrum. Arbitrum achieves these goals through a unique combination of incentives, network protocol design, and virtual machine architecture.

Jan 8, 2023
Tools to help teams develop smart contracts on the Cardano blockchain
Tools to help teams develop smart contracts on the Cardano blockchain

toolkit-for-cardano toolkit-for-cardano simplifies the development of Cardano smart contracts by providing teams with frequently needed tasks: Build T

Dec 19, 2022
A smart contract development toolchain for Go

ethgen - A smart contract development toolchain for Go A simple yet powerful toolchain for Go based smart contract development Compile solidity contra

Sep 14, 2022
Akroma GO client - Akroma is an EVM based application development platform (smart-contracts).

Akroma Akroma is an EVM based application development platform (smart-contracts). Akroma will utilize a Masternode system, and build out an Oracle pla

Dec 11, 2022
A Binance Smart Chain client based on the go-ethereum fork

A Binance Smart Chain client based on the go-ethereum fork

Dec 31, 2022
Automation for faucet-smart with some hacks 😈

give-me-bnb Automation for https://testnet.binance.org/faucet-smart with some hacks ?? Usage $ give-me-bnb -help Usage of give-me-bnb: -proxy string

Nov 19, 2022
A smart Hub for holding server stat
A smart Hub for holding server stat

Stat Hub A smart Hub for holding server stat δΈ­ζ–‡θ―΄ζ˜Ž | English README Overview Stat Hub is a service for collecting and displaying servers stat. Stat Hub

Aug 29, 2020
A Binance Smart Chain client based on the erigon fork

Erigon Erigon is an implementation of Ethereum (aka "Ethereum client"), on the efficiency frontier, written in Go. System Requirements Usage Getting S

Sep 17, 2022
A Gomora template for building dApps and web3-powered API and smart contract listeners

Gomora dApp A Gomora template for building dApps and web3-powered API and smart contract listeners Local Development Setup the .env file first cp .env

Feb 15, 2022
A guide to smart contract security best practices

Smart Contract Security Best Practices Visit the documentation site: https://consensys.github.io/smart-contract-best-practices/ Read the docs in Chine

Dec 27, 2022