repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
prometheus/node_exporter | collector/cpu_freebsd.go | NewStatCollector | func NewStatCollector() (Collector, error) {
return &statCollector{
cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue},
temp: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "temperature_celsius"),
"CPU temperature",
[]string{"cpu"}, nil,
), prometheus.GaugeValue},
}, nil
} | go | func NewStatCollector() (Collector, error) {
return &statCollector{
cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue},
temp: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(namespace, cpuCollectorSubsystem, "temperature_celsius"),
"CPU temperature",
[]string{"cpu"}, nil,
), prometheus.GaugeValue},
}, nil
} | [
"func",
"NewStatCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"return",
"&",
"statCollector",
"{",
"cpu",
":",
"typedDesc",
"{",
"nodeCPUSecondsDesc",
",",
"prometheus",
".",
"CounterValue",
"}",
",",
"temp",
":",
"typedDesc",
"{",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"cpuCollectorSubsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"nil",
",",
")",
",",
"prometheus",
".",
"GaugeValue",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewStatCollector returns a new Collector exposing CPU stats. | [
"NewStatCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"CPU",
"stats",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/cpu_freebsd.go#L93-L102 | train |
prometheus/node_exporter | collector/bonding_linux.go | NewBondingCollector | func NewBondingCollector() (Collector, error) {
return &bondingCollector{
slaves: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(namespace, "bonding", "slaves"),
"Number of configured slaves per bonding interface.",
[]string{"master"}, nil,
), prometheus.GaugeValue},
active: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(namespace, "bonding", "active"),
"Number of active slaves per bonding interface.",
[]string{"master"}, nil,
), prometheus.GaugeValue},
}, nil
} | go | func NewBondingCollector() (Collector, error) {
return &bondingCollector{
slaves: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(namespace, "bonding", "slaves"),
"Number of configured slaves per bonding interface.",
[]string{"master"}, nil,
), prometheus.GaugeValue},
active: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(namespace, "bonding", "active"),
"Number of active slaves per bonding interface.",
[]string{"master"}, nil,
), prometheus.GaugeValue},
}, nil
} | [
"func",
"NewBondingCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"return",
"&",
"bondingCollector",
"{",
"slaves",
":",
"typedDesc",
"{",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"nil",
",",
")",
",",
"prometheus",
".",
"GaugeValue",
"}",
",",
"active",
":",
"typedDesc",
"{",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"nil",
",",
")",
",",
"prometheus",
".",
"GaugeValue",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewBondingCollector returns a newly allocated bondingCollector.
// It exposes the number of configured and active slave of linux bonding interfaces. | [
"NewBondingCollector",
"returns",
"a",
"newly",
"allocated",
"bondingCollector",
".",
"It",
"exposes",
"the",
"number",
"of",
"configured",
"and",
"active",
"slave",
"of",
"linux",
"bonding",
"interfaces",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/bonding_linux.go#L39-L52 | train |
prometheus/node_exporter | collector/entropy_linux.go | NewEntropyCollector | func NewEntropyCollector() (Collector, error) {
return &entropyCollector{
entropyAvail: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "entropy_available_bits"),
"Bits of available entropy.",
nil, nil,
),
}, nil
} | go | func NewEntropyCollector() (Collector, error) {
return &entropyCollector{
entropyAvail: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "entropy_available_bits"),
"Bits of available entropy.",
nil, nil,
),
}, nil
} | [
"func",
"NewEntropyCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"return",
"&",
"entropyCollector",
"{",
"entropyAvail",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewEntropyCollector returns a new Collector exposing entropy stats. | [
"NewEntropyCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"entropy",
"stats",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/entropy_linux.go#L33-L41 | train |
prometheus/node_exporter | collector/systemd_linux.go | NewSystemdCollector | func NewSystemdCollector() (Collector, error) {
const subsystem = "systemd"
unitDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "unit_state"),
"Systemd unit", []string{"name", "state", "type"}, nil,
)
unitStartTimeDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "unit_start_time_seconds"),
"Start time of the unit since unix epoch in seconds.", []string{"name"}, nil,
)
unitTasksCurrentDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "unit_tasks_current"),
"Current number of tasks per Systemd unit", []string{"name"}, nil,
)
unitTasksMaxDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "unit_tasks_max"),
"Maximum number of tasks per Systemd unit", []string{"name"}, nil,
)
systemRunningDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "system_running"),
"Whether the system is operational (see 'systemctl is-system-running')",
nil, nil,
)
summaryDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "units"),
"Summary of systemd unit states", []string{"state"}, nil)
nRestartsDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "service_restart_total"),
"Service unit count of Restart triggers", []string{"state"}, nil)
timerLastTriggerDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "timer_last_trigger_seconds"),
"Seconds since epoch of last trigger.", []string{"name"}, nil)
socketAcceptedConnectionsDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "socket_accepted_connections_total"),
"Total number of accepted socket connections", []string{"name"}, nil)
socketCurrentConnectionsDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "socket_current_connections"),
"Current number of socket connections", []string{"name"}, nil)
socketRefusedConnectionsDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "socket_refused_connections_total"),
"Total number of refused socket connections", []string{"name"}, nil)
unitWhitelistPattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *unitWhitelist))
unitBlacklistPattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *unitBlacklist))
return &systemdCollector{
unitDesc: unitDesc,
unitStartTimeDesc: unitStartTimeDesc,
unitTasksCurrentDesc: unitTasksCurrentDesc,
unitTasksMaxDesc: unitTasksMaxDesc,
systemRunningDesc: systemRunningDesc,
summaryDesc: summaryDesc,
nRestartsDesc: nRestartsDesc,
timerLastTriggerDesc: timerLastTriggerDesc,
socketAcceptedConnectionsDesc: socketAcceptedConnectionsDesc,
socketCurrentConnectionsDesc: socketCurrentConnectionsDesc,
socketRefusedConnectionsDesc: socketRefusedConnectionsDesc,
unitWhitelistPattern: unitWhitelistPattern,
unitBlacklistPattern: unitBlacklistPattern,
}, nil
} | go | func NewSystemdCollector() (Collector, error) {
const subsystem = "systemd"
unitDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "unit_state"),
"Systemd unit", []string{"name", "state", "type"}, nil,
)
unitStartTimeDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "unit_start_time_seconds"),
"Start time of the unit since unix epoch in seconds.", []string{"name"}, nil,
)
unitTasksCurrentDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "unit_tasks_current"),
"Current number of tasks per Systemd unit", []string{"name"}, nil,
)
unitTasksMaxDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "unit_tasks_max"),
"Maximum number of tasks per Systemd unit", []string{"name"}, nil,
)
systemRunningDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "system_running"),
"Whether the system is operational (see 'systemctl is-system-running')",
nil, nil,
)
summaryDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "units"),
"Summary of systemd unit states", []string{"state"}, nil)
nRestartsDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "service_restart_total"),
"Service unit count of Restart triggers", []string{"state"}, nil)
timerLastTriggerDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "timer_last_trigger_seconds"),
"Seconds since epoch of last trigger.", []string{"name"}, nil)
socketAcceptedConnectionsDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "socket_accepted_connections_total"),
"Total number of accepted socket connections", []string{"name"}, nil)
socketCurrentConnectionsDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "socket_current_connections"),
"Current number of socket connections", []string{"name"}, nil)
socketRefusedConnectionsDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "socket_refused_connections_total"),
"Total number of refused socket connections", []string{"name"}, nil)
unitWhitelistPattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *unitWhitelist))
unitBlacklistPattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *unitBlacklist))
return &systemdCollector{
unitDesc: unitDesc,
unitStartTimeDesc: unitStartTimeDesc,
unitTasksCurrentDesc: unitTasksCurrentDesc,
unitTasksMaxDesc: unitTasksMaxDesc,
systemRunningDesc: systemRunningDesc,
summaryDesc: summaryDesc,
nRestartsDesc: nRestartsDesc,
timerLastTriggerDesc: timerLastTriggerDesc,
socketAcceptedConnectionsDesc: socketAcceptedConnectionsDesc,
socketCurrentConnectionsDesc: socketCurrentConnectionsDesc,
socketRefusedConnectionsDesc: socketRefusedConnectionsDesc,
unitWhitelistPattern: unitWhitelistPattern,
unitBlacklistPattern: unitBlacklistPattern,
}, nil
} | [
"func",
"NewSystemdCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"const",
"subsystem",
"=",
"\"",
"\"",
"\n\n",
"unitDesc",
":=",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"nil",
",",
")",
"\n",
"unitStartTimeDesc",
":=",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"nil",
",",
")",
"\n",
"unitTasksCurrentDesc",
":=",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"nil",
",",
")",
"\n",
"unitTasksMaxDesc",
":=",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"nil",
",",
")",
"\n",
"systemRunningDesc",
":=",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
"\n",
"summaryDesc",
":=",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"nil",
")",
"\n",
"nRestartsDesc",
":=",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"nil",
")",
"\n",
"timerLastTriggerDesc",
":=",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"nil",
")",
"\n",
"socketAcceptedConnectionsDesc",
":=",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"nil",
")",
"\n",
"socketCurrentConnectionsDesc",
":=",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"nil",
")",
"\n",
"socketRefusedConnectionsDesc",
":=",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"nil",
")",
"\n",
"unitWhitelistPattern",
":=",
"regexp",
".",
"MustCompile",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"*",
"unitWhitelist",
")",
")",
"\n",
"unitBlacklistPattern",
":=",
"regexp",
".",
"MustCompile",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"*",
"unitBlacklist",
")",
")",
"\n\n",
"return",
"&",
"systemdCollector",
"{",
"unitDesc",
":",
"unitDesc",
",",
"unitStartTimeDesc",
":",
"unitStartTimeDesc",
",",
"unitTasksCurrentDesc",
":",
"unitTasksCurrentDesc",
",",
"unitTasksMaxDesc",
":",
"unitTasksMaxDesc",
",",
"systemRunningDesc",
":",
"systemRunningDesc",
",",
"summaryDesc",
":",
"summaryDesc",
",",
"nRestartsDesc",
":",
"nRestartsDesc",
",",
"timerLastTriggerDesc",
":",
"timerLastTriggerDesc",
",",
"socketAcceptedConnectionsDesc",
":",
"socketAcceptedConnectionsDesc",
",",
"socketCurrentConnectionsDesc",
":",
"socketCurrentConnectionsDesc",
",",
"socketRefusedConnectionsDesc",
":",
"socketRefusedConnectionsDesc",
",",
"unitWhitelistPattern",
":",
"unitWhitelistPattern",
",",
"unitBlacklistPattern",
":",
"unitBlacklistPattern",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewSystemdCollector returns a new Collector exposing systemd statistics. | [
"NewSystemdCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"systemd",
"statistics",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/systemd_linux.go#L64-L124 | train |
prometheus/node_exporter | collector/exec_bsd.go | NewExecCollector | func NewExecCollector() (Collector, error) {
// From sys/vm/vm_meter.c:
// All are of type CTLTYPE_UINT.
//
// vm.stats.sys.v_swtch: Context switches
// vm.stats.sys.v_trap: Traps
// vm.stats.sys.v_syscall: System calls
// vm.stats.sys.v_intr: Device interrupts
// vm.stats.sys.v_soft: Software interrupts
// vm.stats.vm.v_forks: Number of fork() calls
return &execCollector{
sysctls: []bsdSysctl{
{
name: "exec_context_switches_total",
description: "Context switches since system boot. Resets at architecture unsigned integer.",
mib: "vm.stats.sys.v_swtch",
},
{
name: "exec_traps_total",
description: "Traps since system boot. Resets at architecture unsigned integer.",
mib: "vm.stats.sys.v_trap",
},
{
name: "exec_system_calls_total",
description: "System calls since system boot. Resets at architecture unsigned integer.",
mib: "vm.stats.sys.v_syscall",
},
{
name: "exec_device_interrupts_total",
description: "Device interrupts since system boot. Resets at architecture unsigned integer.",
mib: "vm.stats.sys.v_intr",
},
{
name: "exec_software_interrupts_total",
description: "Software interrupts since system boot. Resets at architecture unsigned integer.",
mib: "vm.stats.sys.v_soft",
},
{
name: "exec_forks_total",
description: "Number of fork() calls since system boot. Resets at architecture unsigned integer.",
mib: "vm.stats.vm.v_forks",
},
},
}, nil
} | go | func NewExecCollector() (Collector, error) {
// From sys/vm/vm_meter.c:
// All are of type CTLTYPE_UINT.
//
// vm.stats.sys.v_swtch: Context switches
// vm.stats.sys.v_trap: Traps
// vm.stats.sys.v_syscall: System calls
// vm.stats.sys.v_intr: Device interrupts
// vm.stats.sys.v_soft: Software interrupts
// vm.stats.vm.v_forks: Number of fork() calls
return &execCollector{
sysctls: []bsdSysctl{
{
name: "exec_context_switches_total",
description: "Context switches since system boot. Resets at architecture unsigned integer.",
mib: "vm.stats.sys.v_swtch",
},
{
name: "exec_traps_total",
description: "Traps since system boot. Resets at architecture unsigned integer.",
mib: "vm.stats.sys.v_trap",
},
{
name: "exec_system_calls_total",
description: "System calls since system boot. Resets at architecture unsigned integer.",
mib: "vm.stats.sys.v_syscall",
},
{
name: "exec_device_interrupts_total",
description: "Device interrupts since system boot. Resets at architecture unsigned integer.",
mib: "vm.stats.sys.v_intr",
},
{
name: "exec_software_interrupts_total",
description: "Software interrupts since system boot. Resets at architecture unsigned integer.",
mib: "vm.stats.sys.v_soft",
},
{
name: "exec_forks_total",
description: "Number of fork() calls since system boot. Resets at architecture unsigned integer.",
mib: "vm.stats.vm.v_forks",
},
},
}, nil
} | [
"func",
"NewExecCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"// From sys/vm/vm_meter.c:",
"// All are of type CTLTYPE_UINT.",
"//",
"// vm.stats.sys.v_swtch: Context switches",
"// vm.stats.sys.v_trap: Traps",
"// vm.stats.sys.v_syscall: System calls",
"// vm.stats.sys.v_intr: Device interrupts",
"// vm.stats.sys.v_soft: Software interrupts",
"// vm.stats.vm.v_forks: Number of fork() calls",
"return",
"&",
"execCollector",
"{",
"sysctls",
":",
"[",
"]",
"bsdSysctl",
"{",
"{",
"name",
":",
"\"",
"\"",
",",
"description",
":",
"\"",
"\"",
",",
"mib",
":",
"\"",
"\"",
",",
"}",
",",
"{",
"name",
":",
"\"",
"\"",
",",
"description",
":",
"\"",
"\"",
",",
"mib",
":",
"\"",
"\"",
",",
"}",
",",
"{",
"name",
":",
"\"",
"\"",
",",
"description",
":",
"\"",
"\"",
",",
"mib",
":",
"\"",
"\"",
",",
"}",
",",
"{",
"name",
":",
"\"",
"\"",
",",
"description",
":",
"\"",
"\"",
",",
"mib",
":",
"\"",
"\"",
",",
"}",
",",
"{",
"name",
":",
"\"",
"\"",
",",
"description",
":",
"\"",
"\"",
",",
"mib",
":",
"\"",
"\"",
",",
"}",
",",
"{",
"name",
":",
"\"",
"\"",
",",
"description",
":",
"\"",
"\"",
",",
"mib",
":",
"\"",
"\"",
",",
"}",
",",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewExecCollector returns a new Collector exposing system execution statistics. | [
"NewExecCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"system",
"execution",
"statistics",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/exec_bsd.go#L32-L77 | train |
prometheus/node_exporter | collector/exec_bsd.go | Update | func (c *execCollector) Update(ch chan<- prometheus.Metric) error {
for _, m := range c.sysctls {
v, err := m.Value()
if err != nil {
return err
}
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
namespace+"_"+m.name,
m.description,
nil, nil,
), prometheus.CounterValue, v)
}
return nil
} | go | func (c *execCollector) Update(ch chan<- prometheus.Metric) error {
for _, m := range c.sysctls {
v, err := m.Value()
if err != nil {
return err
}
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
namespace+"_"+m.name,
m.description,
nil, nil,
), prometheus.CounterValue, v)
}
return nil
} | [
"func",
"(",
"c",
"*",
"execCollector",
")",
"Update",
"(",
"ch",
"chan",
"<-",
"prometheus",
".",
"Metric",
")",
"error",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"c",
".",
"sysctls",
"{",
"v",
",",
"err",
":=",
"m",
".",
"Value",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"prometheus",
".",
"NewDesc",
"(",
"namespace",
"+",
"\"",
"\"",
"+",
"m",
".",
"name",
",",
"m",
".",
"description",
",",
"nil",
",",
"nil",
",",
")",
",",
"prometheus",
".",
"CounterValue",
",",
"v",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Update pushes exec statistics onto ch | [
"Update",
"pushes",
"exec",
"statistics",
"onto",
"ch"
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/exec_bsd.go#L80-L96 | train |
prometheus/node_exporter | collector/textfile.go | Update | func (c *textFileCollector) Update(ch chan<- prometheus.Metric) error {
error := 0.0
mtimes := map[string]time.Time{}
// Iterate over files and accumulate their metrics.
files, err := ioutil.ReadDir(c.path)
if err != nil && c.path != "" {
log.Errorf("Error reading textfile collector directory %q: %s", c.path, err)
error = 1.0
}
for _, f := range files {
if !strings.HasSuffix(f.Name(), ".prom") {
continue
}
path := filepath.Join(c.path, f.Name())
file, err := os.Open(path)
if err != nil {
log.Errorf("Error opening %q: %v", path, err)
error = 1.0
continue
}
defer file.Close()
var parser expfmt.TextParser
parsedFamilies, err := parser.TextToMetricFamilies(file)
if err != nil {
log.Errorf("Error parsing %q: %v", path, err)
error = 1.0
continue
}
if hasTimestamps(parsedFamilies) {
log.Errorf("Textfile %q contains unsupported client-side timestamps, skipping entire file", path)
error = 1.0
continue
}
for _, mf := range parsedFamilies {
if mf.Help == nil {
help := fmt.Sprintf("Metric read from %s", path)
mf.Help = &help
}
}
// Only set this once it has been parsed and validated, so that
// a failure does not appear fresh.
stat, err := file.Stat()
if err != nil {
log.Errorf("Error stat'ing %q: %v", path, err)
error = 1.0
continue
}
mtimes[f.Name()] = stat.ModTime()
for _, mf := range parsedFamilies {
convertMetricFamily(mf, ch)
}
}
c.exportMTimes(mtimes, ch)
// Export if there were errors.
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
"node_textfile_scrape_error",
"1 if there was an error opening or reading a file, 0 otherwise",
nil, nil,
),
prometheus.GaugeValue, error,
)
return nil
} | go | func (c *textFileCollector) Update(ch chan<- prometheus.Metric) error {
error := 0.0
mtimes := map[string]time.Time{}
// Iterate over files and accumulate their metrics.
files, err := ioutil.ReadDir(c.path)
if err != nil && c.path != "" {
log.Errorf("Error reading textfile collector directory %q: %s", c.path, err)
error = 1.0
}
for _, f := range files {
if !strings.HasSuffix(f.Name(), ".prom") {
continue
}
path := filepath.Join(c.path, f.Name())
file, err := os.Open(path)
if err != nil {
log.Errorf("Error opening %q: %v", path, err)
error = 1.0
continue
}
defer file.Close()
var parser expfmt.TextParser
parsedFamilies, err := parser.TextToMetricFamilies(file)
if err != nil {
log.Errorf("Error parsing %q: %v", path, err)
error = 1.0
continue
}
if hasTimestamps(parsedFamilies) {
log.Errorf("Textfile %q contains unsupported client-side timestamps, skipping entire file", path)
error = 1.0
continue
}
for _, mf := range parsedFamilies {
if mf.Help == nil {
help := fmt.Sprintf("Metric read from %s", path)
mf.Help = &help
}
}
// Only set this once it has been parsed and validated, so that
// a failure does not appear fresh.
stat, err := file.Stat()
if err != nil {
log.Errorf("Error stat'ing %q: %v", path, err)
error = 1.0
continue
}
mtimes[f.Name()] = stat.ModTime()
for _, mf := range parsedFamilies {
convertMetricFamily(mf, ch)
}
}
c.exportMTimes(mtimes, ch)
// Export if there were errors.
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
"node_textfile_scrape_error",
"1 if there was an error opening or reading a file, 0 otherwise",
nil, nil,
),
prometheus.GaugeValue, error,
)
return nil
} | [
"func",
"(",
"c",
"*",
"textFileCollector",
")",
"Update",
"(",
"ch",
"chan",
"<-",
"prometheus",
".",
"Metric",
")",
"error",
"{",
"error",
":=",
"0.0",
"\n",
"mtimes",
":=",
"map",
"[",
"string",
"]",
"time",
".",
"Time",
"{",
"}",
"\n\n",
"// Iterate over files and accumulate their metrics.",
"files",
",",
"err",
":=",
"ioutil",
".",
"ReadDir",
"(",
"c",
".",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"c",
".",
"path",
"!=",
"\"",
"\"",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"c",
".",
"path",
",",
"err",
")",
"\n",
"error",
"=",
"1.0",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"f",
":=",
"range",
"files",
"{",
"if",
"!",
"strings",
".",
"HasSuffix",
"(",
"f",
".",
"Name",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"continue",
"\n",
"}",
"\n",
"path",
":=",
"filepath",
".",
"Join",
"(",
"c",
".",
"path",
",",
"f",
".",
"Name",
"(",
")",
")",
"\n",
"file",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"path",
",",
"err",
")",
"\n",
"error",
"=",
"1.0",
"\n",
"continue",
"\n",
"}",
"\n",
"defer",
"file",
".",
"Close",
"(",
")",
"\n",
"var",
"parser",
"expfmt",
".",
"TextParser",
"\n",
"parsedFamilies",
",",
"err",
":=",
"parser",
".",
"TextToMetricFamilies",
"(",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"path",
",",
"err",
")",
"\n",
"error",
"=",
"1.0",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"hasTimestamps",
"(",
"parsedFamilies",
")",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"path",
")",
"\n",
"error",
"=",
"1.0",
"\n",
"continue",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"mf",
":=",
"range",
"parsedFamilies",
"{",
"if",
"mf",
".",
"Help",
"==",
"nil",
"{",
"help",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"path",
")",
"\n",
"mf",
".",
"Help",
"=",
"&",
"help",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Only set this once it has been parsed and validated, so that",
"// a failure does not appear fresh.",
"stat",
",",
"err",
":=",
"file",
".",
"Stat",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"path",
",",
"err",
")",
"\n",
"error",
"=",
"1.0",
"\n",
"continue",
"\n",
"}",
"\n",
"mtimes",
"[",
"f",
".",
"Name",
"(",
")",
"]",
"=",
"stat",
".",
"ModTime",
"(",
")",
"\n\n",
"for",
"_",
",",
"mf",
":=",
"range",
"parsedFamilies",
"{",
"convertMetricFamily",
"(",
"mf",
",",
"ch",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"c",
".",
"exportMTimes",
"(",
"mtimes",
",",
"ch",
")",
"\n\n",
"// Export if there were errors.",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"prometheus",
".",
"NewDesc",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"prometheus",
".",
"GaugeValue",
",",
"error",
",",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Update implements the Collector interface. | [
"Update",
"implements",
"the",
"Collector",
"interface",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/textfile.go#L185-L255 | train |
prometheus/node_exporter | collector/textfile.go | hasTimestamps | func hasTimestamps(parsedFamilies map[string]*dto.MetricFamily) bool {
for _, mf := range parsedFamilies {
for _, m := range mf.Metric {
if m.TimestampMs != nil {
return true
}
}
}
return false
} | go | func hasTimestamps(parsedFamilies map[string]*dto.MetricFamily) bool {
for _, mf := range parsedFamilies {
for _, m := range mf.Metric {
if m.TimestampMs != nil {
return true
}
}
}
return false
} | [
"func",
"hasTimestamps",
"(",
"parsedFamilies",
"map",
"[",
"string",
"]",
"*",
"dto",
".",
"MetricFamily",
")",
"bool",
"{",
"for",
"_",
",",
"mf",
":=",
"range",
"parsedFamilies",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"mf",
".",
"Metric",
"{",
"if",
"m",
".",
"TimestampMs",
"!=",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // hasTimestamps returns true when metrics contain unsupported timestamps. | [
"hasTimestamps",
"returns",
"true",
"when",
"metrics",
"contain",
"unsupported",
"timestamps",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/textfile.go#L258-L267 | train |
prometheus/node_exporter | collector/vmstat_linux.go | NewvmStatCollector | func NewvmStatCollector() (Collector, error) {
pattern := regexp.MustCompile(*vmStatFields)
return &vmStatCollector{
fieldPattern: pattern,
}, nil
} | go | func NewvmStatCollector() (Collector, error) {
pattern := regexp.MustCompile(*vmStatFields)
return &vmStatCollector{
fieldPattern: pattern,
}, nil
} | [
"func",
"NewvmStatCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"pattern",
":=",
"regexp",
".",
"MustCompile",
"(",
"*",
"vmStatFields",
")",
"\n",
"return",
"&",
"vmStatCollector",
"{",
"fieldPattern",
":",
"pattern",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewvmStatCollector returns a new Collector exposing vmstat stats. | [
"NewvmStatCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"vmstat",
"stats",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/vmstat_linux.go#L47-L52 | train |
prometheus/node_exporter | collector/wifi_linux.go | NewWifiCollector | func NewWifiCollector() (Collector, error) {
const (
subsystem = "wifi"
)
var (
labels = []string{"device", "mac_address"}
)
return &wifiCollector{
interfaceFrequencyHertz: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "interface_frequency_hertz"),
"The current frequency a WiFi interface is operating at, in hertz.",
[]string{"device"},
nil,
),
stationInfo: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_info"),
"Labeled WiFi interface station information as provided by the operating system.",
[]string{"device", "bssid", "ssid", "mode"},
nil,
),
stationConnectedSecondsTotal: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_connected_seconds_total"),
"The total number of seconds a station has been connected to an access point.",
labels,
nil,
),
stationInactiveSeconds: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_inactive_seconds"),
"The number of seconds since any wireless activity has occurred on a station.",
labels,
nil,
),
stationReceiveBitsPerSecond: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_receive_bits_per_second"),
"The current WiFi receive bitrate of a station, in bits per second.",
labels,
nil,
),
stationTransmitBitsPerSecond: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_transmit_bits_per_second"),
"The current WiFi transmit bitrate of a station, in bits per second.",
labels,
nil,
),
stationReceiveBytesTotal: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_receive_bytes_total"),
"The total number of bytes received by a WiFi station.",
labels,
nil,
),
stationTransmitBytesTotal: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_transmit_bytes_total"),
"The total number of bytes transmitted by a WiFi station.",
labels,
nil,
),
stationSignalDBM: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_signal_dbm"),
"The current WiFi signal strength, in decibel-milliwatts (dBm).",
labels,
nil,
),
stationTransmitRetriesTotal: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_transmit_retries_total"),
"The total number of times a station has had to retry while sending a packet.",
labels,
nil,
),
stationTransmitFailedTotal: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_transmit_failed_total"),
"The total number of times a station has failed to send a packet.",
labels,
nil,
),
stationBeaconLossTotal: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_beacon_loss_total"),
"The total number of times a station has detected a beacon loss.",
labels,
nil,
),
}, nil
} | go | func NewWifiCollector() (Collector, error) {
const (
subsystem = "wifi"
)
var (
labels = []string{"device", "mac_address"}
)
return &wifiCollector{
interfaceFrequencyHertz: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "interface_frequency_hertz"),
"The current frequency a WiFi interface is operating at, in hertz.",
[]string{"device"},
nil,
),
stationInfo: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_info"),
"Labeled WiFi interface station information as provided by the operating system.",
[]string{"device", "bssid", "ssid", "mode"},
nil,
),
stationConnectedSecondsTotal: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_connected_seconds_total"),
"The total number of seconds a station has been connected to an access point.",
labels,
nil,
),
stationInactiveSeconds: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_inactive_seconds"),
"The number of seconds since any wireless activity has occurred on a station.",
labels,
nil,
),
stationReceiveBitsPerSecond: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_receive_bits_per_second"),
"The current WiFi receive bitrate of a station, in bits per second.",
labels,
nil,
),
stationTransmitBitsPerSecond: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_transmit_bits_per_second"),
"The current WiFi transmit bitrate of a station, in bits per second.",
labels,
nil,
),
stationReceiveBytesTotal: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_receive_bytes_total"),
"The total number of bytes received by a WiFi station.",
labels,
nil,
),
stationTransmitBytesTotal: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_transmit_bytes_total"),
"The total number of bytes transmitted by a WiFi station.",
labels,
nil,
),
stationSignalDBM: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_signal_dbm"),
"The current WiFi signal strength, in decibel-milliwatts (dBm).",
labels,
nil,
),
stationTransmitRetriesTotal: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_transmit_retries_total"),
"The total number of times a station has had to retry while sending a packet.",
labels,
nil,
),
stationTransmitFailedTotal: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_transmit_failed_total"),
"The total number of times a station has failed to send a packet.",
labels,
nil,
),
stationBeaconLossTotal: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "station_beacon_loss_total"),
"The total number of times a station has detected a beacon loss.",
labels,
nil,
),
}, nil
} | [
"func",
"NewWifiCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"const",
"(",
"subsystem",
"=",
"\"",
"\"",
"\n",
")",
"\n\n",
"var",
"(",
"labels",
"=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"\n",
")",
"\n\n",
"return",
"&",
"wifiCollector",
"{",
"interfaceFrequencyHertz",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"nil",
",",
")",
",",
"stationInfo",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"nil",
",",
")",
",",
"stationConnectedSecondsTotal",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"labels",
",",
"nil",
",",
")",
",",
"stationInactiveSeconds",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"labels",
",",
"nil",
",",
")",
",",
"stationReceiveBitsPerSecond",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"labels",
",",
"nil",
",",
")",
",",
"stationTransmitBitsPerSecond",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"labels",
",",
"nil",
",",
")",
",",
"stationReceiveBytesTotal",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"labels",
",",
"nil",
",",
")",
",",
"stationTransmitBytesTotal",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"labels",
",",
"nil",
",",
")",
",",
"stationSignalDBM",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"labels",
",",
"nil",
",",
")",
",",
"stationTransmitRetriesTotal",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"labels",
",",
"nil",
",",
")",
",",
"stationTransmitFailedTotal",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"labels",
",",
"nil",
",",
")",
",",
"stationBeaconLossTotal",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"labels",
",",
"nil",
",",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewWifiCollector returns a new Collector exposing Wifi statistics. | [
"NewWifiCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"Wifi",
"statistics",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/wifi_linux.go#L64-L158 | train |
prometheus/node_exporter | collector/wifi_linux.go | newWifiStater | func newWifiStater(fixtures string) (wifiStater, error) {
if fixtures != "" {
return &mockWifiStater{
fixtures: fixtures,
}, nil
}
return wifi.New()
} | go | func newWifiStater(fixtures string) (wifiStater, error) {
if fixtures != "" {
return &mockWifiStater{
fixtures: fixtures,
}, nil
}
return wifi.New()
} | [
"func",
"newWifiStater",
"(",
"fixtures",
"string",
")",
"(",
"wifiStater",
",",
"error",
")",
"{",
"if",
"fixtures",
"!=",
"\"",
"\"",
"{",
"return",
"&",
"mockWifiStater",
"{",
"fixtures",
":",
"fixtures",
",",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"wifi",
".",
"New",
"(",
")",
"\n",
"}"
] | // All code below this point is used to assist with end-to-end tests for
// the wifi collector, since wifi devices are not available in CI.
// newWifiStater determines if mocked test fixtures from files should be used for
// collecting wifi metrics, or if package wifi should be used. | [
"All",
"code",
"below",
"this",
"point",
"is",
"used",
"to",
"assist",
"with",
"end",
"-",
"to",
"-",
"end",
"tests",
"for",
"the",
"wifi",
"collector",
"since",
"wifi",
"devices",
"are",
"not",
"available",
"in",
"CI",
".",
"newWifiStater",
"determines",
"if",
"mocked",
"test",
"fixtures",
"from",
"files",
"should",
"be",
"used",
"for",
"collecting",
"wifi",
"metrics",
"or",
"if",
"package",
"wifi",
"should",
"be",
"used",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/wifi_linux.go#L344-L352 | train |
prometheus/node_exporter | collector/mdadm_linux.go | evalBuildline | func evalBuildline(buildline string) (int64, error) {
matches := buildlineRE.FindStringSubmatch(buildline)
// +1 to make it more obvious that the whole string containing the info is also returned as matches[0].
if len(matches) < 1+1 {
return 0, fmt.Errorf("too few matches found in buildline: %s", buildline)
}
if len(matches) > 1+1 {
return 0, fmt.Errorf("too many matches found in buildline: %s", buildline)
}
syncedSize, err := strconv.ParseInt(matches[1], 10, 64)
if err != nil {
return 0, fmt.Errorf("%s in buildline: %s", err, buildline)
}
return syncedSize, nil
} | go | func evalBuildline(buildline string) (int64, error) {
matches := buildlineRE.FindStringSubmatch(buildline)
// +1 to make it more obvious that the whole string containing the info is also returned as matches[0].
if len(matches) < 1+1 {
return 0, fmt.Errorf("too few matches found in buildline: %s", buildline)
}
if len(matches) > 1+1 {
return 0, fmt.Errorf("too many matches found in buildline: %s", buildline)
}
syncedSize, err := strconv.ParseInt(matches[1], 10, 64)
if err != nil {
return 0, fmt.Errorf("%s in buildline: %s", err, buildline)
}
return syncedSize, nil
} | [
"func",
"evalBuildline",
"(",
"buildline",
"string",
")",
"(",
"int64",
",",
"error",
")",
"{",
"matches",
":=",
"buildlineRE",
".",
"FindStringSubmatch",
"(",
"buildline",
")",
"\n\n",
"// +1 to make it more obvious that the whole string containing the info is also returned as matches[0].",
"if",
"len",
"(",
"matches",
")",
"<",
"1",
"+",
"1",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"buildline",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"matches",
")",
">",
"1",
"+",
"1",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"buildline",
")",
"\n",
"}",
"\n\n",
"syncedSize",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"matches",
"[",
"1",
"]",
",",
"10",
",",
"64",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
",",
"buildline",
")",
"\n",
"}",
"\n\n",
"return",
"syncedSize",
",",
"nil",
"\n",
"}"
] | // evalBuildline gets the size that has already been synced out of the sync-line. | [
"evalBuildline",
"gets",
"the",
"size",
"that",
"has",
"already",
"been",
"synced",
"out",
"of",
"the",
"sync",
"-",
"line",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/mdadm_linux.go#L111-L130 | train |
prometheus/node_exporter | collector/infiniband_linux.go | infinibandDevices | func infinibandDevices(infinibandPath string) ([]string, error) {
devices, err := filepath.Glob(filepath.Join(infinibandPath, "/*"))
if err != nil {
return nil, err
}
if len(devices) < 1 {
log.Debugf("Unable to detect InfiniBand devices")
err = errInfinibandNoDevicesFound
return nil, err
}
// Extract just the filenames which equate to the device names.
for i, device := range devices {
devices[i] = filepath.Base(device)
}
return devices, nil
} | go | func infinibandDevices(infinibandPath string) ([]string, error) {
devices, err := filepath.Glob(filepath.Join(infinibandPath, "/*"))
if err != nil {
return nil, err
}
if len(devices) < 1 {
log.Debugf("Unable to detect InfiniBand devices")
err = errInfinibandNoDevicesFound
return nil, err
}
// Extract just the filenames which equate to the device names.
for i, device := range devices {
devices[i] = filepath.Base(device)
}
return devices, nil
} | [
"func",
"infinibandDevices",
"(",
"infinibandPath",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"devices",
",",
"err",
":=",
"filepath",
".",
"Glob",
"(",
"filepath",
".",
"Join",
"(",
"infinibandPath",
",",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"devices",
")",
"<",
"1",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n",
"err",
"=",
"errInfinibandNoDevicesFound",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Extract just the filenames which equate to the device names.",
"for",
"i",
",",
"device",
":=",
"range",
"devices",
"{",
"devices",
"[",
"i",
"]",
"=",
"filepath",
".",
"Base",
"(",
"device",
")",
"\n",
"}",
"\n\n",
"return",
"devices",
",",
"nil",
"\n",
"}"
] | // infinibandDevices retrieves a list of InfiniBand devices. | [
"infinibandDevices",
"retrieves",
"a",
"list",
"of",
"InfiniBand",
"devices",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/infiniband_linux.go#L112-L130 | train |
prometheus/node_exporter | collector/infiniband_linux.go | infinibandPorts | func infinibandPorts(infinibandPath, device string) ([]string, error) {
ports, err := filepath.Glob(filepath.Join(infinibandPath, device, "ports/*"))
if err != nil {
return nil, err
}
if len(ports) < 1 {
log.Debugf("Unable to detect ports for %s", device)
err = errInfinibandNoPortsFound
return nil, err
}
// Extract just the filenames which equates to the port numbers.
for i, port := range ports {
ports[i] = filepath.Base(port)
}
return ports, nil
} | go | func infinibandPorts(infinibandPath, device string) ([]string, error) {
ports, err := filepath.Glob(filepath.Join(infinibandPath, device, "ports/*"))
if err != nil {
return nil, err
}
if len(ports) < 1 {
log.Debugf("Unable to detect ports for %s", device)
err = errInfinibandNoPortsFound
return nil, err
}
// Extract just the filenames which equates to the port numbers.
for i, port := range ports {
ports[i] = filepath.Base(port)
}
return ports, nil
} | [
"func",
"infinibandPorts",
"(",
"infinibandPath",
",",
"device",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"ports",
",",
"err",
":=",
"filepath",
".",
"Glob",
"(",
"filepath",
".",
"Join",
"(",
"infinibandPath",
",",
"device",
",",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"ports",
")",
"<",
"1",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"device",
")",
"\n",
"err",
"=",
"errInfinibandNoPortsFound",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Extract just the filenames which equates to the port numbers.",
"for",
"i",
",",
"port",
":=",
"range",
"ports",
"{",
"ports",
"[",
"i",
"]",
"=",
"filepath",
".",
"Base",
"(",
"port",
")",
"\n",
"}",
"\n\n",
"return",
"ports",
",",
"nil",
"\n",
"}"
] | // Retrieve a list of ports for the InfiniBand device. | [
"Retrieve",
"a",
"list",
"of",
"ports",
"for",
"the",
"InfiniBand",
"device",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/infiniband_linux.go#L133-L151 | train |
prometheus/node_exporter | collector/boot_time_solaris.go | Update | func (c *bootTimeCollector) Update(ch chan<- prometheus.Metric) error {
tok, err := kstat.Open()
if err != nil {
return err
}
defer tok.Close()
ks, err := tok.Lookup("unix", 0, "system_misc")
if err != nil {
return err
}
v, err := ks.GetNamed("boot_time")
if err != nil {
return err
}
ch <- c.boottime.mustNewConstMetric(float64(v.UintVal))
return nil
} | go | func (c *bootTimeCollector) Update(ch chan<- prometheus.Metric) error {
tok, err := kstat.Open()
if err != nil {
return err
}
defer tok.Close()
ks, err := tok.Lookup("unix", 0, "system_misc")
if err != nil {
return err
}
v, err := ks.GetNamed("boot_time")
if err != nil {
return err
}
ch <- c.boottime.mustNewConstMetric(float64(v.UintVal))
return nil
} | [
"func",
"(",
"c",
"*",
"bootTimeCollector",
")",
"Update",
"(",
"ch",
"chan",
"<-",
"prometheus",
".",
"Metric",
")",
"error",
"{",
"tok",
",",
"err",
":=",
"kstat",
".",
"Open",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"defer",
"tok",
".",
"Close",
"(",
")",
"\n\n",
"ks",
",",
"err",
":=",
"tok",
".",
"Lookup",
"(",
"\"",
"\"",
",",
"0",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"v",
",",
"err",
":=",
"ks",
".",
"GetNamed",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"ch",
"<-",
"c",
".",
"boottime",
".",
"mustNewConstMetric",
"(",
"float64",
"(",
"v",
".",
"UintVal",
")",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // newBootTimeCollector returns a new Collector exposing system boot time on Solaris systems.
// Update pushes boot time onto ch | [
"newBootTimeCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"system",
"boot",
"time",
"on",
"Solaris",
"systems",
".",
"Update",
"pushes",
"boot",
"time",
"onto",
"ch"
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/boot_time_solaris.go#L45-L66 | train |
prometheus/node_exporter | collector/hwmon_linux.go | sysReadFile | func sysReadFile(file string) ([]byte, error) {
f, err := os.Open(file)
if err != nil {
return nil, err
}
defer f.Close()
// On some machines, hwmon drivers are broken and return EAGAIN. This causes
// Go's ioutil.ReadFile implementation to poll forever.
//
// Since we either want to read data or bail immediately, do the simplest
// possible read using syscall directly.
b := make([]byte, 128)
n, err := syscall.Read(int(f.Fd()), b)
if err != nil {
return nil, err
}
return b[:n], nil
} | go | func sysReadFile(file string) ([]byte, error) {
f, err := os.Open(file)
if err != nil {
return nil, err
}
defer f.Close()
// On some machines, hwmon drivers are broken and return EAGAIN. This causes
// Go's ioutil.ReadFile implementation to poll forever.
//
// Since we either want to read data or bail immediately, do the simplest
// possible read using syscall directly.
b := make([]byte, 128)
n, err := syscall.Read(int(f.Fd()), b)
if err != nil {
return nil, err
}
return b[:n], nil
} | [
"func",
"sysReadFile",
"(",
"file",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"// On some machines, hwmon drivers are broken and return EAGAIN. This causes",
"// Go's ioutil.ReadFile implementation to poll forever.",
"//",
"// Since we either want to read data or bail immediately, do the simplest",
"// possible read using syscall directly.",
"b",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"128",
")",
"\n",
"n",
",",
"err",
":=",
"syscall",
".",
"Read",
"(",
"int",
"(",
"f",
".",
"Fd",
"(",
")",
")",
",",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"b",
"[",
":",
"n",
"]",
",",
"nil",
"\n",
"}"
] | // sysReadFile is a simplified ioutil.ReadFile that invokes syscall.Read directly. | [
"sysReadFile",
"is",
"a",
"simplified",
"ioutil",
".",
"ReadFile",
"that",
"invokes",
"syscall",
".",
"Read",
"directly",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/hwmon_linux.go#L78-L97 | train |
prometheus/node_exporter | collector/xfs_linux.go | NewXFSCollector | func NewXFSCollector() (Collector, error) {
fs, err := sysfs.NewFS(*sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %v", err)
}
return &xfsCollector{
fs: fs,
}, nil
} | go | func NewXFSCollector() (Collector, error) {
fs, err := sysfs.NewFS(*sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %v", err)
}
return &xfsCollector{
fs: fs,
}, nil
} | [
"func",
"NewXFSCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"fs",
",",
"err",
":=",
"sysfs",
".",
"NewFS",
"(",
"*",
"sysPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"xfsCollector",
"{",
"fs",
":",
"fs",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewXFSCollector returns a new Collector exposing XFS statistics. | [
"NewXFSCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"XFS",
"statistics",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/xfs_linux.go#L34-L43 | train |
prometheus/node_exporter | collector/memory_bsd.go | NewMemoryCollector | func NewMemoryCollector() (Collector, error) {
tmp32, err := unix.SysctlUint32("vm.stats.vm.v_page_size")
if err != nil {
return nil, fmt.Errorf("sysctl(vm.stats.vm.v_page_size) failed: %s", err)
}
size := float64(tmp32)
mibSwapTotal := "vm.swap_total"
/* swap_total is FreeBSD specific. Fall back to Dfly specific mib if not present. */
_, err = unix.SysctlUint32(mibSwapTotal)
if err != nil {
mibSwapTotal = "vm.swap_size"
}
fromPage := func(v float64) float64 {
return v * size
}
return &memoryCollector{
pageSize: uint64(tmp32),
sysctls: []bsdSysctl{
// Descriptions via: https://wiki.freebsd.org/Memory
{
name: "active_bytes",
description: "Recently used by userland",
mib: "vm.stats.vm.v_active_count",
conversion: fromPage,
},
{
name: "inactive_bytes",
description: "Not recently used by userland",
mib: "vm.stats.vm.v_inactive_count",
conversion: fromPage,
},
{
name: "wired_bytes",
description: "Locked in memory by kernel, mlock, etc",
mib: "vm.stats.vm.v_wire_count",
conversion: fromPage,
},
{
name: "cache_bytes",
description: "Almost free, backed by swap or files, available for re-allocation",
mib: "vm.stats.vm.v_cache_count",
conversion: fromPage,
},
{
name: "buffer_bytes",
description: "Disk IO Cache entries for non ZFS filesystems, only usable by kernel",
mib: "vfs.bufspace",
dataType: bsdSysctlTypeCLong,
},
{
name: "free_bytes",
description: "Unallocated, available for allocation",
mib: "vm.stats.vm.v_free_count",
conversion: fromPage,
},
{
name: "size_bytes",
description: "Total physical memory size",
mib: "vm.stats.vm.v_page_count",
conversion: fromPage,
},
{
name: "swap_size_bytes",
description: "Total swap memory size",
mib: mibSwapTotal,
dataType: bsdSysctlTypeUint64,
},
// Descriptions via: top(1)
{
name: "swap_in_bytes_total",
description: "Bytes paged in from swap devices",
mib: "vm.stats.vm.v_swappgsin",
valueType: prometheus.CounterValue,
conversion: fromPage,
},
{
name: "swap_out_bytes_total",
description: "Bytes paged out to swap devices",
mib: "vm.stats.vm.v_swappgsout",
valueType: prometheus.CounterValue,
conversion: fromPage,
},
},
}, nil
} | go | func NewMemoryCollector() (Collector, error) {
tmp32, err := unix.SysctlUint32("vm.stats.vm.v_page_size")
if err != nil {
return nil, fmt.Errorf("sysctl(vm.stats.vm.v_page_size) failed: %s", err)
}
size := float64(tmp32)
mibSwapTotal := "vm.swap_total"
/* swap_total is FreeBSD specific. Fall back to Dfly specific mib if not present. */
_, err = unix.SysctlUint32(mibSwapTotal)
if err != nil {
mibSwapTotal = "vm.swap_size"
}
fromPage := func(v float64) float64 {
return v * size
}
return &memoryCollector{
pageSize: uint64(tmp32),
sysctls: []bsdSysctl{
// Descriptions via: https://wiki.freebsd.org/Memory
{
name: "active_bytes",
description: "Recently used by userland",
mib: "vm.stats.vm.v_active_count",
conversion: fromPage,
},
{
name: "inactive_bytes",
description: "Not recently used by userland",
mib: "vm.stats.vm.v_inactive_count",
conversion: fromPage,
},
{
name: "wired_bytes",
description: "Locked in memory by kernel, mlock, etc",
mib: "vm.stats.vm.v_wire_count",
conversion: fromPage,
},
{
name: "cache_bytes",
description: "Almost free, backed by swap or files, available for re-allocation",
mib: "vm.stats.vm.v_cache_count",
conversion: fromPage,
},
{
name: "buffer_bytes",
description: "Disk IO Cache entries for non ZFS filesystems, only usable by kernel",
mib: "vfs.bufspace",
dataType: bsdSysctlTypeCLong,
},
{
name: "free_bytes",
description: "Unallocated, available for allocation",
mib: "vm.stats.vm.v_free_count",
conversion: fromPage,
},
{
name: "size_bytes",
description: "Total physical memory size",
mib: "vm.stats.vm.v_page_count",
conversion: fromPage,
},
{
name: "swap_size_bytes",
description: "Total swap memory size",
mib: mibSwapTotal,
dataType: bsdSysctlTypeUint64,
},
// Descriptions via: top(1)
{
name: "swap_in_bytes_total",
description: "Bytes paged in from swap devices",
mib: "vm.stats.vm.v_swappgsin",
valueType: prometheus.CounterValue,
conversion: fromPage,
},
{
name: "swap_out_bytes_total",
description: "Bytes paged out to swap devices",
mib: "vm.stats.vm.v_swappgsout",
valueType: prometheus.CounterValue,
conversion: fromPage,
},
},
}, nil
} | [
"func",
"NewMemoryCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"tmp32",
",",
"err",
":=",
"unix",
".",
"SysctlUint32",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"size",
":=",
"float64",
"(",
"tmp32",
")",
"\n\n",
"mibSwapTotal",
":=",
"\"",
"\"",
"\n",
"/* swap_total is FreeBSD specific. Fall back to Dfly specific mib if not present. */",
"_",
",",
"err",
"=",
"unix",
".",
"SysctlUint32",
"(",
"mibSwapTotal",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"mibSwapTotal",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"fromPage",
":=",
"func",
"(",
"v",
"float64",
")",
"float64",
"{",
"return",
"v",
"*",
"size",
"\n",
"}",
"\n\n",
"return",
"&",
"memoryCollector",
"{",
"pageSize",
":",
"uint64",
"(",
"tmp32",
")",
",",
"sysctls",
":",
"[",
"]",
"bsdSysctl",
"{",
"// Descriptions via: https://wiki.freebsd.org/Memory",
"{",
"name",
":",
"\"",
"\"",
",",
"description",
":",
"\"",
"\"",
",",
"mib",
":",
"\"",
"\"",
",",
"conversion",
":",
"fromPage",
",",
"}",
",",
"{",
"name",
":",
"\"",
"\"",
",",
"description",
":",
"\"",
"\"",
",",
"mib",
":",
"\"",
"\"",
",",
"conversion",
":",
"fromPage",
",",
"}",
",",
"{",
"name",
":",
"\"",
"\"",
",",
"description",
":",
"\"",
"\"",
",",
"mib",
":",
"\"",
"\"",
",",
"conversion",
":",
"fromPage",
",",
"}",
",",
"{",
"name",
":",
"\"",
"\"",
",",
"description",
":",
"\"",
"\"",
",",
"mib",
":",
"\"",
"\"",
",",
"conversion",
":",
"fromPage",
",",
"}",
",",
"{",
"name",
":",
"\"",
"\"",
",",
"description",
":",
"\"",
"\"",
",",
"mib",
":",
"\"",
"\"",
",",
"dataType",
":",
"bsdSysctlTypeCLong",
",",
"}",
",",
"{",
"name",
":",
"\"",
"\"",
",",
"description",
":",
"\"",
"\"",
",",
"mib",
":",
"\"",
"\"",
",",
"conversion",
":",
"fromPage",
",",
"}",
",",
"{",
"name",
":",
"\"",
"\"",
",",
"description",
":",
"\"",
"\"",
",",
"mib",
":",
"\"",
"\"",
",",
"conversion",
":",
"fromPage",
",",
"}",
",",
"{",
"name",
":",
"\"",
"\"",
",",
"description",
":",
"\"",
"\"",
",",
"mib",
":",
"mibSwapTotal",
",",
"dataType",
":",
"bsdSysctlTypeUint64",
",",
"}",
",",
"// Descriptions via: top(1)",
"{",
"name",
":",
"\"",
"\"",
",",
"description",
":",
"\"",
"\"",
",",
"mib",
":",
"\"",
"\"",
",",
"valueType",
":",
"prometheus",
".",
"CounterValue",
",",
"conversion",
":",
"fromPage",
",",
"}",
",",
"{",
"name",
":",
"\"",
"\"",
",",
"description",
":",
"\"",
"\"",
",",
"mib",
":",
"\"",
"\"",
",",
"valueType",
":",
"prometheus",
".",
"CounterValue",
",",
"conversion",
":",
"fromPage",
",",
"}",
",",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewMemoryCollector returns a new Collector exposing memory stats. | [
"NewMemoryCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"memory",
"stats",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/memory_bsd.go#L41-L128 | train |
prometheus/node_exporter | collector/memory_bsd.go | Update | func (c *memoryCollector) Update(ch chan<- prometheus.Metric) error {
for _, m := range c.sysctls {
v, err := m.Value()
if err != nil {
return fmt.Errorf("couldn't get memory: %s", err)
}
// Most are gauges.
if m.valueType == 0 {
m.valueType = prometheus.GaugeValue
}
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, memorySubsystem, m.name),
m.description,
nil, nil,
), m.valueType, v)
}
swapUsed, err := c.kvm.SwapUsedPages()
if err != nil {
return fmt.Errorf("couldn't get kvm: %s", err)
}
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, memorySubsystem, "swap_used_bytes"),
"Currently allocated swap",
nil, nil,
), prometheus.GaugeValue, float64(swapUsed*c.pageSize))
return nil
} | go | func (c *memoryCollector) Update(ch chan<- prometheus.Metric) error {
for _, m := range c.sysctls {
v, err := m.Value()
if err != nil {
return fmt.Errorf("couldn't get memory: %s", err)
}
// Most are gauges.
if m.valueType == 0 {
m.valueType = prometheus.GaugeValue
}
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, memorySubsystem, m.name),
m.description,
nil, nil,
), m.valueType, v)
}
swapUsed, err := c.kvm.SwapUsedPages()
if err != nil {
return fmt.Errorf("couldn't get kvm: %s", err)
}
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, memorySubsystem, "swap_used_bytes"),
"Currently allocated swap",
nil, nil,
), prometheus.GaugeValue, float64(swapUsed*c.pageSize))
return nil
} | [
"func",
"(",
"c",
"*",
"memoryCollector",
")",
"Update",
"(",
"ch",
"chan",
"<-",
"prometheus",
".",
"Metric",
")",
"error",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"c",
".",
"sysctls",
"{",
"v",
",",
"err",
":=",
"m",
".",
"Value",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Most are gauges.",
"if",
"m",
".",
"valueType",
"==",
"0",
"{",
"m",
".",
"valueType",
"=",
"prometheus",
".",
"GaugeValue",
"\n",
"}",
"\n\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"memorySubsystem",
",",
"m",
".",
"name",
")",
",",
"m",
".",
"description",
",",
"nil",
",",
"nil",
",",
")",
",",
"m",
".",
"valueType",
",",
"v",
")",
"\n",
"}",
"\n\n",
"swapUsed",
",",
"err",
":=",
"c",
".",
"kvm",
".",
"SwapUsedPages",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"memorySubsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"prometheus",
".",
"GaugeValue",
",",
"float64",
"(",
"swapUsed",
"*",
"c",
".",
"pageSize",
")",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Update checks relevant sysctls for current memory usage, and kvm for swap
// usage. | [
"Update",
"checks",
"relevant",
"sysctls",
"for",
"current",
"memory",
"usage",
"and",
"kvm",
"for",
"swap",
"usage",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/memory_bsd.go#L132-L165 | train |
prometheus/node_exporter | collector/netdev_common.go | NewNetDevCollector | func NewNetDevCollector() (Collector, error) {
pattern := regexp.MustCompile(*netdevIgnoredDevices)
return &netDevCollector{
subsystem: "network",
ignoredDevicesPattern: pattern,
metricDescs: map[string]*prometheus.Desc{},
}, nil
} | go | func NewNetDevCollector() (Collector, error) {
pattern := regexp.MustCompile(*netdevIgnoredDevices)
return &netDevCollector{
subsystem: "network",
ignoredDevicesPattern: pattern,
metricDescs: map[string]*prometheus.Desc{},
}, nil
} | [
"func",
"NewNetDevCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"pattern",
":=",
"regexp",
".",
"MustCompile",
"(",
"*",
"netdevIgnoredDevices",
")",
"\n",
"return",
"&",
"netDevCollector",
"{",
"subsystem",
":",
"\"",
"\"",
",",
"ignoredDevicesPattern",
":",
"pattern",
",",
"metricDescs",
":",
"map",
"[",
"string",
"]",
"*",
"prometheus",
".",
"Desc",
"{",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewNetDevCollector returns a new Collector exposing network device stats. | [
"NewNetDevCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"network",
"device",
"stats",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/netdev_common.go#L43-L50 | train |
prometheus/node_exporter | collector/bcache_linux.go | NewBcacheCollector | func NewBcacheCollector() (Collector, error) {
fs, err := sysfs.NewFS(*sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %v", err)
}
return &bcacheCollector{
fs: fs,
}, nil
} | go | func NewBcacheCollector() (Collector, error) {
fs, err := sysfs.NewFS(*sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %v", err)
}
return &bcacheCollector{
fs: fs,
}, nil
} | [
"func",
"NewBcacheCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"fs",
",",
"err",
":=",
"sysfs",
".",
"NewFS",
"(",
"*",
"sysPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"bcacheCollector",
"{",
"fs",
":",
"fs",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewBcacheCollector returns a newly allocated bcacheCollector.
// It exposes a number of Linux bcache statistics. | [
"NewBcacheCollector",
"returns",
"a",
"newly",
"allocated",
"bcacheCollector",
".",
"It",
"exposes",
"a",
"number",
"of",
"Linux",
"bcache",
"statistics",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/bcache_linux.go#L38-L47 | train |
prometheus/node_exporter | collector/bcache_linux.go | Update | func (c *bcacheCollector) Update(ch chan<- prometheus.Metric) error {
stats, err := c.fs.BcacheStats()
if err != nil {
return fmt.Errorf("failed to retrieve bcache stats: %v", err)
}
for _, s := range stats {
c.updateBcacheStats(ch, s)
}
return nil
} | go | func (c *bcacheCollector) Update(ch chan<- prometheus.Metric) error {
stats, err := c.fs.BcacheStats()
if err != nil {
return fmt.Errorf("failed to retrieve bcache stats: %v", err)
}
for _, s := range stats {
c.updateBcacheStats(ch, s)
}
return nil
} | [
"func",
"(",
"c",
"*",
"bcacheCollector",
")",
"Update",
"(",
"ch",
"chan",
"<-",
"prometheus",
".",
"Metric",
")",
"error",
"{",
"stats",
",",
"err",
":=",
"c",
".",
"fs",
".",
"BcacheStats",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"s",
":=",
"range",
"stats",
"{",
"c",
".",
"updateBcacheStats",
"(",
"ch",
",",
"s",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Update reads and exposes bcache stats.
// It implements the Collector interface. | [
"Update",
"reads",
"and",
"exposes",
"bcache",
"stats",
".",
"It",
"implements",
"the",
"Collector",
"interface",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/bcache_linux.go#L51-L61 | train |
prometheus/node_exporter | collector/nfsd_linux.go | updateNFSdReplyCacheStats | func (c *nfsdCollector) updateNFSdReplyCacheStats(ch chan<- prometheus.Metric, s *nfs.ReplyCache) {
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsdSubsystem, "reply_cache_hits_total"),
"Total number of NFSd Reply Cache hits (client lost server response).",
nil,
nil,
),
prometheus.CounterValue,
float64(s.Hits))
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsdSubsystem, "reply_cache_misses_total"),
"Total number of NFSd Reply Cache an operation that requires caching (idempotent).",
nil,
nil,
),
prometheus.CounterValue,
float64(s.Misses))
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsdSubsystem, "reply_cache_nocache_total"),
"Total number of NFSd Reply Cache non-idempotent operations (rename/delete/…).",
nil,
nil,
),
prometheus.CounterValue,
float64(s.NoCache))
} | go | func (c *nfsdCollector) updateNFSdReplyCacheStats(ch chan<- prometheus.Metric, s *nfs.ReplyCache) {
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsdSubsystem, "reply_cache_hits_total"),
"Total number of NFSd Reply Cache hits (client lost server response).",
nil,
nil,
),
prometheus.CounterValue,
float64(s.Hits))
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsdSubsystem, "reply_cache_misses_total"),
"Total number of NFSd Reply Cache an operation that requires caching (idempotent).",
nil,
nil,
),
prometheus.CounterValue,
float64(s.Misses))
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsdSubsystem, "reply_cache_nocache_total"),
"Total number of NFSd Reply Cache non-idempotent operations (rename/delete/…).",
nil,
nil,
),
prometheus.CounterValue,
float64(s.NoCache))
} | [
"func",
"(",
"c",
"*",
"nfsdCollector",
")",
"updateNFSdReplyCacheStats",
"(",
"ch",
"chan",
"<-",
"prometheus",
".",
"Metric",
",",
"s",
"*",
"nfs",
".",
"ReplyCache",
")",
"{",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"nfsdSubsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"Hits",
")",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"nfsdSubsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"Misses",
")",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"nfsdSubsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"",
"",
"nil",
",",
"nil",
",",
")",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"NoCache",
")",
")",
"\n",
"}"
] | // updateNFSdReplyCacheStats collects statistics for the reply cache. | [
"updateNFSdReplyCacheStats",
"collects",
"statistics",
"for",
"the",
"reply",
"cache",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/nfsd_linux.go#L84-L112 | train |
prometheus/node_exporter | collector/nfsd_linux.go | updateNFSdFileHandlesStats | func (c *nfsdCollector) updateNFSdFileHandlesStats(ch chan<- prometheus.Metric, s *nfs.FileHandles) {
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsdSubsystem, "file_handles_stale_total"),
"Total number of NFSd stale file handles",
nil,
nil,
),
prometheus.CounterValue,
float64(s.Stale))
// NOTE: Other FileHandles entries are unused in the kernel.
} | go | func (c *nfsdCollector) updateNFSdFileHandlesStats(ch chan<- prometheus.Metric, s *nfs.FileHandles) {
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsdSubsystem, "file_handles_stale_total"),
"Total number of NFSd stale file handles",
nil,
nil,
),
prometheus.CounterValue,
float64(s.Stale))
// NOTE: Other FileHandles entries are unused in the kernel.
} | [
"func",
"(",
"c",
"*",
"nfsdCollector",
")",
"updateNFSdFileHandlesStats",
"(",
"ch",
"chan",
"<-",
"prometheus",
".",
"Metric",
",",
"s",
"*",
"nfs",
".",
"FileHandles",
")",
"{",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"nfsdSubsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"Stale",
")",
")",
"\n",
"// NOTE: Other FileHandles entries are unused in the kernel.",
"}"
] | // updateNFSdFileHandlesStats collects statistics for the file handles. | [
"updateNFSdFileHandlesStats",
"collects",
"statistics",
"for",
"the",
"file",
"handles",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/nfsd_linux.go#L115-L126 | train |
prometheus/node_exporter | collector/nfsd_linux.go | updateNFSdThreadsStats | func (c *nfsdCollector) updateNFSdThreadsStats(ch chan<- prometheus.Metric, s *nfs.Threads) {
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsdSubsystem, "server_threads"),
"Total number of NFSd kernel threads that are running.",
nil,
nil,
),
prometheus.GaugeValue,
float64(s.Threads))
} | go | func (c *nfsdCollector) updateNFSdThreadsStats(ch chan<- prometheus.Metric, s *nfs.Threads) {
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsdSubsystem, "server_threads"),
"Total number of NFSd kernel threads that are running.",
nil,
nil,
),
prometheus.GaugeValue,
float64(s.Threads))
} | [
"func",
"(",
"c",
"*",
"nfsdCollector",
")",
"updateNFSdThreadsStats",
"(",
"ch",
"chan",
"<-",
"prometheus",
".",
"Metric",
",",
"s",
"*",
"nfs",
".",
"Threads",
")",
"{",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"nfsdSubsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"prometheus",
".",
"GaugeValue",
",",
"float64",
"(",
"s",
".",
"Threads",
")",
")",
"\n",
"}"
] | // updateNFSdThreadsStats collects statistics for kernel server threads. | [
"updateNFSdThreadsStats",
"collects",
"statistics",
"for",
"kernel",
"server",
"threads",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/nfsd_linux.go#L151-L161 | train |
prometheus/node_exporter | collector/nfsd_linux.go | updateNFSdReadAheadCacheStats | func (c *nfsdCollector) updateNFSdReadAheadCacheStats(ch chan<- prometheus.Metric, s *nfs.ReadAheadCache) {
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsdSubsystem, "read_ahead_cache_size_blocks"),
"How large the read ahead cache is in blocks.",
nil,
nil,
),
prometheus.GaugeValue,
float64(s.CacheSize))
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsdSubsystem, "read_ahead_cache_not_found_total"),
"Total number of NFSd read ahead cache not found.",
nil,
nil,
),
prometheus.CounterValue,
float64(s.NotFound))
} | go | func (c *nfsdCollector) updateNFSdReadAheadCacheStats(ch chan<- prometheus.Metric, s *nfs.ReadAheadCache) {
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsdSubsystem, "read_ahead_cache_size_blocks"),
"How large the read ahead cache is in blocks.",
nil,
nil,
),
prometheus.GaugeValue,
float64(s.CacheSize))
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsdSubsystem, "read_ahead_cache_not_found_total"),
"Total number of NFSd read ahead cache not found.",
nil,
nil,
),
prometheus.CounterValue,
float64(s.NotFound))
} | [
"func",
"(",
"c",
"*",
"nfsdCollector",
")",
"updateNFSdReadAheadCacheStats",
"(",
"ch",
"chan",
"<-",
"prometheus",
".",
"Metric",
",",
"s",
"*",
"nfs",
".",
"ReadAheadCache",
")",
"{",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"nfsdSubsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"prometheus",
".",
"GaugeValue",
",",
"float64",
"(",
"s",
".",
"CacheSize",
")",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"nfsdSubsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"NotFound",
")",
")",
"\n",
"}"
] | // updateNFSdReadAheadCacheStats collects statistics for the read ahead cache. | [
"updateNFSdReadAheadCacheStats",
"collects",
"statistics",
"for",
"the",
"read",
"ahead",
"cache",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/nfsd_linux.go#L164-L183 | train |
prometheus/node_exporter | collector/nfsd_linux.go | updateNFSdServerRPCStats | func (c *nfsdCollector) updateNFSdServerRPCStats(ch chan<- prometheus.Metric, s *nfs.ServerRPC) {
badRPCDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsdSubsystem, "rpc_errors_total"),
"Total number of NFSd RPC errors by error type.",
[]string{"error"},
nil,
)
ch <- prometheus.MustNewConstMetric(
badRPCDesc,
prometheus.CounterValue,
float64(s.BadFmt), "fmt")
ch <- prometheus.MustNewConstMetric(
badRPCDesc,
prometheus.CounterValue,
float64(s.BadAuth), "auth")
ch <- prometheus.MustNewConstMetric(
badRPCDesc,
prometheus.CounterValue,
float64(s.BadcInt), "cInt")
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsdSubsystem, "server_rpcs_total"),
"Total number of NFSd RPCs.",
nil,
nil,
),
prometheus.CounterValue,
float64(s.RPCCount))
} | go | func (c *nfsdCollector) updateNFSdServerRPCStats(ch chan<- prometheus.Metric, s *nfs.ServerRPC) {
badRPCDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsdSubsystem, "rpc_errors_total"),
"Total number of NFSd RPC errors by error type.",
[]string{"error"},
nil,
)
ch <- prometheus.MustNewConstMetric(
badRPCDesc,
prometheus.CounterValue,
float64(s.BadFmt), "fmt")
ch <- prometheus.MustNewConstMetric(
badRPCDesc,
prometheus.CounterValue,
float64(s.BadAuth), "auth")
ch <- prometheus.MustNewConstMetric(
badRPCDesc,
prometheus.CounterValue,
float64(s.BadcInt), "cInt")
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsdSubsystem, "server_rpcs_total"),
"Total number of NFSd RPCs.",
nil,
nil,
),
prometheus.CounterValue,
float64(s.RPCCount))
} | [
"func",
"(",
"c",
"*",
"nfsdCollector",
")",
"updateNFSdServerRPCStats",
"(",
"ch",
"chan",
"<-",
"prometheus",
".",
"Metric",
",",
"s",
"*",
"nfs",
".",
"ServerRPC",
")",
"{",
"badRPCDesc",
":=",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"nfsdSubsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"nil",
",",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"badRPCDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"BadFmt",
")",
",",
"\"",
"\"",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"badRPCDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"BadAuth",
")",
",",
"\"",
"\"",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"badRPCDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"BadcInt",
")",
",",
"\"",
"\"",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"nfsdSubsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"RPCCount",
")",
")",
"\n",
"}"
] | // updateNFSdServerRPCStats collects statistics for kernel server RPCs. | [
"updateNFSdServerRPCStats",
"collects",
"statistics",
"for",
"kernel",
"server",
"RPCs",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/nfsd_linux.go#L213-L241 | train |
prometheus/node_exporter | collector/nfsd_linux.go | updateNFSdRequestsv2Stats | func (c *nfsdCollector) updateNFSdRequestsv2Stats(ch chan<- prometheus.Metric, s *nfs.V2Stats) {
const proto = "2"
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.GetAttr), proto, "GetAttr")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.SetAttr), proto, "SetAttr")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.Root), proto, "Root")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.Lookup), proto, "Lookup")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.ReadLink), proto, "ReadLink")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.Read), proto, "Read")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.WrCache), proto, "WrCache")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.Write), proto, "Write")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.Create), proto, "Create")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.Remove), proto, "Remove")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.Rename), proto, "Rename")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.Link), proto, "Link")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.SymLink), proto, "SymLink")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.MkDir), proto, "MkDir")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.RmDir), proto, "RmDir")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.ReadDir), proto, "ReadDir")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.FsStat), proto, "FsStat")
} | go | func (c *nfsdCollector) updateNFSdRequestsv2Stats(ch chan<- prometheus.Metric, s *nfs.V2Stats) {
const proto = "2"
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.GetAttr), proto, "GetAttr")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.SetAttr), proto, "SetAttr")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.Root), proto, "Root")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.Lookup), proto, "Lookup")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.ReadLink), proto, "ReadLink")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.Read), proto, "Read")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.WrCache), proto, "WrCache")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.Write), proto, "Write")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.Create), proto, "Create")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.Remove), proto, "Remove")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.Rename), proto, "Rename")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.Link), proto, "Link")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.SymLink), proto, "SymLink")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.MkDir), proto, "MkDir")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.RmDir), proto, "RmDir")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.ReadDir), proto, "ReadDir")
ch <- prometheus.MustNewConstMetric(c.requestsDesc, prometheus.CounterValue,
float64(s.FsStat), proto, "FsStat")
} | [
"func",
"(",
"c",
"*",
"nfsdCollector",
")",
"updateNFSdRequestsv2Stats",
"(",
"ch",
"chan",
"<-",
"prometheus",
".",
"Metric",
",",
"s",
"*",
"nfs",
".",
"V2Stats",
")",
"{",
"const",
"proto",
"=",
"\"",
"\"",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"requestsDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"GetAttr",
")",
",",
"proto",
",",
"\"",
"\"",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"requestsDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"SetAttr",
")",
",",
"proto",
",",
"\"",
"\"",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"requestsDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"Root",
")",
",",
"proto",
",",
"\"",
"\"",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"requestsDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"Lookup",
")",
",",
"proto",
",",
"\"",
"\"",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"requestsDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"ReadLink",
")",
",",
"proto",
",",
"\"",
"\"",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"requestsDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"Read",
")",
",",
"proto",
",",
"\"",
"\"",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"requestsDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"WrCache",
")",
",",
"proto",
",",
"\"",
"\"",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"requestsDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"Write",
")",
",",
"proto",
",",
"\"",
"\"",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"requestsDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"Create",
")",
",",
"proto",
",",
"\"",
"\"",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"requestsDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"Remove",
")",
",",
"proto",
",",
"\"",
"\"",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"requestsDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"Rename",
")",
",",
"proto",
",",
"\"",
"\"",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"requestsDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"Link",
")",
",",
"proto",
",",
"\"",
"\"",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"requestsDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"SymLink",
")",
",",
"proto",
",",
"\"",
"\"",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"requestsDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"MkDir",
")",
",",
"proto",
",",
"\"",
"\"",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"requestsDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"RmDir",
")",
",",
"proto",
",",
"\"",
"\"",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"requestsDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"ReadDir",
")",
",",
"proto",
",",
"\"",
"\"",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"requestsDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"FsStat",
")",
",",
"proto",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // updateNFSdRequestsv2Stats collects statistics for NFSv2 requests. | [
"updateNFSdRequestsv2Stats",
"collects",
"statistics",
"for",
"NFSv2",
"requests",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/nfsd_linux.go#L244-L280 | train |
prometheus/node_exporter | collector/supervisord.go | NewSupervisordCollector | func NewSupervisordCollector() (Collector, error) {
var (
subsystem = "supervisord"
labelNames = []string{"name", "group"}
)
return &supervisordCollector{
upDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "up"),
"Process Up",
labelNames,
nil,
),
stateDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "state"),
"Process State",
labelNames,
nil,
),
exitStatusDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "exit_status"),
"Process Exit Status",
labelNames,
nil,
),
startTimeDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "start_time_seconds"),
"Process start time",
labelNames,
nil,
),
}, nil
} | go | func NewSupervisordCollector() (Collector, error) {
var (
subsystem = "supervisord"
labelNames = []string{"name", "group"}
)
return &supervisordCollector{
upDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "up"),
"Process Up",
labelNames,
nil,
),
stateDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "state"),
"Process State",
labelNames,
nil,
),
exitStatusDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "exit_status"),
"Process Exit Status",
labelNames,
nil,
),
startTimeDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "start_time_seconds"),
"Process start time",
labelNames,
nil,
),
}, nil
} | [
"func",
"NewSupervisordCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"var",
"(",
"subsystem",
"=",
"\"",
"\"",
"\n",
"labelNames",
"=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"\n",
")",
"\n",
"return",
"&",
"supervisordCollector",
"{",
"upDesc",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"labelNames",
",",
"nil",
",",
")",
",",
"stateDesc",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"labelNames",
",",
"nil",
",",
")",
",",
"exitStatusDesc",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"labelNames",
",",
"nil",
",",
")",
",",
"startTimeDesc",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"labelNames",
",",
"nil",
",",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewSupervisordCollector returns a new Collector exposing supervisord statistics. | [
"NewSupervisordCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"supervisord",
"statistics",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/supervisord.go#L43-L74 | train |
prometheus/node_exporter | collector/interrupts_common.go | NewInterruptsCollector | func NewInterruptsCollector() (Collector, error) {
return &interruptsCollector{
desc: typedDesc{prometheus.NewDesc(
namespace+"_interrupts_total",
"Interrupt details.",
interruptLabelNames, nil,
), prometheus.CounterValue},
}, nil
} | go | func NewInterruptsCollector() (Collector, error) {
return &interruptsCollector{
desc: typedDesc{prometheus.NewDesc(
namespace+"_interrupts_total",
"Interrupt details.",
interruptLabelNames, nil,
), prometheus.CounterValue},
}, nil
} | [
"func",
"NewInterruptsCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"return",
"&",
"interruptsCollector",
"{",
"desc",
":",
"typedDesc",
"{",
"prometheus",
".",
"NewDesc",
"(",
"namespace",
"+",
"\"",
"\"",
",",
"\"",
"\"",
",",
"interruptLabelNames",
",",
"nil",
",",
")",
",",
"prometheus",
".",
"CounterValue",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewInterruptsCollector returns a new Collector exposing interrupts stats. | [
"NewInterruptsCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"interrupts",
"stats",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/interrupts_common.go#L30-L38 | train |
prometheus/node_exporter | collector/loadavg.go | NewLoadavgCollector | func NewLoadavgCollector() (Collector, error) {
return &loadavgCollector{
metric: []typedDesc{
{prometheus.NewDesc(namespace+"_load1", "1m load average.", nil, nil), prometheus.GaugeValue},
{prometheus.NewDesc(namespace+"_load5", "5m load average.", nil, nil), prometheus.GaugeValue},
{prometheus.NewDesc(namespace+"_load15", "15m load average.", nil, nil), prometheus.GaugeValue},
},
}, nil
} | go | func NewLoadavgCollector() (Collector, error) {
return &loadavgCollector{
metric: []typedDesc{
{prometheus.NewDesc(namespace+"_load1", "1m load average.", nil, nil), prometheus.GaugeValue},
{prometheus.NewDesc(namespace+"_load5", "5m load average.", nil, nil), prometheus.GaugeValue},
{prometheus.NewDesc(namespace+"_load15", "15m load average.", nil, nil), prometheus.GaugeValue},
},
}, nil
} | [
"func",
"NewLoadavgCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"return",
"&",
"loadavgCollector",
"{",
"metric",
":",
"[",
"]",
"typedDesc",
"{",
"{",
"prometheus",
".",
"NewDesc",
"(",
"namespace",
"+",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
")",
",",
"prometheus",
".",
"GaugeValue",
"}",
",",
"{",
"prometheus",
".",
"NewDesc",
"(",
"namespace",
"+",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
")",
",",
"prometheus",
".",
"GaugeValue",
"}",
",",
"{",
"prometheus",
".",
"NewDesc",
"(",
"namespace",
"+",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
")",
",",
"prometheus",
".",
"GaugeValue",
"}",
",",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewLoadavgCollector returns a new Collector exposing load average stats. | [
"NewLoadavgCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"load",
"average",
"stats",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/loadavg.go#L35-L43 | train |
prometheus/node_exporter | collector/time.go | NewTimeCollector | func NewTimeCollector() (Collector, error) {
return &timeCollector{
desc: prometheus.NewDesc(
namespace+"_time_seconds",
"System time in seconds since epoch (1970).",
nil, nil,
),
}, nil
} | go | func NewTimeCollector() (Collector, error) {
return &timeCollector{
desc: prometheus.NewDesc(
namespace+"_time_seconds",
"System time in seconds since epoch (1970).",
nil, nil,
),
}, nil
} | [
"func",
"NewTimeCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"return",
"&",
"timeCollector",
"{",
"desc",
":",
"prometheus",
".",
"NewDesc",
"(",
"namespace",
"+",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewTimeCollector returns a new Collector exposing the current system time in
// seconds since epoch. | [
"NewTimeCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"the",
"current",
"system",
"time",
"in",
"seconds",
"since",
"epoch",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/time.go#L35-L43 | train |
prometheus/node_exporter | collector/tcpstat_linux.go | NewTCPStatCollector | func NewTCPStatCollector() (Collector, error) {
return &tcpStatCollector{
desc: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(namespace, "tcp", "connection_states"),
"Number of connection states.",
[]string{"state"}, nil,
), prometheus.GaugeValue},
}, nil
} | go | func NewTCPStatCollector() (Collector, error) {
return &tcpStatCollector{
desc: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(namespace, "tcp", "connection_states"),
"Number of connection states.",
[]string{"state"}, nil,
), prometheus.GaugeValue},
}, nil
} | [
"func",
"NewTCPStatCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"return",
"&",
"tcpStatCollector",
"{",
"desc",
":",
"typedDesc",
"{",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"nil",
",",
")",
",",
"prometheus",
".",
"GaugeValue",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewTCPStatCollector returns a new Collector exposing network stats. | [
"NewTCPStatCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"network",
"stats",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/tcpstat_linux.go#L65-L73 | train |
prometheus/node_exporter | collector/filesystem_linux.go | GetStats | func (c *filesystemCollector) GetStats() ([]filesystemStats, error) {
mps, err := mountPointDetails()
if err != nil {
return nil, err
}
stats := []filesystemStats{}
for _, labels := range mps {
if c.ignoredMountPointsPattern.MatchString(labels.mountPoint) {
log.Debugf("Ignoring mount point: %s", labels.mountPoint)
continue
}
if c.ignoredFSTypesPattern.MatchString(labels.fsType) {
log.Debugf("Ignoring fs type: %s", labels.fsType)
continue
}
stuckMountsMtx.Lock()
if _, ok := stuckMounts[labels.mountPoint]; ok {
stats = append(stats, filesystemStats{
labels: labels,
deviceError: 1,
})
log.Debugf("Mount point %q is in an unresponsive state", labels.mountPoint)
stuckMountsMtx.Unlock()
continue
}
stuckMountsMtx.Unlock()
// The success channel is used do tell the "watcher" that the stat
// finished successfully. The channel is closed on success.
success := make(chan struct{})
go stuckMountWatcher(labels.mountPoint, success)
buf := new(syscall.Statfs_t)
err = syscall.Statfs(rootfsFilePath(labels.mountPoint), buf)
stuckMountsMtx.Lock()
close(success)
// If the mount has been marked as stuck, unmark it and log it's recovery.
if _, ok := stuckMounts[labels.mountPoint]; ok {
log.Debugf("Mount point %q has recovered, monitoring will resume", labels.mountPoint)
delete(stuckMounts, labels.mountPoint)
}
stuckMountsMtx.Unlock()
if err != nil {
stats = append(stats, filesystemStats{
labels: labels,
deviceError: 1,
})
log.Debugf("Error on statfs() system call for %q: %s", rootfsFilePath(labels.mountPoint), err)
continue
}
var ro float64
for _, option := range strings.Split(labels.options, ",") {
if option == "ro" {
ro = 1
break
}
}
stats = append(stats, filesystemStats{
labels: labels,
size: float64(buf.Blocks) * float64(buf.Bsize),
free: float64(buf.Bfree) * float64(buf.Bsize),
avail: float64(buf.Bavail) * float64(buf.Bsize),
files: float64(buf.Files),
filesFree: float64(buf.Ffree),
ro: ro,
})
}
return stats, nil
} | go | func (c *filesystemCollector) GetStats() ([]filesystemStats, error) {
mps, err := mountPointDetails()
if err != nil {
return nil, err
}
stats := []filesystemStats{}
for _, labels := range mps {
if c.ignoredMountPointsPattern.MatchString(labels.mountPoint) {
log.Debugf("Ignoring mount point: %s", labels.mountPoint)
continue
}
if c.ignoredFSTypesPattern.MatchString(labels.fsType) {
log.Debugf("Ignoring fs type: %s", labels.fsType)
continue
}
stuckMountsMtx.Lock()
if _, ok := stuckMounts[labels.mountPoint]; ok {
stats = append(stats, filesystemStats{
labels: labels,
deviceError: 1,
})
log.Debugf("Mount point %q is in an unresponsive state", labels.mountPoint)
stuckMountsMtx.Unlock()
continue
}
stuckMountsMtx.Unlock()
// The success channel is used do tell the "watcher" that the stat
// finished successfully. The channel is closed on success.
success := make(chan struct{})
go stuckMountWatcher(labels.mountPoint, success)
buf := new(syscall.Statfs_t)
err = syscall.Statfs(rootfsFilePath(labels.mountPoint), buf)
stuckMountsMtx.Lock()
close(success)
// If the mount has been marked as stuck, unmark it and log it's recovery.
if _, ok := stuckMounts[labels.mountPoint]; ok {
log.Debugf("Mount point %q has recovered, monitoring will resume", labels.mountPoint)
delete(stuckMounts, labels.mountPoint)
}
stuckMountsMtx.Unlock()
if err != nil {
stats = append(stats, filesystemStats{
labels: labels,
deviceError: 1,
})
log.Debugf("Error on statfs() system call for %q: %s", rootfsFilePath(labels.mountPoint), err)
continue
}
var ro float64
for _, option := range strings.Split(labels.options, ",") {
if option == "ro" {
ro = 1
break
}
}
stats = append(stats, filesystemStats{
labels: labels,
size: float64(buf.Blocks) * float64(buf.Bsize),
free: float64(buf.Bfree) * float64(buf.Bsize),
avail: float64(buf.Bavail) * float64(buf.Bsize),
files: float64(buf.Files),
filesFree: float64(buf.Ffree),
ro: ro,
})
}
return stats, nil
} | [
"func",
"(",
"c",
"*",
"filesystemCollector",
")",
"GetStats",
"(",
")",
"(",
"[",
"]",
"filesystemStats",
",",
"error",
")",
"{",
"mps",
",",
"err",
":=",
"mountPointDetails",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"stats",
":=",
"[",
"]",
"filesystemStats",
"{",
"}",
"\n",
"for",
"_",
",",
"labels",
":=",
"range",
"mps",
"{",
"if",
"c",
".",
"ignoredMountPointsPattern",
".",
"MatchString",
"(",
"labels",
".",
"mountPoint",
")",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"labels",
".",
"mountPoint",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"if",
"c",
".",
"ignoredFSTypesPattern",
".",
"MatchString",
"(",
"labels",
".",
"fsType",
")",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"labels",
".",
"fsType",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"stuckMountsMtx",
".",
"Lock",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"stuckMounts",
"[",
"labels",
".",
"mountPoint",
"]",
";",
"ok",
"{",
"stats",
"=",
"append",
"(",
"stats",
",",
"filesystemStats",
"{",
"labels",
":",
"labels",
",",
"deviceError",
":",
"1",
",",
"}",
")",
"\n",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"labels",
".",
"mountPoint",
")",
"\n",
"stuckMountsMtx",
".",
"Unlock",
"(",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"stuckMountsMtx",
".",
"Unlock",
"(",
")",
"\n\n",
"// The success channel is used do tell the \"watcher\" that the stat",
"// finished successfully. The channel is closed on success.",
"success",
":=",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
"\n",
"go",
"stuckMountWatcher",
"(",
"labels",
".",
"mountPoint",
",",
"success",
")",
"\n\n",
"buf",
":=",
"new",
"(",
"syscall",
".",
"Statfs_t",
")",
"\n",
"err",
"=",
"syscall",
".",
"Statfs",
"(",
"rootfsFilePath",
"(",
"labels",
".",
"mountPoint",
")",
",",
"buf",
")",
"\n\n",
"stuckMountsMtx",
".",
"Lock",
"(",
")",
"\n",
"close",
"(",
"success",
")",
"\n",
"// If the mount has been marked as stuck, unmark it and log it's recovery.",
"if",
"_",
",",
"ok",
":=",
"stuckMounts",
"[",
"labels",
".",
"mountPoint",
"]",
";",
"ok",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"labels",
".",
"mountPoint",
")",
"\n",
"delete",
"(",
"stuckMounts",
",",
"labels",
".",
"mountPoint",
")",
"\n",
"}",
"\n",
"stuckMountsMtx",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"stats",
"=",
"append",
"(",
"stats",
",",
"filesystemStats",
"{",
"labels",
":",
"labels",
",",
"deviceError",
":",
"1",
",",
"}",
")",
"\n",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"rootfsFilePath",
"(",
"labels",
".",
"mountPoint",
")",
",",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"var",
"ro",
"float64",
"\n",
"for",
"_",
",",
"option",
":=",
"range",
"strings",
".",
"Split",
"(",
"labels",
".",
"options",
",",
"\"",
"\"",
")",
"{",
"if",
"option",
"==",
"\"",
"\"",
"{",
"ro",
"=",
"1",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"stats",
"=",
"append",
"(",
"stats",
",",
"filesystemStats",
"{",
"labels",
":",
"labels",
",",
"size",
":",
"float64",
"(",
"buf",
".",
"Blocks",
")",
"*",
"float64",
"(",
"buf",
".",
"Bsize",
")",
",",
"free",
":",
"float64",
"(",
"buf",
".",
"Bfree",
")",
"*",
"float64",
"(",
"buf",
".",
"Bsize",
")",
",",
"avail",
":",
"float64",
"(",
"buf",
".",
"Bavail",
")",
"*",
"float64",
"(",
"buf",
".",
"Bsize",
")",
",",
"files",
":",
"float64",
"(",
"buf",
".",
"Files",
")",
",",
"filesFree",
":",
"float64",
"(",
"buf",
".",
"Ffree",
")",
",",
"ro",
":",
"ro",
",",
"}",
")",
"\n",
"}",
"\n",
"return",
"stats",
",",
"nil",
"\n",
"}"
] | // GetStats returns filesystem stats. | [
"GetStats",
"returns",
"filesystem",
"stats",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/filesystem_linux.go#L41-L113 | train |
prometheus/node_exporter | collector/filesystem_linux.go | stuckMountWatcher | func stuckMountWatcher(mountPoint string, success chan struct{}) {
select {
case <-success:
// Success
case <-time.After(mountTimeout):
// Timed out, mark mount as stuck
stuckMountsMtx.Lock()
select {
case <-success:
// Success came in just after the timeout was reached, don't label the mount as stuck
default:
log.Debugf("Mount point %q timed out, it is being labeled as stuck and will not be monitored", mountPoint)
stuckMounts[mountPoint] = struct{}{}
}
stuckMountsMtx.Unlock()
}
} | go | func stuckMountWatcher(mountPoint string, success chan struct{}) {
select {
case <-success:
// Success
case <-time.After(mountTimeout):
// Timed out, mark mount as stuck
stuckMountsMtx.Lock()
select {
case <-success:
// Success came in just after the timeout was reached, don't label the mount as stuck
default:
log.Debugf("Mount point %q timed out, it is being labeled as stuck and will not be monitored", mountPoint)
stuckMounts[mountPoint] = struct{}{}
}
stuckMountsMtx.Unlock()
}
} | [
"func",
"stuckMountWatcher",
"(",
"mountPoint",
"string",
",",
"success",
"chan",
"struct",
"{",
"}",
")",
"{",
"select",
"{",
"case",
"<-",
"success",
":",
"// Success",
"case",
"<-",
"time",
".",
"After",
"(",
"mountTimeout",
")",
":",
"// Timed out, mark mount as stuck",
"stuckMountsMtx",
".",
"Lock",
"(",
")",
"\n",
"select",
"{",
"case",
"<-",
"success",
":",
"// Success came in just after the timeout was reached, don't label the mount as stuck",
"default",
":",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"mountPoint",
")",
"\n",
"stuckMounts",
"[",
"mountPoint",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"stuckMountsMtx",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // stuckMountWatcher listens on the given success channel and if the channel closes
// then the watcher does nothing. If instead the timeout is reached, the
// mount point that is being watched is marked as stuck. | [
"stuckMountWatcher",
"listens",
"on",
"the",
"given",
"success",
"channel",
"and",
"if",
"the",
"channel",
"closes",
"then",
"the",
"watcher",
"does",
"nothing",
".",
"If",
"instead",
"the",
"timeout",
"is",
"reached",
"the",
"mount",
"point",
"that",
"is",
"being",
"watched",
"is",
"marked",
"as",
"stuck",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/filesystem_linux.go#L118-L134 | train |
prometheus/node_exporter | collector/conntrack_linux.go | NewConntrackCollector | func NewConntrackCollector() (Collector, error) {
return &conntrackCollector{
current: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_entries"),
"Number of currently allocated flow entries for connection tracking.",
nil, nil,
),
limit: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_entries_limit"),
"Maximum size of connection tracking table.",
nil, nil,
),
}, nil
} | go | func NewConntrackCollector() (Collector, error) {
return &conntrackCollector{
current: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_entries"),
"Number of currently allocated flow entries for connection tracking.",
nil, nil,
),
limit: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_entries_limit"),
"Maximum size of connection tracking table.",
nil, nil,
),
}, nil
} | [
"func",
"NewConntrackCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"return",
"&",
"conntrackCollector",
"{",
"current",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"limit",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewConntrackCollector returns a new Collector exposing conntrack stats. | [
"NewConntrackCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"conntrack",
"stats",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/conntrack_linux.go#L32-L45 | train |
prometheus/node_exporter | collector/nfs_linux.go | NewNfsCollector | func NewNfsCollector() (Collector, error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %v", err)
}
return &nfsCollector{
fs: fs,
nfsNetReadsDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsSubsystem, "packets_total"),
"Total NFSd network packets (sent+received) by protocol type.",
[]string{"protocol"},
nil,
),
nfsNetConnectionsDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsSubsystem, "connections_total"),
"Total number of NFSd TCP connections.",
nil,
nil,
),
nfsRPCOperationsDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsSubsystem, "rpcs_total"),
"Total number of RPCs performed.",
nil,
nil,
),
nfsRPCRetransmissionsDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsSubsystem, "rpc_retransmissions_total"),
"Number of RPC transmissions performed.",
nil,
nil,
),
nfsRPCAuthenticationRefreshesDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsSubsystem, "rpc_authentication_refreshes_total"),
"Number of RPC authentication refreshes performed.",
nil,
nil,
),
nfsProceduresDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsSubsystem, "requests_total"),
"Number of NFS procedures invoked.",
[]string{"proto", "method"},
nil,
),
}, nil
} | go | func NewNfsCollector() (Collector, error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %v", err)
}
return &nfsCollector{
fs: fs,
nfsNetReadsDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsSubsystem, "packets_total"),
"Total NFSd network packets (sent+received) by protocol type.",
[]string{"protocol"},
nil,
),
nfsNetConnectionsDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsSubsystem, "connections_total"),
"Total number of NFSd TCP connections.",
nil,
nil,
),
nfsRPCOperationsDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsSubsystem, "rpcs_total"),
"Total number of RPCs performed.",
nil,
nil,
),
nfsRPCRetransmissionsDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsSubsystem, "rpc_retransmissions_total"),
"Number of RPC transmissions performed.",
nil,
nil,
),
nfsRPCAuthenticationRefreshesDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsSubsystem, "rpc_authentication_refreshes_total"),
"Number of RPC authentication refreshes performed.",
nil,
nil,
),
nfsProceduresDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, nfsSubsystem, "requests_total"),
"Number of NFS procedures invoked.",
[]string{"proto", "method"},
nil,
),
}, nil
} | [
"func",
"NewNfsCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"fs",
",",
"err",
":=",
"procfs",
".",
"NewFS",
"(",
"*",
"procPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"nfsCollector",
"{",
"fs",
":",
"fs",
",",
"nfsNetReadsDesc",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"nfsSubsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"nil",
",",
")",
",",
"nfsNetConnectionsDesc",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"nfsSubsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"nfsRPCOperationsDesc",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"nfsSubsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"nfsRPCRetransmissionsDesc",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"nfsSubsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"nfsRPCAuthenticationRefreshesDesc",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"nfsSubsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"nfsProceduresDesc",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"nfsSubsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"nil",
",",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewNfsCollector returns a new Collector exposing NFS statistics. | [
"NewNfsCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"NFS",
"statistics",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/nfs_linux.go#L46-L91 | train |
prometheus/node_exporter | collector/nfs_linux.go | updateNFSClientRPCStats | func (c *nfsCollector) updateNFSClientRPCStats(ch chan<- prometheus.Metric, s *nfs.ClientRPC) {
ch <- prometheus.MustNewConstMetric(c.nfsRPCOperationsDesc, prometheus.CounterValue,
float64(s.RPCCount))
ch <- prometheus.MustNewConstMetric(c.nfsRPCRetransmissionsDesc, prometheus.CounterValue,
float64(s.Retransmissions))
ch <- prometheus.MustNewConstMetric(c.nfsRPCAuthenticationRefreshesDesc, prometheus.CounterValue,
float64(s.AuthRefreshes))
} | go | func (c *nfsCollector) updateNFSClientRPCStats(ch chan<- prometheus.Metric, s *nfs.ClientRPC) {
ch <- prometheus.MustNewConstMetric(c.nfsRPCOperationsDesc, prometheus.CounterValue,
float64(s.RPCCount))
ch <- prometheus.MustNewConstMetric(c.nfsRPCRetransmissionsDesc, prometheus.CounterValue,
float64(s.Retransmissions))
ch <- prometheus.MustNewConstMetric(c.nfsRPCAuthenticationRefreshesDesc, prometheus.CounterValue,
float64(s.AuthRefreshes))
} | [
"func",
"(",
"c",
"*",
"nfsCollector",
")",
"updateNFSClientRPCStats",
"(",
"ch",
"chan",
"<-",
"prometheus",
".",
"Metric",
",",
"s",
"*",
"nfs",
".",
"ClientRPC",
")",
"{",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"nfsRPCOperationsDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"RPCCount",
")",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"nfsRPCRetransmissionsDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"Retransmissions",
")",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"nfsRPCAuthenticationRefreshesDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"s",
".",
"AuthRefreshes",
")",
")",
"\n",
"}"
] | // updateNFSClientRPCStats collects statistics for kernel server RPCs. | [
"updateNFSClientRPCStats",
"collects",
"statistics",
"for",
"kernel",
"server",
"RPCs",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/nfs_linux.go#L123-L130 | train |
prometheus/node_exporter | collector/nfs_linux.go | updateNFSRequestsv2Stats | func (c *nfsCollector) updateNFSRequestsv2Stats(ch chan<- prometheus.Metric, s *nfs.V2Stats) {
const proto = "2"
v := reflect.ValueOf(s).Elem()
for i := 0; i < v.NumField(); i++ {
field := v.Field(i)
ch <- prometheus.MustNewConstMetric(c.nfsProceduresDesc, prometheus.CounterValue,
float64(field.Uint()), proto, v.Type().Field(i).Name)
}
} | go | func (c *nfsCollector) updateNFSRequestsv2Stats(ch chan<- prometheus.Metric, s *nfs.V2Stats) {
const proto = "2"
v := reflect.ValueOf(s).Elem()
for i := 0; i < v.NumField(); i++ {
field := v.Field(i)
ch <- prometheus.MustNewConstMetric(c.nfsProceduresDesc, prometheus.CounterValue,
float64(field.Uint()), proto, v.Type().Field(i).Name)
}
} | [
"func",
"(",
"c",
"*",
"nfsCollector",
")",
"updateNFSRequestsv2Stats",
"(",
"ch",
"chan",
"<-",
"prometheus",
".",
"Metric",
",",
"s",
"*",
"nfs",
".",
"V2Stats",
")",
"{",
"const",
"proto",
"=",
"\"",
"\"",
"\n\n",
"v",
":=",
"reflect",
".",
"ValueOf",
"(",
"s",
")",
".",
"Elem",
"(",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"v",
".",
"NumField",
"(",
")",
";",
"i",
"++",
"{",
"field",
":=",
"v",
".",
"Field",
"(",
"i",
")",
"\n\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"nfsProceduresDesc",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"field",
".",
"Uint",
"(",
")",
")",
",",
"proto",
",",
"v",
".",
"Type",
"(",
")",
".",
"Field",
"(",
"i",
")",
".",
"Name",
")",
"\n",
"}",
"\n",
"}"
] | // updateNFSRequestsv2Stats collects statistics for NFSv2 requests. | [
"updateNFSRequestsv2Stats",
"collects",
"statistics",
"for",
"NFSv2",
"requests",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/nfs_linux.go#L133-L143 | train |
prometheus/node_exporter | collector/netclass_linux.go | NewNetClassCollector | func NewNetClassCollector() (Collector, error) {
fs, err := sysfs.NewFS(*sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %v", err)
}
pattern := regexp.MustCompile(*netclassIgnoredDevices)
return &netClassCollector{
fs: fs,
subsystem: "network",
ignoredDevicesPattern: pattern,
metricDescs: map[string]*prometheus.Desc{},
}, nil
} | go | func NewNetClassCollector() (Collector, error) {
fs, err := sysfs.NewFS(*sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %v", err)
}
pattern := regexp.MustCompile(*netclassIgnoredDevices)
return &netClassCollector{
fs: fs,
subsystem: "network",
ignoredDevicesPattern: pattern,
metricDescs: map[string]*prometheus.Desc{},
}, nil
} | [
"func",
"NewNetClassCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"fs",
",",
"err",
":=",
"sysfs",
".",
"NewFS",
"(",
"*",
"sysPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"pattern",
":=",
"regexp",
".",
"MustCompile",
"(",
"*",
"netclassIgnoredDevices",
")",
"\n",
"return",
"&",
"netClassCollector",
"{",
"fs",
":",
"fs",
",",
"subsystem",
":",
"\"",
"\"",
",",
"ignoredDevicesPattern",
":",
"pattern",
",",
"metricDescs",
":",
"map",
"[",
"string",
"]",
"*",
"prometheus",
".",
"Desc",
"{",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewNetClassCollector returns a new Collector exposing network class stats. | [
"NewNetClassCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"network",
"class",
"stats",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/netclass_linux.go#L44-L56 | train |
prometheus/node_exporter | collector/boot_time_bsd.go | newBootTimeCollector | func newBootTimeCollector() (Collector, error) {
return &bootTimeCollector{
boottime: bsdSysctl{
name: "boot_time_seconds",
description: "Unix time of last boot, including microseconds.",
mib: "kern.boottime",
dataType: bsdSysctlTypeStructTimeval,
},
}, nil
} | go | func newBootTimeCollector() (Collector, error) {
return &bootTimeCollector{
boottime: bsdSysctl{
name: "boot_time_seconds",
description: "Unix time of last boot, including microseconds.",
mib: "kern.boottime",
dataType: bsdSysctlTypeStructTimeval,
},
}, nil
} | [
"func",
"newBootTimeCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"return",
"&",
"bootTimeCollector",
"{",
"boottime",
":",
"bsdSysctl",
"{",
"name",
":",
"\"",
"\"",
",",
"description",
":",
"\"",
"\"",
",",
"mib",
":",
"\"",
"\"",
",",
"dataType",
":",
"bsdSysctlTypeStructTimeval",
",",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // newBootTimeCollector returns a new Collector exposing system boot time on BSD systems. | [
"newBootTimeCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"system",
"boot",
"time",
"on",
"BSD",
"systems",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/boot_time_bsd.go#L30-L39 | train |
prometheus/node_exporter | collector/boot_time_bsd.go | Update | func (c *bootTimeCollector) Update(ch chan<- prometheus.Metric) error {
v, err := c.boottime.Value()
if err != nil {
return err
}
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", c.boottime.name),
c.boottime.description,
nil, nil,
), prometheus.GaugeValue, v)
return nil
} | go | func (c *bootTimeCollector) Update(ch chan<- prometheus.Metric) error {
v, err := c.boottime.Value()
if err != nil {
return err
}
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", c.boottime.name),
c.boottime.description,
nil, nil,
), prometheus.GaugeValue, v)
return nil
} | [
"func",
"(",
"c",
"*",
"bootTimeCollector",
")",
"Update",
"(",
"ch",
"chan",
"<-",
"prometheus",
".",
"Metric",
")",
"error",
"{",
"v",
",",
"err",
":=",
"c",
".",
"boottime",
".",
"Value",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"\"",
"\"",
",",
"c",
".",
"boottime",
".",
"name",
")",
",",
"c",
".",
"boottime",
".",
"description",
",",
"nil",
",",
"nil",
",",
")",
",",
"prometheus",
".",
"GaugeValue",
",",
"v",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Update pushes boot time onto ch | [
"Update",
"pushes",
"boot",
"time",
"onto",
"ch"
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/boot_time_bsd.go#L42-L56 | train |
prometheus/node_exporter | collector/filesystem_common.go | NewFilesystemCollector | func NewFilesystemCollector() (Collector, error) {
subsystem := "filesystem"
mountPointPattern := regexp.MustCompile(*ignoredMountPoints)
filesystemsTypesPattern := regexp.MustCompile(*ignoredFSTypes)
sizeDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "size_bytes"),
"Filesystem size in bytes.",
filesystemLabelNames, nil,
)
freeDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "free_bytes"),
"Filesystem free space in bytes.",
filesystemLabelNames, nil,
)
availDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "avail_bytes"),
"Filesystem space available to non-root users in bytes.",
filesystemLabelNames, nil,
)
filesDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "files"),
"Filesystem total file nodes.",
filesystemLabelNames, nil,
)
filesFreeDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "files_free"),
"Filesystem total free file nodes.",
filesystemLabelNames, nil,
)
roDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "readonly"),
"Filesystem read-only status.",
filesystemLabelNames, nil,
)
deviceErrorDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "device_error"),
"Whether an error occurred while getting statistics for the given device.",
filesystemLabelNames, nil,
)
return &filesystemCollector{
ignoredMountPointsPattern: mountPointPattern,
ignoredFSTypesPattern: filesystemsTypesPattern,
sizeDesc: sizeDesc,
freeDesc: freeDesc,
availDesc: availDesc,
filesDesc: filesDesc,
filesFreeDesc: filesFreeDesc,
roDesc: roDesc,
deviceErrorDesc: deviceErrorDesc,
}, nil
} | go | func NewFilesystemCollector() (Collector, error) {
subsystem := "filesystem"
mountPointPattern := regexp.MustCompile(*ignoredMountPoints)
filesystemsTypesPattern := regexp.MustCompile(*ignoredFSTypes)
sizeDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "size_bytes"),
"Filesystem size in bytes.",
filesystemLabelNames, nil,
)
freeDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "free_bytes"),
"Filesystem free space in bytes.",
filesystemLabelNames, nil,
)
availDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "avail_bytes"),
"Filesystem space available to non-root users in bytes.",
filesystemLabelNames, nil,
)
filesDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "files"),
"Filesystem total file nodes.",
filesystemLabelNames, nil,
)
filesFreeDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "files_free"),
"Filesystem total free file nodes.",
filesystemLabelNames, nil,
)
roDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "readonly"),
"Filesystem read-only status.",
filesystemLabelNames, nil,
)
deviceErrorDesc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, subsystem, "device_error"),
"Whether an error occurred while getting statistics for the given device.",
filesystemLabelNames, nil,
)
return &filesystemCollector{
ignoredMountPointsPattern: mountPointPattern,
ignoredFSTypesPattern: filesystemsTypesPattern,
sizeDesc: sizeDesc,
freeDesc: freeDesc,
availDesc: availDesc,
filesDesc: filesDesc,
filesFreeDesc: filesFreeDesc,
roDesc: roDesc,
deviceErrorDesc: deviceErrorDesc,
}, nil
} | [
"func",
"NewFilesystemCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"subsystem",
":=",
"\"",
"\"",
"\n",
"mountPointPattern",
":=",
"regexp",
".",
"MustCompile",
"(",
"*",
"ignoredMountPoints",
")",
"\n",
"filesystemsTypesPattern",
":=",
"regexp",
".",
"MustCompile",
"(",
"*",
"ignoredFSTypes",
")",
"\n\n",
"sizeDesc",
":=",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"filesystemLabelNames",
",",
"nil",
",",
")",
"\n\n",
"freeDesc",
":=",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"filesystemLabelNames",
",",
"nil",
",",
")",
"\n\n",
"availDesc",
":=",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"filesystemLabelNames",
",",
"nil",
",",
")",
"\n\n",
"filesDesc",
":=",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"filesystemLabelNames",
",",
"nil",
",",
")",
"\n\n",
"filesFreeDesc",
":=",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"filesystemLabelNames",
",",
"nil",
",",
")",
"\n\n",
"roDesc",
":=",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"filesystemLabelNames",
",",
"nil",
",",
")",
"\n\n",
"deviceErrorDesc",
":=",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"subsystem",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"filesystemLabelNames",
",",
"nil",
",",
")",
"\n\n",
"return",
"&",
"filesystemCollector",
"{",
"ignoredMountPointsPattern",
":",
"mountPointPattern",
",",
"ignoredFSTypesPattern",
":",
"filesystemsTypesPattern",
",",
"sizeDesc",
":",
"sizeDesc",
",",
"freeDesc",
":",
"freeDesc",
",",
"availDesc",
":",
"availDesc",
",",
"filesDesc",
":",
"filesDesc",
",",
"filesFreeDesc",
":",
"filesFreeDesc",
",",
"roDesc",
":",
"roDesc",
",",
"deviceErrorDesc",
":",
"deviceErrorDesc",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewFilesystemCollector returns a new Collector exposing filesystems stats. | [
"NewFilesystemCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"filesystems",
"stats",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/filesystem_common.go#L69-L127 | train |
prometheus/node_exporter | collector/pressure_linux.go | NewPressureStatsCollector | func NewPressureStatsCollector() (Collector, error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %v", err)
}
return &pressureStatsCollector{
cpu: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "pressure", "cpu_waiting_seconds_total"),
"Total time in seconds that processes have waited for CPU time",
nil, nil,
),
io: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "pressure", "io_waiting_seconds_total"),
"Total time in seconds that processes have waited due to IO congestion",
nil, nil,
),
ioFull: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "pressure", "io_stalled_seconds_total"),
"Total time in seconds no process could make progress due to IO congestion",
nil, nil,
),
mem: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "pressure", "memory_waiting_seconds_total"),
"Total time in seconds that processes have waited for memory",
nil, nil,
),
memFull: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "pressure", "memory_stalled_seconds_total"),
"Total time in seconds no process could make progress due to memory congestion",
nil, nil,
),
fs: fs,
}, nil
} | go | func NewPressureStatsCollector() (Collector, error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %v", err)
}
return &pressureStatsCollector{
cpu: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "pressure", "cpu_waiting_seconds_total"),
"Total time in seconds that processes have waited for CPU time",
nil, nil,
),
io: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "pressure", "io_waiting_seconds_total"),
"Total time in seconds that processes have waited due to IO congestion",
nil, nil,
),
ioFull: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "pressure", "io_stalled_seconds_total"),
"Total time in seconds no process could make progress due to IO congestion",
nil, nil,
),
mem: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "pressure", "memory_waiting_seconds_total"),
"Total time in seconds that processes have waited for memory",
nil, nil,
),
memFull: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "pressure", "memory_stalled_seconds_total"),
"Total time in seconds no process could make progress due to memory congestion",
nil, nil,
),
fs: fs,
}, nil
} | [
"func",
"NewPressureStatsCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"fs",
",",
"err",
":=",
"procfs",
".",
"NewFS",
"(",
"*",
"procPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"pressureStatsCollector",
"{",
"cpu",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"io",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"ioFull",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"mem",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"memFull",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"nil",
",",
"nil",
",",
")",
",",
"fs",
":",
"fs",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewPressureStatsCollector returns a Collector exposing pressure stall information | [
"NewPressureStatsCollector",
"returns",
"a",
"Collector",
"exposing",
"pressure",
"stall",
"information"
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/pressure_linux.go#L45-L79 | train |
prometheus/node_exporter | collector/pressure_linux.go | Update | func (c *pressureStatsCollector) Update(ch chan<- prometheus.Metric) error {
for _, res := range psiResources {
log.Debugf("collecting statistics for resource: %s", res)
vals, err := c.fs.NewPSIStatsForResource(res)
if err != nil {
log.Debug("pressure information is unavailable, you need a Linux kernel >= 4.20 and/or CONFIG_PSI enabled for your kernel")
return nil
}
switch res {
case "cpu":
ch <- prometheus.MustNewConstMetric(c.cpu, prometheus.CounterValue, float64(vals.Some.Total)/1000.0/1000.0)
case "io":
ch <- prometheus.MustNewConstMetric(c.io, prometheus.CounterValue, float64(vals.Some.Total)/1000.0/1000.0)
ch <- prometheus.MustNewConstMetric(c.ioFull, prometheus.CounterValue, float64(vals.Full.Total)/1000.0/1000.0)
case "memory":
ch <- prometheus.MustNewConstMetric(c.mem, prometheus.CounterValue, float64(vals.Some.Total)/1000.0/1000.0)
ch <- prometheus.MustNewConstMetric(c.memFull, prometheus.CounterValue, float64(vals.Full.Total)/1000.0/1000.0)
default:
log.Debugf("did not account for resource: %s", res)
}
}
return nil
} | go | func (c *pressureStatsCollector) Update(ch chan<- prometheus.Metric) error {
for _, res := range psiResources {
log.Debugf("collecting statistics for resource: %s", res)
vals, err := c.fs.NewPSIStatsForResource(res)
if err != nil {
log.Debug("pressure information is unavailable, you need a Linux kernel >= 4.20 and/or CONFIG_PSI enabled for your kernel")
return nil
}
switch res {
case "cpu":
ch <- prometheus.MustNewConstMetric(c.cpu, prometheus.CounterValue, float64(vals.Some.Total)/1000.0/1000.0)
case "io":
ch <- prometheus.MustNewConstMetric(c.io, prometheus.CounterValue, float64(vals.Some.Total)/1000.0/1000.0)
ch <- prometheus.MustNewConstMetric(c.ioFull, prometheus.CounterValue, float64(vals.Full.Total)/1000.0/1000.0)
case "memory":
ch <- prometheus.MustNewConstMetric(c.mem, prometheus.CounterValue, float64(vals.Some.Total)/1000.0/1000.0)
ch <- prometheus.MustNewConstMetric(c.memFull, prometheus.CounterValue, float64(vals.Full.Total)/1000.0/1000.0)
default:
log.Debugf("did not account for resource: %s", res)
}
}
return nil
} | [
"func",
"(",
"c",
"*",
"pressureStatsCollector",
")",
"Update",
"(",
"ch",
"chan",
"<-",
"prometheus",
".",
"Metric",
")",
"error",
"{",
"for",
"_",
",",
"res",
":=",
"range",
"psiResources",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"res",
")",
"\n",
"vals",
",",
"err",
":=",
"c",
".",
"fs",
".",
"NewPSIStatsForResource",
"(",
"res",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"switch",
"res",
"{",
"case",
"\"",
"\"",
":",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"cpu",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"vals",
".",
"Some",
".",
"Total",
")",
"/",
"1000.0",
"/",
"1000.0",
")",
"\n",
"case",
"\"",
"\"",
":",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"io",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"vals",
".",
"Some",
".",
"Total",
")",
"/",
"1000.0",
"/",
"1000.0",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"ioFull",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"vals",
".",
"Full",
".",
"Total",
")",
"/",
"1000.0",
"/",
"1000.0",
")",
"\n",
"case",
"\"",
"\"",
":",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"mem",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"vals",
".",
"Some",
".",
"Total",
")",
"/",
"1000.0",
"/",
"1000.0",
")",
"\n",
"ch",
"<-",
"prometheus",
".",
"MustNewConstMetric",
"(",
"c",
".",
"memFull",
",",
"prometheus",
".",
"CounterValue",
",",
"float64",
"(",
"vals",
".",
"Full",
".",
"Total",
")",
"/",
"1000.0",
"/",
"1000.0",
")",
"\n",
"default",
":",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"res",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Update calls procfs.NewPSIStatsForResource for the different resources and updates the values | [
"Update",
"calls",
"procfs",
".",
"NewPSIStatsForResource",
"for",
"the",
"different",
"resources",
"and",
"updates",
"the",
"values"
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/pressure_linux.go#L82-L105 | train |
prometheus/node_exporter | collector/netstat_linux.go | NewNetStatCollector | func NewNetStatCollector() (Collector, error) {
pattern := regexp.MustCompile(*netStatFields)
return &netStatCollector{
fieldPattern: pattern,
}, nil
} | go | func NewNetStatCollector() (Collector, error) {
pattern := regexp.MustCompile(*netStatFields)
return &netStatCollector{
fieldPattern: pattern,
}, nil
} | [
"func",
"NewNetStatCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"pattern",
":=",
"regexp",
".",
"MustCompile",
"(",
"*",
"netStatFields",
")",
"\n",
"return",
"&",
"netStatCollector",
"{",
"fieldPattern",
":",
"pattern",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewNetStatCollector takes and returns
// a new Collector exposing network stats. | [
"NewNetStatCollector",
"takes",
"and",
"returns",
"a",
"new",
"Collector",
"exposing",
"network",
"stats",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/netstat_linux.go#L49-L54 | train |
prometheus/node_exporter | collector/zfs.go | NewZFSCollector | func NewZFSCollector() (Collector, error) {
return &zfsCollector{
linuxProcpathBase: "spl/kstat/zfs",
linuxZpoolIoPath: "/*/io",
linuxPathMap: map[string]string{
"zfs_abd": "abdstats",
"zfs_arc": "arcstats",
"zfs_dbuf": "dbuf_stats",
"zfs_dmu_tx": "dmu_tx",
"zfs_dnode": "dnodestats",
"zfs_fm": "fm",
"zfs_vdev_cache": "vdev_cache_stats", // vdev_cache is deprecated
"zfs_vdev_mirror": "vdev_mirror_stats",
"zfs_xuio": "xuio_stats", // no known consumers of the XUIO interface on Linux exist
"zfs_zfetch": "zfetchstats",
"zfs_zil": "zil",
},
}, nil
} | go | func NewZFSCollector() (Collector, error) {
return &zfsCollector{
linuxProcpathBase: "spl/kstat/zfs",
linuxZpoolIoPath: "/*/io",
linuxPathMap: map[string]string{
"zfs_abd": "abdstats",
"zfs_arc": "arcstats",
"zfs_dbuf": "dbuf_stats",
"zfs_dmu_tx": "dmu_tx",
"zfs_dnode": "dnodestats",
"zfs_fm": "fm",
"zfs_vdev_cache": "vdev_cache_stats", // vdev_cache is deprecated
"zfs_vdev_mirror": "vdev_mirror_stats",
"zfs_xuio": "xuio_stats", // no known consumers of the XUIO interface on Linux exist
"zfs_zfetch": "zfetchstats",
"zfs_zil": "zil",
},
}, nil
} | [
"func",
"NewZFSCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"return",
"&",
"zfsCollector",
"{",
"linuxProcpathBase",
":",
"\"",
"\"",
",",
"linuxZpoolIoPath",
":",
"\"",
"\"",
",",
"linuxPathMap",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"// vdev_cache is deprecated",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"// no known consumers of the XUIO interface on Linux exist",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
",",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewZFSCollector returns a new Collector exposing ZFS statistics. | [
"NewZFSCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"ZFS",
"statistics",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/zfs.go#L42-L60 | train |
prometheus/node_exporter | collector/arp_linux.go | NewARPCollector | func NewARPCollector() (Collector, error) {
return &arpCollector{
entries: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "arp", "entries"),
"ARP entries by device",
[]string{"device"}, nil,
),
}, nil
} | go | func NewARPCollector() (Collector, error) {
return &arpCollector{
entries: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "arp", "entries"),
"ARP entries by device",
[]string{"device"}, nil,
),
}, nil
} | [
"func",
"NewARPCollector",
"(",
")",
"(",
"Collector",
",",
"error",
")",
"{",
"return",
"&",
"arpCollector",
"{",
"entries",
":",
"prometheus",
".",
"NewDesc",
"(",
"prometheus",
".",
"BuildFQName",
"(",
"namespace",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"nil",
",",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewARPCollector returns a new Collector exposing ARP stats. | [
"NewARPCollector",
"returns",
"a",
"new",
"Collector",
"exposing",
"ARP",
"stats",
"."
] | c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4 | https://github.com/prometheus/node_exporter/blob/c3ce1ea6d8a12f49033a8cd884b7e8d7d36ea6c4/collector/arp_linux.go#L37-L45 | train |
hybridgroup/gobot | api/basic_auth.go | BasicAuth | func BasicAuth(username, password string) http.HandlerFunc {
// Inspired by https://github.com/codegangsta/martini-contrib/blob/master/auth/
return func(res http.ResponseWriter, req *http.Request) {
if !secureCompare(req.Header.Get("Authorization"),
"Basic "+base64.StdEncoding.EncodeToString([]byte(username+":"+password)),
) {
res.Header().Set("WWW-Authenticate",
"Basic realm=\"Authorization Required\"",
)
http.Error(res, "Not Authorized", http.StatusUnauthorized)
}
}
} | go | func BasicAuth(username, password string) http.HandlerFunc {
// Inspired by https://github.com/codegangsta/martini-contrib/blob/master/auth/
return func(res http.ResponseWriter, req *http.Request) {
if !secureCompare(req.Header.Get("Authorization"),
"Basic "+base64.StdEncoding.EncodeToString([]byte(username+":"+password)),
) {
res.Header().Set("WWW-Authenticate",
"Basic realm=\"Authorization Required\"",
)
http.Error(res, "Not Authorized", http.StatusUnauthorized)
}
}
} | [
"func",
"BasicAuth",
"(",
"username",
",",
"password",
"string",
")",
"http",
".",
"HandlerFunc",
"{",
"// Inspired by https://github.com/codegangsta/martini-contrib/blob/master/auth/",
"return",
"func",
"(",
"res",
"http",
".",
"ResponseWriter",
",",
"req",
"*",
"http",
".",
"Request",
")",
"{",
"if",
"!",
"secureCompare",
"(",
"req",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
",",
"\"",
"\"",
"+",
"base64",
".",
"StdEncoding",
".",
"EncodeToString",
"(",
"[",
"]",
"byte",
"(",
"username",
"+",
"\"",
"\"",
"+",
"password",
")",
")",
",",
")",
"{",
"res",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\\\"",
"\\\"",
"\"",
",",
")",
"\n",
"http",
".",
"Error",
"(",
"res",
",",
"\"",
"\"",
",",
"http",
".",
"StatusUnauthorized",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // BasicAuth returns basic auth handler. | [
"BasicAuth",
"returns",
"basic",
"auth",
"handler",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/api/basic_auth.go#L10-L22 | train |
hybridgroup/gobot | platforms/nats/nats_driver.go | NewDriver | func NewDriver(a *Adaptor, topic string) *Driver {
m := &Driver{
name: gobot.DefaultName("NATS"),
topic: topic,
connection: a,
Eventer: gobot.NewEventer(),
Commander: gobot.NewCommander(),
}
return m
} | go | func NewDriver(a *Adaptor, topic string) *Driver {
m := &Driver{
name: gobot.DefaultName("NATS"),
topic: topic,
connection: a,
Eventer: gobot.NewEventer(),
Commander: gobot.NewCommander(),
}
return m
} | [
"func",
"NewDriver",
"(",
"a",
"*",
"Adaptor",
",",
"topic",
"string",
")",
"*",
"Driver",
"{",
"m",
":=",
"&",
"Driver",
"{",
"name",
":",
"gobot",
".",
"DefaultName",
"(",
"\"",
"\"",
")",
",",
"topic",
":",
"topic",
",",
"connection",
":",
"a",
",",
"Eventer",
":",
"gobot",
".",
"NewEventer",
"(",
")",
",",
"Commander",
":",
"gobot",
".",
"NewCommander",
"(",
")",
",",
"}",
"\n\n",
"return",
"m",
"\n",
"}"
] | // NewDriver returns a new Gobot NATS Driver | [
"NewDriver",
"returns",
"a",
"new",
"Gobot",
"NATS",
"Driver"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/nats/nats_driver.go#L23-L33 | train |
hybridgroup/gobot | platforms/nats/nats_driver.go | Publish | func (m *Driver) Publish(data interface{}) bool {
message := data.([]byte)
return m.adaptor().Publish(m.topic, message)
} | go | func (m *Driver) Publish(data interface{}) bool {
message := data.([]byte)
return m.adaptor().Publish(m.topic, message)
} | [
"func",
"(",
"m",
"*",
"Driver",
")",
"Publish",
"(",
"data",
"interface",
"{",
"}",
")",
"bool",
"{",
"message",
":=",
"data",
".",
"(",
"[",
"]",
"byte",
")",
"\n",
"return",
"m",
".",
"adaptor",
"(",
")",
".",
"Publish",
"(",
"m",
".",
"topic",
",",
"message",
")",
"\n",
"}"
] | // Publish a message to the current device topic | [
"Publish",
"a",
"message",
"to",
"the",
"current",
"device",
"topic"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/nats/nats_driver.go#L67-L70 | train |
hybridgroup/gobot | platforms/joystick/joystick_driver.go | handleEvent | func (j *Driver) handleEvent(event sdl.Event) error {
switch data := event.(type) {
case *sdl.JoyAxisEvent:
if data.Which == j.adaptor().joystick.InstanceID() {
axis := j.findName(data.Axis, j.config.Axis)
if axis == "" {
return fmt.Errorf("Unknown Axis: %v", data.Axis)
}
j.Publish(j.Event(axis), data.Value)
}
case *sdl.JoyButtonEvent:
if data.Which == j.adaptor().joystick.InstanceID() {
button := j.findName(data.Button, j.config.Buttons)
if button == "" {
return fmt.Errorf("Unknown Button: %v", data.Button)
}
if data.State == 1 {
j.Publish(j.Event(fmt.Sprintf("%s_press", button)), nil)
} else {
j.Publish(j.Event(fmt.Sprintf("%s_release", button)), nil)
}
}
case *sdl.JoyHatEvent:
if data.Which == j.adaptor().joystick.InstanceID() {
hat := j.findHatName(data.Value, data.Hat, j.config.Hats)
if hat == "" {
return fmt.Errorf("Unknown Hat: %v %v", data.Hat, data.Value)
} else if hat == "released" {
hat = previousHat
j.Publish(j.Event(fmt.Sprintf("%s_release", hat)), true)
} else {
previousHat = hat
j.Publish(j.Event(fmt.Sprintf("%s_press", hat)), true)
}
}
}
return nil
} | go | func (j *Driver) handleEvent(event sdl.Event) error {
switch data := event.(type) {
case *sdl.JoyAxisEvent:
if data.Which == j.adaptor().joystick.InstanceID() {
axis := j.findName(data.Axis, j.config.Axis)
if axis == "" {
return fmt.Errorf("Unknown Axis: %v", data.Axis)
}
j.Publish(j.Event(axis), data.Value)
}
case *sdl.JoyButtonEvent:
if data.Which == j.adaptor().joystick.InstanceID() {
button := j.findName(data.Button, j.config.Buttons)
if button == "" {
return fmt.Errorf("Unknown Button: %v", data.Button)
}
if data.State == 1 {
j.Publish(j.Event(fmt.Sprintf("%s_press", button)), nil)
} else {
j.Publish(j.Event(fmt.Sprintf("%s_release", button)), nil)
}
}
case *sdl.JoyHatEvent:
if data.Which == j.adaptor().joystick.InstanceID() {
hat := j.findHatName(data.Value, data.Hat, j.config.Hats)
if hat == "" {
return fmt.Errorf("Unknown Hat: %v %v", data.Hat, data.Value)
} else if hat == "released" {
hat = previousHat
j.Publish(j.Event(fmt.Sprintf("%s_release", hat)), true)
} else {
previousHat = hat
j.Publish(j.Event(fmt.Sprintf("%s_press", hat)), true)
}
}
}
return nil
} | [
"func",
"(",
"j",
"*",
"Driver",
")",
"handleEvent",
"(",
"event",
"sdl",
".",
"Event",
")",
"error",
"{",
"switch",
"data",
":=",
"event",
".",
"(",
"type",
")",
"{",
"case",
"*",
"sdl",
".",
"JoyAxisEvent",
":",
"if",
"data",
".",
"Which",
"==",
"j",
".",
"adaptor",
"(",
")",
".",
"joystick",
".",
"InstanceID",
"(",
")",
"{",
"axis",
":=",
"j",
".",
"findName",
"(",
"data",
".",
"Axis",
",",
"j",
".",
"config",
".",
"Axis",
")",
"\n",
"if",
"axis",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"data",
".",
"Axis",
")",
"\n",
"}",
"\n",
"j",
".",
"Publish",
"(",
"j",
".",
"Event",
"(",
"axis",
")",
",",
"data",
".",
"Value",
")",
"\n",
"}",
"\n",
"case",
"*",
"sdl",
".",
"JoyButtonEvent",
":",
"if",
"data",
".",
"Which",
"==",
"j",
".",
"adaptor",
"(",
")",
".",
"joystick",
".",
"InstanceID",
"(",
")",
"{",
"button",
":=",
"j",
".",
"findName",
"(",
"data",
".",
"Button",
",",
"j",
".",
"config",
".",
"Buttons",
")",
"\n",
"if",
"button",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"data",
".",
"Button",
")",
"\n",
"}",
"\n",
"if",
"data",
".",
"State",
"==",
"1",
"{",
"j",
".",
"Publish",
"(",
"j",
".",
"Event",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"button",
")",
")",
",",
"nil",
")",
"\n",
"}",
"else",
"{",
"j",
".",
"Publish",
"(",
"j",
".",
"Event",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"button",
")",
")",
",",
"nil",
")",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"*",
"sdl",
".",
"JoyHatEvent",
":",
"if",
"data",
".",
"Which",
"==",
"j",
".",
"adaptor",
"(",
")",
".",
"joystick",
".",
"InstanceID",
"(",
")",
"{",
"hat",
":=",
"j",
".",
"findHatName",
"(",
"data",
".",
"Value",
",",
"data",
".",
"Hat",
",",
"j",
".",
"config",
".",
"Hats",
")",
"\n",
"if",
"hat",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"data",
".",
"Hat",
",",
"data",
".",
"Value",
")",
"\n",
"}",
"else",
"if",
"hat",
"==",
"\"",
"\"",
"{",
"hat",
"=",
"previousHat",
"\n",
"j",
".",
"Publish",
"(",
"j",
".",
"Event",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"hat",
")",
")",
",",
"true",
")",
"\n",
"}",
"else",
"{",
"previousHat",
"=",
"hat",
"\n",
"j",
".",
"Publish",
"(",
"j",
".",
"Event",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"hat",
")",
")",
",",
"true",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // HandleEvent publishes an specific event according to data received | [
"HandleEvent",
"publishes",
"an",
"specific",
"event",
"according",
"to",
"data",
"received"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/joystick/joystick_driver.go#L171-L208 | train |
hybridgroup/gobot | platforms/joystick/joystick_driver.go | findHatName | func (j *Driver) findHatName(id uint8, hat uint8, list []hat) string {
for _, lHat := range list {
if int(id) == lHat.ID && int(hat) == lHat.Hat {
return lHat.Name
}
}
return ""
} | go | func (j *Driver) findHatName(id uint8, hat uint8, list []hat) string {
for _, lHat := range list {
if int(id) == lHat.ID && int(hat) == lHat.Hat {
return lHat.Name
}
}
return ""
} | [
"func",
"(",
"j",
"*",
"Driver",
")",
"findHatName",
"(",
"id",
"uint8",
",",
"hat",
"uint8",
",",
"list",
"[",
"]",
"hat",
")",
"string",
"{",
"for",
"_",
",",
"lHat",
":=",
"range",
"list",
"{",
"if",
"int",
"(",
"id",
")",
"==",
"lHat",
".",
"ID",
"&&",
"int",
"(",
"hat",
")",
"==",
"lHat",
".",
"Hat",
"{",
"return",
"lHat",
".",
"Name",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // findHatName returns name from hat found by id in provided list | [
"findHatName",
"returns",
"name",
"from",
"hat",
"found",
"by",
"id",
"in",
"provided",
"list"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/joystick/joystick_driver.go#L220-L227 | train |
hybridgroup/gobot | platforms/joystick/joystick_driver.go | loadFile | func (j *Driver) loadFile() error {
file, e := ioutil.ReadFile(j.configPath)
if e != nil {
return e
}
var jsontype joystickConfig
json.Unmarshal(file, &jsontype)
j.config = jsontype
return nil
} | go | func (j *Driver) loadFile() error {
file, e := ioutil.ReadFile(j.configPath)
if e != nil {
return e
}
var jsontype joystickConfig
json.Unmarshal(file, &jsontype)
j.config = jsontype
return nil
} | [
"func",
"(",
"j",
"*",
"Driver",
")",
"loadFile",
"(",
")",
"error",
"{",
"file",
",",
"e",
":=",
"ioutil",
".",
"ReadFile",
"(",
"j",
".",
"configPath",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"return",
"e",
"\n",
"}",
"\n\n",
"var",
"jsontype",
"joystickConfig",
"\n",
"json",
".",
"Unmarshal",
"(",
"file",
",",
"&",
"jsontype",
")",
"\n",
"j",
".",
"config",
"=",
"jsontype",
"\n",
"return",
"nil",
"\n",
"}"
] | // loadFile load the joystick config from a .json file | [
"loadFile",
"load",
"the",
"joystick",
"config",
"from",
"a",
".",
"json",
"file"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/joystick/joystick_driver.go#L230-L240 | train |
hybridgroup/gobot | sysfs/fs_mock.go | Seek | func (f *MockFile) Seek(offset int64, whence int) (ret int64, err error) {
return offset, nil
} | go | func (f *MockFile) Seek(offset int64, whence int) (ret int64, err error) {
return offset, nil
} | [
"func",
"(",
"f",
"*",
"MockFile",
")",
"Seek",
"(",
"offset",
"int64",
",",
"whence",
"int",
")",
"(",
"ret",
"int64",
",",
"err",
"error",
")",
"{",
"return",
"offset",
",",
"nil",
"\n",
"}"
] | // Seek seeks to a specific offset in a file | [
"Seek",
"seeks",
"to",
"a",
"specific",
"offset",
"in",
"a",
"file"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/fs_mock.go#L48-L50 | train |
hybridgroup/gobot | sysfs/fs_mock.go | WriteString | func (f *MockFile) WriteString(s string) (ret int, err error) {
f.Contents = s
f.Seq = f.fs.next()
return len(s), nil
} | go | func (f *MockFile) WriteString(s string) (ret int, err error) {
f.Contents = s
f.Seq = f.fs.next()
return len(s), nil
} | [
"func",
"(",
"f",
"*",
"MockFile",
")",
"WriteString",
"(",
"s",
"string",
")",
"(",
"ret",
"int",
",",
"err",
"error",
")",
"{",
"f",
".",
"Contents",
"=",
"s",
"\n",
"f",
".",
"Seq",
"=",
"f",
".",
"fs",
".",
"next",
"(",
")",
"\n",
"return",
"len",
"(",
"s",
")",
",",
"nil",
"\n",
"}"
] | // WriteString writes s to f.Contents | [
"WriteString",
"writes",
"s",
"to",
"f",
".",
"Contents"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/fs_mock.go#L53-L57 | train |
hybridgroup/gobot | sysfs/fs_mock.go | Read | func (f *MockFile) Read(b []byte) (n int, err error) {
if f.fs.WithReadError {
return 0, readErr
}
count := len(b)
if len(f.Contents) < count {
count = len(f.Contents)
}
copy(b, []byte(f.Contents)[:count])
f.Seq = f.fs.next()
return count, nil
} | go | func (f *MockFile) Read(b []byte) (n int, err error) {
if f.fs.WithReadError {
return 0, readErr
}
count := len(b)
if len(f.Contents) < count {
count = len(f.Contents)
}
copy(b, []byte(f.Contents)[:count])
f.Seq = f.fs.next()
return count, nil
} | [
"func",
"(",
"f",
"*",
"MockFile",
")",
"Read",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"if",
"f",
".",
"fs",
".",
"WithReadError",
"{",
"return",
"0",
",",
"readErr",
"\n",
"}",
"\n\n",
"count",
":=",
"len",
"(",
"b",
")",
"\n",
"if",
"len",
"(",
"f",
".",
"Contents",
")",
"<",
"count",
"{",
"count",
"=",
"len",
"(",
"f",
".",
"Contents",
")",
"\n",
"}",
"\n",
"copy",
"(",
"b",
",",
"[",
"]",
"byte",
"(",
"f",
".",
"Contents",
")",
"[",
":",
"count",
"]",
")",
"\n",
"f",
".",
"Seq",
"=",
"f",
".",
"fs",
".",
"next",
"(",
")",
"\n\n",
"return",
"count",
",",
"nil",
"\n",
"}"
] | // Read copies b bytes from f.Contents | [
"Read",
"copies",
"b",
"bytes",
"from",
"f",
".",
"Contents"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/fs_mock.go#L65-L78 | train |
hybridgroup/gobot | sysfs/fs_mock.go | ReadAt | func (f *MockFile) ReadAt(b []byte, off int64) (n int, err error) {
return f.Read(b)
} | go | func (f *MockFile) ReadAt(b []byte, off int64) (n int, err error) {
return f.Read(b)
} | [
"func",
"(",
"f",
"*",
"MockFile",
")",
"ReadAt",
"(",
"b",
"[",
"]",
"byte",
",",
"off",
"int64",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"return",
"f",
".",
"Read",
"(",
"b",
")",
"\n",
"}"
] | // ReadAt calls MockFile.Read | [
"ReadAt",
"calls",
"MockFile",
".",
"Read"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/fs_mock.go#L81-L83 | train |
hybridgroup/gobot | sysfs/fs_mock.go | NewMockFilesystem | func NewMockFilesystem(files []string) *MockFilesystem {
m := &MockFilesystem{
Files: make(map[string]*MockFile),
}
for i := range files {
m.Add(files[i])
}
return m
} | go | func NewMockFilesystem(files []string) *MockFilesystem {
m := &MockFilesystem{
Files: make(map[string]*MockFile),
}
for i := range files {
m.Add(files[i])
}
return m
} | [
"func",
"NewMockFilesystem",
"(",
"files",
"[",
"]",
"string",
")",
"*",
"MockFilesystem",
"{",
"m",
":=",
"&",
"MockFilesystem",
"{",
"Files",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"MockFile",
")",
",",
"}",
"\n\n",
"for",
"i",
":=",
"range",
"files",
"{",
"m",
".",
"Add",
"(",
"files",
"[",
"i",
"]",
")",
"\n",
"}",
"\n\n",
"return",
"m",
"\n",
"}"
] | // NewMockFilesystem returns a new MockFilesystem given a list of file paths | [
"NewMockFilesystem",
"returns",
"a",
"new",
"MockFilesystem",
"given",
"a",
"list",
"of",
"file",
"paths"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/fs_mock.go#L96-L106 | train |
hybridgroup/gobot | sysfs/fs_mock.go | OpenFile | func (fs *MockFilesystem) OpenFile(name string, flag int, perm os.FileMode) (file File, err error) {
f, ok := fs.Files[name]
if ok {
f.Opened = true
f.Closed = false
return f, nil
}
return (*MockFile)(nil), &os.PathError{Err: errors.New(name + ": No such file.")}
} | go | func (fs *MockFilesystem) OpenFile(name string, flag int, perm os.FileMode) (file File, err error) {
f, ok := fs.Files[name]
if ok {
f.Opened = true
f.Closed = false
return f, nil
}
return (*MockFile)(nil), &os.PathError{Err: errors.New(name + ": No such file.")}
} | [
"func",
"(",
"fs",
"*",
"MockFilesystem",
")",
"OpenFile",
"(",
"name",
"string",
",",
"flag",
"int",
",",
"perm",
"os",
".",
"FileMode",
")",
"(",
"file",
"File",
",",
"err",
"error",
")",
"{",
"f",
",",
"ok",
":=",
"fs",
".",
"Files",
"[",
"name",
"]",
"\n",
"if",
"ok",
"{",
"f",
".",
"Opened",
"=",
"true",
"\n",
"f",
".",
"Closed",
"=",
"false",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}",
"\n",
"return",
"(",
"*",
"MockFile",
")",
"(",
"nil",
")",
",",
"&",
"os",
".",
"PathError",
"{",
"Err",
":",
"errors",
".",
"New",
"(",
"name",
"+",
"\"",
"\"",
")",
"}",
"\n",
"}"
] | // OpenFile opens file name from fs.Files, if the file does not exist it returns an os.PathError | [
"OpenFile",
"opens",
"file",
"name",
"from",
"fs",
".",
"Files",
"if",
"the",
"file",
"does",
"not",
"exist",
"it",
"returns",
"an",
"os",
".",
"PathError"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/fs_mock.go#L109-L117 | train |
hybridgroup/gobot | sysfs/fs_mock.go | Stat | func (fs *MockFilesystem) Stat(name string) (os.FileInfo, error) {
_, ok := fs.Files[name]
if ok {
// return file based mock FileInfo
tmpFile, err := ioutil.TempFile("", name)
if err != nil {
return nil, err
}
defer os.Remove(tmpFile.Name())
return os.Stat(tmpFile.Name())
}
dirName := name + "/"
for path := range fs.Files {
if strings.HasPrefix(path, dirName) {
// return dir based mock FileInfo
tmpDir, err := ioutil.TempDir("", name)
if err != nil {
return nil, err
}
defer os.RemoveAll(tmpDir)
return os.Stat(tmpDir)
}
}
return nil, &os.PathError{Err: errors.New(name + ": No such file.")}
} | go | func (fs *MockFilesystem) Stat(name string) (os.FileInfo, error) {
_, ok := fs.Files[name]
if ok {
// return file based mock FileInfo
tmpFile, err := ioutil.TempFile("", name)
if err != nil {
return nil, err
}
defer os.Remove(tmpFile.Name())
return os.Stat(tmpFile.Name())
}
dirName := name + "/"
for path := range fs.Files {
if strings.HasPrefix(path, dirName) {
// return dir based mock FileInfo
tmpDir, err := ioutil.TempDir("", name)
if err != nil {
return nil, err
}
defer os.RemoveAll(tmpDir)
return os.Stat(tmpDir)
}
}
return nil, &os.PathError{Err: errors.New(name + ": No such file.")}
} | [
"func",
"(",
"fs",
"*",
"MockFilesystem",
")",
"Stat",
"(",
"name",
"string",
")",
"(",
"os",
".",
"FileInfo",
",",
"error",
")",
"{",
"_",
",",
"ok",
":=",
"fs",
".",
"Files",
"[",
"name",
"]",
"\n",
"if",
"ok",
"{",
"// return file based mock FileInfo",
"tmpFile",
",",
"err",
":=",
"ioutil",
".",
"TempFile",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"os",
".",
"Remove",
"(",
"tmpFile",
".",
"Name",
"(",
")",
")",
"\n\n",
"return",
"os",
".",
"Stat",
"(",
"tmpFile",
".",
"Name",
"(",
")",
")",
"\n",
"}",
"\n\n",
"dirName",
":=",
"name",
"+",
"\"",
"\"",
"\n",
"for",
"path",
":=",
"range",
"fs",
".",
"Files",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"path",
",",
"dirName",
")",
"{",
"// return dir based mock FileInfo",
"tmpDir",
",",
"err",
":=",
"ioutil",
".",
"TempDir",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"os",
".",
"RemoveAll",
"(",
"tmpDir",
")",
"\n\n",
"return",
"os",
".",
"Stat",
"(",
"tmpDir",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"&",
"os",
".",
"PathError",
"{",
"Err",
":",
"errors",
".",
"New",
"(",
"name",
"+",
"\"",
"\"",
")",
"}",
"\n",
"}"
] | // Stat returns a generic FileInfo for all files in fs.Files.
// If the file does not exist it returns an os.PathError | [
"Stat",
"returns",
"a",
"generic",
"FileInfo",
"for",
"all",
"files",
"in",
"fs",
".",
"Files",
".",
"If",
"the",
"file",
"does",
"not",
"exist",
"it",
"returns",
"an",
"os",
".",
"PathError"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/fs_mock.go#L121-L149 | train |
hybridgroup/gobot | sysfs/fs_mock.go | Add | func (fs *MockFilesystem) Add(name string) *MockFile {
f := &MockFile{
Seq: -1,
fd: uintptr(time.Now().UnixNano() & 0xffff),
fs: fs,
}
fs.Files[name] = f
return f
} | go | func (fs *MockFilesystem) Add(name string) *MockFile {
f := &MockFile{
Seq: -1,
fd: uintptr(time.Now().UnixNano() & 0xffff),
fs: fs,
}
fs.Files[name] = f
return f
} | [
"func",
"(",
"fs",
"*",
"MockFilesystem",
")",
"Add",
"(",
"name",
"string",
")",
"*",
"MockFile",
"{",
"f",
":=",
"&",
"MockFile",
"{",
"Seq",
":",
"-",
"1",
",",
"fd",
":",
"uintptr",
"(",
"time",
".",
"Now",
"(",
")",
".",
"UnixNano",
"(",
")",
"&",
"0xffff",
")",
",",
"fs",
":",
"fs",
",",
"}",
"\n",
"fs",
".",
"Files",
"[",
"name",
"]",
"=",
"f",
"\n",
"return",
"f",
"\n",
"}"
] | // Add adds a new file to fs.Files given a name, and returns the newly created file | [
"Add",
"adds",
"a",
"new",
"file",
"to",
"fs",
".",
"Files",
"given",
"a",
"name",
"and",
"returns",
"the",
"newly",
"created",
"file"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/sysfs/fs_mock.go#L152-L160 | train |
hybridgroup/gobot | platforms/dji/tello/crc.go | CalculateCRC8 | func CalculateCRC8(pkt []byte) byte {
crc := byte(0x77)
for _, val := range pkt {
crc = crc8table[(crc^byte(val))&0xff]
}
return crc
} | go | func CalculateCRC8(pkt []byte) byte {
crc := byte(0x77)
for _, val := range pkt {
crc = crc8table[(crc^byte(val))&0xff]
}
return crc
} | [
"func",
"CalculateCRC8",
"(",
"pkt",
"[",
"]",
"byte",
")",
"byte",
"{",
"crc",
":=",
"byte",
"(",
"0x77",
")",
"\n",
"for",
"_",
",",
"val",
":=",
"range",
"pkt",
"{",
"crc",
"=",
"crc8table",
"[",
"(",
"crc",
"^",
"byte",
"(",
"val",
")",
")",
"&",
"0xff",
"]",
"\n",
"}",
"\n\n",
"return",
"crc",
"\n",
"}"
] | // CalculateCRC8 calculates the starting CRC8 byte for packet. | [
"CalculateCRC8",
"calculates",
"the",
"starting",
"CRC8",
"byte",
"for",
"packet",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dji/tello/crc.go#L23-L30 | train |
hybridgroup/gobot | platforms/dji/tello/crc.go | CalculateCRC16 | func CalculateCRC16(pkt []byte) uint16 {
crc := uint16(0x3692)
for _, val := range pkt {
crc = crc16table[(crc^uint16(val))&0xff] ^ (crc >> 8)
}
return crc
} | go | func CalculateCRC16(pkt []byte) uint16 {
crc := uint16(0x3692)
for _, val := range pkt {
crc = crc16table[(crc^uint16(val))&0xff] ^ (crc >> 8)
}
return crc
} | [
"func",
"CalculateCRC16",
"(",
"pkt",
"[",
"]",
"byte",
")",
"uint16",
"{",
"crc",
":=",
"uint16",
"(",
"0x3692",
")",
"\n",
"for",
"_",
",",
"val",
":=",
"range",
"pkt",
"{",
"crc",
"=",
"crc16table",
"[",
"(",
"crc",
"^",
"uint16",
"(",
"val",
")",
")",
"&",
"0xff",
"]",
"^",
"(",
"crc",
">>",
"8",
")",
"\n",
"}",
"\n\n",
"return",
"crc",
"\n",
"}"
] | // CalculateCRC16 calculates the ending CRC16 bytes for packet. | [
"CalculateCRC16",
"calculates",
"the",
"ending",
"CRC16",
"bytes",
"for",
"packet",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/dji/tello/crc.go#L52-L59 | train |
hybridgroup/gobot | drivers/spi/mcp3204.go | AnalogRead | func (d *MCP3204Driver) AnalogRead(pin string) (value int, err error) {
channel, _ := strconv.Atoi(pin)
value, err = d.Read(channel)
if err != nil {
value = int(gobot.ToScale(gobot.FromScale(float64(value), 0, 4095), 0, 1023))
}
return
} | go | func (d *MCP3204Driver) AnalogRead(pin string) (value int, err error) {
channel, _ := strconv.Atoi(pin)
value, err = d.Read(channel)
if err != nil {
value = int(gobot.ToScale(gobot.FromScale(float64(value), 0, 4095), 0, 1023))
}
return
} | [
"func",
"(",
"d",
"*",
"MCP3204Driver",
")",
"AnalogRead",
"(",
"pin",
"string",
")",
"(",
"value",
"int",
",",
"err",
"error",
")",
"{",
"channel",
",",
"_",
":=",
"strconv",
".",
"Atoi",
"(",
"pin",
")",
"\n",
"value",
",",
"err",
"=",
"d",
".",
"Read",
"(",
"channel",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"value",
"=",
"int",
"(",
"gobot",
".",
"ToScale",
"(",
"gobot",
".",
"FromScale",
"(",
"float64",
"(",
"value",
")",
",",
"0",
",",
"4095",
")",
",",
"0",
",",
"1023",
")",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // AnalogRead returns value from analog reading of specified pin, scaled to 0-1023 value. | [
"AnalogRead",
"returns",
"value",
"from",
"analog",
"reading",
"of",
"specified",
"pin",
"scaled",
"to",
"0",
"-",
"1023",
"value",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/spi/mcp3204.go#L98-L106 | train |
hybridgroup/gobot | drivers/i2c/ads1x15_driver.go | Start | func (d *ADS1x15Driver) Start() (err error) {
bus := d.GetBusOrDefault(d.connector.GetDefaultBus())
address := d.GetAddressOrDefault(ADS1x15DefaultAddress)
if d.connection, err = d.connector.GetConnection(address, bus); err != nil {
return err
}
return
} | go | func (d *ADS1x15Driver) Start() (err error) {
bus := d.GetBusOrDefault(d.connector.GetDefaultBus())
address := d.GetAddressOrDefault(ADS1x15DefaultAddress)
if d.connection, err = d.connector.GetConnection(address, bus); err != nil {
return err
}
return
} | [
"func",
"(",
"d",
"*",
"ADS1x15Driver",
")",
"Start",
"(",
")",
"(",
"err",
"error",
")",
"{",
"bus",
":=",
"d",
".",
"GetBusOrDefault",
"(",
"d",
".",
"connector",
".",
"GetDefaultBus",
"(",
")",
")",
"\n",
"address",
":=",
"d",
".",
"GetAddressOrDefault",
"(",
"ADS1x15DefaultAddress",
")",
"\n\n",
"if",
"d",
".",
"connection",
",",
"err",
"=",
"d",
".",
"connector",
".",
"GetConnection",
"(",
"address",
",",
"bus",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // Start initializes the sensor | [
"Start",
"initializes",
"the",
"sensor"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/ads1x15_driver.go#L148-L157 | train |
hybridgroup/gobot | drivers/i2c/ads1x15_driver.go | BestGainForVoltage | func (d *ADS1x15Driver) BestGainForVoltage(voltage float64) (bestGain int, err error) {
var max float64
difference := math.MaxFloat64
currentBestGain := -1
for key, value := range d.gainVoltage {
max = math.Max(max, value)
newDiff := value - voltage
if newDiff >= 0 && newDiff < difference {
difference = newDiff
currentBestGain = key
}
}
if currentBestGain < 0 {
err = fmt.Errorf("The maximum voltage which can be read is %f", max)
return
}
bestGain = currentBestGain
return
} | go | func (d *ADS1x15Driver) BestGainForVoltage(voltage float64) (bestGain int, err error) {
var max float64
difference := math.MaxFloat64
currentBestGain := -1
for key, value := range d.gainVoltage {
max = math.Max(max, value)
newDiff := value - voltage
if newDiff >= 0 && newDiff < difference {
difference = newDiff
currentBestGain = key
}
}
if currentBestGain < 0 {
err = fmt.Errorf("The maximum voltage which can be read is %f", max)
return
}
bestGain = currentBestGain
return
} | [
"func",
"(",
"d",
"*",
"ADS1x15Driver",
")",
"BestGainForVoltage",
"(",
"voltage",
"float64",
")",
"(",
"bestGain",
"int",
",",
"err",
"error",
")",
"{",
"var",
"max",
"float64",
"\n",
"difference",
":=",
"math",
".",
"MaxFloat64",
"\n",
"currentBestGain",
":=",
"-",
"1",
"\n\n",
"for",
"key",
",",
"value",
":=",
"range",
"d",
".",
"gainVoltage",
"{",
"max",
"=",
"math",
".",
"Max",
"(",
"max",
",",
"value",
")",
"\n",
"newDiff",
":=",
"value",
"-",
"voltage",
"\n",
"if",
"newDiff",
">=",
"0",
"&&",
"newDiff",
"<",
"difference",
"{",
"difference",
"=",
"newDiff",
"\n",
"currentBestGain",
"=",
"key",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"currentBestGain",
"<",
"0",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"max",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"bestGain",
"=",
"currentBestGain",
"\n",
"return",
"\n",
"}"
] | // BestGainForVoltage returns the gain the most adapted to read up to the specified difference of potential. | [
"BestGainForVoltage",
"returns",
"the",
"gain",
"the",
"most",
"adapted",
"to",
"read",
"up",
"to",
"the",
"specified",
"difference",
"of",
"potential",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/ads1x15_driver.go#L200-L221 | train |
hybridgroup/gobot | platforms/beaglebone/beaglebone_adaptor.go | DigitalWrite | func (b *Adaptor) DigitalWrite(pin string, val byte) (err error) {
if strings.Contains(pin, "usr") {
fi, e := sysfs.OpenFile(b.usrLed+pin+"/brightness", os.O_WRONLY|os.O_APPEND, 0666)
defer fi.Close()
if e != nil {
return e
}
_, err = fi.WriteString(strconv.Itoa(int(val)))
return err
}
sysfsPin, err := b.DigitalPin(pin, sysfs.OUT)
if err != nil {
return err
}
return sysfsPin.Write(int(val))
} | go | func (b *Adaptor) DigitalWrite(pin string, val byte) (err error) {
if strings.Contains(pin, "usr") {
fi, e := sysfs.OpenFile(b.usrLed+pin+"/brightness", os.O_WRONLY|os.O_APPEND, 0666)
defer fi.Close()
if e != nil {
return e
}
_, err = fi.WriteString(strconv.Itoa(int(val)))
return err
}
sysfsPin, err := b.DigitalPin(pin, sysfs.OUT)
if err != nil {
return err
}
return sysfsPin.Write(int(val))
} | [
"func",
"(",
"b",
"*",
"Adaptor",
")",
"DigitalWrite",
"(",
"pin",
"string",
",",
"val",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"if",
"strings",
".",
"Contains",
"(",
"pin",
",",
"\"",
"\"",
")",
"{",
"fi",
",",
"e",
":=",
"sysfs",
".",
"OpenFile",
"(",
"b",
".",
"usrLed",
"+",
"pin",
"+",
"\"",
"\"",
",",
"os",
".",
"O_WRONLY",
"|",
"os",
".",
"O_APPEND",
",",
"0666",
")",
"\n",
"defer",
"fi",
".",
"Close",
"(",
")",
"\n",
"if",
"e",
"!=",
"nil",
"{",
"return",
"e",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"fi",
".",
"WriteString",
"(",
"strconv",
".",
"Itoa",
"(",
"int",
"(",
"val",
")",
")",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"sysfsPin",
",",
"err",
":=",
"b",
".",
"DigitalPin",
"(",
"pin",
",",
"sysfs",
".",
"OUT",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"sysfsPin",
".",
"Write",
"(",
"int",
"(",
"val",
")",
")",
"\n",
"}"
] | // DigitalWrite writes a digital value to specified pin.
// valid usr pin values are usr0, usr1, usr2 and usr3 | [
"DigitalWrite",
"writes",
"a",
"digital",
"value",
"to",
"specified",
"pin",
".",
"valid",
"usr",
"pin",
"values",
"are",
"usr0",
"usr1",
"usr2",
"and",
"usr3"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/beaglebone/beaglebone_adaptor.go#L162-L177 | train |
hybridgroup/gobot | platforms/beaglebone/beaglebone_adaptor.go | DigitalPin | func (b *Adaptor) DigitalPin(pin string, dir string) (sysfsPin sysfs.DigitalPinner, err error) {
b.mutex.Lock()
defer b.mutex.Unlock()
i, err := b.translatePin(pin)
if err != nil {
return
}
if b.digitalPins[i] == nil {
b.digitalPins[i] = sysfs.NewDigitalPin(i)
if err = muxPin(pin, "gpio"); err != nil {
return
}
err := b.digitalPins[i].Export()
if err != nil {
return nil, err
}
}
if err = b.digitalPins[i].Direction(dir); err != nil {
return
}
return b.digitalPins[i], nil
} | go | func (b *Adaptor) DigitalPin(pin string, dir string) (sysfsPin sysfs.DigitalPinner, err error) {
b.mutex.Lock()
defer b.mutex.Unlock()
i, err := b.translatePin(pin)
if err != nil {
return
}
if b.digitalPins[i] == nil {
b.digitalPins[i] = sysfs.NewDigitalPin(i)
if err = muxPin(pin, "gpio"); err != nil {
return
}
err := b.digitalPins[i].Export()
if err != nil {
return nil, err
}
}
if err = b.digitalPins[i].Direction(dir); err != nil {
return
}
return b.digitalPins[i], nil
} | [
"func",
"(",
"b",
"*",
"Adaptor",
")",
"DigitalPin",
"(",
"pin",
"string",
",",
"dir",
"string",
")",
"(",
"sysfsPin",
"sysfs",
".",
"DigitalPinner",
",",
"err",
"error",
")",
"{",
"b",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"b",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"i",
",",
"err",
":=",
"b",
".",
"translatePin",
"(",
"pin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"b",
".",
"digitalPins",
"[",
"i",
"]",
"==",
"nil",
"{",
"b",
".",
"digitalPins",
"[",
"i",
"]",
"=",
"sysfs",
".",
"NewDigitalPin",
"(",
"i",
")",
"\n",
"if",
"err",
"=",
"muxPin",
"(",
"pin",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"err",
":=",
"b",
".",
"digitalPins",
"[",
"i",
"]",
".",
"Export",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
"=",
"b",
".",
"digitalPins",
"[",
"i",
"]",
".",
"Direction",
"(",
"dir",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"return",
"b",
".",
"digitalPins",
"[",
"i",
"]",
",",
"nil",
"\n",
"}"
] | // DigitalPin retrieves digital pin value by name | [
"DigitalPin",
"retrieves",
"digital",
"pin",
"value",
"by",
"name"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/beaglebone/beaglebone_adaptor.go#L180-L203 | train |
hybridgroup/gobot | platforms/beaglebone/beaglebone_adaptor.go | AnalogRead | func (b *Adaptor) AnalogRead(pin string) (val int, err error) {
analogPin, err := b.translateAnalogPin(pin)
if err != nil {
return
}
fi, err := sysfs.OpenFile(fmt.Sprintf("%v/%v", b.analogPath, analogPin), os.O_RDONLY, 0644)
defer fi.Close()
if err != nil {
return
}
var buf = make([]byte, 1024)
_, err = fi.Read(buf)
if err != nil {
return
}
val, _ = strconv.Atoi(strings.Split(string(buf), "\n")[0])
return
} | go | func (b *Adaptor) AnalogRead(pin string) (val int, err error) {
analogPin, err := b.translateAnalogPin(pin)
if err != nil {
return
}
fi, err := sysfs.OpenFile(fmt.Sprintf("%v/%v", b.analogPath, analogPin), os.O_RDONLY, 0644)
defer fi.Close()
if err != nil {
return
}
var buf = make([]byte, 1024)
_, err = fi.Read(buf)
if err != nil {
return
}
val, _ = strconv.Atoi(strings.Split(string(buf), "\n")[0])
return
} | [
"func",
"(",
"b",
"*",
"Adaptor",
")",
"AnalogRead",
"(",
"pin",
"string",
")",
"(",
"val",
"int",
",",
"err",
"error",
")",
"{",
"analogPin",
",",
"err",
":=",
"b",
".",
"translateAnalogPin",
"(",
"pin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"fi",
",",
"err",
":=",
"sysfs",
".",
"OpenFile",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"b",
".",
"analogPath",
",",
"analogPin",
")",
",",
"os",
".",
"O_RDONLY",
",",
"0644",
")",
"\n",
"defer",
"fi",
".",
"Close",
"(",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"var",
"buf",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"1024",
")",
"\n",
"_",
",",
"err",
"=",
"fi",
".",
"Read",
"(",
"buf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"val",
",",
"_",
"=",
"strconv",
".",
"Atoi",
"(",
"strings",
".",
"Split",
"(",
"string",
"(",
"buf",
")",
",",
"\"",
"\\n",
"\"",
")",
"[",
"0",
"]",
")",
"\n",
"return",
"\n",
"}"
] | // AnalogRead returns an analog value from specified pin | [
"AnalogRead",
"returns",
"an",
"analog",
"value",
"from",
"specified",
"pin"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/beaglebone/beaglebone_adaptor.go#L242-L262 | train |
hybridgroup/gobot | platforms/beaglebone/beaglebone_adaptor.go | translatePin | func (b *Adaptor) translatePin(pin string) (value int, err error) {
if val, ok := b.pinMap[pin]; ok {
value = val
} else {
err = errors.New("Not a valid pin")
}
return
} | go | func (b *Adaptor) translatePin(pin string) (value int, err error) {
if val, ok := b.pinMap[pin]; ok {
value = val
} else {
err = errors.New("Not a valid pin")
}
return
} | [
"func",
"(",
"b",
"*",
"Adaptor",
")",
"translatePin",
"(",
"pin",
"string",
")",
"(",
"value",
"int",
",",
"err",
"error",
")",
"{",
"if",
"val",
",",
"ok",
":=",
"b",
".",
"pinMap",
"[",
"pin",
"]",
";",
"ok",
"{",
"value",
"=",
"val",
"\n",
"}",
"else",
"{",
"err",
"=",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // translatePin converts digital pin name to pin position | [
"translatePin",
"converts",
"digital",
"pin",
"name",
"to",
"pin",
"position"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/beaglebone/beaglebone_adaptor.go#L327-L334 | train |
hybridgroup/gobot | platforms/beaglebone/beaglebone_adaptor.go | translateAnalogPin | func (b *Adaptor) translateAnalogPin(pin string) (value string, err error) {
if val, ok := b.analogPinMap[pin]; ok {
value = val
} else {
err = errors.New("Not a valid analog pin")
}
return
} | go | func (b *Adaptor) translateAnalogPin(pin string) (value string, err error) {
if val, ok := b.analogPinMap[pin]; ok {
value = val
} else {
err = errors.New("Not a valid analog pin")
}
return
} | [
"func",
"(",
"b",
"*",
"Adaptor",
")",
"translateAnalogPin",
"(",
"pin",
"string",
")",
"(",
"value",
"string",
",",
"err",
"error",
")",
"{",
"if",
"val",
",",
"ok",
":=",
"b",
".",
"analogPinMap",
"[",
"pin",
"]",
";",
"ok",
"{",
"value",
"=",
"val",
"\n",
"}",
"else",
"{",
"err",
"=",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // translateAnalogPin converts analog pin name to pin position | [
"translateAnalogPin",
"converts",
"analog",
"pin",
"name",
"to",
"pin",
"position"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/beaglebone/beaglebone_adaptor.go#L346-L353 | train |
hybridgroup/gobot | drivers/gpio/buzzer_driver.go | NewBuzzerDriver | func NewBuzzerDriver(a DigitalWriter, pin string) *BuzzerDriver {
l := &BuzzerDriver{
name: gobot.DefaultName("Buzzer"),
pin: pin,
connection: a,
high: false,
BPM: 96.0,
}
return l
} | go | func NewBuzzerDriver(a DigitalWriter, pin string) *BuzzerDriver {
l := &BuzzerDriver{
name: gobot.DefaultName("Buzzer"),
pin: pin,
connection: a,
high: false,
BPM: 96.0,
}
return l
} | [
"func",
"NewBuzzerDriver",
"(",
"a",
"DigitalWriter",
",",
"pin",
"string",
")",
"*",
"BuzzerDriver",
"{",
"l",
":=",
"&",
"BuzzerDriver",
"{",
"name",
":",
"gobot",
".",
"DefaultName",
"(",
"\"",
"\"",
")",
",",
"pin",
":",
"pin",
",",
"connection",
":",
"a",
",",
"high",
":",
"false",
",",
"BPM",
":",
"96.0",
",",
"}",
"\n\n",
"return",
"l",
"\n",
"}"
] | // NewBuzzerDriver return a new BuzzerDriver given a DigitalWriter and pin. | [
"NewBuzzerDriver",
"return",
"a",
"new",
"BuzzerDriver",
"given",
"a",
"DigitalWriter",
"and",
"pin",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/buzzer_driver.go#L140-L150 | train |
hybridgroup/gobot | drivers/gpio/buzzer_driver.go | Toggle | func (l *BuzzerDriver) Toggle() (err error) {
if l.State() {
err = l.Off()
} else {
err = l.On()
}
return
} | go | func (l *BuzzerDriver) Toggle() (err error) {
if l.State() {
err = l.Off()
} else {
err = l.On()
}
return
} | [
"func",
"(",
"l",
"*",
"BuzzerDriver",
")",
"Toggle",
"(",
")",
"(",
"err",
"error",
")",
"{",
"if",
"l",
".",
"State",
"(",
")",
"{",
"err",
"=",
"l",
".",
"Off",
"(",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"l",
".",
"On",
"(",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Toggle sets the buzzer to the opposite of it's current state | [
"Toggle",
"sets",
"the",
"buzzer",
"to",
"the",
"opposite",
"of",
"it",
"s",
"current",
"state"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/buzzer_driver.go#L196-L203 | train |
hybridgroup/gobot | utils.go | Rand | func Rand(max int) int {
i, _ := rand.Int(rand.Reader, big.NewInt(int64(max)))
return int(i.Int64())
} | go | func Rand(max int) int {
i, _ := rand.Int(rand.Reader, big.NewInt(int64(max)))
return int(i.Int64())
} | [
"func",
"Rand",
"(",
"max",
"int",
")",
"int",
"{",
"i",
",",
"_",
":=",
"rand",
".",
"Int",
"(",
"rand",
".",
"Reader",
",",
"big",
".",
"NewInt",
"(",
"int64",
"(",
"max",
")",
")",
")",
"\n",
"return",
"int",
"(",
"i",
".",
"Int64",
"(",
")",
")",
"\n",
"}"
] | // Rand returns a positive random int up to max | [
"Rand",
"returns",
"a",
"positive",
"random",
"int",
"up",
"to",
"max"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/utils.go#L36-L39 | train |
hybridgroup/gobot | utils.go | FromScale | func FromScale(input, min, max float64) float64 {
return (input - math.Min(min, max)) / (math.Max(min, max) - math.Min(min, max))
} | go | func FromScale(input, min, max float64) float64 {
return (input - math.Min(min, max)) / (math.Max(min, max) - math.Min(min, max))
} | [
"func",
"FromScale",
"(",
"input",
",",
"min",
",",
"max",
"float64",
")",
"float64",
"{",
"return",
"(",
"input",
"-",
"math",
".",
"Min",
"(",
"min",
",",
"max",
")",
")",
"/",
"(",
"math",
".",
"Max",
"(",
"min",
",",
"max",
")",
"-",
"math",
".",
"Min",
"(",
"min",
",",
"max",
")",
")",
"\n",
"}"
] | // FromScale returns a converted input from min, max to 0.0...1.0. | [
"FromScale",
"returns",
"a",
"converted",
"input",
"from",
"min",
"max",
"to",
"0",
".",
"0",
"...",
"1",
".",
"0",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/utils.go#L42-L44 | train |
hybridgroup/gobot | utils.go | ToScale | func ToScale(input, min, max float64) float64 {
i := input*(math.Max(min, max)-math.Min(min, max)) + math.Min(min, max)
if i < math.Min(min, max) {
return math.Min(min, max)
} else if i > math.Max(min, max) {
return math.Max(min, max)
} else {
return i
}
} | go | func ToScale(input, min, max float64) float64 {
i := input*(math.Max(min, max)-math.Min(min, max)) + math.Min(min, max)
if i < math.Min(min, max) {
return math.Min(min, max)
} else if i > math.Max(min, max) {
return math.Max(min, max)
} else {
return i
}
} | [
"func",
"ToScale",
"(",
"input",
",",
"min",
",",
"max",
"float64",
")",
"float64",
"{",
"i",
":=",
"input",
"*",
"(",
"math",
".",
"Max",
"(",
"min",
",",
"max",
")",
"-",
"math",
".",
"Min",
"(",
"min",
",",
"max",
")",
")",
"+",
"math",
".",
"Min",
"(",
"min",
",",
"max",
")",
"\n",
"if",
"i",
"<",
"math",
".",
"Min",
"(",
"min",
",",
"max",
")",
"{",
"return",
"math",
".",
"Min",
"(",
"min",
",",
"max",
")",
"\n",
"}",
"else",
"if",
"i",
">",
"math",
".",
"Max",
"(",
"min",
",",
"max",
")",
"{",
"return",
"math",
".",
"Max",
"(",
"min",
",",
"max",
")",
"\n",
"}",
"else",
"{",
"return",
"i",
"\n",
"}",
"\n",
"}"
] | // ToScale returns a converted input from 0...1 to min...max scale.
// If input is less than min then ToScale returns min.
// If input is greater than max then ToScale returns max | [
"ToScale",
"returns",
"a",
"converted",
"input",
"from",
"0",
"...",
"1",
"to",
"min",
"...",
"max",
"scale",
".",
"If",
"input",
"is",
"less",
"than",
"min",
"then",
"ToScale",
"returns",
"min",
".",
"If",
"input",
"is",
"greater",
"than",
"max",
"then",
"ToScale",
"returns",
"max"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/utils.go#L49-L58 | train |
hybridgroup/gobot | utils.go | Rescale | func Rescale(input, fromMin, fromMax, toMin, toMax float64) float64 {
return (input-fromMin)*(toMax-toMin)/(fromMax-fromMin) + toMin
} | go | func Rescale(input, fromMin, fromMax, toMin, toMax float64) float64 {
return (input-fromMin)*(toMax-toMin)/(fromMax-fromMin) + toMin
} | [
"func",
"Rescale",
"(",
"input",
",",
"fromMin",
",",
"fromMax",
",",
"toMin",
",",
"toMax",
"float64",
")",
"float64",
"{",
"return",
"(",
"input",
"-",
"fromMin",
")",
"*",
"(",
"toMax",
"-",
"toMin",
")",
"/",
"(",
"fromMax",
"-",
"fromMin",
")",
"+",
"toMin",
"\n",
"}"
] | // Rescale performs a direct linear rescaling of a number from one scale to another. | [
"Rescale",
"performs",
"a",
"direct",
"linear",
"rescaling",
"of",
"a",
"number",
"from",
"one",
"scale",
"to",
"another",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/utils.go#L61-L63 | train |
hybridgroup/gobot | utils.go | DefaultName | func DefaultName(name string) string {
return fmt.Sprintf("%s-%X", name, Rand(int(^uint(0)>>1)))
} | go | func DefaultName(name string) string {
return fmt.Sprintf("%s-%X", name, Rand(int(^uint(0)>>1)))
} | [
"func",
"DefaultName",
"(",
"name",
"string",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"name",
",",
"Rand",
"(",
"int",
"(",
"^",
"uint",
"(",
"0",
")",
">>",
"1",
")",
")",
")",
"\n",
"}"
] | // DefaultName returns a sensible random default name
// for a robot, adaptor or driver | [
"DefaultName",
"returns",
"a",
"sensible",
"random",
"default",
"name",
"for",
"a",
"robot",
"adaptor",
"or",
"driver"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/utils.go#L67-L69 | train |
hybridgroup/gobot | drivers/i2c/grovepi_driver.go | Start | func (d *GrovePiDriver) Start() (err error) {
bus := d.GetBusOrDefault(d.connector.GetDefaultBus())
address := d.GetAddressOrDefault(grovePiAddress)
d.connection, err = d.connector.GetConnection(address, bus)
if err != nil {
return err
}
return
} | go | func (d *GrovePiDriver) Start() (err error) {
bus := d.GetBusOrDefault(d.connector.GetDefaultBus())
address := d.GetAddressOrDefault(grovePiAddress)
d.connection, err = d.connector.GetConnection(address, bus)
if err != nil {
return err
}
return
} | [
"func",
"(",
"d",
"*",
"GrovePiDriver",
")",
"Start",
"(",
")",
"(",
"err",
"error",
")",
"{",
"bus",
":=",
"d",
".",
"GetBusOrDefault",
"(",
"d",
".",
"connector",
".",
"GetDefaultBus",
"(",
")",
")",
"\n",
"address",
":=",
"d",
".",
"GetAddressOrDefault",
"(",
"grovePiAddress",
")",
"\n\n",
"d",
".",
"connection",
",",
"err",
"=",
"d",
".",
"connector",
".",
"GetConnection",
"(",
"address",
",",
"bus",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // Start initialized the GrovePi | [
"Start",
"initialized",
"the",
"GrovePi"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/grovepi_driver.go#L73-L83 | train |
hybridgroup/gobot | drivers/i2c/grovepi_driver.go | AnalogRead | func (d *GrovePiDriver) AnalogRead(pin string) (value int, err error) {
pin = getPin(pin)
var pinNum int
pinNum, err = strconv.Atoi(pin)
if err != nil {
return
}
value, err = d.readAnalog(byte(pinNum))
return
} | go | func (d *GrovePiDriver) AnalogRead(pin string) (value int, err error) {
pin = getPin(pin)
var pinNum int
pinNum, err = strconv.Atoi(pin)
if err != nil {
return
}
value, err = d.readAnalog(byte(pinNum))
return
} | [
"func",
"(",
"d",
"*",
"GrovePiDriver",
")",
"AnalogRead",
"(",
"pin",
"string",
")",
"(",
"value",
"int",
",",
"err",
"error",
")",
"{",
"pin",
"=",
"getPin",
"(",
"pin",
")",
"\n\n",
"var",
"pinNum",
"int",
"\n",
"pinNum",
",",
"err",
"=",
"strconv",
".",
"Atoi",
"(",
"pin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"value",
",",
"err",
"=",
"d",
".",
"readAnalog",
"(",
"byte",
"(",
"pinNum",
")",
")",
"\n\n",
"return",
"\n",
"}"
] | // AnalogRead returns value from analog pin implementing the AnalogReader interface. | [
"AnalogRead",
"returns",
"value",
"from",
"analog",
"pin",
"implementing",
"the",
"AnalogReader",
"interface",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/grovepi_driver.go#L99-L111 | train |
hybridgroup/gobot | drivers/i2c/grovepi_driver.go | DigitalRead | func (d *GrovePiDriver) DigitalRead(pin string) (val int, err error) {
pin = getPin(pin)
var pinNum int
pinNum, err = strconv.Atoi(pin)
if err != nil {
return
}
if dir, ok := d.digitalPins[pinNum]; !ok || dir != "input" {
d.PinMode(byte(pinNum), "input")
d.digitalPins[pinNum] = "input"
}
val, err = d.readDigital(byte(pinNum))
return
} | go | func (d *GrovePiDriver) DigitalRead(pin string) (val int, err error) {
pin = getPin(pin)
var pinNum int
pinNum, err = strconv.Atoi(pin)
if err != nil {
return
}
if dir, ok := d.digitalPins[pinNum]; !ok || dir != "input" {
d.PinMode(byte(pinNum), "input")
d.digitalPins[pinNum] = "input"
}
val, err = d.readDigital(byte(pinNum))
return
} | [
"func",
"(",
"d",
"*",
"GrovePiDriver",
")",
"DigitalRead",
"(",
"pin",
"string",
")",
"(",
"val",
"int",
",",
"err",
"error",
")",
"{",
"pin",
"=",
"getPin",
"(",
"pin",
")",
"\n\n",
"var",
"pinNum",
"int",
"\n",
"pinNum",
",",
"err",
"=",
"strconv",
".",
"Atoi",
"(",
"pin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"dir",
",",
"ok",
":=",
"d",
".",
"digitalPins",
"[",
"pinNum",
"]",
";",
"!",
"ok",
"||",
"dir",
"!=",
"\"",
"\"",
"{",
"d",
".",
"PinMode",
"(",
"byte",
"(",
"pinNum",
")",
",",
"\"",
"\"",
")",
"\n",
"d",
".",
"digitalPins",
"[",
"pinNum",
"]",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"val",
",",
"err",
"=",
"d",
".",
"readDigital",
"(",
"byte",
"(",
"pinNum",
")",
")",
"\n\n",
"return",
"\n",
"}"
] | // DigitalRead performs a read on a digital pin. | [
"DigitalRead",
"performs",
"a",
"read",
"on",
"a",
"digital",
"pin",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/grovepi_driver.go#L114-L131 | train |
hybridgroup/gobot | drivers/i2c/grovepi_driver.go | WriteAnalog | func (d *GrovePiDriver) WriteAnalog(pin byte, val byte) error {
buf := []byte{CommandWriteAnalog, pin, val, 0}
_, err := d.connection.Write(buf)
time.Sleep(2 * time.Millisecond)
data := make([]byte, 1)
_, err = d.connection.Read(data)
return err
} | go | func (d *GrovePiDriver) WriteAnalog(pin byte, val byte) error {
buf := []byte{CommandWriteAnalog, pin, val, 0}
_, err := d.connection.Write(buf)
time.Sleep(2 * time.Millisecond)
data := make([]byte, 1)
_, err = d.connection.Read(data)
return err
} | [
"func",
"(",
"d",
"*",
"GrovePiDriver",
")",
"WriteAnalog",
"(",
"pin",
"byte",
",",
"val",
"byte",
")",
"error",
"{",
"buf",
":=",
"[",
"]",
"byte",
"{",
"CommandWriteAnalog",
",",
"pin",
",",
"val",
",",
"0",
"}",
"\n",
"_",
",",
"err",
":=",
"d",
".",
"connection",
".",
"Write",
"(",
"buf",
")",
"\n\n",
"time",
".",
"Sleep",
"(",
"2",
"*",
"time",
".",
"Millisecond",
")",
"\n\n",
"data",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"1",
")",
"\n",
"_",
",",
"err",
"=",
"d",
".",
"connection",
".",
"Read",
"(",
"data",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // WriteAnalog writes PWM aka analog to the GrovePi. Not yet working. | [
"WriteAnalog",
"writes",
"PWM",
"aka",
"analog",
"to",
"the",
"GrovePi",
".",
"Not",
"yet",
"working",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/grovepi_driver.go#L154-L164 | train |
hybridgroup/gobot | drivers/i2c/grovepi_driver.go | PinMode | func (d *GrovePiDriver) PinMode(pin byte, mode string) error {
var b []byte
if mode == "output" {
b = []byte{CommandPinMode, pin, 1, 0}
} else {
b = []byte{CommandPinMode, pin, 0, 0}
}
_, err := d.connection.Write(b)
time.Sleep(2 * time.Millisecond)
_, err = d.connection.ReadByte()
return err
} | go | func (d *GrovePiDriver) PinMode(pin byte, mode string) error {
var b []byte
if mode == "output" {
b = []byte{CommandPinMode, pin, 1, 0}
} else {
b = []byte{CommandPinMode, pin, 0, 0}
}
_, err := d.connection.Write(b)
time.Sleep(2 * time.Millisecond)
_, err = d.connection.ReadByte()
return err
} | [
"func",
"(",
"d",
"*",
"GrovePiDriver",
")",
"PinMode",
"(",
"pin",
"byte",
",",
"mode",
"string",
")",
"error",
"{",
"var",
"b",
"[",
"]",
"byte",
"\n",
"if",
"mode",
"==",
"\"",
"\"",
"{",
"b",
"=",
"[",
"]",
"byte",
"{",
"CommandPinMode",
",",
"pin",
",",
"1",
",",
"0",
"}",
"\n",
"}",
"else",
"{",
"b",
"=",
"[",
"]",
"byte",
"{",
"CommandPinMode",
",",
"pin",
",",
"0",
",",
"0",
"}",
"\n",
"}",
"\n",
"_",
",",
"err",
":=",
"d",
".",
"connection",
".",
"Write",
"(",
"b",
")",
"\n\n",
"time",
".",
"Sleep",
"(",
"2",
"*",
"time",
".",
"Millisecond",
")",
"\n\n",
"_",
",",
"err",
"=",
"d",
".",
"connection",
".",
"ReadByte",
"(",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // PinMode sets the pin mode to input or output. | [
"PinMode",
"sets",
"the",
"pin",
"mode",
"to",
"input",
"or",
"output",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/grovepi_driver.go#L167-L181 | train |
hybridgroup/gobot | drivers/i2c/grovepi_driver.go | readAnalog | func (d *GrovePiDriver) readAnalog(pin byte) (int, error) {
b := []byte{CommandReadAnalog, pin, 0, 0}
_, err := d.connection.Write(b)
if err != nil {
return 0, err
}
time.Sleep(2 * time.Millisecond)
data := make([]byte, 3)
_, err = d.connection.Read(data)
if err != nil || data[0] != CommandReadAnalog {
return -1, err
}
v1 := int(data[1])
v2 := int(data[2])
return ((v1 * 256) + v2), nil
} | go | func (d *GrovePiDriver) readAnalog(pin byte) (int, error) {
b := []byte{CommandReadAnalog, pin, 0, 0}
_, err := d.connection.Write(b)
if err != nil {
return 0, err
}
time.Sleep(2 * time.Millisecond)
data := make([]byte, 3)
_, err = d.connection.Read(data)
if err != nil || data[0] != CommandReadAnalog {
return -1, err
}
v1 := int(data[1])
v2 := int(data[2])
return ((v1 * 256) + v2), nil
} | [
"func",
"(",
"d",
"*",
"GrovePiDriver",
")",
"readAnalog",
"(",
"pin",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"b",
":=",
"[",
"]",
"byte",
"{",
"CommandReadAnalog",
",",
"pin",
",",
"0",
",",
"0",
"}",
"\n",
"_",
",",
"err",
":=",
"d",
".",
"connection",
".",
"Write",
"(",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"time",
".",
"Sleep",
"(",
"2",
"*",
"time",
".",
"Millisecond",
")",
"\n\n",
"data",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"3",
")",
"\n",
"_",
",",
"err",
"=",
"d",
".",
"connection",
".",
"Read",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"data",
"[",
"0",
"]",
"!=",
"CommandReadAnalog",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n\n",
"v1",
":=",
"int",
"(",
"data",
"[",
"1",
"]",
")",
"\n",
"v2",
":=",
"int",
"(",
"data",
"[",
"2",
"]",
")",
"\n",
"return",
"(",
"(",
"v1",
"*",
"256",
")",
"+",
"v2",
")",
",",
"nil",
"\n",
"}"
] | // readAnalog reads analog value from the GrovePi. | [
"readAnalog",
"reads",
"analog",
"value",
"from",
"the",
"GrovePi",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/grovepi_driver.go#L194-L212 | train |
hybridgroup/gobot | drivers/i2c/grovepi_driver.go | readDigital | func (d *GrovePiDriver) readDigital(pin byte) (val int, err error) {
buf := []byte{CommandReadDigital, pin, 0, 0}
_, err = d.connection.Write(buf)
if err != nil {
return
}
time.Sleep(2 * time.Millisecond)
data := make([]byte, 2)
_, err = d.connection.Read(data)
if err != nil || data[0] != CommandReadDigital {
return 0, err
}
return int(data[1]), err
} | go | func (d *GrovePiDriver) readDigital(pin byte) (val int, err error) {
buf := []byte{CommandReadDigital, pin, 0, 0}
_, err = d.connection.Write(buf)
if err != nil {
return
}
time.Sleep(2 * time.Millisecond)
data := make([]byte, 2)
_, err = d.connection.Read(data)
if err != nil || data[0] != CommandReadDigital {
return 0, err
}
return int(data[1]), err
} | [
"func",
"(",
"d",
"*",
"GrovePiDriver",
")",
"readDigital",
"(",
"pin",
"byte",
")",
"(",
"val",
"int",
",",
"err",
"error",
")",
"{",
"buf",
":=",
"[",
"]",
"byte",
"{",
"CommandReadDigital",
",",
"pin",
",",
"0",
",",
"0",
"}",
"\n",
"_",
",",
"err",
"=",
"d",
".",
"connection",
".",
"Write",
"(",
"buf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"time",
".",
"Sleep",
"(",
"2",
"*",
"time",
".",
"Millisecond",
")",
"\n\n",
"data",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"2",
")",
"\n",
"_",
",",
"err",
"=",
"d",
".",
"connection",
".",
"Read",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"data",
"[",
"0",
"]",
"!=",
"CommandReadDigital",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"int",
"(",
"data",
"[",
"1",
"]",
")",
",",
"err",
"\n",
"}"
] | // readDigital reads digitally from the GrovePi. | [
"readDigital",
"reads",
"digitally",
"from",
"the",
"GrovePi",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/grovepi_driver.go#L215-L231 | train |
hybridgroup/gobot | drivers/i2c/grovepi_driver.go | writeDigital | func (d *GrovePiDriver) writeDigital(pin byte, val byte) error {
buf := []byte{CommandWriteDigital, pin, val, 0}
_, err := d.connection.Write(buf)
time.Sleep(2 * time.Millisecond)
_, err = d.connection.ReadByte()
return err
} | go | func (d *GrovePiDriver) writeDigital(pin byte, val byte) error {
buf := []byte{CommandWriteDigital, pin, val, 0}
_, err := d.connection.Write(buf)
time.Sleep(2 * time.Millisecond)
_, err = d.connection.ReadByte()
return err
} | [
"func",
"(",
"d",
"*",
"GrovePiDriver",
")",
"writeDigital",
"(",
"pin",
"byte",
",",
"val",
"byte",
")",
"error",
"{",
"buf",
":=",
"[",
"]",
"byte",
"{",
"CommandWriteDigital",
",",
"pin",
",",
"val",
",",
"0",
"}",
"\n",
"_",
",",
"err",
":=",
"d",
".",
"connection",
".",
"Write",
"(",
"buf",
")",
"\n\n",
"time",
".",
"Sleep",
"(",
"2",
"*",
"time",
".",
"Millisecond",
")",
"\n\n",
"_",
",",
"err",
"=",
"d",
".",
"connection",
".",
"ReadByte",
"(",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] | // writeDigital writes digitally to the GrovePi. | [
"writeDigital",
"writes",
"digitally",
"to",
"the",
"GrovePi",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/grovepi_driver.go#L234-L243 | train |
hybridgroup/gobot | drivers/i2c/i2c.go | NewConnection | func NewConnection(bus I2cDevice, address int) (connection *i2cConnection) {
return &i2cConnection{bus: bus, address: address, mutex: &sync.Mutex{}}
} | go | func NewConnection(bus I2cDevice, address int) (connection *i2cConnection) {
return &i2cConnection{bus: bus, address: address, mutex: &sync.Mutex{}}
} | [
"func",
"NewConnection",
"(",
"bus",
"I2cDevice",
",",
"address",
"int",
")",
"(",
"connection",
"*",
"i2cConnection",
")",
"{",
"return",
"&",
"i2cConnection",
"{",
"bus",
":",
"bus",
",",
"address",
":",
"address",
",",
"mutex",
":",
"&",
"sync",
".",
"Mutex",
"{",
"}",
"}",
"\n",
"}"
] | // NewConnection creates and returns a new connection to a specific
// i2c device on a bus and address. | [
"NewConnection",
"creates",
"and",
"returns",
"a",
"new",
"connection",
"to",
"a",
"specific",
"i2c",
"device",
"on",
"a",
"bus",
"and",
"address",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/i2c.go#L73-L75 | train |
hybridgroup/gobot | drivers/i2c/i2c.go | Read | func (c *i2cConnection) Read(data []byte) (read int, err error) {
c.mutex.Lock()
defer c.mutex.Unlock()
if err = c.bus.SetAddress(c.address); err != nil {
return 0, err
}
read, err = c.bus.Read(data)
return
} | go | func (c *i2cConnection) Read(data []byte) (read int, err error) {
c.mutex.Lock()
defer c.mutex.Unlock()
if err = c.bus.SetAddress(c.address); err != nil {
return 0, err
}
read, err = c.bus.Read(data)
return
} | [
"func",
"(",
"c",
"*",
"i2cConnection",
")",
"Read",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"read",
"int",
",",
"err",
"error",
")",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"err",
"=",
"c",
".",
"bus",
".",
"SetAddress",
"(",
"c",
".",
"address",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"read",
",",
"err",
"=",
"c",
".",
"bus",
".",
"Read",
"(",
"data",
")",
"\n",
"return",
"\n",
"}"
] | // Read data from an i2c device. | [
"Read",
"data",
"from",
"an",
"i2c",
"device",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/i2c.go#L78-L87 | train |
hybridgroup/gobot | drivers/i2c/i2c.go | Write | func (c *i2cConnection) Write(data []byte) (written int, err error) {
c.mutex.Lock()
defer c.mutex.Unlock()
if err = c.bus.SetAddress(c.address); err != nil {
return 0, err
}
written, err = c.bus.Write(data)
return
} | go | func (c *i2cConnection) Write(data []byte) (written int, err error) {
c.mutex.Lock()
defer c.mutex.Unlock()
if err = c.bus.SetAddress(c.address); err != nil {
return 0, err
}
written, err = c.bus.Write(data)
return
} | [
"func",
"(",
"c",
"*",
"i2cConnection",
")",
"Write",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"written",
"int",
",",
"err",
"error",
")",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"err",
"=",
"c",
".",
"bus",
".",
"SetAddress",
"(",
"c",
".",
"address",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"written",
",",
"err",
"=",
"c",
".",
"bus",
".",
"Write",
"(",
"data",
")",
"\n",
"return",
"\n",
"}"
] | // Write data to an i2c device. | [
"Write",
"data",
"to",
"an",
"i2c",
"device",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/i2c.go#L90-L99 | train |
hybridgroup/gobot | drivers/i2c/i2c.go | Close | func (c *i2cConnection) Close() error {
c.mutex.Lock()
defer c.mutex.Unlock()
return c.bus.Close()
} | go | func (c *i2cConnection) Close() error {
c.mutex.Lock()
defer c.mutex.Unlock()
return c.bus.Close()
} | [
"func",
"(",
"c",
"*",
"i2cConnection",
")",
"Close",
"(",
")",
"error",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"c",
".",
"bus",
".",
"Close",
"(",
")",
"\n",
"}"
] | // Close connection to i2c device. | [
"Close",
"connection",
"to",
"i2c",
"device",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/i2c.go#L102-L107 | train |
hybridgroup/gobot | drivers/i2c/i2c.go | ReadByte | func (c *i2cConnection) ReadByte() (val byte, err error) {
c.mutex.Lock()
defer c.mutex.Unlock()
if err := c.bus.SetAddress(c.address); err != nil {
return 0, err
}
return c.bus.ReadByte()
} | go | func (c *i2cConnection) ReadByte() (val byte, err error) {
c.mutex.Lock()
defer c.mutex.Unlock()
if err := c.bus.SetAddress(c.address); err != nil {
return 0, err
}
return c.bus.ReadByte()
} | [
"func",
"(",
"c",
"*",
"i2cConnection",
")",
"ReadByte",
"(",
")",
"(",
"val",
"byte",
",",
"err",
"error",
")",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"err",
":=",
"c",
".",
"bus",
".",
"SetAddress",
"(",
"c",
".",
"address",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"return",
"c",
".",
"bus",
".",
"ReadByte",
"(",
")",
"\n",
"}"
] | // ReadByte reads a single byte from the i2c device. | [
"ReadByte",
"reads",
"a",
"single",
"byte",
"from",
"the",
"i2c",
"device",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/i2c.go#L110-L118 | train |
hybridgroup/gobot | drivers/i2c/i2c.go | WriteByteData | func (c *i2cConnection) WriteByteData(reg uint8, val uint8) (err error) {
c.mutex.Lock()
defer c.mutex.Unlock()
if err := c.bus.SetAddress(c.address); err != nil {
return err
}
return c.bus.WriteByteData(reg, val)
} | go | func (c *i2cConnection) WriteByteData(reg uint8, val uint8) (err error) {
c.mutex.Lock()
defer c.mutex.Unlock()
if err := c.bus.SetAddress(c.address); err != nil {
return err
}
return c.bus.WriteByteData(reg, val)
} | [
"func",
"(",
"c",
"*",
"i2cConnection",
")",
"WriteByteData",
"(",
"reg",
"uint8",
",",
"val",
"uint8",
")",
"(",
"err",
"error",
")",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"err",
":=",
"c",
".",
"bus",
".",
"SetAddress",
"(",
"c",
".",
"address",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"c",
".",
"bus",
".",
"WriteByteData",
"(",
"reg",
",",
"val",
")",
"\n",
"}"
] | // WriteByteData writes a byte value to a register on the i2c device. | [
"WriteByteData",
"writes",
"a",
"byte",
"value",
"to",
"a",
"register",
"on",
"the",
"i2c",
"device",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/i2c.go#L154-L162 | train |
hybridgroup/gobot | drivers/i2c/i2c.go | WriteBlockData | func (c *i2cConnection) WriteBlockData(reg uint8, b []byte) (err error) {
c.mutex.Lock()
defer c.mutex.Unlock()
if err := c.bus.SetAddress(c.address); err != nil {
return err
}
return c.bus.WriteBlockData(reg, b)
} | go | func (c *i2cConnection) WriteBlockData(reg uint8, b []byte) (err error) {
c.mutex.Lock()
defer c.mutex.Unlock()
if err := c.bus.SetAddress(c.address); err != nil {
return err
}
return c.bus.WriteBlockData(reg, b)
} | [
"func",
"(",
"c",
"*",
"i2cConnection",
")",
"WriteBlockData",
"(",
"reg",
"uint8",
",",
"b",
"[",
"]",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"err",
":=",
"c",
".",
"bus",
".",
"SetAddress",
"(",
"c",
".",
"address",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"c",
".",
"bus",
".",
"WriteBlockData",
"(",
"reg",
",",
"b",
")",
"\n",
"}"
] | // WriteBlockData writes a block of bytes to a register on the i2c device. | [
"WriteBlockData",
"writes",
"a",
"block",
"of",
"bytes",
"to",
"a",
"register",
"on",
"the",
"i2c",
"device",
"."
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/i2c/i2c.go#L176-L184 | train |
hybridgroup/gobot | platforms/raspi/raspi_adaptor.go | NewAdaptor | func NewAdaptor() *Adaptor {
r := &Adaptor{
mutex: &sync.Mutex{},
name: gobot.DefaultName("RaspberryPi"),
digitalPins: make(map[int]*sysfs.DigitalPin),
pwmPins: make(map[int]*PWMPin),
PiBlasterPeriod: 10000000,
}
content, _ := readFile()
for _, v := range strings.Split(string(content), "\n") {
if strings.Contains(v, "Revision") {
s := strings.Split(string(v), " ")
version, _ := strconv.ParseInt("0x"+s[len(s)-1], 0, 64)
r.i2cDefaultBus = 1
r.spiDefaultBus = 0
r.spiDefaultChip = 0
r.spiDefaultMode = 0
r.spiDefaultMaxSpeed = 500000
if version <= 3 {
r.revision = "1"
r.i2cDefaultBus = 0
} else if version <= 15 {
r.revision = "2"
} else {
r.revision = "3"
}
}
}
return r
} | go | func NewAdaptor() *Adaptor {
r := &Adaptor{
mutex: &sync.Mutex{},
name: gobot.DefaultName("RaspberryPi"),
digitalPins: make(map[int]*sysfs.DigitalPin),
pwmPins: make(map[int]*PWMPin),
PiBlasterPeriod: 10000000,
}
content, _ := readFile()
for _, v := range strings.Split(string(content), "\n") {
if strings.Contains(v, "Revision") {
s := strings.Split(string(v), " ")
version, _ := strconv.ParseInt("0x"+s[len(s)-1], 0, 64)
r.i2cDefaultBus = 1
r.spiDefaultBus = 0
r.spiDefaultChip = 0
r.spiDefaultMode = 0
r.spiDefaultMaxSpeed = 500000
if version <= 3 {
r.revision = "1"
r.i2cDefaultBus = 0
} else if version <= 15 {
r.revision = "2"
} else {
r.revision = "3"
}
}
}
return r
} | [
"func",
"NewAdaptor",
"(",
")",
"*",
"Adaptor",
"{",
"r",
":=",
"&",
"Adaptor",
"{",
"mutex",
":",
"&",
"sync",
".",
"Mutex",
"{",
"}",
",",
"name",
":",
"gobot",
".",
"DefaultName",
"(",
"\"",
"\"",
")",
",",
"digitalPins",
":",
"make",
"(",
"map",
"[",
"int",
"]",
"*",
"sysfs",
".",
"DigitalPin",
")",
",",
"pwmPins",
":",
"make",
"(",
"map",
"[",
"int",
"]",
"*",
"PWMPin",
")",
",",
"PiBlasterPeriod",
":",
"10000000",
",",
"}",
"\n",
"content",
",",
"_",
":=",
"readFile",
"(",
")",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"strings",
".",
"Split",
"(",
"string",
"(",
"content",
")",
",",
"\"",
"\\n",
"\"",
")",
"{",
"if",
"strings",
".",
"Contains",
"(",
"v",
",",
"\"",
"\"",
")",
"{",
"s",
":=",
"strings",
".",
"Split",
"(",
"string",
"(",
"v",
")",
",",
"\"",
"\"",
")",
"\n",
"version",
",",
"_",
":=",
"strconv",
".",
"ParseInt",
"(",
"\"",
"\"",
"+",
"s",
"[",
"len",
"(",
"s",
")",
"-",
"1",
"]",
",",
"0",
",",
"64",
")",
"\n",
"r",
".",
"i2cDefaultBus",
"=",
"1",
"\n",
"r",
".",
"spiDefaultBus",
"=",
"0",
"\n",
"r",
".",
"spiDefaultChip",
"=",
"0",
"\n",
"r",
".",
"spiDefaultMode",
"=",
"0",
"\n",
"r",
".",
"spiDefaultMaxSpeed",
"=",
"500000",
"\n",
"if",
"version",
"<=",
"3",
"{",
"r",
".",
"revision",
"=",
"\"",
"\"",
"\n",
"r",
".",
"i2cDefaultBus",
"=",
"0",
"\n",
"}",
"else",
"if",
"version",
"<=",
"15",
"{",
"r",
".",
"revision",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"r",
".",
"revision",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"r",
"\n",
"}"
] | // NewAdaptor creates a Raspi Adaptor | [
"NewAdaptor",
"creates",
"a",
"Raspi",
"Adaptor"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/raspi/raspi_adaptor.go#L41-L71 | train |
hybridgroup/gobot | platforms/raspi/raspi_adaptor.go | Name | func (r *Adaptor) Name() string {
r.mutex.Lock()
defer r.mutex.Unlock()
return r.name
} | go | func (r *Adaptor) Name() string {
r.mutex.Lock()
defer r.mutex.Unlock()
return r.name
} | [
"func",
"(",
"r",
"*",
"Adaptor",
")",
"Name",
"(",
")",
"string",
"{",
"r",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"return",
"r",
".",
"name",
"\n",
"}"
] | // Name returns the Adaptor's name | [
"Name",
"returns",
"the",
"Adaptor",
"s",
"name"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/raspi/raspi_adaptor.go#L74-L79 | train |
hybridgroup/gobot | platforms/raspi/raspi_adaptor.go | SetName | func (r *Adaptor) SetName(n string) {
r.mutex.Lock()
defer r.mutex.Unlock()
r.name = n
} | go | func (r *Adaptor) SetName(n string) {
r.mutex.Lock()
defer r.mutex.Unlock()
r.name = n
} | [
"func",
"(",
"r",
"*",
"Adaptor",
")",
"SetName",
"(",
"n",
"string",
")",
"{",
"r",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"r",
".",
"name",
"=",
"n",
"\n",
"}"
] | // SetName sets the Adaptor's name | [
"SetName",
"sets",
"the",
"Adaptor",
"s",
"name"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/raspi/raspi_adaptor.go#L82-L87 | train |
hybridgroup/gobot | platforms/raspi/raspi_adaptor.go | DigitalWrite | func (r *Adaptor) DigitalWrite(pin string, val byte) (err error) {
sysfsPin, err := r.DigitalPin(pin, sysfs.OUT)
if err != nil {
return err
}
return sysfsPin.Write(int(val))
} | go | func (r *Adaptor) DigitalWrite(pin string, val byte) (err error) {
sysfsPin, err := r.DigitalPin(pin, sysfs.OUT)
if err != nil {
return err
}
return sysfsPin.Write(int(val))
} | [
"func",
"(",
"r",
"*",
"Adaptor",
")",
"DigitalWrite",
"(",
"pin",
"string",
",",
"val",
"byte",
")",
"(",
"err",
"error",
")",
"{",
"sysfsPin",
",",
"err",
":=",
"r",
".",
"DigitalPin",
"(",
"pin",
",",
"sysfs",
".",
"OUT",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"sysfsPin",
".",
"Write",
"(",
"int",
"(",
"val",
")",
")",
"\n",
"}"
] | // DigitalWrite writes digital value to specified pin | [
"DigitalWrite",
"writes",
"digital",
"value",
"to",
"specified",
"pin"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/raspi/raspi_adaptor.go#L176-L182 | train |
hybridgroup/gobot | platforms/raspi/raspi_adaptor.go | PWMPin | func (r *Adaptor) PWMPin(pin string) (raspiPWMPin sysfs.PWMPinner, err error) {
i, err := r.translatePin(pin)
if err != nil {
return
}
r.mutex.Lock()
defer r.mutex.Unlock()
if r.pwmPins[i] == nil {
r.pwmPins[i] = NewPWMPin(strconv.Itoa(i))
r.pwmPins[i].SetPeriod(r.PiBlasterPeriod)
}
return r.pwmPins[i], nil
} | go | func (r *Adaptor) PWMPin(pin string) (raspiPWMPin sysfs.PWMPinner, err error) {
i, err := r.translatePin(pin)
if err != nil {
return
}
r.mutex.Lock()
defer r.mutex.Unlock()
if r.pwmPins[i] == nil {
r.pwmPins[i] = NewPWMPin(strconv.Itoa(i))
r.pwmPins[i].SetPeriod(r.PiBlasterPeriod)
}
return r.pwmPins[i], nil
} | [
"func",
"(",
"r",
"*",
"Adaptor",
")",
"PWMPin",
"(",
"pin",
"string",
")",
"(",
"raspiPWMPin",
"sysfs",
".",
"PWMPinner",
",",
"err",
"error",
")",
"{",
"i",
",",
"err",
":=",
"r",
".",
"translatePin",
"(",
"pin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"r",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"r",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"r",
".",
"pwmPins",
"[",
"i",
"]",
"==",
"nil",
"{",
"r",
".",
"pwmPins",
"[",
"i",
"]",
"=",
"NewPWMPin",
"(",
"strconv",
".",
"Itoa",
"(",
"i",
")",
")",
"\n",
"r",
".",
"pwmPins",
"[",
"i",
"]",
".",
"SetPeriod",
"(",
"r",
".",
"PiBlasterPeriod",
")",
"\n",
"}",
"\n\n",
"return",
"r",
".",
"pwmPins",
"[",
"i",
"]",
",",
"nil",
"\n",
"}"
] | // PWMPin returns a raspi.PWMPin which provides the sysfs.PWMPinner interface | [
"PWMPin",
"returns",
"a",
"raspi",
".",
"PWMPin",
"which",
"provides",
"the",
"sysfs",
".",
"PWMPinner",
"interface"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/platforms/raspi/raspi_adaptor.go#L255-L270 | train |
hybridgroup/gobot | drivers/gpio/aip1640_driver.go | NewAIP1640Driver | func NewAIP1640Driver(a gobot.Connection, clockPin string, dataPin string) *AIP1640Driver {
t := &AIP1640Driver{
name: gobot.DefaultName("AIP1640Driver"),
pinClock: NewDirectPinDriver(a, clockPin),
pinData: NewDirectPinDriver(a, dataPin),
intensity: 7,
connection: a,
Commander: gobot.NewCommander(),
}
/* TODO : Add commands */
return t
} | go | func NewAIP1640Driver(a gobot.Connection, clockPin string, dataPin string) *AIP1640Driver {
t := &AIP1640Driver{
name: gobot.DefaultName("AIP1640Driver"),
pinClock: NewDirectPinDriver(a, clockPin),
pinData: NewDirectPinDriver(a, dataPin),
intensity: 7,
connection: a,
Commander: gobot.NewCommander(),
}
/* TODO : Add commands */
return t
} | [
"func",
"NewAIP1640Driver",
"(",
"a",
"gobot",
".",
"Connection",
",",
"clockPin",
"string",
",",
"dataPin",
"string",
")",
"*",
"AIP1640Driver",
"{",
"t",
":=",
"&",
"AIP1640Driver",
"{",
"name",
":",
"gobot",
".",
"DefaultName",
"(",
"\"",
"\"",
")",
",",
"pinClock",
":",
"NewDirectPinDriver",
"(",
"a",
",",
"clockPin",
")",
",",
"pinData",
":",
"NewDirectPinDriver",
"(",
"a",
",",
"dataPin",
")",
",",
"intensity",
":",
"7",
",",
"connection",
":",
"a",
",",
"Commander",
":",
"gobot",
".",
"NewCommander",
"(",
")",
",",
"}",
"\n\n",
"/* TODO : Add commands */",
"return",
"t",
"\n",
"}"
] | // NewAIP1640Driver return a new AIP1640Driver given a gobot.Connection and the clock, data and strobe pins | [
"NewAIP1640Driver",
"return",
"a",
"new",
"AIP1640Driver",
"given",
"a",
"gobot",
".",
"Connection",
"and",
"the",
"clock",
"data",
"and",
"strobe",
"pins"
] | 58db149a40a113aec7d6068fb9418b7e05de1802 | https://github.com/hybridgroup/gobot/blob/58db149a40a113aec7d6068fb9418b7e05de1802/drivers/gpio/aip1640_driver.go#L34-L47 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.