请耐心等待我,Grafana / Telegraf / InfluxDB让我感觉不舒服。
我成功地按照教程通过snmp轮询路由器并绘制其流量图。尼斯!
现在,我需要一个包含每个时间范围流量的表格,尤其是每天。像这样:
| Day | ifHCInOctets | ifHCOutOctets | Total |
|-------------------|---------------|---------------|----------|
| February 21, 2017 | xy GB | xy GB | xy GB |
| February 20, 2017 | xy GB | xy GB | xy GB |
| February 19, 2017 | xy GB | xy GB | xy GB |
我在How can I aggregate metrics per day in a Grafana table?看到了这个建议,但网页编辑器不能用它来表达(?)。
感谢您的阅读。
编辑:感谢您的评论,非常感谢。实际上,我的值是累积计数器,就像它们通过SNMP轮询一样。我主要关注https://lkhill.com/telegraf-influx-grafana-network-stats/的教程。
所以,我的任务似乎是生成一个理智的数据库,并记录数据增量(还必须考虑计数器翻转,对吧?)。我怎么能做到这一点?我的Google-Fu让我失望了。
结果SHOW TAG KEYS& SHOW FIELD KEYS如下:
Connected to http://localhost:8086 version 1.4.2
InfluxDB shell version: 1.4.2
SHOW TAG KEYS;
name: cpu
tagKey
------
cpu
host
name: disk
tagKey
------
device
fstype
host
mode
path
name: diskio
tagKey
------
host
name
name: interface
tagKey
------
agent_host
dot3StatsIndex
host
hostname
ifDescr
ifIndex
name: kernel
tagKey
------
host
name: mem
tagKey
------
host
name: processes
tagKey
------
host
name: snmp
tagKey
------
agent_host
host
hostname
ifName
name: swap
tagKey
------
host
name: system
tagKey
------
host
SHOW FIELD KEYS;
name: cpu
fieldKey fieldType
-------- ---------
usage_guest float
usage_guest_nice float
usage_idle float
usage_iowait float
usage_irq float
usage_nice float
usage_softirq float
usage_steal float
usage_system float
usage_user float
name: disk
fieldKey fieldType
-------- ---------
free integer
inodes_free integer
inodes_total integer
inodes_used integer
total integer
used integer
used_percent float
name: diskio
fieldKey fieldType
-------- ---------
io_time integer
iops_in_progress integer
read_bytes integer
read_time integer
reads integer
weighted_io_time integer
write_bytes integer
write_time integer
writes integer
name: interface
fieldKey fieldType
-------- ---------
dot3StatsAlignmentErrors integer
dot3StatsCarrierSenseErrors integer
dot3StatsDeferredTransmissions integer
dot3StatsDuplexStatus integer
dot3StatsEtherChipSet string
dot3StatsExcessiveCollisions integer
dot3StatsFCSErrors integer
dot3StatsFrameTooLongs integer
dot3StatsInternalMacReceiveErrors integer
dot3StatsInternalMacTransmitErrors integer
dot3StatsLateCollisions integer
dot3StatsMultipleCollisionFrames integer
dot3StatsSQETestErrors integer
dot3StatsSingleCollisionFrames integer
dot3StatsSymbolErrors integer
ifAdminStatus integer
ifAlias string
ifConnectorPresent integer
ifCounterDiscontinuityTime integer
ifDescr string
ifHCInBroadcastPkts integer
ifHCInMulticastPkts integer
ifHCInOctets integer
ifHCInUcastPkts integer
ifHCOutBroadcastPkts integer
ifHCOutMulticastPkts integer
ifHCOutOctets integer
ifHCOutUcastPkts integer
ifHighSpeed integer
ifInBroadcastPkts integer
ifInDiscards integer
ifInErrors integer
ifInMulticastPkts integer
ifInOctets integer
ifInUcastPkts integer
ifInUnknownProtos integer
ifLastChange integer
ifLinkUpDownTrapEnable integer
ifMtu integer
ifName string
ifOperStatus integer
ifOutBroadcastPkts integer
ifOutDiscards integer
ifOutErrors integer
ifOutMulticastPkts integer
ifOutOctets integer
ifOutUcastPkts integer
ifPhysAddress string
ifPromiscuousMode integer
ifSpeed integer
ifType integer
name: kernel
fieldKey fieldType
-------- ---------
boot_time integer
context_switches integer
interrupts integer
processes_forked integer
name: mem
fieldKey fieldType
-------- ---------
active integer
available integer
available_percent float
buffered integer
cached integer
free integer
inactive integer
slab integer
total integer
used integer
used_percent float
name: processes
fieldKey fieldType
-------- ---------
blocked integer
dead integer
idle integer
paging integer
running integer
sleeping integer
stopped integer
total integer
total_threads integer
unknown integer
zombies integer
name: snmp
fieldKey fieldType
-------- ---------
ifAlias string
ifConnectorPresent integer
ifCounterDiscontinuityTime integer
ifHCInBroadcastPkts integer
ifHCInMulticastPkts integer
ifHCInOctets integer
ifHCInUcastPkts integer
ifHCOutBroadcastPkts integer
ifHCOutMulticastPkts integer
ifHCOutOctets integer
ifHCOutUcastPkts integer
ifHighSpeed integer
ifInBroadcastPkts integer
ifInMulticastPkts integer
ifLinkUpDownTrapEnable integer
ifName string
ifOutBroadcastPkts integer
ifOutMulticastPkts integer
ifPromiscuousMode integer
uptime integer
name: swap
fieldKey fieldType
-------- ---------
free integer
in integer
out integer
total integer
used integer
used_percent float
name: system
fieldKey fieldType
-------- ---------
load1 float
load15 float
load5 float
n_cpus integer
n_users integer
uptime integer
uptime_format string
答案 0 :(得分:0)
The generic method: you simply sum (or aggregate another way) your values by time period. That should look pretty familiar (I'm assuming, values of your metric shows the delta, the amount of traffic that gone through since the previous measurement, NOT a cumulative counter):
SELECT sum("ifHCInOctets") FROM "YourMeasurement" WHERE time > now() - 10d GROUP BY time(1d)
In Grafana, it's gonna be looking like
SELECT sum("ifHCInOctets") FROM "YourMeasurement" WHERE $timeFilter GROUP BY time($interval)
Just don't forget to configure your interval explicitly.
Though if you just add more details about your measurements, it's going to be easier for you to obtain more precise advice.
UPDATE: So, it is cumulative. Fine.
Then here's the thing: you can have your deltas with DIFFERENCE()
between series grouped by time period. And in case of the cumulative counters - obviously, you need only the last value in the series.
Although, here's two things.
First: it looks like you don't have the overall counter, but rather couple of counters per some group(s).
Looking at your schema (tags, particularly) I can presume it's host-based (and, perhaps, interfaces are to be considered as well). Thus, you should add grouping by host, otherwise DIFFERENCE()
would yield utter nonsense, because value would be taken only by timestamp, with no regard what counter is that.
Second... I got no idea if the counters could be reset throughout the period you're interested in.
But if they could - I don't really know yet how to handle it (except with Kapacitor).
It's kind of ok if you aim to have a sequence of deltas per period to be shown as throughput - you'd know that sudden "deep into the negs and back" peeks were counters' reset.
But if you intend to further aggregate this (like, sum this deltas through the day) - it would impact that value.
So, it's gonna look something like
SELECT DIFFERENCE(LAST("ifHCInOctets")) FROM "YourMeasurement" WHERE $timeFilter GROUP BY host, ifName, time($interval)
That's gonna be your throughput per period in $interval
.