小编Mar*_*arc的帖子

Prometheus为Mac OS X预构建二进制文件

我在Mac OS X上试用Prometheus.我查看了下载内容并没有直接指示哪个版本适用于Mac.我试过docker在Mac上运行Prometheus.只想在不使用docker的Mac上直接运行它.有谁知道要选择哪个版本.

那里有很少的BSD可供挑选.我知道Mac也是BSD.只要它是bsd,不确定哪一个匹配或无关紧要?

除了那些二进制文件,我认为brew install应该做的工作

macos prometheus

11
推荐指数
1
解决办法
3766
查看次数

如何使用警报管理器配置普罗米修斯?

docker-compose.yml: 这是运行 prometheus、node-exporter 和 alert-manager 服务的 docker -compose。所有服务都运行良好。甚至prometheus的目标菜单中的健康状况也显示正常。

version: '2'

services:

    prometheus:
        image: prom/prometheus
        privileged: true
        volumes:
            - ./prometheus.yml:/etc/prometheus/prometheus.yml
            - ./alertmanger/alert.rules:/alert.rules
        command:
            - '--config.file=/etc/prometheus/prometheus.yml'
        ports:
            - '9090:9090'

    node-exporter:
        image: prom/node-exporter
        ports:
            - '9100:9100'

    alertmanager:
        image: prom/alertmanager
        privileged: true
        volumes:
             - ./alertmanager/alertmanager.yml:/alertmanager.yml
        command:
            - '--config.file=/alertmanager.yml'
        ports:
            - '9093:9093'
Run Code Online (Sandbox Code Playgroud)

普罗米修斯.yml

这是带有目标和警报目标集的 prometheus 配置文件。警报管理器目标网址工作正常。

global:
  scrape_interval: 5s
  external_labels:
    monitor: 'my-monitor'

# this is where I have simple alert rules
rule_files:
  - ./alertmanager/alert.rules

scrape_configs:
    - job_name: 'prometheus'
      static_configs: 
        - targets: ['localhost:9090']

    - job_name: …
Run Code Online (Sandbox Code Playgroud)

docker-compose prometheus

8
推荐指数
1
解决办法
1万
查看次数

使用 golang 双向 TLS 身份验证信任特定客户端

我已经在 Go 中成功设置了 TLS 相互身份验证客户端/服务器一段时间了,但现在希望进行一些小的调整。

具体来说,我想知道是否有一种方法只需要特定的客户端证书即可进行相互身份验证。

我目前正在使用这样的东西:

    // Load cert and build pool
    caCert, _ := ioutil.ReadFile(caPath)        
    caCertPool := x509.NewCertPool()
    caCertPool.AppendCertsFromPEM(caCert)

    // Require client authentication
    tlsConfig := &tls.Config{
        ClientAuth: tls.RequireAndVerifyClientCert,
        ClientCAs: caCertPool,
    }
Run Code Online (Sandbox Code Playgroud)

效果很好,但是如果我正在读取的 PEM 文件实际上是一个证书链(A 由 B 颁发,B 是根 CA),这实际上最终会信任 B 颁发的任何证书,但我不这样做想。

有什么方法可以调整此代码以仅信任特定的 A 证书吗?

看来,如果我只在加载的 PEM 文件中包含 A,服务器握手代码会告诉客户端“将由 A 签名的所有证书发送给我”,这当然不是我想要的,因为证书 A 不是由 A 签名的。

理想情况下,我想说“您特别需要证书 A”才能成功连接。有这样的机制吗?

ssl go

5
推荐指数
1
解决办法
2187
查看次数

当我尝试使用“ net / http”获取某些图像时,为什么会收到“ net / http:等待连接时请求已取消”的信息

我正在用Go语言编写网络爬虫,以在Internet上收集图像。我的搜寻器大部分时间都在工作,但有时无法以某种方式获取图像。

这是我的片段:

package main

import (
    "fmt"
    "net/http"
    "time"
)

func main() {
    var client http.Client
    var resp *http.Response

    // var imageUrl = "https://i.stack.imgur.com/tKsDb.png"  // It works well
    var imageUrl = "https://precious.jp/mwimgs/b/1/-/img_b1ec6cf54ff3a4260fb77d3d3de918a5275780.jpg"  // It fails

    req, _ := http.NewRequest("GET", imageUrl, nil)
    req.Header.Add("User-Agent", "My Test")

    client.Timeout = 3 * time.Second
    resp, err := client.Do(req)
    if err != nil {
        fmt.Println(err.Error())  // Fails here
        return
    }
    defer resp.Body.Close()

    if resp.StatusCode != http.StatusOK {
        fmt.Printf("Failure: %d\n", resp.StatusCode)
    } else {
        fmt.Printf("Success: %d\n", resp.StatusCode) …
Run Code Online (Sandbox Code Playgroud)

networking http go

5
推荐指数
1
解决办法
1万
查看次数

Golang 使用 rsa 签署结构

我有一个Transaction包含以下字段的结构,

type Transaction struct {
    Sender    string `json:"sender"`
    Receiver  string `json:"receiver"`
    Signature string `json:"signature"`
    Amount    int64  `json:"amount"`
}
Run Code Online (Sandbox Code Playgroud)

我还有一个函数GetPrivateKey(),它返回一个*rsa.PrivateKey

func GetPrivateKey() (*rsa.PrivateKey, error) {
    key, err := ioutil.ReadFile("/Users/xxx/.ssh/id_rsa")
    if err != nil {
        return nil, err
    }

    block, _ := pem.Decode(key)
    der, err := x509.ParsePKCS1PrivateKey(block.Bytes)
    if err != nil {
       return nil, err
    }
    return der, err
 }
Run Code Online (Sandbox Code Playgroud)

我的计划是transaction使用系统中已有的私钥对结构的内容进行签名,然后将其作为字符串存储signature在结构的字段中,为此,我有一个函数SignPayload()

func SignPayload(txnObj *Transaction) error {
    privateKey, err := GetPrivateKey()
    if err …
Run Code Online (Sandbox Code Playgroud)

cryptography rsa go

4
推荐指数
1
解决办法
4388
查看次数

fasthttp.Client结合goroutine的正确使用

我是 Go 新手,正在寻找使用 goroutine 的正确net/http方法fasthttp。不幸的是,那里没有很多fasthttp客户示例。

我找到了以下代码:(示例1

package main

import (
    "bufio"
    "fmt"
    "github.com/valyala/fasthttp"
    "log"
    "net"
    "os"
    "sync"
    "time"
)

func grabPage(fastClient *fasthttp.Client, i int, wg *sync.WaitGroup) {
    defer wg.Done()
    _, body, err := fastClient.GetTimeout(nil, "https://en.wikipedia.org/wiki/Immanuel_Kant", time.Duration(time.Second*20))
    if err != nil {
        log.Fatal(err)
    }
    f, err := os.Create(fmt.Sprintf("./data/%d.txt", i))
    if err != nil {
        log.Fatal(err)
    }
    defer f.Close()
    w := bufio.NewWriter(f)
    w.Write(body)
}

func main() {
    var wg sync.WaitGroup
    total := 500

    c …
Run Code Online (Sandbox Code Playgroud)

client http go goroutine fasthttp

4
推荐指数
1
解决办法
4942
查看次数

如何手动计算和验证证书签名请求的签名

  • 我已经创建了一个密钥对

openssl genrsa -out test1 2048

  • 然后使用该密钥创建证书签名请求

openssl req -new -key test1 -subj "/CN=foo" -out foo.csr

  • 使用验证该证书openssl req -in foo.csr -text
    • 它包含我生成的密钥对的公钥

            Public Key Algorithm: rsaEncryption
            Public-Key: (2048 bit)
            Modulus:
                00:ca:c5:29:98:08:05:30:30:03:08:eb:23:c2:af:
                3e:2e:2d:dc:11:96:cb:2f:d1:1f:7f:41:a4:00:13:
                8a:ee:4b:36:5b:f2:c1:d1:0f:8b:27:11:34:08:bd:
                4d:df:7e:6d:7a:d7:f9:dd:ea:62:ad:fa:8f:8c:eb:
                47:5f:55:82:2c:13:c2:11:41:12:b9:87:0b:3d:08:
                86:1b:ad:71:16:89:1c:fa:07:4a:86:8f:80:a9:99:
                37:f7:e2:d4:d3:d8:b2:5f:7f:c9:05:51:73:f0:c8:
                59:ec:c3:09:a2:03:a5:6e:ec:8b:d9:9c:11:de:d3:
                df:55:a5:3f:0c:36:d6:93:8a:70:a0:b9:61:cd:c9:
                4a:09:ad:f7:3e:fd:ce:6f:5c:bb:00:69:e9:3b:3d:
                85:3b:01:1d:8f:6a:a7:d4:61:f9:b5:07:1e:90:ed:
                ab:3b:41:cc:db:e8:a0:e7:88:b7:77:35:66:30:b7:
                a6:cd:ea:d6:12:f5:ef:82:63:e9:46:29:2e:7c:10:
                0e:32:fd:04:2d:cd:62:0e:4b:74:46:f7:fd:f6:4a:
                8d:fb:82:9d:37:11:50:ea:9f:f0:d6:64:2b:50:a4:
                f0:18:6e:81:28:11:04:db:2a:0a:f7:b1:70:c5:78:
                fe:ed:e3:55:2c:64:f4:a5:a0:96:f5:11:3a:27:2c:
                5a:51
            Exponent: 65537 (0x10001)
      
      Run Code Online (Sandbox Code Playgroud)
    • 我在创建 CSR 时提供的主题属性

              Subject: CN=foo
      
      Run Code Online (Sandbox Code Playgroud)
    • 数字签名信息

      签名算法:sha256WithRSAEncryption 92:b0:82:a5:aa:98:4a:62:5a:84:8a:15:5c:6f:48:dc:e3:ec:7f:d5:04:e8:c1: 47:55:3c:b3:57:84:16:ff:5a:0d:29:2c:16:f2:cc:0c:18:c3:1f:d5:e1:57:3a:dd:8b: b1:c6:92:c3:fe:cb:2b:9d:7d:79:d5:64:eb:31:00:8b:5e:77:48:ce:66:6f:dd:7b:71: 41:f9:aa:6e:ea:ea:59:e0:cd:f8:db:a9:13:18:d2:2a:fc:12:25:b3:01:44:0c:b1:02: f7:1a:0f:d0:07:04:1d:9f:6f:a1:58:91:87:25:4a:d6:47:a6:b5:4e:3c:a1:fd:b6:6c: c3:96:16: c1:ab:00:d2:4c:95:ee:2c:01:2d:cf:0e:d0:62:1b:4f:0e:34: e3:e8:85:50: 63:74:eb:1f:ac:95:30:d4:df:43:7f:58:11:90:35:29:9d:85:94:dc:c8:c2:29:81:46: 71:20:62:9c:9c:f8:ef:ed:bc:8b:e3:d5:41:b3:14:f7:43:c6:b2:74:c2:22:06:a2:af: 88:68:2e:67:c4:de:ed:61:37:41:d6:df:8a:76:7d:42:5d:98:d3:c9:19:8b:1d:26:73: 92:95:0f:ba:c1:78:3a:55:87:e0:3e:16:13:34:6e:21:13:b9:da:b8:66:f3:0a:ec:79: ae:1a:95:6c:04:cf:b8:b5

以下是我的疑问:

  1. 它考虑了哪些数据字段来计算签名?
  2. 我们可以手动创建签名并使用 CSR 中提到的签名进行验证吗?

encryption openssl pki public-key-encryption public-key

3
推荐指数
1
解决办法
1601
查看次数

Nodejs中的cursorTo有什么用?

我读了一个nodejs的文件,遇到了一个方法cursorTo,我不明白它。请有人解释一下。

function refreshConsole () {
    if (Settings.properties.preventMessageFlicker) {
        readline.cursorTo(process.stdout, 0, 0);
    } else {
        process.stdout.write('\033c');
    }
}
Run Code Online (Sandbox Code Playgroud)

node.js

2
推荐指数
1
解决办法
2716
查看次数

任何人都可以解释这个使用方法表达式的程序

我正在阅读一些教程,但我无法理解表达式是什么.任何人都可以向我解释这个代码以及为什么/什么时候应该使用它?

 // Method call with "method expression" syntax
 func main() {
    dog := Dog{}
    b := (*Dog).Bark // method expression 
    b(&dog, 5)
 }
 type Dog struct {}

 // Methods have a receiver, and can also have a pointer
 func (d *Dog) Bark(n int) {
   for i := 0; i < n; i++ {
      fmt.Println("Bark");
   }
 }
Run Code Online (Sandbox Code Playgroud)

go

1
推荐指数
1
解决办法
324
查看次数

Golang 读取 csv 消耗的内存空间是磁盘空间的 2 倍以上

我正在使用 Golang 将大量 CSV 文件加载到结构中。结构是

type csvData struct {
    Index   []time.Time
    Columns map[string][]float64
}    
Run Code Online (Sandbox Code Playgroud)

我有一个解析器使用:

csv.NewReader(file).ReadAll()
Run Code Online (Sandbox Code Playgroud)

然后我迭代行,并将值转换为其类型:time.Timefloat64

问题是这些文件在磁盘上占用了 5GB 空间。一旦我将它们加载到内存中,它们就会消耗 12GB!

我使用ioutil.ReadFile(path)后发现,正如预期的那样,这几乎与磁盘上的大小完全相同。

这是我的解析器的代码,为了可读性省略了错误,如果您可以帮助我排除故障:

csv.NewReader(file).ReadAll()
Run Code Online (Sandbox Code Playgroud)

我尝试通过在函数调用结束时将columnData和设置为 nil 来进行故障排除,但没有任何变化。reader

csv go

1
推荐指数
1
解决办法
1492
查看次数