-
Notifications
You must be signed in to change notification settings - Fork 0
/
criprof.go
executable file
·54 lines (45 loc) · 1.13 KB
/
criprof.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright © 2022-2023 Christian R. Vozar
// Licensed under the MIT License. All rights reserved.
package criprof
import (
"encoding/json"
"fmt"
"os"
)
// EnvironmentVariables is used to cache all environment variables read at
// execution.
var EnvironmentVariables map[string]string
func init() {
EnvironmentVariables = environMap()
}
// Inventory holds an application's container and runtime information.
type Inventory struct {
Hostname string `json:"hostname"`
ID string `json:"id"`
ImageFormat string `json:"image_format"`
PID int `json:"pid"`
Runtime string `json:"runtime"`
Scheduler string `json:"scheduler"`
}
// New returns a new Inventory with populated values.
func New() *Inventory {
f, _ := getImageFormat()
h, _ := getHostname()
return &Inventory{
Hostname: h,
ID: getContainerID(),
ImageFormat: f,
PID: os.Getpid(),
Runtime: getRuntime(),
Scheduler: getScheduler(),
}
}
// JSON returns the Inventory as JSON string.
func (i Inventory) JSON() string {
j, err := json.Marshal(i)
if err != nil {
fmt.Println(err)
return ""
}
return string(j)
}