/
main.go
658 lines (562 loc) · 21.7 KB
/
main.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
//
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
package main
import (
"bytes"
"encoding/json"
"errors"
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
"time"
"github.com/newrelic/newrelic-php-agent/daemon/internal/newrelic"
"github.com/newrelic/newrelic-php-agent/daemon/internal/newrelic/config"
"github.com/newrelic/newrelic-php-agent/daemon/internal/newrelic/limits"
"github.com/newrelic/newrelic-php-agent/daemon/internal/newrelic/log"
"github.com/newrelic/newrelic-php-agent/daemon/internal/newrelic/utilization"
"github.com/newrelic/newrelic-php-agent/daemon/internal/newrelic/version"
)
// A custom FlagSet with special argument handling is used. This allows the
// daemon to use alias arguments (--port is an alias for --address), and to
// issue a warning if both flags are set (that's what daemonFlagWarning is used
// for).
type DaemonFlagSet struct {
flag.FlagSet
cfg *Config
}
type daemonFlagWarning struct {
error
}
func (e *daemonFlagWarning) Error() string {
return e.error.Error()
}
func createDaemonFlagSet(cfg *Config) *DaemonFlagSet {
flagSet := flag.NewFlagSet("", flag.ContinueOnError)
// This prevents parsing errors from being printed. Instead, we'll print
// those ourselves.
flagSet.SetOutput(ioutil.Discard)
// Print an empty string instead of the default usage if the initial flags
// fail to parse. If it failed because of -h or -help flags, we'll print it
// ourselves.
flagSet.Usage = func() { fmt.Fprint(os.Stderr, "") }
flagSet.StringVar(&cfg.ConfigFile, "c", cfg.ConfigFile, "config file location")
flagSet.StringVar(&cfg.BindPort, "port", cfg.BindPort, "")
flagSet.StringVar(&cfg.BindAddr, "address", cfg.BindAddr, "")
flagSet.StringVar(&cfg.Proxy, "proxy", cfg.Proxy, "")
flagSet.StringVar(&cfg.Pidfile, "pidfile", cfg.Pidfile, "")
flagSet.BoolVar(&cfg.NoPidfile, "no-pidfile", cfg.NoPidfile, "")
flagSet.StringVar(&cfg.LogFile, "logfile", cfg.LogFile, "")
flagSet.Var(&cfg.LogLevel, "loglevel", "LogLevel")
flagSet.StringVar(&cfg.AuditFile, "auditlog", cfg.AuditFile, "")
flagSet.BoolVar(&cfg.Utilization, "utilization", cfg.Utilization, "")
flagSet.BoolVar(&cfg.Foreground, "f", cfg.Foreground, "")
flagSet.BoolVar(&cfg.WatchdogForeground, "watchdog-foreground", cfg.WatchdogForeground, "")
flagSet.BoolVar(&cfg.Foreground, "foreground", cfg.Foreground, "")
flagSet.BoolVar(&cfg.Agent, "agent", cfg.Agent, "")
flagSet.StringVar(&cfg.CAFile, "cafile", cfg.CAFile, "")
flagSet.StringVar(&cfg.CAPath, "capath", cfg.CAPath, "")
flagSet.BoolVar(&cfg.IntegrationMode, "integration", cfg.IntegrationMode, "")
flagSet.IntVar(&cfg.PProfPort, "pprof", cfg.PProfPort, "")
flagSet.BoolVar(&printVersion, "version", false, "")
flagSet.BoolVar(&printVersion, "v", false, "")
flagSet.DurationVar(&cfg.WaitForPort, "wait-for-port", 3*time.Second, "")
flagSet.Var(config.NewFlagParserShim(cfg), "define", "")
return &DaemonFlagSet{*flagSet, cfg}
}
func (df *DaemonFlagSet) Parse(args []string) error {
// First pass: parse arguments to obtain the config file location
err := df.FlagSet.Parse(args)
if err != nil {
return err
}
// Second pass: pass the config file, if it was given
err = parseConfigFile(df.cfg)
if err != nil {
return err
}
// Thirds pass: pass arguments again to give command line arguments
// precedence over config file arguments
err = df.FlagSet.Parse(args)
if err != nil {
return err
}
// Fourth pass: Consistency checks
//
// The daemon offers two competing flags, --port and --address. However, both
// cannot be set simultaneously. Examine whether each of these values
// has been set. If neither is set, use the default value. If both
// have been set, log a warning and use --address, which takes precedence.
//
// Internally, the daemon uses --address for the listening address. Take care
// to set --address to whatever --port has been supplied. Moreover, if neither
// flag has been set, set --address to the daemon's default value, to match legacy
// daemon behavior.
portFlag := df.FlagSet.Lookup("port").Value
addrFlag := df.FlagSet.Lookup("address").Value
if addrFlag.String() == "" && portFlag.String() == "" {
// Both flags are empty. Use the default.
addrFlag.Set(newrelic.DefaultListenSocket())
} else if addrFlag.String() != "" && portFlag.String() != "" {
// Both flags are set. Use --address and write a warning.
err = &daemonFlagWarning{
errors.New(fmt.Sprintf("Both --port and --address are set. Using --address: %s", addrFlag.String())),
}
} else if addrFlag.String() == "" {
// Only --port is given. Copy the value into --address.
addrFlag.Set(portFlag.String())
}
return err
}
// Program usage text. Note the options are organized in an attempt to
// place the most relevant choices near the top.
const usage = `Usage: newrelic-daemon [OPTIONS]
Options:
-c <config-file> Set the path to the configuration file
--logfile <file> Set the path to the log file
--loglevel <level> Log level (error, warning, info or debug)
Default: info
--pidfile <file> Set the path to the process id file
--port <port> Listen on the specified port or socket file path
Only one of --port or --address may be set; if both are
set, --address takes precedence
--address <addr> Listen on the specified host:port or socket file path
Only one of --port or --address may be set; if both are
set, --address takes precedence
--proxy <url> Proxy credentials to use
--auditlog <file> Set the path to the audit file
--cafile <file> Set the path to root CA bundle
--capath <dir> Set the path to a directory of root CA certs
--wait-for-port <timeout> Prevent forking into the background until the
daemon is listening on its configured port, or
until the timeout is hit
Default: 3s
--watchdog-foreground The watchdog process remains in the foreground
--define <setting>=<value> Set a setting (as in newrelic.cfg) to a value
Uses the same syntax as newrelic.cfg
Takes precedence over config file settings
-f, --foreground The worker process remains in the foreground
-h, --help Print this message and exit
-v, --version Print version information and exit
Note: command line options have higher priority than their corresponding
option in the configuration file.
Please visit https://docs.newrelic.com/docs/agents/php-agent for additional help.
`
const legacyNotice = `Warning!
You are using legacy command-line flags. We plan to remove the following flags
in a future version:
[-p pidfile]
[-d level]
[-c config]
[-l logfile]
[-P port]
[-s]
[-n]
[-b SSL-certificate-bundle]
[-S SSL-certificate-path]
[-H host]
[-x proxy]
[-a auditlog]
Please use the shiny new flags listed with the -h or --help flag.
`
// A Role determines how the current daemon process should behave.
type Role int
const (
// RoleProgenitor indicates a daemon process whose sole responsiblity is
// to respawn itself in a new session and exit. This ensures the daemon
// can outlive its original parent and does not have a controlling TTY.
// When the agent spawns a daemon, the aforementioned is what we want
// to happen. For that reason it is the default behavior.
RoleProgenitor Role = iota
// RoleWatcher indicates a daemon process that spawns and supervises workers.
// When a worker exits unexpectedly, the watcher logs the error and
// spawns a new worker.
RoleWatcher
// RoleWorker indicates a daemon process that creates and binds a listener,
// collects data, and executes the harvest.
RoleWorker
)
// Config provides the effective settings for the daemon.
type Config struct {
BindPort string `config:"port"` // Listener bind address, path=UDS, port=TCP
BindAddr string `config:"address"` // Listener bind address, <host:port>, since agent v9.2
Proxy string `config:"proxy"` // Proxy credentials to use for reporting
Pidfile string `config:"pidfile"` // Path to daemon pid file
NoPidfile bool `config:"-"` // Used to avoid two processes using pidfile
LogFile string `config:"logfile"` // Path to daemon log file
LogLevel log.Level `config:"loglevel"` // Log level
AuditFile string `config:"auditlog"` // Path to audit log
ConfigFile string `config:"-"` // Location of config file
Foreground bool `config:"-"` // Remain in foreground
WatchdogForeground bool `config:"-"` // Let the watchdog process remain in foreground
Role Role `config:"-"` // This daemon's role
Utilization bool `config:"-"` // Whether to print utilization data and exit
DetectAWS bool `config:"utilization.detect_aws"` // Whether to detect if this is running on AWS in utilization
DetectAzure bool `config:"utilization.detect_azure"` // Whether to detect if this is running on Azure in utilization
DetectGCP bool `config:"utilization.detect_gcp"` // Whether to detect if this is running on GCP in utilization
DetectPCF bool `config:"utilization.detect_pcf"` // Whether to detect if this is running on PCF in utilization
DetectDocker bool `config:"utilization.detect_docker"` // Whether to detect if this is in a Docker container in utilization
DetectKubernetes bool `config:"utilization.detect_kubernetes"` // Whether to detect if this is in a Kubernetes cluster
LogicalProcessors int `config:"utilization.logical_processors"` // Customer provided number of logical processors for pricing control.
TotalRamMIB int `config:"utilization.total_ram_mib"` // Customer provided total RAM in mebibytes for pricing control.
BillingHostname string `config:"utilization.billing_hostname"` // Customer provided hostname for pricing control.
Agent bool `config:"-"` // Used to indicate if spawned by agent
MaxFiles uint64 `config:"rlimit_files"` // Maximum number of open file descriptors
PProfPort int `config:"-"` // Port for pprof web server
CAPath string `config:"ssl_ca_path"` // Path to a directory of root CA certificates.
CAFile string `config:"ssl_ca_bundle"` // Path to a file containing a bundle of root CA certificates.
IntegrationMode bool `config:"-"` // Whether to log integration test output
AppTimeout config.Timeout `config:"app_timeout"` // Inactivity timeout for applications.
WaitForPort time.Duration `config:"wait_for_port"` // How long to wait for the worker process to open a port.
}
func (cfg *Config) MakeUtilConfig() utilization.Config {
return utilization.Config{
DetectAWS: cfg.DetectAWS,
DetectAzure: cfg.DetectAzure,
DetectGCP: cfg.DetectGCP,
DetectPCF: cfg.DetectPCF,
DetectDocker: cfg.DetectDocker,
DetectKubernetes: cfg.DetectKubernetes,
LogicalProcessors: cfg.LogicalProcessors,
TotalRamMIB: cfg.TotalRamMIB,
BillingHostname: cfg.BillingHostname,
}
}
var (
printVersion = false
)
var (
exitStatus int
exitMutex sync.Mutex
)
func shouldCreatePidfile(cfg *Config) bool {
if cfg.NoPidfile || "" == cfg.Pidfile {
return false
}
return cfg.Role == RoleWatcher || cfg.Role == RoleWorker
}
// This helper function exists so that the pidfile cleanup defer will not be in
// the same function as the actual exit call.
func run(cfg *Config) {
if shouldCreatePidfile(cfg) {
pidFile, err := newrelic.CreatePidFile(cfg.Pidfile)
if err != nil {
if err == newrelic.ErrLocked {
// another process has already holds the pid file lock
return
}
log.Errorf("could not create pid file: %v", err)
setExitStatus(1)
return
}
defer pidFile.Remove()
log.Debugf("pidfile=%s", pidFile.Name())
if _, err := pidFile.Write(); err != nil {
log.Errorf("could not write pid to file: %v", err)
setExitStatus(1)
return
}
}
switch cfg.Role {
case RoleProgenitor:
runProgenitor(cfg)
case RoleWatcher:
runWatcher(cfg)
case RoleWorker:
runWorker(cfg)
default:
log.Errorf("invalid role: %d", cfg.Role)
setExitStatus(1)
}
}
func main() {
// Respect GOMAXPROCS if set; otherwise, use all available CPUs.
if os.Getenv("GOMAXPROCS") == "" {
runtime.GOMAXPROCS(runtime.NumCPU())
}
cfg := configure()
if printVersion {
fmt.Printf("New Relic daemon version %s\n", version.Full())
fmt.Println("(C) Copyright 2009-2019 New Relic Inc. All rights reserved.")
fmt.Println()
return
}
if cfg.Utilization {
util := utilization.Gather(utilization.Config{
DetectAWS: true,
DetectAzure: true,
DetectGCP: true,
DetectPCF: true,
DetectDocker: true,
DetectKubernetes: true,
})
str, err := json.MarshalIndent(util, "", "\t")
if err != nil {
fmt.Printf("Error gathering utilization: %s", err.Error())
os.Exit(1)
}
fmt.Printf("%s\n", str)
os.Exit(0)
}
if err := initLog(cfg); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
log.Infof("%s", banner(cfg))
// Used to not log out the proxy, which has potentially secret credentials
var proxy bool = false
for i := range os.Args {
if proxy {
log.Debugf("ARGV[%d]: **REDACTED**", i)
proxy = false
} else {
log.Debugf("ARGV[%d]: %s", i, os.Args[i])
if ("--proxy" == os.Args[i]) {
proxy = true
}
}
}
log.Debugf("process role is %v", cfg.Role)
run(cfg)
os.Exit(exitStatus)
}
func createLegacyFlagSet(cfg *Config) *flag.FlagSet {
legacyFlagSet := flag.NewFlagSet("", flag.ContinueOnError)
legacyFlagSet.SetOutput(ioutil.Discard)
legacyFlagSet.Usage = func() { fmt.Fprint(os.Stderr, "") }
legacyFlagSet.StringVar(&cfg.ConfigFile, "c", cfg.ConfigFile, "config file location")
legacyFlagSet.StringVar(&cfg.BindAddr, "P", cfg.BindAddr, "")
legacyFlagSet.StringVar(&cfg.Proxy, "x", cfg.Proxy, "")
legacyFlagSet.StringVar(&cfg.Pidfile, "p", cfg.Pidfile, "")
// no-pidfile needs to be in here to pass to the worker process
legacyFlagSet.BoolVar(&cfg.NoPidfile, "no-pidfile", cfg.NoPidfile, "")
legacyFlagSet.StringVar(&cfg.LogFile, "l", cfg.LogFile, "")
legacyFlagSet.Var(&cfg.LogLevel, "d", "LogLevel")
legacyFlagSet.StringVar(&cfg.AuditFile, "a", cfg.AuditFile, "")
legacyFlagSet.BoolVar(&cfg.Foreground, "f", cfg.Foreground, "")
legacyFlagSet.BoolVar(&cfg.Agent, "A", cfg.Agent, "")
legacyFlagSet.StringVar(&cfg.CAFile, "b", cfg.CAFile, "")
legacyFlagSet.StringVar(&cfg.CAPath, "S", cfg.CAPath, "")
return legacyFlagSet
}
func parseConfigFile(cfg *Config) error {
if cfg.ConfigFile != "" {
if err := config.ParseFile(cfg.ConfigFile, cfg); err != nil {
return err
}
}
return nil
}
var (
defaultCfg = Config{
LogLevel: log.LogInfo,
LogFile: "",
AuditFile: "",
MaxFiles: 2048, // to match the legacy daemon behavior
NoPidfile: false,
DetectAWS: true,
DetectAzure: true,
DetectGCP: true,
DetectPCF: true,
DetectDocker: true,
AppTimeout: config.Timeout(limits.DefaultAppTimeout),
}
)
// configure parses the command line options, and, if provided, the
// configuration file and returns a Config with the results.
//
// This function exits on error.
func configure() *Config {
cfg := defaultCfg
args := os.Args[1:]
flagSet := createDaemonFlagSet(&cfg)
err := flagSet.Parse(args)
// If no error or just a warning was returned, this means we work with
// new arguments. If an error was returned, we try to parse legacy
// arguments.
_, isWarning := err.(*daemonFlagWarning)
if err != nil && !isWarning {
// If the error was due to the -h or -help flag, print usage.
if err == flag.ErrHelp {
fmt.Fprint(os.Stderr, usage)
os.Exit(2)
}
// Were they trying to use valid legacy flags? We'll reset the config
// struct in case it was modified and store the error in case the flags
// turn out to be invalid.
cfg = defaultCfg
legacyFlagSet := createLegacyFlagSet(&cfg)
firstError := err
if err := legacyFlagSet.Parse(args); err != nil {
fmt.Fprintf(os.Stderr, "%s\n", firstError)
fmt.Fprint(os.Stderr, "\n", usage)
os.Exit(1)
}
// We now know they're using valid legacy flags, so warn 'em
fmt.Fprintf(os.Stderr, legacyNotice)
if err := parseConfigFile(&cfg); err != nil {
fmt.Fprintf(os.Stderr, "invalid configuration: %v\n", err)
os.Exit(1)
}
legacyFlagSet.Parse(args)
} else if err != nil && isWarning {
fmt.Fprintf(os.Stderr, "%v\n", err)
}
cfg.Role = getRole()
if cfg.Role == RoleProgenitor {
// The --foreground and --watchdog-foreground flags override
// the progenitor role.
if cfg.Foreground {
cfg.Role = RoleWorker
} else if cfg.WatchdogForeground {
cfg.Role = RoleWatcher
}
}
return &cfg
}
const RoleEnvironmentVariable = "NEW_RELIC_DAEMON_ROLE"
func getRole() Role {
switch strings.ToLower(os.Getenv(RoleEnvironmentVariable)) {
case "watcher":
return RoleWatcher
case "worker":
return RoleWorker
default:
return RoleProgenitor
}
}
func setExitStatus(code int) {
exitMutex.Lock()
defer exitMutex.Unlock()
if code > exitStatus {
exitStatus = code
}
}
// spawnWatcher respawns the current process in a new session.
func spawnWatcher(cfg *Config) (*exec.Cmd, error) {
// The current directory is going to be changed to the root directory
// just before calling exec(2). If name is relative to the current
// directory, convert to an absolute path so exec(2) can still find us.
name, err := exec.LookPath(os.Args[0])
if err != nil {
return nil, err
}
name, err = filepath.Abs(name)
if err != nil {
return nil, err
}
env := Environment(os.Environ())
env.Set(RoleEnvironmentVariable, "watcher")
env.Set("PWD", "/")
cmd := exec.Command(name, os.Args[1:]...)
cmd.Dir = "/"
cmd.Env = []string(env)
return cmd, cmd.Start()
}
// Environment adds convenience methods to []string for treating its
// elements as environment variables in KEY=VALUE form as provided by
// os.Environ() and given to exec.Cmd.Env.
type Environment []string
// Index returns the index of the first instance of key in the Environment.
func (env Environment) Index(key string) int {
for i := range env {
eq := strings.IndexByte(env[i], '=')
if eq != -1 && env[i][:eq] == key {
return i
}
}
return -1
}
// Set sets the value of the environment variable given by key. The
// environment variable will be added if it does not already exist.
func (env *Environment) Set(key, value string) {
if i := env.Index(key); i != -1 {
(*env)[i] = key + "=" + value
} else {
*env = append(*env, key+"="+value)
}
}
// initLog opens the daemon log based on the current configuration settings.
// If no log has been specified, initLog will try the following standard
// locations.
//
// /var/log/newrelic/newrelic-daemon.log
// /var/log/newrelic-daemon.log
//
// If no suitable location can be found, a generic error is returned.
func initLog(cfg *Config) error {
if cfg.LogFile != "" {
return log.Init(cfg.LogLevel, cfg.LogFile)
}
standardDirs := []string{"/var/log/newrelic", "/var/log"}
for _, dir := range standardDirs {
path := filepath.Join(dir, "newrelic-daemon.log")
err := log.Init(cfg.LogLevel, path)
if err == nil {
return nil
}
}
return fmt.Errorf("unable to find a suitable log file location, "+
"please check that %s exists and is writable", standardDirs[0])
}
func (r Role) String() string {
switch r {
case RoleProgenitor:
return "progenitor"
case RoleWatcher:
return "watcher"
case RoleWorker:
return "worker"
default:
return "unknown(" + strconv.Itoa(int(r)) + ")"
}
}
func banner(cfg *Config) string {
buf := &bytes.Buffer{}
fmt.Fprintf(buf, "New Relic daemon version %s [", version.Full())
fmt.Fprintf(buf, "listen=%q", cfg.BindAddr)
if cfg.Agent {
fmt.Fprint(buf, " startup=agent")
} else {
fmt.Fprint(buf, " startup=init")
}
// process info
fmt.Fprint(buf, " pid=", os.Getpid())
fmt.Fprint(buf, " ppid=", os.Getppid())
fmt.Fprint(buf, " uid=", os.Getuid())
fmt.Fprint(buf, " euid=", os.Geteuid())
fmt.Fprint(buf, " gid=", os.Getgid())
fmt.Fprint(buf, " egid=", os.Getegid())
// go compiler + runtime info
fmt.Fprint(buf, ` runtime="`, runtime.Version(), `"`)
fmt.Fprint(buf, " GOMAXPROCS=", runtime.GOMAXPROCS(-1))
fmt.Fprint(buf, " GOOS=", runtime.GOOS)
fmt.Fprint(buf, " GOARCH=", runtime.GOARCH)
fmt.Fprint(buf, "]")
return buf.String()
}
// A borkedSyscallError describes the failed handling of missing system calls
// on very old Xen Linux kernels.
type borkedSyscallError string
func (e borkedSyscallError) Error() string {
version := "unknown"
if runtime.GOOS == "linux" {
if v, err := ioutil.ReadFile("/proc/sys/kernel/osrelease"); err == nil {
version = string(v)
}
}
return fmt.Sprintf(
"Your operating system is not supported by this New Relic"+
" product. If you have any questions or believe you reached this"+
" message in error, please file a ticket with New Relic support."+
" version=%s reason='%s is missing, but did not return -ENOSYS'",
version, string(e))
}