git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/sysinfo/README.md (about)

     1  # Sysinfo
     2  
     3  [![Build Status](https://img.shields.io/github/workflow/status/zcalusic/sysinfo/Test)](https://git.sr.ht/~pingoo/stdx/sysinfo/actions/workflows/test.yaml)
     4  [![Go Report Card](https://goreportcard.com/badge/git.sr.ht/~pingoo/stdx/sysinfo)](https://goreportcard.com/report/git.sr.ht/~pingoo/stdx/sysinfo)
     5  [![GoDoc](https://godoc.org/git.sr.ht/~pingoo/stdx/sysinfo?status.svg)](https://godoc.org/git.sr.ht/~pingoo/stdx/sysinfo)
     6  [![License](https://img.shields.io/badge/license-MIT-a31f34.svg?maxAge=2592000)](https://git.sr.ht/~pingoo/stdx/sysinfo/blob/master/LICENSE)
     7  [![Powered by](https://img.shields.io/badge/powered_by-Go-5272b4.svg?maxAge=2592000)](https://go.dev/)
     8  [![Platform](https://img.shields.io/badge/platform-Linux-009bde.svg?maxAge=2592000)](https://www.linuxfoundation.org/)
     9  
    10  Package sysinfo is a Go library providing Linux OS / kernel / hardware system information. It's completely standalone,
    11  has no dependencies on the host system, doesn't execute external programs, doesn't even import other Go libraries. It
    12  collects only "inventory type" information, things that don't change often.
    13  
    14  ## Code Example
    15  
    16  ```go
    17  package main
    18  
    19  import (
    20  	"encoding/json"
    21  	"fmt"
    22  	"log"
    23  	"os/user"
    24  
    25  	"git.sr.ht/~pingoo/stdx/sysinfo"
    26  )
    27  
    28  func main() {
    29  	current, err := user.Current()
    30  	if err != nil {
    31  		log.Fatal(err)
    32  	}
    33  
    34  	if current.Uid != "0" {
    35  		log.Fatal("requires superuser privilege")
    36  	}
    37  
    38  	var si sysinfo.SysInfo
    39  
    40  	si.GetSysInfo()
    41  
    42  	data, err := json.MarshalIndent(&si, "", "  ")
    43  	if err != nil {
    44  		log.Fatal(err)
    45  	}
    46  
    47  	fmt.Println(string(data))
    48  }
    49  ```
    50  
    51  ## Motivation
    52  
    53  I couldn't find any self-contained library that would provide set of data/features I needed. So another sysinfo was
    54  born.
    55  
    56  The purpose of the library is to collect only inventory info. No metrics like CPU usage or load average will be added.
    57  The rule of thumb is, if it's changing during the day, every day, it doesn't belong in the library.
    58  
    59  The library should work well on any modern/supported Linux distribution. There are no plans to add support for older
    60  unsupported Linux distributions/kernels, to keep the code clean and robust and reduce the maintenance burden.
    61  
    62  ## Requirements
    63  
    64  Sysinfo requires:
    65  
    66  - Linux kernel 4.2 or later
    67  - access to /sys & /proc Linux virtual file systems
    68  - access to various files in /etc, /var, /run FS hierarchy
    69  - superuser privileges (to access SMBIOS/DMI table and detect RAM size and properties)
    70  
    71  Sysinfo doesn't require ANY other external utility on the target system, which is its primary strength, IMHO.
    72  
    73  It depends on Linux internals heavily, so there are no plans to support other operating systems.
    74  
    75  ## Installation
    76  
    77  Just use go get.
    78  
    79  ```
    80  go get git.sr.ht/~pingoo/stdx/sysinfo
    81  ```
    82  
    83  There's also a very simple utility demonstrating sysinfo library capabilities. Start it (as superuser) to get pretty
    84  formatted JSON output of all the info that sysinfo library provides. Due to its simplicity, the source code of the
    85  utility also doubles down as an example of how to use the library.
    86  
    87  ```
    88  go get git.sr.ht/~pingoo/stdx/sysinfo/cmd/sysinfo
    89  ```
    90  
    91  --
    92  
    93  Build demo utility in Docker container:  https://github.com/mattscilipoti/compile_sysinfo
    94  
    95  ## Sample output
    96  
    97  ```json
    98  {
    99    "sysinfo": {
   100      "version": "0.9.1",
   101      "timestamp": "2016-09-24T13:30:28.369498856+02:00"
   102    },
   103    "node": {
   104      "hostname": "web12",
   105      "machineid": "04aa55927ebd390829367c1757b98cac",
   106      "timezone": "Europe/Zagreb"
   107    },
   108    "os": {
   109      "name": "CentOS Linux 7 (Core)",
   110      "vendor": "centos",
   111      "version": "7",
   112      "release": "7.2.1511",
   113      "architecture": "amd64"
   114    },
   115    "kernel": {
   116      "release": "3.10.0-327.13.1.el7.x86_64",
   117      "version": "#1 SMP Thu Mar 31 16:04:38 UTC 2016",
   118      "architecture": "x86_64"
   119    },
   120    "product": {
   121      "name": "RH2288H V3",
   122      "vendor": "Huawei",
   123      "version": "V100R003",
   124      "serial": "2103711GEL10F3430658"
   125    },
   126    "board": {
   127      "name": "BC11HGSA0",
   128      "vendor": "Huawei",
   129      "version": "V100R003",
   130      "serial": "033HXVCNG3107624"
   131    },
   132    "chassis": {
   133      "type": 17,
   134      "vendor": "Huawei"
   135    },
   136    "bios": {
   137      "vendor": "Insyde Corp.",
   138      "version": "3.16",
   139      "date": "03/16/2016"
   140    },
   141    "cpu": {
   142      "vendor": "GenuineIntel",
   143      "model": "Intel(R) Xeon(R) CPU E5-2630 v3 @ 2.40GHz",
   144      "speed": 2400,
   145      "cache": 20480,
   146      "cpus": 1,
   147      "cores": 8,
   148      "threads": 16
   149    },
   150    "memory": {
   151      "type": "DRAM",
   152      "speed": 2133,
   153      "size": 65536
   154    },
   155    "storage": [
   156      {
   157        "name": "sda",
   158        "driver": "sd",
   159        "vendor": "ATA",
   160        "model": "ST9500620NS",
   161        "serial": "9XF2HZ9K",
   162        "size": 500
   163      }
   164    ],
   165    "network": [
   166      {
   167        "name": "enp3s0f1",
   168        "driver": "ixgbe",
   169        "macaddress": "84:ad:5a:e3:79:71",
   170        "port": "fibre",
   171        "speed": 10000
   172      }
   173    ]
   174  }
   175  ```
   176  
   177  ## Contributors
   178  
   179  Contributors are welcome, just open a new issue / pull request.
   180  
   181  ## License
   182  
   183  ```
   184  The MIT License (MIT)
   185  
   186  Copyright © 2016 Zlatko Čalušić
   187  
   188  Permission is hereby granted, free of charge, to any person obtaining a copy
   189  of this software and associated documentation files (the "Software"), to deal
   190  in the Software without restriction, including without limitation the rights
   191  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   192  copies of the Software, and to permit persons to whom the Software is
   193  furnished to do so, subject to the following conditions:
   194  
   195  The above copyright notice and this permission notice shall be included in all
   196  copies or substantial portions of the Software.
   197  
   198  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   199  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   200  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   201  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   202  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   203  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
   204  SOFTWARE.
   205  ```