日志数据(Log Data)不会被直接用于终端用户的报告。因为一个报告所需要的数据很多,直接使用会直接影响报告的呈现效率。
为了解决这个问题,归档过程就应运而成,它会将日志数据归档为归档数据。然后报表就能使用这些归档数据呈现报表了。
欢迎加入Matomo中文网。请加入官方QQ群255820112(点击滚动至本页末可扫描二维码),随时提问,有问必答。
举例
让我们来举个例子,有个网站每天会有1000个页面访问。它的日志数据就会是下面的样子(省略号表示其他属性) 。
URL Time …
/homepage 17:00:19 …
/about 17:01:10 …
/homepage 17:05:30 …
/categories 17:06:14 …
/homepage 17:10:03 ……
归档过程聚合原始数据成归档数据。如果你想构建每个页面访问次数的报表(找到最热门的网页),归档会列举所有的网页并计算每个网页的访问次数。
URL Page views
/homepage 205
/categories 67
/about 5
…
这个数据就是归档数据。 对1000个PV进行预计算看起来似乎是多余的,不过当处理大量数据的时候就尤显必要了。
何时归档
默认情况下,归档数据是按需计算和缓存的。当某个报表被请求的时候,Piwik会检查所需的归档数据是否存在,如果不存在它会启动归档。
提前归档
当追踪的网站流量很大时,按需归档会花费很多时间。在这种情况下,按需归档必须被禁用,取而代之的是将归档变成后台定时任务。
提前归档可以针对每个站点和日期区间(除了自定义日期范围),命令如下:
$ ./console core:archive
通常设置的方法是使用cron(Linux定时任务)固定间隔时间执行。
这个命令会记住最后运行的位置,只有在有新记录的时候才会继续执行。
如何执行
日志数据会按照站点、周期(日、周、月、年或自定义时间段)、分段条件(Segment)进行归档。
归档的逻辑是由插件来定义的。插件定义的所有报表会被一起归档,而不是单个单个归档。
如果分段条件(Segment)没有被指定,并且数据没找到,每个插件的每个报表会一次性被生成和缓存。如果分段条件被指定,所请求数据对应插件的所有报表会被生成和缓存。
周期聚合
归档数据的运算方式依赖于周期的类型:
- 按天数据是直接归档原始日志数据
- 按周、按月、按年或自定时间段是使用按天数据进行计算的。
比如说,按周的归档数据是将期间的每天的归档数据进行二次归档的。这样处理效率会比较高。
插件归档器
插件如果想归档报告和数值指标的话,可以自定义一个归档器,它只需要继承 Piwik\Plugin\Archiver。这个类会被自动检测到并在归档过程中自动被调用(还记得Piwik的扩展点吗?)。
日志数据的聚合由LogAggregator 来处理。归档数据的聚合由ArchiveProcessor::aggregateDataTableRecords() 和ArchiveProcessor::aggregateNumericMetrics()这两个方法 来完成
插件可以通过Piwik\Plugin\Archiver来访问LogAggregator 和ArchiveProcessor实例。详细了解Matomo的MySQL后台是如何实现聚合的,请阅读Piwik数据库结构。
持久化归档数据
归档数据通过ArchiveProcessor进行持久化。
数值指标通过insertNumericRecord插入到数据库。
报表数据首先会使用DataTable::getSerialized()进行序列化,然后通过ArchiveProcessor::insertBlobRecord()插入到数据库中。
// insert a numeric metric
$myFancyMetric = // … calculate the metric value …
$archiveProcessor->insertNumericRecord(‘MyPlugin_myFancyMetric’, $myFancyMetric);
// insert a record (with all of its subtables)
$maxRowsInTable = Config::getInstance()->General[‘datatable_archiving_maximum_rows_standard’];j
$dataTable = // … build by aggregating visits …
$serializedData = $dataTable->getSerialized(
$maxRowsInTable,
$maxRowsInSubtable = $maxRowsInTable,
$columnToSortBy = Metrics::INDEX_NB_VISITS
);
$archiveProcessor->insertBlobRecords(‘MyPlugin_myFancyReport’, $serializedData);
持久化的报告和数值指标是用站点ID,日期,分段条件进行索引的。归档的日期和时间也是与数据关联的。请查看归档表的Piwik数据库表结构会有更直观的认识。
报表是如何以blob的形式被存储在archive_blob_*表中的呢?
当插入一条blob记录的时候,archive_blob_$year_$month 数据表会出现一行新数据。这行新数据用于创建根DataTable。DataTable的子表也会以新行进行存储,不过子表会100个一组分开进行存储。比如说记录 MyPlugin_myFancyReport_chunk_100_199表示包含ID100-199的子表 。在这种情况,archive表的value列就包含了blob数组的序列化数据,形如array([subtableId] => [subtableBlob])。
idarchive | name | value | Description |
1 | Actions_actions_url |
gzcompress( $serializedRootTableBlob ) | 包含根表的blob数据 |
1 | Actions_actions_url_chunk_0_99 |
gzcompress(serialize( array([subtableId]=>[serializedSubtableBlob]) )) | 包含ID为0-99的子表的blob数组(0不能去掉,它表示根表ID) |
1 | Actions_actions_url_chunk_100_199 | … | 包含ID为100-199的子表的blob数组 |
1 | Actions_actions_url_chunk_200_299 | … | 包含ID为200-299的子表的blob数组 |
报表 vs 记录
当报表(report)被归档之后,它就不再叫报表(report),而是成为记录(record )了。之所以把它们区分开来是因为多个报表可以来自于一个记录(record)。
比如说,UerSettings插件使用一条记录存储访客浏览器详情。这条记录可以用来生成 UserSettings.getBrowserVersion 和 UserSettings.getBrowser两个报表。第二张报表只需要将第一报表进行简单处理即可。考虑到新的报表会为站点/周期/分段条件的各种组合条件进行缓存,如果插件将两个报表都归档的话,实属空间浪费。
记录存储指南
当持久化记录的时候,请千万小心,尽量保持存储数据尽量小。在插入记录作为归档数据之前,请确认下是否严格遵守了以下原则:
- 记录存储是的列名请不要使用字符串,而是使用对应列ID(在PHP文件中定义常量)
- Metadata请不要随报告一起存储。取而代之,在API中将记录转化成报告时将metadata添加进去。
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Your article helped me a lot, is there any more related content? Thanks!
pharmacy prices levitra: xenical online pharmacy uk – buy medication without an rx
paypal viagra australia: VGR Sources – generic viagra 10mg
sildenafil australia: VGR Sources – otc viagra usa
generic sildenafil paypal: VGR Sources – buy cheap viagra from india
sildenafil 50 mg tablet price in india VGR Sources generic viagra over the counter
medicine viagra india: cialis generic viagra – cost of sildenafil in mexico
blue pill viagra: VGR Sources – where can i buy viagra online
https://vgrsources.com/# canadian prices for sildenafil
order sildenafil 50 mg: VGR Sources – 100g viagra
viagra kaufen sildenafil 100mg online uk cheap genuine viagra online
price viagra 100mg: order viagra online singapore – viagra generics
viagra by pfizer: VGR Sources – viagra medicine online
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
viagra 4 sale: real viagra from canada – sildenafil compare prices
viagra price without insurance: VGR Sources – super viagra online
sildenafil buy cheap VGR Sources how to buy viagra usa
how to buy viagra online canada: viagra purchase in india – viagra price comparison canada
https://vgrsources.com/# generic sildenafil us
viagra tablet online: VGR Sources – erectile dysfunction viagra
sildenafil tablets coupon: VGR Sources – buy sildenafil without a prescription
sildenafil generic cost VGR Sources buy female viagra online india
sildenafil pills uk: VGR Sources – us over the counter viagra
viagra tablet canada: how can i get sildenafil – sildenafil citrate medication
canadian pharmacy viagra 50 mg: cheap generic viagra 50mg – viagra 25mg price
buy viagra pharmacy uk VGR Sources Preis Viagra 50 mg
best female viagra 2018: where can i get viagra in canada – brand viagra from canada
https://vgrsources.com/# buy cheap viagra
female viagra drug canada: no rx viagra – viagra 1500mg
viagra 100mg uk: VGR Sources – buy viagra online usa no prescription
how do i buy viagra: viagra 6 pills – viagra from mexico to us
buy viagra wholesale: VGR Sources – where to buy women viagra
cheapest price for sildenafil 100 mg: generic viagra online usa – sildenafil online free shipping
where can i buy over the counter viagra VGR Sources safe buy viagra online
purchase viagra safely online: sildenafil no prescription – sildenafil 50 mg no prescription
compare sildenafil prices: viagra 50 mg tablet buy online – 25mg viagra
where to buy cheap viagra pills: VGR Sources – best female viagra 2018
https://vgrsources.com/# viagra 25mg price in india
cheapest online viagra VGR Sources viagra generic coupon
buy viagra over the counter nz: VGR Sources – cheapest pharmacy price for viagra
viagra pills uk: buy viagra discover card – viagra online no rx
best generic sildenafil: VGR Sources – viagra 100 mg tablet price
super viagra 30 mg sildenafil viagra daily
viagra non prescription: VGR Sources – viagra mastercard online pharmacy
viagra prescription australia: VGR Sources – viagra 100mg india price
viagra cheap canadian pharmacy: canadian drugstore viagra – where can i order generic viagra
https://vgrsources.com/# order sildenafil 100mg
buy viagra hong kong: purchase viagra online cheap – best price for generic sildenafil
20mg sildenafil online prescription buy viagra 25 mg online india viagra over the counter us
viagra online cheap price: viagra online over the counter – how to buy viagra no prescription
where to get viagra for women: VGR Sources – viagra brand name in india
viagrarel.com/: VGR Sources – no prescription cheap viagra
sildenafil 20 mg discount viagra canada for sale sildenafil 58
viagra tablet online: VGR Sources – sildenafil 12.5 mg
where can you get women’s viagra: mail order viagra canada – viagra 1998
generic viagra 20 mg: buy sildenafil canada – viagra online no rx
https://vgrsources.com/# sildenafil australia buy
how can i get viagra in canada sildenafil otc canada cost of viagra 100
viagra 50mg online order: VGR Sources – viagra 250 mg
purchase 200mg sildenafil: buy sildenafil 20 mg – over the counter female viagra pills
online prescriptions for viagra: VGR Sources – viagra in india online
order viagra on line VGR Sources cheapest viagra in united states
otc viagra 2018: buy viagra south africa online – viagra tablets price in uk
viagra for women pills: VGR Sources – where to get women viagra
viagra 150 mg online: VGR Sources – cheap generic viagra 100mg canada
https://vgrsources.com/# cheap viagra 50mg
over the counter viagra in us VGR Sources sildenafil generic costs
us viagra over the counter: VGR Sources – purchase viagra in australia
SemagluPharm: SemagluPharm – Safe delivery in the US
side effects of lipitor 10 mg: Safe atorvastatin purchase without RX – atorvastatin and clopidogrel
PredniPharm: buy prednisone without rx – prednisone cost canada
Crestor home delivery USA Crestor Pharm Crestor Pharm
Crestor Pharm: Buy cholesterol medicine online cheap – generic rosuvastatin 5 mg
are there any dietary restrictions while taking crestor: CrestorPharm – pitavastatin vs rosuvastatin
https://crestorpharm.shop/# Crestor Pharm
Online statin therapy without RX: rosuvastatin 5 mg pink pill – Crestor home delivery USA
10 mg prednisone 50 mg prednisone from canada Predni Pharm
LipiPharm: USA-based pharmacy Lipitor delivery – prilosec and lipitor
Predni Pharm: Predni Pharm – prednisone tabs 20 mg
LipiPharm: Lipi Pharm – Discreet shipping for Lipitor
Semaglu Pharm: SemagluPharm – Rybelsus side effects and dosage
atorvastatin and clopidogrel does lipitor remove plaque Safe atorvastatin purchase without RX
https://semaglupharm.com/# SemagluPharm
side effects of crestor 40 mg: Crestor Pharm – Crestor mail order USA
prednisone pills for sale: over the counter prednisone cheap – PredniPharm
rosuvastatin and joint pain: Crestor Pharm – CrestorPharm
generic over the counter prednisone Predni Pharm 200 mg prednisone daily
Lipi Pharm: side effects of lipitor 10 mg – LipiPharm
PredniPharm: prednisone pill prices – prednisone 10mg buy online
does lipitor cause fatigue Atorvastatin online pharmacy what happens if you stop lipitor suddenly
PredniPharm: Predni Pharm – generic prednisone otc
Online pharmacy Rybelsus Semaglu Pharm Semaglu Pharm
Online statin therapy without RX: CrestorPharm – Crestor Pharm
Generic Crestor for high cholesterol: Crestor Pharm – п»їBuy Crestor without prescription
CrestorPharm: Affordable cholesterol-lowering pills – Crestor Pharm
Semaglu Pharm: Rybelsus online pharmacy reviews – No prescription diabetes meds online
http://crestorpharm.com/# rosuvastatin tab 5mg
Semaglu Pharm SemagluPharm Semaglu Pharm
CrestorPharm: CrestorPharm – CrestorPharm
what happens if semaglutide gets warm: SemagluPharm – SemagluPharm
Discreet shipping for Lipitor: Lipi Pharm – Order cholesterol medication online
PredniPharm prednisone 2 mg PredniPharm
Discreet shipping for Lipitor: can you overdose on lipitor – Generic Lipitor fast delivery
Order rosuvastatin online legally: are there any dietary restrictions while taking rosuvastatin – Crestor Pharm
semaglutide success stories Semaglutide tablets without prescription Semaglu Pharm
https://crestorpharm.com/# CrestorPharm
buy 40 mg prednisone: prednisone 10 mg coupon – Predni Pharm
prednisone 5mg coupon: 10 mg prednisone – Predni Pharm
LipiPharm Safe atorvastatin purchase without RX Lipi Pharm
LipiPharm: Lipi Pharm – Lipi Pharm
PredniPharm: Predni Pharm – buy prednisone without a prescription
LipiPharm can you lose weight on lipitor LipiPharm
https://semaglupharm.shop/# SemagluPharm
Semaglu Pharm: SemagluPharm – SemagluPharm
CrestorPharm: CrestorPharm – CrestorPharm
LipiPharm Safe atorvastatin purchase without RX can i drink alcohol with lipitor
No prescription diabetes meds online: buy rybelsus from canada – SemagluPharm
Semaglu Pharm Semaglu Pharm Semaglu Pharm
https://semaglupharm.com/# Order Rybelsus discreetly
CrestorPharm: Crestor home delivery USA – Crestor Pharm
Online statin therapy without RX: Crestor home delivery USA – cardiprin е’Њ rosuvastatin
Semaglutide tablets without prescription Semaglu Pharm Semaglu Pharm
https://semaglupharm.shop/# Rybelsus side effects and dosage
prednisone coupon: prednisone 50 mg price – prednisone 50 mg coupon
Predni Pharm: buy prednisone online india – Predni Pharm
http://lipipharm.com/# LipiPharm
https://semaglupharm.shop/# Rybelsus for blood sugar control
does rosuvastatin cause memory loss: crestor rhabdomyolysis – CrestorPharm
best place to get semaglutide: Semaglu Pharm – rybelsus max dose
crestor intensity Crestor Pharm crestor long term side effects
https://semaglupharm.com/# rybelsus order online
purchase prednisone 10mg: over the counter prednisone cream – prednisone pill
semaglutide insurance coverage: SemagluPharm – п»їBuy Rybelsus online USA
https://semaglupharm.com/# Semaglu Pharm
buy prednisone 1 mg mexico prednisone tablet 100 mg Predni Pharm
http://semaglupharm.com/# Where to buy Semaglutide legally
SemagluPharm: Semaglu Pharm – SemagluPharm
PredniPharm: buy prednisone online without a script – prednisone online india
https://semaglupharm.com/# does rybelsus cause acid reflux
can i take rosuvastatin in the morning Crestor 10mg / 20mg / 40mg online Crestor Pharm
prednisone 21 pack: prednisone canada pharmacy – Predni Pharm
rybelsus obesity: semaglutide results – Semaglu Pharm
https://semaglupharm.com/# Semaglutide tablets without prescription
average price of prednisone PredniPharm PredniPharm
https://prednipharm.shop/# Predni Pharm
CrestorPharm: CrestorPharm – Crestor Pharm
rosuvastatin (crestor): Crestor mail order USA – buy rosuvastatin
https://semaglupharm.com/# SemagluPharm
buy prednisone nz Predni Pharm prednisone 12 tablets price
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
CrestorPharm: CrestorPharm – Over-the-counter Crestor USA
https://semaglupharm.com/# SemagluPharm
Generic Lipitor fast delivery: generic version of lipitor – LipiPharm
rosuvastatin and weight gain CrestorPharm Crestor Pharm
Predni Pharm: PredniPharm – buy prednisone online paypal
https://semaglupharm.com/# Online pharmacy Rybelsus
http://crestorpharm.com/# Crestor Pharm
PredniPharm: Predni Pharm – buy prednisone from canada
Over-the-counter Crestor USA Affordable cholesterol-lowering pills crestor drug class
LipiPharm: Affordable Lipitor alternatives USA – LipiPharm
https://semaglupharm.com/# SemagluPharm
https://medsfrommexico.shop/# Meds From Mexico
India Pharm Global: India Pharm Global – India Pharm Global
buy drugs from canada: Canada Pharm Global – best rated canadian pharmacy
medicine in mexico pharmacies mexican rx online best online pharmacies in mexico
https://indiapharmglobal.com/# cheapest online pharmacy india
buying prescription drugs in mexico: Meds From Mexico – mexican border pharmacies shipping to usa
canada drugs online review: canada ed drugs – best canadian online pharmacy
medicine in mexico pharmacies Meds From Mexico Meds From Mexico
http://indiapharmglobal.com/# India Pharm Global
https://indiapharmglobal.shop/# India Pharm Global
canadian pharmacy tampa: Canada Pharm Global – canadian medications
canadian pharmacy no scripts: canadian pharmacy ed medications – vipps approved canadian online pharmacy
pharmacy website india India Pharm Global п»їlegitimate online pharmacies india
https://canadapharmglobal.com/# canadian pharmacy prices
mexican mail order pharmacies: mexican rx online – Meds From Mexico
canadianpharmacymeds: canadian neighbor pharmacy – best mail order pharmacy canada
https://medsfrommexico.com/# Meds From Mexico
canadian pharmacy 24 com Canada Pharm Global adderall canadian pharmacy
https://canadapharmglobal.com/# best canadian pharmacy
midlertidig tann apotek: tГёymunnbind apotek – Rask Apotek
Svenska Pharma Svenska Pharma Svenska Pharma
https://svenskapharma.com/# Svenska Pharma
farmacia ferrer: casenlax 10 mg – farmicia
glidemiddel apotek: plus apotek – hallux valgus stГёtte apotek
http://svenskapharma.com/# nätapoteket
cepillo oral-b io precio farmasia Papa Farma
https://efarmaciait.com/# farmcie
farmacia murcia cerca de mi: movicol gel – Papa Farma
EFarmaciaIt: 60 cp – axil flaconcini 400 mg
http://efarmaciait.com/# EFarmaciaIt
Papa Farma Papa Farma Papa Farma
EFarmaciaIt: EFarmaciaIt – farmae’ parafarmacia online
Svenska Pharma: Svenska Pharma – Svenska Pharma
https://raskapotek.shop/# Rask Apotek
https://efarmaciait.com/# locoidon a cosa serve
Papa Farma Papa Farma femibion 2 prospecto
billig smoothie: Svenska Pharma – Svenska Pharma
http://svenskapharma.com/# Svenska Pharma
Papa Farma Papa Farma para que sirve brentan crema
Svenska Pharma: Svenska Pharma – Svenska Pharma
Rask Apotek: Rask Apotek – Rask Apotek
https://svenskapharma.shop/# Svenska Pharma
https://raskapotek.shop/# hydrokinon apotek
farmacia veterinaria online spedizione gratuita EFarmaciaIt EFarmaciaIt
EFarmaciaIt: ozempic vendita online – EFarmaciaIt
https://raskapotek.com/# peroksid apotek
corona test apotek: receptbelagda vГ¤rktabletter – apotek recept pГҐ nГ¤tet