telegraf输入插件(如[[inputs.mem]])如何获取数据?

时间:2019-10-30 16:30:18

标签: telegraf telegraf-inputs-plugin

当我们需要与内存相关的统计信息时,我们在[[inputs.mem]] 文件中添加输入插件。

[[inputs.statsd]]
  • 对于应用程序统计信息,我们将输入保持为statsd,我们使用UDP将其从应用程序的统计信息推送到使用其主机和端口的telegraf。
[[inputs.mem]]

有人可以解释val primary_key=order_id for (i <- commonColumnsList){ val column_name = i val tempDataFrameForNew = newDataFrame.selectExpr(s"concat($primaryKey,$i) as concatenated") val tempDataFrameOld = oldDataFrame.selectExpr(s"concat($primaryKey,$i) as concatenated") //Get those records which aren common in both old/new tables matchCountCalculated = tempDataFrameForNew.intersect(tempDataFrameOld) //Get those records which aren't common in both old/new tables nonMatchCountCalculated = tempDataFrameOld.unionAll(tempDataFrameForNew).except(matchCountCalculated) //Total Null/Non-Null Counts in both old and new tables. nullsCountInNewDataFrame = newDataFrame.select(s"$i").filter(x => x.isNullAt(0)).count().toInt nullsCountInOldDataFrame = oldDataFrame.select(s"$i").filter(x => x.isNullAt(0)).count().toInt nonNullsCountInNewDataFrame = newDFCount - nullsCountInNewDataFrame nonNullsCountInOldDataFrame = oldDFCount - nullsCountInOldDataFrame //Put the result for a given column in a Seq variable, later convert it to Dataframe. tempSeq = tempSeq :+ Row(column_name, matchCountCalculated.toString, nonMatchCountCalculated.toString, (nullsCountInNewDataFrame - nullsCountInOldDataFrame).toString, (nonNullsCountInNewDataFrame - nonNullsCountInOldDataFrame).toString) } // Final Step: Create DataFrame using Seq and some Schema. spark.createDataFrame(spark.sparkContext.parallelize(tempSeq), schema) 输入插件如何获取与内存相关的数据吗?因为在这种情况下没有人将数据推送到Telegraf。

1 个答案:

答案 0 :(得分:0)

Telegraf使用为Go编写的系统库检索系统数据。目前,它正在使用gopsutil库。该库上面的链接包含一个示例,说明如何在任何Go程序中使用它。

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)
}

此库支持许多不同的操作系统,并具有用于处理各种系统信息的模块,例如cpu,内存,磁盘和网络使用情况。您可以看到将它们整合到telegraf项目here中的位置。