Ash
Ash

Reputation: 145

How does telegraf input plugin like [[inputs.mem]] fetch data?

When we need memory related stats we add input plugin in telegraf.conf file.

[[inputs.mem]] 
[[inputs.statsd]]

Could someone explain how does [[inputs.mem]] input plugins get data related to memory? Because no one is pushing data to telegraf in this case.

Upvotes: 1

Views: 801

Answers (1)

NikNye
NikNye

Reputation: 129

Telegraf retrieves system data using system libraries written for Go. At this time it is using the gopsutil library. This library's link above includes an example of how it could be used within any Go program.

func main() {
    v, _ := mem.VirtualMemory()

    // almost every return value is a struct
    fmt.Printf("Total: %v, Free:%v, UsedPercent:%f%%\n", v.Total, v.Free, v.UsedPercent)

    // convert to JSON. String() is also implemented
    fmt.Println(v)
}

This library supports a number of different operating systems and has modules for a variety of system information such as cpu, memory, disk, and networking usage. You can see where these are incorporated into the telegraf project here.

Upvotes: 1

Related Questions