diskutil

package module
v0.0.0-...-6836d4d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2019 License: BSD-3-Clause Imports: 8 Imported by: 0

README

Golang Disk Utils

This package is used for go codes to get MegaRaid stat.

Usage

At first, you need install MegaRAID in your servers.

Create a DiskStatus struct by calling diskutil.NewDiskStatus(). You need provide the MegaCli binary path and the count of RAID card in your server.

	ds, err := diskutil.NewDiskStatus(megaPath, adapterCount)
	if err != nil {
		fmt.Fprintf(os.Stderr, "DiskStatus New error: %v\n", err)
		return
	}

	err = ds.Get()
	if err != nil {
		fmt.Fprintf(os.Stderr, "DiskStatus Get error: %v\n", err)
		return
	}
	fmt.Println(ds)

After calling Get(), you can visit any stat in the DiskStatus like this:

	for i, ads := range ds.AdapterStats {
		fmt.Printf("adapter #%d \n", i)
		for j, pds := range ads.PhysicalDriveStats {
			pdStatus := pds.FirmwareState
			pdName := []string{pds.Brand, pds.Model, pds.SerialNumber}
			pdSN := strings.Join(pdName, " ")
			fmt.Printf("PD%d: %s status: %s\n", j, pdSN, pdStatus)
		}
		fmt.Printf("\n")
	}

If you focus on the disk which is broken, you can use ListBrokenDrive() to get them:

	brokenVds, brokenPds, err := ds.ListBrokenDrive()
	if err != nil {
		fmt.Fprintf(os.Stderr, "DiskStatus ListBrokenDrive error: %v\n", err)
		return
	}
	for _, bvd := range brokenVds {
		fmt.Println(bvd)
	}
	for _, bpd := range brokenPds {
		fmt.Println(bpd)
	}

Or you can print the DiskStatus in json format by calling ToJson():

	jsonStatus, err := ds.ToJson()
	if err != nil {
		fmt.Fprintf(os.Stderr, "DiskStatus ToJson error: %v\n", err)
		return
	}
	fmt.Println(jsonStatus)

	{
		"adapter_stats": [
			{
				"id": 0, 
				"virtual_drive_stats": [
					{
						"virtual_drive": 0, 
						"name": "", 
						"size": "278.875 GB", 
						"state": "Optimal", 
						"number_of_drives": 1, 
						"encryption_type": "None"
					}
				], 
				"physical_drive_stats": [
					{
						"enclosure_device_id": 64, 
						"device_id": 8, 
						"slot_number": 0, 
						"media_error_count": 0, 
						"other_error_count": 0, 
						"predictive_failure_count": 0, 
						"pd_type": "SAS", 
						"raw_size": "279.396 GB [0x22ecb25c Sectors]", 
						"firmware_state": "Online, Spun Up", 
						"brand": "SEAGATE", 
						"model": "ST9300605SS", 
						"serial_number": "00046XP4MQNJ", 
						"drive_emperature": "65C (149.00 F)"
					}
				]
			}
		]
	}

Full sample code is in /examples. Try it to test this package:

go build -v examples/printDiskStat.go
sudo ./printDiskStat

GoDoc

Visit Godoc to get full api documents:

https://godoc.org/github.com/buaazp/diskutil

Issue

If you meet some problems in your servers, please create a github issue or contact me:

weibo: @招牌疯子
mail: zp@buaa.us

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdapterStat

type AdapterStat struct {
	AdapterId          int                 `json:"adapter_id"`
	VirtualDriveStats  []VirtualDriveStat  `json:"virtual_drive_stats"`
	PhysicalDriveStats []PhysicalDriveStat `json:"physical_drive_stats"`
}

AdapterStat is a struct to get the Adapter Stat of a RAID card. AdapterStat has VirtualDriveStats and PhysicalDriveStats in itself.

func (*AdapterStat) String

func (a *AdapterStat) String() string

String() is used to get the print string.

func (*AdapterStat) ToJson

func (a *AdapterStat) ToJson() (string, error)

ToJson() is used to get the json encoded string.

type DiskStatus

type DiskStatus struct {
	AdapterStats []AdapterStat `json:"adapter_stats"`
	// contains filtered or unexported fields
}

DiskStatus is a struct to get all Adapters' Stat of the server

func NewDiskStatus

func NewDiskStatus(megaCliPath string, adapterCount int) (*DiskStatus, error)

NewDiskStatus() use the megaCliPath and apapterCount to build a DiskStatus.

func (*DiskStatus) Get

func (d *DiskStatus) Get() error

Get() is used to get all the stat of a DiskStatus.

func (*DiskStatus) GetPhysicalDrive

func (d *DiskStatus) GetPhysicalDrive() error

GetPhysicalDrive() is used to get the PhysicalDriveStat of a DiskStatus.

func (*DiskStatus) GetVirtualDrive

func (d *DiskStatus) GetVirtualDrive() error

GetVirtualDrive() is used to get the VirtualDriveStat of a DiskStatus.

func (*DiskStatus) ListBrokenDrive

func (d *DiskStatus) ListBrokenDrive() ([]VirtualDriveStat, []PhysicalDriveStat, error)

ListBrokenDrive() is used to list the Broken Drives of a DiskStatus.

func (*DiskStatus) ListBrokenPhysicalDrive

func (d *DiskStatus) ListBrokenPhysicalDrive() ([]PhysicalDriveStat, error)

ListBrokenPhysicalDrive() is used to list the Broken Physical Drives of a DiskStatus.

func (*DiskStatus) ListBrokenVirtualDrive

func (d *DiskStatus) ListBrokenVirtualDrive() ([]VirtualDriveStat, error)

ListBrokenVirtualDrive() is used to list the Broken Virtual Drives of a DiskStatus.

func (*DiskStatus) String

func (d *DiskStatus) String() string

String() is used to get the print string.

func (*DiskStatus) ToJson

func (d *DiskStatus) ToJson() (string, error)

ToJson() is used to get the json encoded string.

type PhysicalDriveStat

type PhysicalDriveStat struct {
	EnclosureDeviceId      string `json:"enclosure_device_id"`
	DeviceId               int    `json:"device_id"`
	SlotNumber             int    `json:"slot_number"`
	MediaErrorCount        int    `json:"media_error_count"`
	OtherErrorCount        int    `json:"other_error_count"`
	PredictiveFailureCount int    `json:"predictive_failure_count"`
	Pdtype                 string `json:"pd_type"`
	RawSize                string `json:"raw_size"`
	FirmwareState          string `json:"firmware_state"`
	Brand                  string `json:"brand"`
	Model                  string `json:"model"`
	SerialNumber           string `json:"serial_number"`
	DriveTemperature       string `json:"drive_emperature"`
}

PhysicalDriveStat is a struct to get the Physical Drive Stat of a RAID card.

func (*PhysicalDriveStat) String

func (p *PhysicalDriveStat) String() string

String() is used to get the print string.

func (*PhysicalDriveStat) ToJson

func (p *PhysicalDriveStat) ToJson() (string, error)

ToJson() is used to get the json encoded string.

type VirtualDriveStat

type VirtualDriveStat struct {
	VirtualDrive   int    `json:"virtual_drive"`
	Name           string `json:"name"`
	Size           string `json:"size"`
	State          string `json:"state"`
	NumberOfDrives int    `json:"number_of_drives"`
	Encryptiontype string `json:"encryption_type"`
}

VirtualDriveStat is a struct to get the Virtual Drive Stat of a RAID card.

func (*VirtualDriveStat) String

func (v *VirtualDriveStat) String() string

String() is used to get the print string.

func (*VirtualDriveStat) ToJson

func (v *VirtualDriveStat) ToJson() (string, error)

ToJson() is used to get the json encoded string.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL