Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use shirou/gopsutil for getting CPU info on Linux #970

Merged
merged 1 commit into from
Mar 1, 2024
Merged

Conversation

Arthur1
Copy link
Member

@Arthur1 Arthur1 commented Feb 21, 2024

On Linux with arm64 architecture, CPU stats are not included in the host meta data sent by mackerel-agent.

スクリーンショット 2024-02-29 2 40 10

This problem is caused by the different format of /proc/cpuinfo in arm64. cf.) https://blog.arthur1.dev/entry/2024/02/22/094044 (ja)

It can be solved by using shirou/gopsutil, a library that enables the acquisition of CPU information that also takes into account the arm architecture.

Test

arm64

before

$ curl -s 'https://api.mackerelio.com/api/v0/hosts/******' \
--header $MACKEREL_API_HEADER | jq '.host.meta.cpu | length'
4
$ curl -s 'https://api.mackerelio.com/api/v0/hosts/******' \
--header $MACKEREL_API_HEADER | jq '.host.meta.cpu[0]'
{}

after

$ curl -s 'https://api.mackerelio.com/api/v0/hosts/******' \
--header $MACKEREL_API_HEADER | jq '.host.meta.cpu | length'
4
$ curl -s 'https://api.mackerelio.com/api/v0/hosts/******' \
--header $MACKEREL_API_HEADER | jq '.host.meta.cpu[0]'
{
  "cache_size": "0 KB",
  "core_id": "0",
  "cores": "1",
  "family": "",
  "mhz": "1800",
  "model": "0xd08",
  "model_name": "Cortex-A72",
  "physical_id": "",
  "stepping": "3",
  "vendor_id": "ARM"
}
スクリーンショット 2024-02-29 0 39 15

x86_64

There are no regressions.

before

$ curl -s 'https://api.mackerelio.com/api/v0/hosts/******' \
--header $MACKEREL_API_HEADER | jq '.host.meta.cpu | length'
2
$ curl -s 'https://api.mackerelio.com/api/v0/hosts/******' \
--header $MACKEREL_API_HEADER | jq '.host.meta.cpu[0]'
{
  "cache_size": "36608 KB",
  "core_id": "0",
  "cores": "1",
  "family": "6",
  "mhz": "2499.998",
  "model": "85",
  "model_name": "Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz",
  "physical_id": "0",
  "stepping": "7",
  "vendor_id": "GenuineIntel"
}

after

$ curl -s 'https://api.mackerelio.com/api/v0/hosts/******' \
--header $MACKEREL_API_HEADER | jq '.host.meta.cpu | length'
2
$ curl -s 'https://api.mackerelio.com/api/v0/hosts/******' \
--header $MACKEREL_API_HEADER | jq '.host.meta.cpu[0]'
{
  "cache_size": "36608 KB",
  "core_id": "0",
  "cores": "1",
  "family": "6",
  "mhz": "2499.998",
  "model": "85",
  "model_name": "Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz",
  "physical_id": "0",
  "stepping": "7",
  "vendor_id": "GenuineIntel"
}

@Arthur1 Arthur1 changed the title use shirou/gopsutil for get cpuinfo Use shirou/gopsutil for getting CPU info on Linux Feb 28, 2024
@Arthur1 Arthur1 self-assigned this Feb 29, 2024
@Arthur1 Arthur1 merged commit a8580d9 into master Mar 1, 2024
6 checks passed
@Arthur1 Arthur1 deleted the arm-model-name branch March 1, 2024 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants