西维蜀黍

【Prometheus】Metric Name

Metric Names

A metric name…

  • …must comply with the data model for valid characters.
  • …should have a (single-word) application prefix relevant to the domain the metric belongs to. The prefix is sometimes referred to as namespace by client libraries. For metrics specific to an application, the prefix is usually the application name itself. Sometimes, however, metrics are more generic, like standardized metrics exported by client libraries. Examples:
    • prometheus_notifications_total (specific to the Prometheus server)
    • process_cpu_seconds_total (exported by many client libraries)
    • http_request_duration_seconds` (for all HTTP requests)
  • …must have a single unit (i.e. do not mix seconds with milliseconds, or seconds with bytes).
  • …should use base units (e.g. seconds, bytes, meters - not milliseconds, megabytes, kilometers).
  • …should have a suffix describing the unit, in plural form. Note that an accumulating count has total as a suffix, in addition to the unit if applicable.
    • http_request_duration_**seconds**
    • node_memory_usage_**bytes**
    • http_requests_**total** (for a unit-less accumulating count)
    • process_cpu_**seconds_total** (for an accumulating count with unit)
    • foobar_build**_info** (for a pseudo-metric that provides metadata about the running binary)
  • …should represent the same logical thing-being-measured across all label dimensions.
    • request duration
    • bytes of data transfer
    • instantaneous resource usage as a percentage

As a rule of thumb, either the sum() or the avg() over all dimensions of a given metric should be meaningful (though not necessarily useful). If it is not meaningful, split the data up into multiple metrics. For example, having the capacity of various queues in one metric is good, while mixing the capacity of a queue with the current number of elements in the queue is not.

  ...


【Engineering】Monitoring System

Context

While there is a certain intellectual satisfaction to be had by getting a system just right, the purpose of monitoring is to help you run whatever it is that you’re monitoring. That could be a website used directly by your customers, a backend only used internally, or even industrial systems. Fundamentally your customers don’t care how well your monitoring is working, they care how well the services they’re interacting with function. Part of you providing that service should involve some level of monitoring (in the broadest sense of the word) to ensure that things aren’t going badly wrong, but that’s just one part of providing the service.

  ...


【Golang】源码 - json - Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal returns the JSON encoding of v.

Marshal traverses the value v recursively. If an encountered value implements the Marshaler interface and is not a nil pointer, Marshal calls its MarshalJSON method to produce JSON. If no MarshalJSON method is present but the value implements encoding.TextMarshaler instead, Marshal calls its MarshalText method and encodes the result as a JSON string. The nil pointer exception is not strictly necessary but mimics a similar, necessary exception in the behavior of UnmarshalJSON.

  ...


【Golang】关键字 - switch

switch

A switch statement is a shorter way to write a sequence of if - else statements. It runs the first case whose value is equal to the condition expression.

Go’s switch is like the one in C, C++, Java, JavaScript, and PHP, except that Go only runs the selected case, not all the cases that follow. In effect, the break statement that is needed at the end of each case in those languages is provided automatically in Go. Another important difference is that Go’s switch cases need not be constants, and the values involved need not be integers.

  ...


【Hackintosh】知识

ACPI

ACPI 是 Hewlett-Packard, Intel, Microsoft, Phoenix 和 Toshiba 共同制定的一个开放的行业规范。是 The Advanced Configuration and Power Interface 的缩写,也就是“电源管理模式和配置管理的接口规范”。从名字可以看出主要是“电源管理”和“配置管理”。是 BIOS 的一个高级功能模块。

它帮助操作系统合理控制和分配计算机硬件设备的电量,有 了ACPI,操作系统可以根据设备实际情况,根据需要把不同的硬件设备关闭。如Win7或者Win8系统,系统睡眠时,系统把当前信息储存在内存中,只保留内存等几个关键部件硬件的通电,使计算机处在高度节电状态。当然这只是它功能中的很少一部分。

它主要涵盖的功能包括:

  1. System power management(系统电源管理)
  2. Device power management(设备电源管理)
  3. Processor power management(处理器电源管理)
  4. Device and processor performance management(设备及处理器性能管理)
  5. Configuration / Plug and Play(配置/即插即用)
  6. System Events(系统事件)
  7. Battery management(电池管理)
  8. Thermal management(温度管理)
  9. Embedded Controller(嵌入式控制器)
  10. SMBus Controller(SMBus控制器)

在计算机应用平台,ACPI 越来越重要。ACPI由很多表组成,包括:RSDP,SDTH,RSDT,FADT,FACS,DSDT,SSDT,MADT,SBST,XSDT,ECDT,SLIT,SRAT。其中DSDT就是它的一个重要的描述表。

  ...


【macOS】制作macOS Big Sur Beta 镜像

对于 Big Sur,目前只能在一个已经安装了macOS的OS上制作macOS镜像。

Download from macOS

Before you can install the new operating system, you must be enrolled in the Public Beta program. You can do this through Apple’s Public Beta program website. In the Get Started section of the website, click on the “enroll your Mac” link.

This should take you to the “Enroll you devices” webpage. Follow the instructions. In step 2, you will download the “macOS Public Beta Access Utility” which will enroll your Mac into the program. Then the utility will launch Software Update to download and install the Big Sur beta.

https://www.macworld.com/article/234359/how-to-install-the-macos-11-big-sur-public-beta.html

Then insatll macOS Big Sur Beta via System Update

Once finish, you would have this:

  ...


【Hackintosh】更新与维护

常用工具

  • hackintool
  • IORegistryExplorer
  • OpenCore Configurator

OS Setting

Issues

Power Management

Fixing Sleep

https://forum.amd-osx.com/index.php?threads/audiogods-gigabyte-aorus-x570-pro-pro-wifi-ultra-master-big-sur-opencore-0-7-1-efi.1344/post-10975

https://forum.amd-osx.com/index.php?resources/usbtoolbox.12/

选择系统icon更大

NVRAM - UIScale 设置为01

Debug

-boot-args 中加入 -v

boot-args

Here we get to set some variables that will help us with debug output, for us we’ll be using the following boot-args:

-v keepsyms=1 debug=0x12a msgbuf=1048576

踩坑

  • 如果在安装系统的时候,加了上面这些参数,可能会导致无限重启而无法进入安装系统界面,因此在安装系统时,仍然可以使用上面参数进行debug,但是如果发生无限重启时,需要把送上面参数去掉

Now lets go over what each arg does:

  • -v
    • Enables verbose output
  • keepsyms=1
    • Ensures symbols are kept during kernel panics, which are greatly helpful for troubleshooting
  • debug=0x12a
    • Combination of DB_PRT (0x2), DB_KPRT (0x8), DB_SLOG (0x20), and DB_LOG_PI_SCRN (0x100)
    • A full list of values for the latest version of XNU can be found here: debug.h(opens new window)
  • msgbuf=1048576
    • Sets the kernel’s message buffer size, this helps with getting proper logs during boot
    • 1048576 is 1MB(/1024^2), can be larger if required
    • Note not required with DebugEnhancer.kext, however for early kernel logs it’s still required

Ref

Update

Refer to https://dortania.github.io/OpenCore-Post-Install/universal/update.html#updating-opencore-and-macos

Update OpenCore

Note

  • So first, lets mount your hard drive’s EFI and make a copy somewhere safe with MountEFI (opens new window). We won’t be updating the drive’s EFI at first, instead we’ll be grabbing a spare USB to be our crash dummy. This allows us to keep a working copy of OpenCore in case our update goes south

  • For the USB, it must be formatted as GUID. Reason for this is that GUID will automatically create an EFI partition, though this will be hidden by default so you’ll need to mount it with MountEFI.

  • partition, though this will be hidden by default so you’ll need to mount it with MountEFI.

Now you can place your OpenCore EFI on the USB

Replace the OpenCore files with the ones you just downloaded

  • The important ones to update:
    • EFI/BOOT/BOOTx64.efi
    • EFI/OC/OpenCore.efi
    • EFI/OC/Drivers/OpenRuntime(Don’t forget this one, OpenCore will not boot with mismatched versions)
  • You can also update other drivers you have if present, these are just the ones that must be updated in order to boot correctly

Refer to https://dortania.github.io/OpenCore-Post-Install/universal/update.html#updating-opencore

Validate Config.plist

  • Use the OpenCore Utility ocvalidate: this tool will help ensure your config.plist is matching the OpenCore specification of the matching build.
# Enter your OpenCore folder
$ cd /Users/shiwei/Downloads/OpenCore-0.6.9-RELEASE
$ ./Utilities/ocvalidate/ocvalidate /Users/shiwei/Downloads/MyOpenCoreConfig/EFI/OC/Config.plist
  ...


【Golang】使用 - sync.RWMutex

package main

import (
	"sync"
)

// SafeCounter is safe to use concurrently.
type SafeCounter struct {
	mu sync.RWMutex
	v  map[string]int
}

// Inc increments the counter for the given key.
func (c *SafeCounter) Write(key string) {
	c.mu.Lock()
	// Lock so only one goroutine at a time can access the map c.v.
	c.v[key]++
	c.mu.Unlock()
}

// Value returns the current value of the counter for the given key.
func (c *SafeCounter) Read(key string) int {
	c.mu.RLock()
	defer c.mu.RUnlock()
	return c.v[key]
}

func main() {
	c := SafeCounter{v: make(map[string]int)}
	go func() {
		for {
			_ = c.Read("test")
		}
	}()
	go func() {
		for {
			c.Write("test")
		}
	}()
	select {}
}
  ...


【Design Pattern】Concurrency - Read Write Lock Pattern

Readers–writer Lock

In computer science, a readers–writer (single-writer lock, a multi-reader lock, a push lock, or an MRSW lock) is a synchronization primitive that solves one of the readers–writers problems.

An RW lock allows concurrent access for read-only operations, while write operations require exclusive access.

This means that multiple threads can read the data in parallel but an exclusive lock is needed for writing or modifying data. When a writer is writing the data, all other writers or readers will be blocked until the writer is finished writing. A common use might be to control access to a data structure in memory that cannot be updated atomically and is invalid (and should not be read by another thread) until the update is complete.

Readers–writer locks are usually constructed on top of mutexes and condition variables, or on top of semaphores.

  ...


【Golang】源码 - sync包 - Pool

sync.Pool

A Pool is a set of temporary objects that may be individually saved and retrieved.

Any item stored in the Pool may be removed automatically at any time without notification. If the Pool holds the only reference when this happens, the item might be deallocated.

A Pool is safe for use by multiple goroutines simultaneously.

Pool’s purpose is to cache allocated but unused items for later reuse, relieving pressure on the garbage collector. That is, it makes it easy to build efficient, thread-safe free lists. However, it is not suitable for all free lists.

An appropriate use of a Pool is to manage a group of temporary items silently shared among and potentially reused by concurrent independent clients of a package. Pool provides a way to amortize allocation overhead across many clients.

  ...