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

747 Views Asked by At

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

[[inputs.mem]] 
  • For application stats we keep input as statsd, we push stats from application using UDP to telegraf using its host and port.
[[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.

1

There are 1 best solutions below

0
On

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.