-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(BEDS-461) implement get user machine metrics
- Loading branch information
1 parent
7d35b43
commit be26d51
Showing
10 changed files
with
273 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package dataaccess | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/gobitfly/beaconchain/pkg/api/types" | ||
) | ||
|
||
type MachineRepository interface { | ||
GetUserMachineMetrics(context context.Context, userID uint64, limit uint64, offset uint64) (*types.MachineMetricsData, error) | ||
} | ||
|
||
func (d *DataAccessService) GetUserMachineMetrics(ctx context.Context, userID uint64, limit uint64, offset uint64) (*types.MachineMetricsData, error) { | ||
return d.dummy.GetUserMachineMetrics(ctx, userID, limit, offset) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package handlers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gobitfly/beaconchain/pkg/api/types" | ||
) | ||
|
||
func (h *HandlerService) InternalGetUserMachineMetrics(w http.ResponseWriter, r *http.Request) { | ||
h.PublicGetUserMachineMetrics(w, r) | ||
} | ||
|
||
func (h *HandlerService) PublicGetUserMachineMetrics(w http.ResponseWriter, r *http.Request) { | ||
var v validationError | ||
userId, err := GetUserIdByContext(r) | ||
if err != nil { | ||
handleErr(w, r, err) | ||
return | ||
} | ||
q := r.URL.Query() | ||
offset := v.checkUint(q.Get("offset"), "offset") | ||
limit := uint64(180) | ||
if limitParam := q.Get("limit"); limitParam != "" { | ||
limit = v.checkUint(limitParam, "limit") | ||
} | ||
|
||
data, err := h.dai.GetUserMachineMetrics(r.Context(), userId, limit, offset) | ||
if err != nil { | ||
handleErr(w, r, err) | ||
return | ||
} | ||
response := types.GetUserMachineMetricsRespone{ | ||
Data: *data, | ||
} | ||
|
||
returnOk(w, r, response) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package types | ||
|
||
type MachineMetricSystem struct { | ||
Timestamp uint64 `json:"timestamp,omitempty" faker:"boundary_start=1725166800, boundary_end=1725177600"` | ||
ExporterVersion string `json:"exporter_version,omitempty"` | ||
// system | ||
CpuCores uint64 `json:"cpu_cores,omitempty"` | ||
CpuThreads uint64 `json:"cpu_threads,omitempty"` | ||
CpuNodeSystemSecondsTotal uint64 `json:"cpu_node_system_seconds_total,omitempty"` | ||
CpuNodeUserSecondsTotal uint64 `json:"cpu_node_user_seconds_total,omitempty"` | ||
CpuNodeIowaitSecondsTotal uint64 `json:"cpu_node_iowait_seconds_total,omitempty"` | ||
CpuNodeIdleSecondsTotal uint64 `json:"cpu_node_idle_seconds_total,omitempty"` | ||
MemoryNodeBytesTotal uint64 `json:"memory_node_bytes_total,omitempty"` | ||
MemoryNodeBytesFree uint64 `json:"memory_node_bytes_free,omitempty"` | ||
MemoryNodeBytesCached uint64 `json:"memory_node_bytes_cached,omitempty"` | ||
MemoryNodeBytesBuffers uint64 `json:"memory_node_bytes_buffers,omitempty"` | ||
DiskNodeBytesTotal uint64 `json:"disk_node_bytes_total,omitempty"` | ||
DiskNodeBytesFree uint64 `json:"disk_node_bytes_free,omitempty"` | ||
DiskNodeIoSeconds uint64 `json:"disk_node_io_seconds,omitempty"` | ||
DiskNodeReadsTotal uint64 `json:"disk_node_reads_total,omitempty"` | ||
DiskNodeWritesTotal uint64 `json:"disk_node_writes_total,omitempty"` | ||
NetworkNodeBytesTotalReceive uint64 `json:"network_node_bytes_total_receive,omitempty"` | ||
NetworkNodeBytesTotalTransmit uint64 `json:"network_node_bytes_total_transmit,omitempty"` | ||
MiscNodeBootTsSeconds uint64 `json:"misc_node_boot_ts_seconds,omitempty"` | ||
MiscOs string `json:"misc_os,omitempty"` | ||
// do not store in bigtable but include them in generated model | ||
Machine *string `json:"machine,omitempty"` | ||
} | ||
|
||
type MachineMetricValidator struct { | ||
Timestamp uint64 `json:"timestamp,omitempty" faker:"boundary_start=1725166800, boundary_end=1725177600"` | ||
ExporterVersion string `json:"exporter_version,omitempty"` | ||
// process | ||
CpuProcessSecondsTotal uint64 `json:"cpu_process_seconds_total,omitempty"` | ||
MemoryProcessBytes uint64 `json:"memory_process_bytes,omitempty"` | ||
ClientName string `json:"client_name,omitempty"` | ||
ClientVersion string `json:"client_version,omitempty"` | ||
ClientBuild uint64 `json:"client_build,omitempty"` | ||
SyncEth2FallbackConfigured bool `json:"sync_eth2_fallback_configured,omitempty"` | ||
SyncEth2FallbackConnected bool `json:"sync_eth2_fallback_connected,omitempty"` | ||
// validator | ||
ValidatorTotal uint64 `json:"validator_total,omitempty"` | ||
ValidatorActive uint64 `json:"validator_active,omitempty"` | ||
// do not store in bigtable but include them in generated model | ||
Machine *string `json:"machine,omitempty"` | ||
} | ||
|
||
type MachineMetricNode struct { | ||
Timestamp uint64 `json:"timestamp,omitempty" faker:"boundary_start=1725166800, boundary_end=1725177600"` | ||
ExporterVersion string `json:"exporter_version,omitempty"` | ||
// process | ||
CpuProcessSecondsTotal uint64 `json:"cpu_process_seconds_total,omitempty"` | ||
MemoryProcessBytes uint64 `json:"memory_process_bytes,omitempty"` | ||
ClientName string `json:"client_name,omitempty"` | ||
ClientVersion string `json:"client_version,omitempty"` | ||
ClientBuild uint64 `json:"client_build,omitempty"` | ||
SyncEth2FallbackConfigured bool `json:"sync_eth2_fallback_configured,omitempty"` | ||
SyncEth2FallbackConnected bool `json:"sync_eth2_fallback_connected,omitempty"` | ||
// node | ||
DiskBeaconchainBytesTotal uint64 `json:"disk_beaconchain_bytes_total,omitempty"` | ||
NetworkLibp2PBytesTotalReceive uint64 `json:"network_libp2p_bytes_total_receive,omitempty"` | ||
NetworkLibp2PBytesTotalTransmit uint64 `json:"network_libp2p_bytes_total_transmit,omitempty"` | ||
NetworkPeersConnected uint64 `json:"network_peers_connected,omitempty"` | ||
SyncEth1Connected bool `json:"sync_eth1_connected,omitempty"` | ||
SyncEth2Synced bool `json:"sync_eth2_synced,omitempty"` | ||
SyncBeaconHeadSlot uint64 `json:"sync_beacon_head_slot,omitempty"` | ||
SyncEth1FallbackConfigured bool `json:"sync_eth1_fallback_configured,omitempty"` | ||
SyncEth1FallbackConnected bool `json:"sync_eth1_fallback_connected,omitempty"` | ||
// do not store in bigtable but include them in generated model | ||
Machine *string `json:"machine,omitempty"` | ||
} | ||
|
||
type MachineMetricsData struct { | ||
SystemMetrics []*MachineMetricSystem `json:"system_metrics" faker:"slice_len=30"` | ||
ValidatorMetrics []*MachineMetricValidator `json:"validator_metrics" faker:"slice_len=30"` | ||
NodeMetrics []*MachineMetricNode `json:"node_metrics" faker:"slice_len=30"` | ||
} | ||
|
||
type GetUserMachineMetricsRespone ApiDataResponse[MachineMetricsData] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Code generated by tygo. DO NOT EDIT. | ||
/* eslint-disable */ | ||
import type { ApiDataResponse } from './common' | ||
|
||
////////// | ||
// source: machine_metrics.go | ||
|
||
export interface MachineMetricSystem { | ||
timestamp?: number /* uint64 */; | ||
exporter_version?: string; | ||
/** | ||
* system | ||
*/ | ||
cpu_cores?: number /* uint64 */; | ||
cpu_threads?: number /* uint64 */; | ||
cpu_node_system_seconds_total?: number /* uint64 */; | ||
cpu_node_user_seconds_total?: number /* uint64 */; | ||
cpu_node_iowait_seconds_total?: number /* uint64 */; | ||
cpu_node_idle_seconds_total?: number /* uint64 */; | ||
memory_node_bytes_total?: number /* uint64 */; | ||
memory_node_bytes_free?: number /* uint64 */; | ||
memory_node_bytes_cached?: number /* uint64 */; | ||
memory_node_bytes_buffers?: number /* uint64 */; | ||
disk_node_bytes_total?: number /* uint64 */; | ||
disk_node_bytes_free?: number /* uint64 */; | ||
disk_node_io_seconds?: number /* uint64 */; | ||
disk_node_reads_total?: number /* uint64 */; | ||
disk_node_writes_total?: number /* uint64 */; | ||
network_node_bytes_total_receive?: number /* uint64 */; | ||
network_node_bytes_total_transmit?: number /* uint64 */; | ||
misc_node_boot_ts_seconds?: number /* uint64 */; | ||
misc_os?: string; | ||
/** | ||
* do not store in bigtable but include them in generated model | ||
*/ | ||
machine?: string; | ||
} | ||
export interface MachineMetricValidator { | ||
timestamp?: number /* uint64 */; | ||
exporter_version?: string; | ||
/** | ||
* process | ||
*/ | ||
cpu_process_seconds_total?: number /* uint64 */; | ||
memory_process_bytes?: number /* uint64 */; | ||
client_name?: string; | ||
client_version?: string; | ||
client_build?: number /* uint64 */; | ||
sync_eth2_fallback_configured?: boolean; | ||
sync_eth2_fallback_connected?: boolean; | ||
/** | ||
* validator | ||
*/ | ||
validator_total?: number /* uint64 */; | ||
validator_active?: number /* uint64 */; | ||
/** | ||
* do not store in bigtable but include them in generated model | ||
*/ | ||
machine?: string; | ||
} | ||
export interface MachineMetricNode { | ||
timestamp?: number /* uint64 */; | ||
exporter_version?: string; | ||
/** | ||
* process | ||
*/ | ||
cpu_process_seconds_total?: number /* uint64 */; | ||
memory_process_bytes?: number /* uint64 */; | ||
client_name?: string; | ||
client_version?: string; | ||
client_build?: number /* uint64 */; | ||
sync_eth2_fallback_configured?: boolean; | ||
sync_eth2_fallback_connected?: boolean; | ||
/** | ||
* node | ||
*/ | ||
disk_beaconchain_bytes_total?: number /* uint64 */; | ||
network_libp2p_bytes_total_receive?: number /* uint64 */; | ||
network_libp2p_bytes_total_transmit?: number /* uint64 */; | ||
network_peers_connected?: number /* uint64 */; | ||
sync_eth1_connected?: boolean; | ||
sync_eth2_synced?: boolean; | ||
sync_beacon_head_slot?: number /* uint64 */; | ||
sync_eth1_fallback_configured?: boolean; | ||
sync_eth1_fallback_connected?: boolean; | ||
/** | ||
* do not store in bigtable but include them in generated model | ||
*/ | ||
machine?: string; | ||
} | ||
export interface MachineMetricsData { | ||
system_metrics: (MachineMetricSystem | undefined)[]; | ||
validator_metrics: (MachineMetricValidator | undefined)[]; | ||
node_metrics: (MachineMetricNode | undefined)[]; | ||
} | ||
export type GetUserMachineMetricsRespone = ApiDataResponse<MachineMetricsData>; |